Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ncpp2.cpp */
- /* file created with nCpp 1.1 */
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstdlib>
- #include <cstring>
- #define dts "\033[95m::\033[0m"
- #define sq1 "\033[34m[\033[0m"
- #define sq2 "\033[34m]\033[0m"
- using namespace std;
- void msg()
- {
- cout << endl << sq1 << "nCpp v2.1" << sq2 << " " << dts << " New Cpp Template Creator" << endl;
- return;
- }
- void menu()
- {
- cout << endl;
- cout << dts << " Headers to Include" << endl;
- cout << sq1 << "1" << sq2 << "iostream" << endl;
- cout << sq1 << "2" << sq2 << "string" << endl;
- cout << sq1 << "3" << sq1 << "fstream" << endl;
- cout << sq1 << "4" << sq2 << "iomanip" << endl;
- cout << sq1 << "5" << sq2 << "stdlib.h" << endl;
- cout << sq1 << "6" << sq2 << "All the Above" << endl;
- return;
- }
- void edmenu()
- {
- cout << sq1 << "1" << sq2 << "Neovim" << endl;
- cout << sq1 << "2" << sq2 << "Nano" << endl;
- cout << sq1 << "3" << sq2 << "Emacs" << endl;
- return;
- }
- int out(int y, ofstream *fn);
- int main()
- {
- msg();
- char filename[30];
- char menuchoice;
- char edname[15];
- int x;
- int em;
- int p;
- cout << dts << " Enter New Filename: ";
- cin.getline(filename,30);
- string ext = ".cpp";
- string sp = " ";
- string newfile = filename + ext;
- string evar1 = "emacs ";
- string vvar1 = "nvim ";
- string nvar1 = "nano ";
- string expcmd = "export EDITOR=";
- string nvim1 = vvar1 + newfile;
- string nano1 = nvar1 + newfile;
- string emacs1 = evar1 + newfile;
- string q;
- string eq;
- menu();
- cout << dts << " Select Option: ";
- cin >> x;
- ofstream ncppfile;
- ncppfile.open(newfile);
- ncppfile << "/* " << newfile << " */" << endl;
- ncppfile << "/* Created with nCpp 2.1 */ << endl;
- if(x == 1) out(0, &ncppfile);
- if(x == 2) out(1, &ncppfile);
- if(x == 3) out(2, &ncppfile);
- if(x == 4) out(3, &ncppfile);
- if(x == 5) out(4, &ncppfile);
- if(x == 6) { for(int i = 0; i < 5; i++) out(i, &ncppfile); }
- ncppfile << "int main()" << endl;
- ncppfile << "{ " << endl;
- ncppfile << " " << endl;
- ncppfile << "return 0;" << endl;
- ncppfile << "} " << endl;
- ncppfile.close();
- cout << endl << ":: Edit [" << newfile << "] ? (y/n): ";
- cin >> eq;
- if(eq == "y") {
- char enval[256];
- strcpy(enval,getenv("EDITOR"));
- string narf = enval + sp + newfile;
- if(enval == NULL) {
- cout << endl << dts << " No Environment Editor Set.";
- cout << endl << dts << " Set Editor Now? (y/n): ";
- cin >> q;
- if(q == "y") {
- cout << sq1 << "1" << sq2 << "Use Neovim" << endl;
- cout << sq1 << "2" << sq2 << "Use Nano" << endl;
- cout << sq1 << "3" << sq2 << "Use Emacs" << endl;
- cout << sq1 << "4" << sq2 << "Other - Enter Command" << endl;
- cin >> p;
- if(p == 1) { system("export EDITOR=nvim");
- system(nvim1.c_str()); }
- if(p == 2) { system("export EDITOR=nano");
- system(nano1.c_str()); }
- if(p == 3) { system("export EDITOR=emacs");
- system(emacs1.c_str()); }
- if(p == 4) { cout << ":: Enter Command: ";
- cin.getline(edname,15);
- system(expcmd.c_str()); } } }
- else { system(narf.c_str()); } }
- if(q == "n") {
- edmenu();
- cout << dts << " Enter Selection: ";
- cin >> em;
- if(em == 1) { system(nvim1.c_str()); }
- if(em == 2) { system(nano1.c_str()); }
- if(em == 3) { system(emacs1.c_str()); } }
- return 0;
- }
- int out(int y, ofstream *fn)
- {
- char output[5][32];
- strcpy(output[0], "#include <iostream>\n");
- strcpy(output[1], "#include <string>\n");
- strcpy(output[2], "#include <fstream>\n");
- strcpy(output[3], "#include <iomanip>\n");
- strcpy(output[4], "#include <stdlib.h>\n");
- fn->write(output[y], strlen(output[y]));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement