Skip to content

Commit

Permalink
Reconstruction of CLI support for "--comment"
Browse files Browse the repository at this point in the history
Reconstruction of google@1a16703
  • Loading branch information
rachelmsimm committed May 23, 2023
1 parent e0d9f11 commit 4c692da
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions c/tools/brotli.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ typedef struct {
const char* output_path;
const char* dictionary_path;
const char* suffix;
const char* comment;
int not_input_indices[MAX_OPTIONS];
size_t longest_path_len;
size_t input_count;
Expand Down Expand Up @@ -207,6 +208,7 @@ static Command ParseParams(Context* params) {
BROTLI_BOOL keep_set = BROTLI_FALSE;
BROTLI_BOOL lgwin_set = BROTLI_FALSE;
BROTLI_BOOL suffix_set = BROTLI_FALSE;
BROTLI_BOOL comment_set = BROTLI_FALSE;
BROTLI_BOOL after_dash_dash = BROTLI_FALSE;
Command command = ParseAlias(argv[0]);

Expand Down Expand Up @@ -389,6 +391,13 @@ static Command ParseParams(Context* params) {
}
suffix_set = BROTLI_TRUE;
params->suffix = argv[i];
} else if (c == 'C') {
if (comment_set) {
fprintf(stderr, "comment already set\n");
return COMMAND_INVALID;
}
comment_set = BROTLI_TRUE;
params->comment = argv[i];
}
}
} else { /* Double-dash. */
Expand Down Expand Up @@ -535,6 +544,13 @@ static Command ParseParams(Context* params) {
}
suffix_set = BROTLI_TRUE;
params->suffix = value;
} else if (strncmp("comment", arg, key_len) == 0) {
if (comment_set) {
fprintf(stderr, "comment already set\n");
return COMMAND_INVALID;
}
comment_set = BROTLI_TRUE;
params->comment = value;
} else {
fprintf(stderr, "invalid parameter: [%s]\n", arg);
return COMMAND_INVALID;
Expand Down Expand Up @@ -608,6 +624,9 @@ static void PrintHelp(const char* name, BROTLI_BOOL error) {
fprintf(media,
" -S SUF, --suffix=SUF output file suffix (default:'%s')\n",
DEFAULT_SUFFIX);
fprintf(media, // TODO example usage of comment
" -C COMM, --comment=COMM comment for identifying whether data is\n"
" brotli compressed or uncompressed\n");
fprintf(media,
" -V, --version display version and exit\n"
" -Z, --best use best compression level (11) (default)\n"
Expand Down Expand Up @@ -1167,6 +1186,8 @@ int main(int argc, char** argv) {
context.output_path = NULL;
context.dictionary_path = NULL;
context.suffix = DEFAULT_SUFFIX;
context.comment = NULL;

for (i = 0; i < MAX_OPTIONS; ++i) context.not_input_indices[i] = 0;
context.longest_path_len = 1;
context.input_count = 0;
Expand Down

0 comments on commit 4c692da

Please sign in to comment.