Advertisement
Guest User

Untitled

a guest
Jan 30th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. /* ncpp2.cpp */
  2. /* file created with nCpp 1.1 */
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <cstdlib>
  7. #include <cstring>
  8.  
  9. #define dts "\033[95m::\033[0m"
  10. #define sq1 "\033[34m[\033[0m"
  11. #define sq2 "\033[34m]\033[0m"
  12.  
  13. using namespace std;
  14.  
  15. void msg()
  16. {
  17. cout << endl << sq1 << "nCpp v2.1" << sq2 << " " << dts << " New Cpp Template Creator" << endl;
  18. return;
  19. }
  20.  
  21. void menu()
  22. {
  23. cout << endl;
  24. cout << dts << " Headers to Include" << endl;
  25. cout << sq1 << "1" << sq2 << "iostream" << endl;
  26. cout << sq1 << "2" << sq2 << "string" << endl;
  27. cout << sq1 << "3" << sq1 << "fstream" << endl;
  28. cout << sq1 << "4" << sq2 << "iomanip" << endl;
  29. cout << sq1 << "5" << sq2 << "stdlib.h" << endl;
  30. cout << sq1 << "6" << sq2 << "All the Above" << endl;
  31. return;
  32. }
  33.  
  34. void edmenu()
  35. {
  36. cout << sq1 << "1" << sq2 << "Neovim" << endl;
  37. cout << sq1 << "2" << sq2 << "Nano" << endl;
  38. cout << sq1 << "3" << sq2 << "Emacs" << endl;
  39. return;
  40. }
  41.  
  42. int out(int y, ofstream *fn);
  43.  
  44. int main()
  45. {
  46. msg();
  47.  
  48. char filename[30];
  49. char menuchoice;
  50. char edname[15];
  51.  
  52. int x;
  53. int em;
  54. int p;
  55.  
  56. cout << dts << " Enter New Filename: ";
  57. cin.getline(filename,30);
  58.  
  59. string ext = ".cpp";
  60. string sp = " ";
  61. string newfile = filename + ext;
  62. string evar1 = "emacs ";
  63. string vvar1 = "nvim ";
  64. string nvar1 = "nano ";
  65. string expcmd = "export EDITOR=";
  66. string nvim1 = vvar1 + newfile;
  67. string nano1 = nvar1 + newfile;
  68. string emacs1 = evar1 + newfile;
  69. string q;
  70. string eq;
  71.  
  72. menu();
  73. cout << dts << " Select Option: ";
  74. cin >> x;
  75.  
  76. ofstream ncppfile;
  77. ncppfile.open(newfile);
  78. ncppfile << "/* " << newfile << " */" << endl;
  79. ncppfile << "/* Created with nCpp 2.1 */ << endl;
  80.  
  81. if(x == 1) out(0, &ncppfile);
  82. if(x == 2) out(1, &ncppfile);
  83. if(x == 3) out(2, &ncppfile);
  84. if(x == 4) out(3, &ncppfile);
  85. if(x == 5) out(4, &ncppfile);
  86. if(x == 6) { for(int i = 0; i < 5; i++) out(i, &ncppfile); }
  87.  
  88. ncppfile << "int main()" << endl;
  89. ncppfile << "{ " << endl;
  90. ncppfile << " " << endl;
  91. ncppfile << "return 0;" << endl;
  92. ncppfile << "} " << endl;
  93. ncppfile.close();
  94.  
  95. cout << endl << ":: Edit [" << newfile << "] ? (y/n): ";
  96. cin >> eq;
  97. if(eq == "y") {
  98. char enval[256];
  99. strcpy(enval,getenv("EDITOR"));
  100. string narf = enval + sp + newfile;
  101. if(enval == NULL) {
  102. cout << endl << dts << " No Environment Editor Set.";
  103. cout << endl << dts << " Set Editor Now? (y/n): ";
  104. cin >> q;
  105. if(q == "y") {
  106. cout << sq1 << "1" << sq2 << "Use Neovim" << endl;
  107. cout << sq1 << "2" << sq2 << "Use Nano" << endl;
  108. cout << sq1 << "3" << sq2 << "Use Emacs" << endl;
  109. cout << sq1 << "4" << sq2 << "Other - Enter Command" << endl;
  110. cin >> p;
  111. if(p == 1) { system("export EDITOR=nvim");
  112. system(nvim1.c_str()); }
  113. if(p == 2) { system("export EDITOR=nano");
  114. system(nano1.c_str()); }
  115. if(p == 3) { system("export EDITOR=emacs");
  116. system(emacs1.c_str()); }
  117. if(p == 4) { cout << ":: Enter Command: ";
  118. cin.getline(edname,15);
  119. system(expcmd.c_str()); } } }
  120.  
  121. else { system(narf.c_str()); } }
  122. if(q == "n") {
  123. edmenu();
  124. cout << dts << " Enter Selection: ";
  125. cin >> em;
  126. if(em == 1) { system(nvim1.c_str()); }
  127. if(em == 2) { system(nano1.c_str()); }
  128. if(em == 3) { system(emacs1.c_str()); } }
  129.  
  130.  
  131.  
  132.  
  133. return 0;
  134. }
  135.  
  136. int out(int y, ofstream *fn)
  137. {
  138. char output[5][32];
  139. strcpy(output[0], "#include <iostream>\n");
  140. strcpy(output[1], "#include <string>\n");
  141. strcpy(output[2], "#include <fstream>\n");
  142. strcpy(output[3], "#include <iomanip>\n");
  143. strcpy(output[4], "#include <stdlib.h>\n");
  144. fn->write(output[y], strlen(output[y]));
  145. return 1;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement