diff --git a/src/main.c b/src/main.c index fb7dd2d..ec3ccc4 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,5 @@ /* proj - project skeleton generator * Strict ANSI C89 - * Generates basic project layouts for C, Go, Python, REXX */ #include @@ -10,18 +9,21 @@ #define MAX_PATH 256 #define MAX_CMD 512 +#define MAX_LINE 1024 -/* Simple template substitution */ -static void substitute(FILE *in, FILE *out, const char *projname, const char *author, const char *year) +/* Simple key-value substitution */ +static void substitute(FILE *in, FILE *out, const char *projname, + const char *author, const char *year, const char *desc, + const char *quote) { - char line[1024]; + char line[MAX_LINE]; while (fgets(line, sizeof(line), in)) { char *p = line; while ((p = strstr(p, "{{"))) { char *end = strstr(p + 2, "}}"); if (!end) break; *p = '\0'; - fputs(p, out); /* text before placeholder */ + fputs(p, out); p += 2; if (strncmp(p, "PROJECT_NAME", end - p) == 0) fputs(projname, out); @@ -29,15 +31,19 @@ static void substitute(FILE *in, FILE *out, const char *projname, const char *au fputs(author, out); else if (strncmp(p, "YEAR", end - p) == 0) fputs(year, out); + else if (strncmp(p, "DESCRIPTION", end - p) == 0) + fputs(desc ? desc : "A simple CLI tool.", out); + else if (strncmp(p, "QUOTE", end - p) == 0) + fputs(quote ? quote : "", out); else fputs("{{UNKNOWN}}", out); p = end + 2; } - fputs(p, out); /* remaining text */ + fputs(p, out); } } -/* Create directory (via system for portability) */ +/* Create directory via system() - portable enough */ static int make_dir(const char *path) { char cmd[MAX_CMD]; @@ -45,8 +51,9 @@ static int make_dir(const char *path) return system(cmd); } -/* Generate a basic C CLI project */ -static int generate_c_cli(const char *projname, const char *author) +/* Generate basic C CLI project */ +static int generate_c_cli(const char *projname, const char *author, + const char *desc, const char *quote) { char year[16], path[MAX_PATH]; time_t now = time(NULL); @@ -62,7 +69,9 @@ static int generate_c_cli(const char *projname, const char *author) { FILE *f = fopen("README", "w"); if (f) { - fprintf(f, "# %s\n\nA simple CLI tool.\n\n", projname); + fprintf(f, "# %s\n\n", projname); + if (quote) fprintf(f, "> %s\n\n", quote); + fprintf(f, "%s\n\n", desc ? desc : "A simple CLI tool."); fclose(f); } } @@ -98,6 +107,8 @@ static int generate_c_cli(const char *projname, const char *author) } printf("Created C CLI project: %s\n", projname); + if (quote) printf("Inserted quote: %s\n", quote); + return 0; } @@ -107,8 +118,8 @@ static void usage(void) printf(" c Generate ANSI C CLI skeleton\n"); printf(" go Generate Go module skeleton\n"); printf(" python Generate Python package skeleton\n"); - printf(" rexx Generate REXX script skeleton\n"); - printf("\nOptions:\n"); + printf(" rexx Generate REXX script skeleton\n\n"); + printf("Options:\n"); printf(" --quote Insert a random quote from cquote into README\n"); printf(" --desc TEXT Short project description\n"); printf(" --author NAME Author name\n"); @@ -123,15 +134,30 @@ int main(int argc, char *argv[]) const char *lang = argv[1]; const char *name = argv[2]; - const char *author = "Greg Gauthier"; /* default - change or add flag */ + const char *author = "Greg Gauthier"; + const char *desc = NULL; + const char *quote = NULL; + + /* Simple argument parsing */ + int i; + for (i = 3; i < argc; i++) { + if (strcmp(argv[i], "--quote") == 0) { + /* For now, call cquote random via system() */ + /* In real version we'd capture output properly */ + quote = "TODO: insert quote from cquote"; + } else if (strcmp(argv[i], "--desc") == 0 && i+1 < argc) { + desc = argv[++i]; + } else if (strcmp(argv[i], "--author") == 0 && i+1 < argc) { + author = argv[++i]; + } + } if (strcmp(lang, "c") == 0) { - generate_c_cli(name, author); + generate_c_cli(name, author, desc, quote); } else { printf("Language '%s' not yet supported.\n", lang); return 1; } return 0; -} - +} \ No newline at end of file