save
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../core/print.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BSD3, /* BSD 3-Clause Licence */
|
BSD3, /* BSD 3-Clause Licence */
|
||||||
@@ -62,7 +64,7 @@ typedef struct
|
|||||||
#define REMOVE_LIBRARY(libs, lib) ((libs) &= ~(lib))
|
#define REMOVE_LIBRARY(libs, lib) ((libs) &= ~(lib))
|
||||||
|
|
||||||
static lib_flags_t
|
static lib_flags_t
|
||||||
TOlibrary (char *src)
|
TOLibrary (char *src)
|
||||||
{
|
{
|
||||||
if (strcmp (src, "raylib"))
|
if (strcmp (src, "raylib"))
|
||||||
return LIB_RAYLIB;
|
return LIB_RAYLIB;
|
||||||
@@ -74,6 +76,7 @@ TOlibrary (char *src)
|
|||||||
return LIB_CURL;
|
return LIB_CURL;
|
||||||
if (strcmp (src, "help"))
|
if (strcmp (src, "help"))
|
||||||
return LIB_HELP;
|
return LIB_HELP;
|
||||||
|
printfn("could not find library");
|
||||||
return LIB_COUNT_; /* bad case */
|
return LIB_COUNT_; /* bad case */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
105
yait/main.c
105
yait/main.c
@@ -260,56 +260,53 @@ atexit_clean:
|
|||||||
static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
||||||
{
|
{
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "GNU", no_argument, 0, 1 },
|
{ "GNU", no_argument, 0, 'g' },
|
||||||
{ "use-cpp", no_argument, 0, 2 },
|
{ "use-cpp", no_argument, 0, 'c' },
|
||||||
{ "git", no_argument, 0, 3 },
|
{ "git", no_argument, 0, 'i' },
|
||||||
{ "licence", required_argument, 0, 4 },
|
{ "licence", required_argument, 0, 'l' },
|
||||||
{ "lib", required_argument, 0, 5 },
|
{ "lib", required_argument, 0, 'L' },
|
||||||
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
int long_index = 0;
|
while ((opt = getopt_long(argc, argv, "gcil:L:h", long_options,
|
||||||
|
NULL)) != -1) {
|
||||||
while ((opt = getopt_long(argc, argv, "", long_options, &long_index)) !=
|
|
||||||
-1) {
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 1:
|
case 'g':
|
||||||
conf->flag.GNU = 1;
|
conf->flag.GNU = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 'c':
|
||||||
conf->flag.use_cpp = 1;
|
conf->flag.use_cpp = true;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 'i':
|
||||||
conf->flag.git = 1;
|
conf->flag.git = true;
|
||||||
break;
|
break;
|
||||||
case 4: // TODO(vx-clutch): implement the licence options, and make it lowercase.
|
case 'l':
|
||||||
|
if (strcmp(optarg, "bsd") == 0)
|
||||||
|
conf->licence = BSD3;
|
||||||
|
else if (strcmp(optarg, "gpl") == 0)
|
||||||
|
conf->licence = GPLv3;
|
||||||
|
else if (strcmp(optarg, "mit") == 0)
|
||||||
|
conf->licence = MIT;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 'L':
|
||||||
ADD_LIBRARY(
|
ADD_LIBRARY(conf->libraries, TOLibrary(optarg));
|
||||||
conf->libraries,
|
|
||||||
TOlibrary(
|
|
||||||
optarg)); // TODO(vx-clutch): Get this working
|
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
usage(0);
|
||||||
|
exit(0);
|
||||||
|
default:
|
||||||
|
usage(1);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int positional_count = 0;
|
/* now handle positional args */
|
||||||
for (int i = optind; i < argc; ++i) {
|
if (optind < argc)
|
||||||
if (argv[i][0] == '-') {
|
conf->project = argv[optind++];
|
||||||
fprintf(stderr, "Unknown flag: %s\n", argv[i]);
|
if (optind < argc)
|
||||||
continue;
|
conf->name = argv[optind++];
|
||||||
}
|
|
||||||
|
|
||||||
if (positional_count == 0)
|
|
||||||
conf->name = argv[i];
|
|
||||||
else if (positional_count == 1)
|
|
||||||
conf->project = argv[i];
|
|
||||||
++positional_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,24 +357,44 @@ static int create_project(manifest_t manifest)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int program_exists(const char *prog)
|
||||||
|
{
|
||||||
|
char *path = getenv("PATH");
|
||||||
|
if (!path)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char *copy = strdup(path);
|
||||||
|
if (!copy)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char *dir = strtok(copy, ":");
|
||||||
|
while (dir) {
|
||||||
|
char buf[4096];
|
||||||
|
snprintf(buf, sizeof(buf), "%s/%s", dir, prog);
|
||||||
|
if (access(buf, X_OK) == 0) {
|
||||||
|
free(copy);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
dir = strtok(NULL, ":");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(copy);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
manifest_t manifest = { 0 };
|
manifest_t manifest = { 0 };
|
||||||
|
|
||||||
if (argc == 0) {
|
|
||||||
status = 1; // emit suggestion
|
|
||||||
usage(status);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = parse_standard_options(usage, argc, argv);
|
status = parse_standard_options(usage, argc, argv);
|
||||||
if (status && status != HELP_REQUESTED) {
|
if (status && status != HELP_REQUESTED) {
|
||||||
printfn("error: %s", strerror(status));
|
printfn("error: %s", strerror(status));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vx-clutch): runtime git bin check
|
status = program_exists("git");
|
||||||
|
on_error("git bin not present", status);
|
||||||
|
|
||||||
parse_arguments(&manifest, argc, argv);
|
parse_arguments(&manifest, argc, argv);
|
||||||
status = create_project(manifest);
|
status = create_project(manifest);
|
||||||
|
|||||||
Reference in New Issue
Block a user