Skip to content

Commit

Permalink
added os-specific srcml path for properly implementing the "focus on …
Browse files Browse the repository at this point in the history
…a certain code snippet" part
  • Loading branch information
yaad96 committed Feb 27, 2024
1 parent 956f9f8 commit f094f0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const Constants = {
TEMP_JAVA_FILE: "tempExprFile.java",
XML_HEADER: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>",
LEARNING_DR_DIRECTORY:"/LearningDR",
SRCML_BIN_PATH: "C:\\Program Files\\srcML 0.9.5\\bin\\srcml"
SRCML_PATH_WINDOWS: "C:\\Program Files\\srcML 0.9.5\\bin\\srcml",
SRCML_PATH_MAC: "/usr/local/bin/srcml",
SRCML_PATH_LINUX: "/usr/bin/srcml"

};
46 changes: 23 additions & 23 deletions src/utilites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { exec } from "child_process";
import * as path from 'path';
import { writeFile } from 'fs/promises';
import { Constants } from './Constants';
import * as os from 'os';



export async function writeToFile(filePath: string, exprText: string): Promise<void> {
Expand Down Expand Up @@ -34,9 +36,29 @@ export function convertToXML(inputFilePath: string): Promise<string> {
}

export function findLineNumber(xmlFilePath: string): Promise<string> {
const platform = os.platform();
console.log(`The system is running on: ${platform}`);


return new Promise((resolve, reject) => {
// Construct the command
const command = `"${Constants.SRCML_BIN_PATH}" --unit 1 "${xmlFilePath}"`;
const command = "";


if (platform === 'win32') {
const command = `"${Constants.SRCML_PATH_WINDOWS}" --unit 1 "${xmlFilePath}"`;
console.log('This is a Windows system.');
} else if (platform === 'darwin') {
const command = `"${Constants.SRCML_PATH_MAC}" --unit 1 "${xmlFilePath}"`;
console.log('This is a macOS system.');
} else if (platform === 'linux') {
const command = `"${Constants.SRCML_PATH_LINUX}" --unit 1 "${xmlFilePath}"`;
console.log('This is a Linux system.');
} else {
console.log('Unknown or unsupported operating system.');
return;
}


// Execute the command
exec(command, (error, stdout, stderr) => {
Expand All @@ -54,29 +76,7 @@ export function findLineNumber(xmlFilePath: string): Promise<string> {
}


export function getInitialRuleTable(Project: String): Map<string, string> {
const myMap = new Map<string, string>();

// Add some key-value pairs to the map
myMap.set("key1", "1");
myMap.set("key2", "2");
myMap.set("key3", "3");

// Return the map
return myMap;
}

export function getInitialTagTable(Project: String): Map<string, string> {
const myMap = new Map<string, string>();

// Add some key-value pairs to the map
myMap.set("key1", "1");
myMap.set("key2", "2");
myMap.set("key3", "3");

// Return the map
return myMap;
}



Expand Down

0 comments on commit f094f0f

Please sign in to comment.