aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-05-26 14:43:00 -0400
committerGitHub <noreply@github.com>2020-05-26 14:43:00 -0400
commitdf0686fb8b6fefebda0548d39caad2622e2bce89 (patch)
treecbd2d92667a0ab45221a220948f6ee33b2926a1c /src
parentc205840e737b23614a686a9675b896106cee5c64 (diff)
parent065d39bff58c02719abf5a710b22d8355ff1b19d (diff)
downloadspmc-df0686fb8b6fefebda0548d39caad2622e2bce89.tar.gz
Merge pull request #38 from jhunkeler/from-file
From file
Diffstat (limited to 'src')
-rw-r--r--src/spm.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/spm.c b/src/spm.c
index 971d506..bdaab23 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -10,8 +10,9 @@ int RUNTIME_INSTALL = 0;
int RUNTIME_ROOTDIR = 0;
int RUNTIME_LIST = 0;
int RUNTIME_SEARCH = 0;
+char *program_name = NULL;
-void usage(const char *program_name) {
+void usage(void) {
printf("usage: %s [-hVvBIRrmMLS]\n"
" -h, --help show this help message\n"
" -V, --version show version\n"
@@ -30,8 +31,18 @@ void usage(const char *program_name) {
}
extern spm_vars SPM_GLOBAL;
+
+static int reader_install_strlist_append_file(size_t lineno, char **line) {
+ (void)(lineno); // unused parameter
+ (*line) = strip((*line));
+ if (isempty((*line)) || startswith((*line), "#") || startswith((*line), ";") || startswith((*line), "//")) {
+ return 1; // indicate "continue"
+ }
+ return 0; // indicate "ok"
+}
+
int main(int argc, char *argv[], char *arge[]) {
- char *program_name = strdup(argv[0]);
+ program_name = strdup(argv[0]);
// not much to see here yet
// at the moment this will all be random tests, for better or worse
@@ -53,7 +64,7 @@ int main(int argc, char *argv[], char *arge[]) {
memset(package_search_str, '\0', PATH_MAX);
if (argc < 2) {
- usage(program_name);
+ usage();
exit(1);
}
@@ -66,7 +77,7 @@ int main(int argc, char *argv[], char *arge[]) {
// options
if (*arg == '-' || strncmp(arg, "--", 2) == 0) {
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
- usage(program_name);
+ usage();
exit(0);
}
else if (strcmp(arg, "-V") == 0 || strcmp(arg, "--version") == 0) {
@@ -85,7 +96,7 @@ int main(int argc, char *argv[], char *arge[]) {
else if (strcmp(arg, "-m") == 0 || strcmp(arg, "--manifest") == 0) {
if (arg_next == NULL) {
fprintf(stderr, "-m|--manifest requires a directory path\n");
- usage(program_name);
+ usage();
exit(1);
}
manifestlist_append(mf, arg_next);
@@ -116,7 +127,7 @@ int main(int argc, char *argv[], char *arge[]) {
RUNTIME_SEARCH = 1;
if (arg_next == NULL) {
fprintf(stderr, "--search requires a package name\n");
- usage(program_name);
+ usage();
exit(1);
}
strncpy(package_search_str, arg_next, strlen(arg_next));
@@ -126,7 +137,7 @@ int main(int argc, char *argv[], char *arge[]) {
RUNTIME_ROOTDIR = 1;
if (!arg_next) {
fprintf(stderr, "-r|--root requires a path\n");
- usage(program_name);
+ usage();
exit(1);
}
@@ -150,12 +161,29 @@ int main(int argc, char *argv[], char *arge[]) {
}
if ((argc - i) == 0) {
fprintf(stderr, "-R|--remove requires at least one package\n");
- usage(program_name);
+ usage();
exit(1);
}
strlist_append(packages, argv[i]);
}
}
+ else if (strcmp(arg, "-F") == 0 || strcmp(arg, "--from-file") == 0) {
+ RUNTIME_INSTALL = 1;
+ i++;
+ char *next = argv[i];
+ int retval = 0;
+
+ if (next == NULL || startswith(next, "--")) { // do not trap '-' (stdin)
+ fprintf(stderr, "-F|--from-file requires a file path\n");
+ usage();
+ exit(1);
+ }
+
+ retval = strlist_append_file(packages, next, reader_install_strlist_append_file);
+ if (retval < 0) {
+ spm_die();
+ }
+ }
else if (strcmp(arg, "-I") == 0 || strcmp(arg, "--install") == 0) {
RUNTIME_INSTALL = 1;
for (int p = 0; i < argc; p++) {
@@ -167,7 +195,7 @@ int main(int argc, char *argv[], char *arge[]) {
}
if ((argc - i) == 0) {
fprintf(stderr, "-I|--install requires at least one package\n");
- usage(program_name);
+ usage();
exit(1);
}
strlist_append(packages, next);
@@ -176,11 +204,15 @@ int main(int argc, char *argv[], char *arge[]) {
}
else {
printf("Unknown option: %s\n", arg);
- usage(program_name);
+ usage();
exit(1);
}
}
+ if (spmerrno) {
+ spm_die();
+ }
+
// Apply some default manifest locations; unless the user passes -M|--override-manifests
if (override_manifests == 0) {
// Remote package manifests have priority over the local package store
@@ -196,11 +228,11 @@ int main(int argc, char *argv[], char *arge[]) {
if (!RUNTIME_ROOTDIR && RUNTIME_INSTALL) {
fprintf(stderr, "-r|--root requires -I|--install\n");
- usage(program_name);
+ usage();
exit(1);
} else if (!RUNTIME_ROOTDIR && RUNTIME_REMOVE) {
fprintf(stderr, "-r|--root requires -R|--remove\n");
- usage(program_name);
+ usage();
exit(1);
}