Compare commits
13 commits
4115e70d14
...
f89e5f7640
Author | SHA1 | Date | |
---|---|---|---|
f89e5f7640 | |||
0ae80168e3 | |||
d93f62a0cb | |||
8f33d62392 | |||
52bbfa4e65 | |||
8bedc750ba | |||
aaebe09347 | |||
0a776cae37 | |||
f472ad1a6b | |||
dcd2e531e6 | |||
ef49b37648 | |||
6ad609e7fc | |||
b098fd6d69 |
3 changed files with 32 additions and 6 deletions
|
@ -67,12 +67,13 @@ int main(int argc, const char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
SDArchiverParsedStatus parsed_status;
|
||||
__attribute__((cleanup(simple_archiver_list_free)))
|
||||
SDArchiverLinkedList *filenames =
|
||||
simple_archiver_parsed_to_filenames(&parsed);
|
||||
if (!filenames) {
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to resolve filenames from positional arguments!\n");
|
||||
simple_archiver_parsed_to_filenames(&parsed, &parsed_status);
|
||||
if (!filenames || parsed_status != SDAPS_SUCCESS) {
|
||||
fprintf(stderr, "ERROR: %s!\n",
|
||||
simple_archiver_parsed_status_to_str(parsed_status));
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
|
19
src/parser.c
19
src/parser.c
|
@ -131,6 +131,17 @@ int list_remove_same_str_fn(void *data, void *ud) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *simple_archiver_parsed_status_to_str(SDArchiverParsedStatus status) {
|
||||
switch (status) {
|
||||
case SDAPS_SUCCESS:
|
||||
return "Success";
|
||||
case SDAPS_NO_USER_CWD:
|
||||
return "No user current working directory (-C <dir>)";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
void simple_archiver_print_usage(void) {
|
||||
fprintf(stderr, "Usage flags:\n");
|
||||
fprintf(stderr, "-c : create archive file\n");
|
||||
|
@ -367,7 +378,7 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed) {
|
|||
}
|
||||
|
||||
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||
const SDArchiverParsed *parsed) {
|
||||
const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out) {
|
||||
SDArchiverLinkedList *files_list = simple_archiver_list_init();
|
||||
__attribute__((cleanup(simple_archiver_hash_map_free)))
|
||||
SDArchiverHashMap *hash_map = simple_archiver_hash_map_init();
|
||||
|
@ -381,6 +392,9 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
|||
original_cwd = realpath(".", NULL);
|
||||
if (chdir(parsed->user_cwd)) {
|
||||
simple_archiver_list_free(&files_list);
|
||||
if (status_out) {
|
||||
*status_out = SDAPS_NO_USER_CWD;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -607,5 +621,8 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
|||
}
|
||||
}
|
||||
|
||||
if (status_out) {
|
||||
*status_out = SDAPS_SUCCESS;
|
||||
}
|
||||
return files_list;
|
||||
}
|
||||
|
|
10
src/parser.h
10
src/parser.h
|
@ -59,6 +59,14 @@ typedef struct SDArchiverFileInfo {
|
|||
char *link_dest;
|
||||
} SDArchiverFileInfo;
|
||||
|
||||
typedef enum SDArchiverParsedStatus {
|
||||
SDAPS_SUCCESS,
|
||||
SDAPS_NO_USER_CWD,
|
||||
} SDArchiverParsedStatus;
|
||||
|
||||
/// Returned c-string does not need to be free'd.
|
||||
char *simple_archiver_parsed_status_to_str(SDArchiverParsedStatus status);
|
||||
|
||||
void simple_archiver_print_usage(void);
|
||||
|
||||
SDArchiverParsed simple_archiver_create_parsed(void);
|
||||
|
@ -74,6 +82,6 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed);
|
|||
|
||||
/// Each entry in the linked list is an SDArchiverFileInfo object.
|
||||
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||
const SDArchiverParsed *parsed);
|
||||
const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue