-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.c
More file actions
282 lines (268 loc) · 9.69 KB
/
Copy pathcreate.c
File metadata and controls
282 lines (268 loc) · 9.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
const char * C_LANGUAGE = "cproject";
const char * C_PLUS_PLUS = "cplusproject";
const char * C_SHARP = "csproject";
const char * PYTHON = "pyproject";
const char * PERL = "plproject";
const char * RAYLIB = "rlproject";
const char * ASM = "asm";
// test change
bool hasSpaces(char * string){
int length = strlen(string);
for (int i = 0; i < length; i++){
if (string[i] == 32){
return true;
}
}
return false;
}
void addExtension(char * filename, char * extension){
if (strcmp(&filename[strlen(filename)-strlen(extension)], extension)){
strcat(filename, extension);
}
return;
}
void switchSpaces(char * target, char * destination){
int length = strlen(target);
for (int i = 0; i < length; i++){
if (target[i] != 32){ // if target character is not [space]
destination[i] = target[i];
}
else{
destination[i] = 95; //switches spaces with underscores '_'
}
}
destination[length] = 0;
return;
}
void displayHelp(void){
puts("\nCreates a new project");
puts("Usage: create [project-type] [project-name]\n");
puts(" Types:");
puts(" cproject Creates a C language Project");
puts(" cplusproject Creates a C Plus Plus Project");
puts(" csproject Creates a C-Sharp Project using .NET framework");
puts(" pyproject Creates a Python Project");
puts(" plproject Creates a Perl Project");
puts(" rlproject Creates a Raylib Project in C for a VSCode Workspace");
puts(" asm Creates an assembly template with at&t syntax");
puts("\n\n");
return;
}
int main(int argc, char ** argv){
if (argc < 2){
displayHelp();
}
else{
FILE * file;
#ifdef _WIN64
errno_t result;
#endif
char filename[FILENAME_MAX];
if (!strcmp(argv[1], C_LANGUAGE) && argc > 2){
strcpy(filename, argv[2]);
addExtension(filename, ".c");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "#include <stdio.h>\n");
fprintf(file, "#include <stdlib.h>\n\n");
fprintf(file, "int main(int argc, char ** argv){\n\n");
fprintf(file, " return EXIT_SUCCESS;\n");
fprintf(file, "}");
fclose(file);
}
}
else if (!strcmp(argv[1], PYTHON) && argc > 2){
strcpy(filename, argv[2]);
addExtension(filename, ".py");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "def main():\n");
fprintf(file, " \n");
fprintf(file, " return\n\n\n");
fprintf(file, "if __name__ == \"__main__\":\n");
fprintf(file, " main()\n");
fclose(file);
}
}
else if (!strcmp(argv[1], C_PLUS_PLUS) && argc > 2){
strcpy(filename, argv[2]);
addExtension(filename, ".cpp");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "#include <cstdio>\n");
fprintf(file, "#include <cstdlib>\n\n");
fprintf(file, "int main(int argc, char ** argv){\n\n");
fprintf(file, " return EXIT_SUCCESS;\n");
fprintf(file, "}");
fclose(file);
}
}
else if (!strcmp(argv[1], PERL) && argc > 2){
strcpy(filename, argv[2]);
addExtension(filename, ".pl");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "sub main{\n");
fprintf(file, " \n");
fprintf(file, " return;\n");
fprintf(file, "}\n\n");
fprintf(file, "main();");
fclose(file);
}
}
else if (!strcmp(argv[1], C_SHARP) && argc > 2){
char folderCMD[FILENAME_MAX] = "mkdir ";
char makecmd[FILENAME_MAX] = "dotnet new console -o ";
char programName[FILENAME_MAX];
if (hasSpaces(argv[2])){
char temp[FILENAME_MAX] = "\"";
strcat(temp, argv[2]);
strcat(temp, "\"");
strcat(folderCMD, temp);
strcat(makecmd, temp);
}
else{
strcat(folderCMD, argv[2]);
strcat(makecmd, argv[2]);
}
system(folderCMD);
system(makecmd);
strcat(programName, argv[2]);
strcat(programName, "/");
strcat(programName, "Program.cs");
char namespace[FILENAME_MAX];
switchSpaces(argv[2], namespace);
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "using System;\n");
fprintf(file, "using System.Collections.Generic;\n\n\n");
fprintf(file, "namespace %s{\n", namespace);
fprintf(file, " public class Program{\n");
fprintf(file, " public static void Main(string[] argv){\n");
fprintf(file, " \n");
fprintf(file, " return;\n");
fprintf(file, " }\n");
fprintf(file, " }\n");
fprintf(file, "}\n");
fclose(file);
}
}
else if (!strcmp(argv[1], RAYLIB) && argc > 2){
struct stat sb;
if (stat("C:\\raylib\\raylib\\projects\\VSCode", &sb) == 0 && S_ISDIR(sb.st_mode)){
strcpy(filename, argv[2]);
if (hasSpaces(argv[2])){
strcpy(filename, "\"");
strcat(filename, argv[2]);
strcat(filename, "\"");
}
else{
strcpy(filename, argv[2]);
}
char folderCMD[FILENAME_MAX] = "mkdir ";
char makecmd[FILENAME_MAX] = "xcopy /E C:\\raylib\\raylib\\projects\\VSCode ";
strcat(folderCMD, filename);
strcat(makecmd, filename);
system(folderCMD);
system(makecmd);
}
else{
puts("Raylib is either not installed, or is not installed at the expected directory");
}
}
else if (!strcmp(argv[1], "/?")){
displayHelp();
}
else if (!strcmp(argv[1], ASM) && argc > 2){
strcpy(filename, argv[2]);
addExtension(filename, ".s");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, ".section .data\n\n\n\n");
fprintf(file, ".section .text\n\n");
fprintf(file, ".globl main\n\n");
fprintf(file, "main:\n");
fprintf(file, "pushq %%rbp\n");
fprintf(file, "movq %%rsp, %%rbp\n\n\n\n");
#ifdef _WIN64
fprintf(file, "popq %%rbp\n");
#endif
#if defined(__linux__) || defined(__FreeBSD__)
fprintf(file, "leave\n");
#endif
fprintf(file, "xorq %%rax, %%rax\n");
fprintf(file, "retq\n");
fprintf(file, "\n");
fprintf(file, ".size main, .-main\n\n");
#ifdef __FreeBSD__
fprintf(file, ".section .note.GNU-stack,\"\",%%progbits\n\n");
#endif
fclose(file);
}
}
else if (argc == 2 && (!strcmp(argv[1], C_SHARP) || !strcmp(argv[1], PYTHON) || !strcmp(argv[1], C_LANGUAGE) || !strcmp(argv[1], C_PLUS_PLUS) || !strcmp(argv[1], PERL) || !strcmp(argv[1], RAYLIB) || !strcmp(argv[1], ASM))){
displayHelp();
}
else{
strcpy(filename, argv[1]);
addExtension(filename, ".c");
#ifdef _WIN64
result = fopen_s(&file, filename, "wt");
if (!result){
#endif
#if defined(__linux__) || defined(__FreeBSD__)
file = fopen(filename, "wt");
if (file){
#endif
fprintf(file, "#include <stdio.h>\n");
fprintf(file, "#include <stdlib.h>\n\n");
fprintf(file, "int main(int argc, char ** argv){\n\n");
fprintf(file, " return EXIT_SUCCESS;\n");
fprintf(file, "}");
fclose(file);
}
}
}
return EXIT_SUCCESS;
}