save
This commit is contained in:
@@ -191,6 +191,7 @@ int setup_git(manifest_t manifest)
|
|||||||
if (status) {
|
if (status) {
|
||||||
printfn("failed on git initialize: %s", strerror(status));
|
printfn("failed on git initialize: %s", strerror(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +239,7 @@ int create_configure(manifest_t manifest)
|
|||||||
|
|
||||||
int generate_source_code(manifest_t manifest, char *licence_line)
|
int generate_source_code(manifest_t manifest, char *licence_line)
|
||||||
{
|
{
|
||||||
int status, year;
|
int status, year = 0;
|
||||||
|
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm tm = *localtime(&t);
|
struct tm tm = *localtime(&t);
|
||||||
|
|||||||
45
yait/main.c
45
yait/main.c
@@ -32,7 +32,7 @@ usage (int status)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("Usage: yait [OPTION]... PROJECT [NAME]\n");
|
printf ("Usage: yait [OPTION]... <PATH>\n");
|
||||||
printf ("Creates a C project with opinionated defaults.\n");
|
printf ("Creates a C project with opinionated defaults.\n");
|
||||||
printf ("When only given the first argument it will detect your name.\n\n");
|
printf ("When only given the first argument it will detect your name.\n\n");
|
||||||
printf ("Mandatory arguments to long options are mandatory for short options too\n");
|
printf ("Mandatory arguments to long options are mandatory for short options too\n");
|
||||||
@@ -78,6 +78,11 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
|||||||
conf->licence = GPLv3;
|
conf->licence = GPLv3;
|
||||||
else if (strcmp(optarg, "mit") == 0)
|
else if (strcmp(optarg, "mit") == 0)
|
||||||
conf->licence = MIT;
|
conf->licence = MIT;
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "Unknown licence: %s\n",
|
||||||
|
optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
ADD_LIBRARY(conf->libraries, TOLibrary(optarg));
|
ADD_LIBRARY(conf->libraries, TOLibrary(optarg));
|
||||||
@@ -91,11 +96,17 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now handle positional args */
|
if (optind >= argc) {
|
||||||
if (optind < argc)
|
fprintf(stderr, "Missing required <PATH> argument\n");
|
||||||
conf->project = argv[optind++];
|
usage(1);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->project = argv[optind++];
|
||||||
|
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
conf->name = argv[optind++];
|
conf->name = argv[optind++];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,22 +116,24 @@ int get_name(char **output)
|
|||||||
char buffer[128];
|
char buffer[128];
|
||||||
size_t output_len = 0;
|
size_t output_len = 0;
|
||||||
|
|
||||||
pipe = popen("ls -l", "r");
|
*output = NULL; // make sure it's NULL before realloc
|
||||||
|
|
||||||
|
pipe = popen("git config user.name", "r");
|
||||||
if (!pipe)
|
if (!pipe)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
||||||
size_t chunk_len = strlen(buffer);
|
size_t chunk_len = strlen(buffer);
|
||||||
char *new_output = realloc(output, output_len + chunk_len + 1);
|
char *new_output = realloc(*output, output_len + chunk_len + 1);
|
||||||
if (!new_output) {
|
if (!new_output) {
|
||||||
free(output);
|
free(*output);
|
||||||
pclose(pipe);
|
pclose(pipe);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
*output = new_output;
|
*output = new_output;
|
||||||
memcpy(output + output_len, buffer, chunk_len);
|
memcpy((*output) + output_len, buffer, chunk_len);
|
||||||
output_len += chunk_len;
|
output_len += chunk_len;
|
||||||
*output[output_len] = '\0';
|
(*output)[output_len] = '\0';
|
||||||
}
|
}
|
||||||
pclose(pipe);
|
pclose(pipe);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -143,10 +156,18 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = get_name(&manifest.name);
|
parse_arguments(&manifest, argc, argv);
|
||||||
manifest.path = ".";
|
|
||||||
|
if (!manifest.name) {
|
||||||
|
status = get_name(&manifest.name);
|
||||||
|
if (status != 0 || !manifest.name || manifest.name[0] == '\0') {
|
||||||
|
fprintf(stderr, "Could not determine user name\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.path = manifest.project;
|
||||||
|
|
||||||
status = create_project(manifest);
|
status = create_project(manifest);
|
||||||
|
|
||||||
return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user