Compare commits
12 commits
f89e5f7640
...
4115e70d14
Author | SHA1 | Date | |
---|---|---|---|
4115e70d14 | |||
dd29550649 | |||
64cfe57724 | |||
712f2711d7 | |||
8e24d4e3d2 | |||
eff2b44f6d | |||
7c4663daf2 | |||
49f6434601 | |||
e5acb4d730 | |||
d48d458712 | |||
1bbfd8c53d | |||
b9ed8961a4 |
3 changed files with 6 additions and 32 deletions
|
@ -67,13 +67,12 @@ int main(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDArchiverParsedStatus parsed_status;
|
|
||||||
__attribute__((cleanup(simple_archiver_list_free)))
|
__attribute__((cleanup(simple_archiver_list_free)))
|
||||||
SDArchiverLinkedList *filenames =
|
SDArchiverLinkedList *filenames =
|
||||||
simple_archiver_parsed_to_filenames(&parsed, &parsed_status);
|
simple_archiver_parsed_to_filenames(&parsed);
|
||||||
if (!filenames || parsed_status != SDAPS_SUCCESS) {
|
if (!filenames) {
|
||||||
fprintf(stderr, "ERROR: %s!\n",
|
fprintf(stderr,
|
||||||
simple_archiver_parsed_status_to_str(parsed_status));
|
"ERROR: Failed to resolve filenames from positional arguments!\n");
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/parser.c
19
src/parser.c
|
@ -131,17 +131,6 @@ int list_remove_same_str_fn(void *data, void *ud) {
|
||||||
return 0;
|
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) {
|
void simple_archiver_print_usage(void) {
|
||||||
fprintf(stderr, "Usage flags:\n");
|
fprintf(stderr, "Usage flags:\n");
|
||||||
fprintf(stderr, "-c : create archive file\n");
|
fprintf(stderr, "-c : create archive file\n");
|
||||||
|
@ -378,7 +367,7 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||||
const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out) {
|
const SDArchiverParsed *parsed) {
|
||||||
SDArchiverLinkedList *files_list = simple_archiver_list_init();
|
SDArchiverLinkedList *files_list = simple_archiver_list_init();
|
||||||
__attribute__((cleanup(simple_archiver_hash_map_free)))
|
__attribute__((cleanup(simple_archiver_hash_map_free)))
|
||||||
SDArchiverHashMap *hash_map = simple_archiver_hash_map_init();
|
SDArchiverHashMap *hash_map = simple_archiver_hash_map_init();
|
||||||
|
@ -392,9 +381,6 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||||
original_cwd = realpath(".", NULL);
|
original_cwd = realpath(".", NULL);
|
||||||
if (chdir(parsed->user_cwd)) {
|
if (chdir(parsed->user_cwd)) {
|
||||||
simple_archiver_list_free(&files_list);
|
simple_archiver_list_free(&files_list);
|
||||||
if (status_out) {
|
|
||||||
*status_out = SDAPS_NO_USER_CWD;
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,8 +607,5 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status_out) {
|
|
||||||
*status_out = SDAPS_SUCCESS;
|
|
||||||
}
|
|
||||||
return files_list;
|
return files_list;
|
||||||
}
|
}
|
||||||
|
|
10
src/parser.h
10
src/parser.h
|
@ -59,14 +59,6 @@ typedef struct SDArchiverFileInfo {
|
||||||
char *link_dest;
|
char *link_dest;
|
||||||
} SDArchiverFileInfo;
|
} 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);
|
void simple_archiver_print_usage(void);
|
||||||
|
|
||||||
SDArchiverParsed simple_archiver_create_parsed(void);
|
SDArchiverParsed simple_archiver_create_parsed(void);
|
||||||
|
@ -82,6 +74,6 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed);
|
||||||
|
|
||||||
/// Each entry in the linked list is an SDArchiverFileInfo object.
|
/// Each entry in the linked list is an SDArchiverFileInfo object.
|
||||||
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
|
||||||
const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out);
|
const SDArchiverParsed *parsed);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue