diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 39 |
1 files changed, 13 insertions, 26 deletions
@@ -6,16 +6,21 @@ int main(int argc, char **argv) { int opt; - char *output_file_name = NULL; + char *archive_file_name = NULL; + bool create; - while ((opt = getopt(argc, argv, "cvtf:")) != -1) + while ((opt = getopt(argc, argv, "Oxcvtf:")) != -1) { switch (opt) { case 'c': + create = true; + break; + case 'x': + create = false; break; case 'f': - output_file_name = optarg; + archive_file_name = optarg; break; case 'v': break; @@ -25,33 +30,15 @@ int main(int argc, char **argv) return 1; } } - int fd = -1; - if (output_file_name == NULL) - fd = STDOUT_FILENO; - else + if (create) { - fd = open(output_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) - { - perror("main"); + if (archive_write(archive_file_name, argv + optind) == -1) return 1; - } } - - /* printf("out: %s\n", output_file_name); */ - char file_name[PATH_MAX]; - char **files = argv + optind; - for (; *files != NULL; files++) + else { - /* printf("%s\n", *files); */ - bzero(file_name, PATH_MAX); - strcpy(file_name, *files); - file_write(fd, file_name); + if (archive_read(archive_file_name) == -1) + return 1; } - char buf[512] = {'\0'}; - write(fd, buf, 512); - write(fd, buf, 512); - if (fd != STDOUT_FILENO) - close(fd); return 0; } |
