From f094f0ff16757422e83068614cc7fed41821194d Mon Sep 17 00:00:00 2001 From: yaad96 Date: Mon, 26 Feb 2024 22:42:57 -0500 Subject: [PATCH] added os-specific srcml path for properly implementing the "focus on a certain code snippet" part --- src/Constants.ts | 4 +++- src/utilites.ts | 46 +++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Constants.ts b/src/Constants.ts index 841cfcf..61e35df 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -5,6 +5,8 @@ export const Constants = { TEMP_JAVA_FILE: "tempExprFile.java", XML_HEADER: "", 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" }; diff --git a/src/utilites.ts b/src/utilites.ts index d97d42a..afee40d 100644 --- a/src/utilites.ts +++ b/src/utilites.ts @@ -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 { @@ -34,9 +36,29 @@ export function convertToXML(inputFilePath: string): Promise { } export function findLineNumber(xmlFilePath: string): Promise { + 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) => { @@ -54,29 +76,7 @@ export function findLineNumber(xmlFilePath: string): Promise { } -export function getInitialRuleTable(Project: String): Map { - const myMap = new Map(); - // 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 { - const myMap = new Map(); - - // 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; -}