This commit is contained in:
2025-07-23 15:24:21 -04:00
parent 9e94f5ce44
commit eb4c8c51c1
5 changed files with 50 additions and 27 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +0,0 @@
PREFIX=/usr/bin/
CFLAGS=-Wall -Wextra -g
LDFLAGS=
CC=clang

View File

@@ -19,8 +19,10 @@ parse_standard_options (void (*usage) (int), int argc, char **argv)
}
else if (strcmp (argv[i], "--version") == 0)
{
printf ("%s %s %d\nCopyright (C) %d %s.\n%s\nThis is free software: "
"you are free to change and redistribute it.\nThere is NO "
printf ("%s %s %d\nCopyright (C) %d %s.\n%s\nThis is "
"free software: "
"you are free to change and redistribute "
"it.\nThere is NO "
"WARRNTY, to the extent permitted by law.\n",
PROGRAM, VERSION, COMMIT, YEAR, AUTHORS, LICENSE_LINE);
exit (EXIT_SUCCESS);

View File

@@ -24,21 +24,31 @@
#define print_option(option, description) \
printf (" %-20s %-20s\n", option, description)
#ifdef DEBUG
#define on_error(msg, code) \
if (err) \
{ \
fprintf (stderr, "\n"); \
printfn (msg ": %s", strerror (err)); \
return code; \
}
#else
#define on_error(msg, code) \
if (err) \
{ \
printfn (msg ": %s", strerror (err)); \
return code; \
}
#endif
#ifdef DEBUG
#define debug(fmt, ...) \
fprintf (stderr, "\e[0;32m[%8d]\e[0;33m " fmt "\e[0m\n", __LINE__, \
##__VA_ARGS__)
#define debugc(fmt, ...) \
fprintf (stderr, "\e[0;32m[%8d]\e[0;33m " fmt "...\e[0m", __LINE__, \
fprintf (stderr, "\e[0;32m[%8d]\e[0;33m " fmt "... \e[0m", __LINE__, \
##__VA_ARGS__)
#define done fprintf(stderr, "done.\n")
#define done fprintf (stderr, "done.\n")
#else
#define debug(fmt, ...)
#define debugc(fmt, ...)
@@ -84,25 +94,27 @@ usage (int status)
int
main (int argc, char **argv)
{
int err;
if (argc < 2)
{
printfn ("error: not enough arguments.");
return 1;
}
int status = initialize_main (&argc, &argv);
status = parse_standard_options (usage, argc, argv);
err = initialize_main (&argc, &argv);
err = parse_standard_options (usage, argc, argv);
if (status && status != HELP_REQUESTED)
if (err && err != HELP_REQUESTED)
{
printfn ("error: %s", strerror (status));
return status;
printfn ("error: %s", strerror (err));
return err;
}
format_t conf = { 0 };
conf.project = argv[0]; // fix: project name is argv[1]
conf.name = (argc > 1) ? argv[1] : NULL; // fix: name is optional, at argv[2]
conf.project = argv[0];
conf.name = (argc > 1) ? argv[1] : NULL;
if (!conf.name)
{
@@ -114,7 +126,11 @@ main (int argc, char **argv)
conf.flag.clang_format = DEFAULT_CLANG_FORMAT;
conf.licence = DEFAULT_LICENSE;
return create_project (conf);
err = create_project (conf);
if (!err) debug ("project made successfully");
else debug ("something when wrong");
return err;
}
int
@@ -122,16 +138,16 @@ create_project (format_t fmt)
{
int err;
debugc ("sanitize... ");
debugc ("sanitize");
err = sanitize (&fmt);
on_error ("failed to sanitize format", err);
done;
debugc ("take %s", fmt.project);
err = create_and_enter_directory (fmt.project);
depth = 0;
on_error ("failed to create or enter directory", err);
done;
depth = 0;
// debug ("create licenseing");
// err = create_license_if_needed (fmt);
@@ -172,8 +188,17 @@ reset_path_ ()
int
sanitize (format_t *fmt)
{
if (!fmt->project)
fmt->project = DEFAULT_PROJECT_NAME;
if (!fmt->name)
fmt->name = DEFAULT_USER_NAME;
if (fmt->licence != BSD3 && fmt->licence != GPLv3 && fmt->licence != MIT)
fmt->licence = DEFAULT_LICENSE;
fmt->flag.git = fmt->flag.git ? true : DEFAULT_GIT_INIT;
fmt->flag.clang_format
= fmt->flag.clang_format ? true : DEFAULT_CLANG_FORMAT;
fmt->flag.GNU = fmt->flag.GNU ? true : false;
return 0;
}