Add sample code to initial project.

This commit is contained in:
xSlendiX 2022-12-14 11:19:10 +02:00
parent e473c6a2bb
commit d508ca0060

57
main.c
View File

@ -681,9 +681,59 @@ int main(int argc, char **argv) {
fputs("Warning: Cannot open .gitignore!\n", stderr);
}
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
if (!file_exists(src_dir)) {
bool status = makedir(src_dir);
if (!status) {
fputs("Error: Cannot initialize project: Cannot create src directory.\n", stderr);
return 1;
}
fp = fopen(text_format("%s/Main.HC", src_dir), "w+");
fputs("U0 Main() {\n\
\"Hello, world!\\n\";\n\
}\n", fp);
fclose(fp);
fp = fopen(text_format("%s/Load.HC", src_dir), "w+");
fputs("Cd(__DIR__);;\n\
#include \"Main\"\n", fp);
fclose(fp);
fp = fopen(text_format("%s/Run.HC", src_dir), "w+");
fputs("Cd(__DIR__);;\n\
#include \"Load\"\n\
\"Running...\\n\";\n\
Main;\n", fp);
fclose(fp);
fp = fopen(text_format("%s/RunCD.HC", src_dir), "w+");
fputs("#include \"Load\"\n\
\"Running from CD...\\n\";\n\
Main;\n", fp);
fclose(fp);
fp = fopen(text_format("%s/Install.HC", src_dir), "w+");
fputs("// TODO: Add support for multiple partitions, not just C:\n\
if (!FileFind(\"C:/Apps/Main\",,FUF_JUST_DIRS)) {\n\
\"Installing...\n\";\n\
DirMk(\"C:/Apps/Wordle\");\n\
} else \"Updating...\n\";\n\
CopyTree(\"T:/\", \"C:/Apps/Wordle\");\n\
Del(\"C:/Apps/Wordle/RunCD.*\");\n\
\"Done!\n\";\n", fp);
fclose(fp);
}
if (can_run_command("git"))
system(text_format("git init %s", project_path));
free(src_dir);
// Free only if alloc'ed, "." doesn't count since it is embedded in the program itself.
// Trying to free it if it's "." would cause a crash cause of this.
if (argc > 2)
@ -764,9 +814,6 @@ int main(int argc, char **argv) {
text_format("%s/build", project_path);
char *build_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(build_dir, buffer_text_format);
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
if (!file_exists(build_dir)) {
bool status = makedir(build_dir);
if (!status) {
@ -776,6 +823,10 @@ int main(int argc, char **argv) {
}
}
text_format("%s/src", project_path);
char *src_dir = malloc((strlen(buffer_text_format)+1)*sizeof(char));
strcpy(src_dir, buffer_text_format);
// Clear and populate.
puts("Populating build directory...");
clear_directory(build_dir);