Selbstgebastelte, effektive IDE in Atom für viele unabhängige Quellcode-Dateien

Dieser Artikel bezieht sich auf dieses Video:

Hier die Quelltexte zu den beiden Programmen read und cc++, die Includes werden natürlich nicht alle benötigt, aber ich hatte noch keine Zeit, das auszusortieren:

read

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <iomanip>
#include <unistd.h>
using namespace std;

int main(){
  int ret;
  string line;
  cout << "read (fifo reader), v1.0 by HMB" << endl;
  cout << "Waiting...\n";
  while (true){ // Progr runs in an endless loop!
    ifstream inputFile; // We open the file at the beginning
    inputFile.open("reader"); // of the loop and close it
    while (line==""){         // at the end!
      std::getline(inputFile, line); // Thus we receive just one
    }                                // line after the other.
    line = "./" + line; // This is needed by the shell ;)
    cout << "\nReceived this command:\n";
    cout << line << endl; // Control output...
    ret=system(line.c_str()); // Execution on system level
    line=""; // Empty the variable
    cout << "Program returned " << ret << ".\n";
    cout << "\n\n===== read: Waiting for new call... =====\n";
    cout <<     "=====  [Stop w/ CTRL-C or CTRL-Z]   =====\n\n";
    if(inputFile.is_open()) // By closing the file we achieve
    inputFile.close();      // the goal to read one line in
  }                         // one loop.
  return 0;
}

cc++

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <iomanip>
#include <cstddef>
#include <cstdint>
#include <bitset>
using namespace std;

int main(int argc, char *argv[]){
  string a, b, c;
  cout << "\n\n===== cc++ v1.2 by HMB running: =====\n\n";
  cout << "Stage I\n";
  for (int ac=0;ac<argc;ac++){ // ac is loop counter/indicator
      cout << "ac = " << ac << ", argv[" << ac << "] = " << argv[ac] << endl;
  };
  cout << "Stage II\n";
  if (argc==1){
    cout << "Fatal: No filename!" << endl;
    return 1;
  };
  cout << "Stage III\n";
  if (argc==2){
    a=argv[1]; // Filename w/o ext
    cout << "argc = 1, a: " << a << endl;
  };
  cout << "Stage IV\n";
  if (argc==3){
    a=argv[2]; // Filename w/o ext
    b=argv[1]; // Argument no. 1 and only
    cout << "a = " << a << ",\nb = " << b << endl;
  };
  cout << "Stage V\n";
  int onceflag = 0;
  if (b=="-1"){
    // Compile once and finish, do not run!
    onceflag = 1;
    cout << "onceflag set\n";
  };

  c = "/usr/bin/g++ -std=c++17 -Wall -o " + a + " " + a + ".cpp";
  int flag = 2;
  while (1){
    int ret;
    if (flag==2){
      cout << "Executing command:\n-> " << c << endl;
      ret = system(c.c_str());
      cout << "Returned " << ret << endl;
      if (onceflag==1){
        return 0;
      }
    }
    if (ret==0){
      string arg = "";
      cout << "\nEnter arguments if you wish [# for none]: "; cin >> arg;
      string b;
      if (arg != "#"){
        b = "./" + a + " " + arg;
      } else {
        b = "./" + a;
      }

      cout << "\n\n=====   Running your compiled program:    =====\n\n";
      cout << "Command: " << a << endl;
      system(b.c_str());
      cout << "\n\n===== Your compiled program has finished. =====\n\n";
      cout << "Run again? [yes w/ compile = 2, yes w/o compile = 1, no = 0] => ";
      cin >> flag;
      if (flag==0){
        cout << "\n\n===== cc++ finished! =====\n\n";
        break;
      }
    }
  }
  return 0;
}

A WordPress.com Website.