codingame-cpp-merge icon indicating copy to clipboard operation
codingame-cpp-merge copied to clipboard

inclusion of commented out `include`s

Open hadisfr opened this issue 6 years ago • 1 comments

It seems that codingame-cpp-merge tries to include headers from the commented out #include "someheader.hpp" statements. 🤔

hadisfr avatar Jan 26 '19 22:01 hadisfr

It seems that codingame-cpp-merge tries to include headers from the commented out #include "someheader.hpp" statements. 🤔

function processFile(file, include) {
  let processedOnce = false;
  for (let i = 0; i < processOnce.length; i++) {
    if (processOnce[i] == file) {
      processedOnce = true;
      break;
    }
  }

  if (file === mainFile && mainIsProcessed || file == outputFile) {
    return; // Main can be processed on its own at the start
  } else if (path.extname(file) == ".cpp" || path.extname(file) == ".hpp" || path.extname(file) == ".h") {
    console.log('Processing ' + file);
    fs.appendFileSync(outputFile, "/*-- File: " + file + " start --*/\n");
  } else {
    return; // File can be ignored
  }

  if (!processedOnce) {
    let fileContent = fs.readFileSync(file, {encoding: "utf8"});
    let lines = fileContent.split("\n");
    for (let i = 0; i < lines.length; i++) {
      let line = lines[i];
      if (line.indexOf("#include \"") >= 0) {
        // Instead of processing the included file, just add a reference line
        fs.appendFileSync(outputFile, "// " + line + "\n");
      } else if (line.indexOf("#pragma once") >= 0) {
        processOnce.push(file);
      } else {
        fs.appendFileSync(outputFile, line + "\n");
      }
    }
  }

  if (path.extname(file) == ".cpp" || path.extname(file) == ".hpp" || path.extname(file) == ".h") {
    fs.appendFileSync(outputFile, "/*-- File: " + file + " end --*/\n");
  }
}

dezmen3 avatar Mar 25 '24 19:03 dezmen3