diff --git a/main/cmd/pack/desc.c b/main/cmd/pack/desc.c index 97bbaaa..71f534c 100644 --- a/main/cmd/pack/desc.c +++ b/main/cmd/pack/desc.c @@ -58,13 +58,62 @@ static int handle_name(input_file_t *f, void *obj) return 0; } +static int handle_toc_compressor(input_file_t *f, void *obj) +{ + pkg_desc_t *desc = obj; + + desc->toccmp = compressor_by_name(f->line); + + if (desc->toccmp == NULL) { + input_file_complain(f, "unkown compressor"); + return -1; + } + + return 0; +} + +static int handle_data_compressor(input_file_t *f, void *obj) +{ + pkg_desc_t *desc = obj; + + desc->datacmp = compressor_by_name(f->line); + + if (desc->datacmp == NULL) { + input_file_complain(f, "unkown compressor"); + return -1; + } + + return 0; +} + static const keyword_handler_t line_hooks[] = { + { "toc-compressor", handle_toc_compressor }, + { "data-compressor", handle_data_compressor }, { "requires", handle_requires }, { "name", handle_name }, }; #define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0])) +static compressor_t *get_default_compressor(void) +{ + compressor_t *cmp; + + cmp = compressor_by_id(PKG_COMPRESSION_LZMA); + if (cmp != NULL) + return cmp; + + cmp = compressor_by_id(PKG_COMPRESSION_ZLIB); + if (cmp != NULL) + return cmp; + + cmp = compressor_by_id(PKG_COMPRESSION_NONE); + if (cmp != NULL) + return cmp; + + return cmp; +} + int desc_read(const char *path, pkg_desc_t *desc) { input_file_t f; @@ -80,6 +129,19 @@ int desc_read(const char *path, pkg_desc_t *desc) } cleanup_file(&f); + + if (desc->datacmp == NULL) + desc->datacmp = get_default_compressor(); + + if (desc->toccmp == NULL) + desc->toccmp = get_default_compressor(); + + if (desc->datacmp == NULL || desc->toccmp == NULL) { + fputs("no compressor implementations available\n", stderr); + desc_free(desc); + return -1; + } + return 0; } diff --git a/main/cmd/pack/pack.c b/main/cmd/pack/pack.c index cfa07f0..1b57042 100644 --- a/main/cmd/pack/pack.c +++ b/main/cmd/pack/pack.c @@ -1,44 +1,13 @@ #include "pack.h" static const struct option long_opts[] = { - { "toc-compressor", required_argument, NULL, 't' }, - { "file-compressor", required_argument, NULL, 'f' }, { "description", required_argument, NULL, 'd' }, { "file-list", required_argument, NULL, 'l' }, { "repo-dir", required_argument, NULL, 'r' }, { NULL, 0, NULL, 0 }, }; -static const char *short_opts = "t:f:l:r:d:"; - -static compressor_t *get_default_compressor(void) -{ - compressor_t *cmp; - - cmp = compressor_by_id(PKG_COMPRESSION_LZMA); - if (cmp != NULL) - return cmp; - - cmp = compressor_by_id(PKG_COMPRESSION_ZLIB); - if (cmp != NULL) - return cmp; - - cmp = compressor_by_id(PKG_COMPRESSION_NONE); - if (cmp != NULL) - return cmp; - - return cmp; -} - -static compressor_t *try_get_compressor(const char *name) -{ - compressor_t *cmp = compressor_by_name(name); - - if (cmp == NULL) - fprintf(stderr, "unkown compressor: %s\n", name); - - return cmp; -} +static const char *short_opts = "l:r:d:"; static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir) { @@ -56,36 +25,17 @@ static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir) static int cmd_pack(int argc, char **argv) { const char *filelist = NULL, *repodir = NULL, *descfile = NULL; - compressor_t *cmp_toc, *cmp_files; image_entry_t *list = NULL; pkg_writer_t *wr; pkg_desc_t desc; int i; - cmp_toc = get_default_compressor(); - cmp_files = cmp_toc; - - if (cmp_toc == NULL) { - fputs("no compressor implementations available\n", stderr); - return EXIT_FAILURE; - } - for (;;) { i = getopt_long(argc, argv, short_opts, long_opts, NULL); if (i == -1) break; switch (i) { - case 't': - cmp_toc = try_get_compressor(optarg); - if (cmp_toc == NULL) - return EXIT_FAILURE; - break; - case 'f': - cmp_files = try_get_compressor(optarg); - if (cmp_files == NULL) - return EXIT_FAILURE; - break; case 'l': filelist = optarg; break; @@ -130,10 +80,10 @@ static int cmd_pack(int argc, char **argv) goto fail; if (list != NULL) { - if (write_toc(wr, list, cmp_toc)) + if (write_toc(wr, list, desc.toccmp)) goto fail; - if (write_files(wr, list, cmp_files)) + if (write_files(wr, list, desc.datacmp)) goto fail; } @@ -163,11 +113,7 @@ static command_t pack = { " --description, -d Specify a file containing a description of the\n" " package, including information such as package\n" " dependencies, the actual package name, etc.\n" -"\n" -" --toc-compressor, -t \n" -" --file-compressor, -f \n" -" Specify what compressor to use for compressing the table of contents,\n" -" or for compressing files respectively.\n", +"\n", .run_cmd = cmd_pack, }; diff --git a/main/cmd/pack/pack.h b/main/cmd/pack/pack.h index 0fb3526..ace3407 100644 --- a/main/cmd/pack/pack.h +++ b/main/cmd/pack/pack.h @@ -32,6 +32,8 @@ typedef struct dependency_t { } dependency_t; typedef struct { + compressor_t *datacmp; + compressor_t *toccmp; dependency_t *deps; char *name; } pkg_desc_t;