"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "c/cli/mlrcli.c" between
mlr-5.9.0.tar.gz and mlr-5.9.1.tar.gz

About: Miller is like sed, awk, cut, join, and sort for name-indexed data such as CSV and tabular JSON.

mlrcli.c  (mlr-5.9.0):mlrcli.c  (mlr-5.9.1)
skipping to change at line 114 skipping to change at line 114
&mapper_tail_setup, &mapper_tail_setup,
&mapper_tee_setup, &mapper_tee_setup,
&mapper_top_setup, &mapper_top_setup,
&mapper_uniq_setup, &mapper_uniq_setup,
&mapper_unsparsify_setup, &mapper_unsparsify_setup,
}; };
static int mapper_lookup_table_length = sizeof(mapper_lookup_table) / sizeof(map per_lookup_table[0]); static int mapper_lookup_table_length = sizeof(mapper_lookup_table) / sizeof(map per_lookup_table[0]);
// ---------------------------------------------------------------- // ----------------------------------------------------------------
static void cli_load_mlrrc_or_die(cli_opts_t* popts); static void cli_load_mlrrc(cli_opts_t* popts);
static int cli_try_load_mlrrc(cli_opts_t* popts, char* path); static void cli_try_load_mlrrc(cli_opts_t* popts, char* path);
static int handle_mlrrc_line_1(cli_opts_t* popts, char* line); static int handle_mlrrc_line_1(cli_opts_t* popts, char* line);
static int handle_mlrrc_line_2(cli_opts_t* popts, char* line); static int handle_mlrrc_line_2(cli_opts_t* popts, char* line);
static int handle_mlrrc_line_3(cli_opts_t* popts, char* line); static int handle_mlrrc_line_3(cli_opts_t* popts, char* line);
static int handle_mlrrc_line_4(cli_opts_t* popts, char** argv, int argc); static int handle_mlrrc_line_4(cli_opts_t* popts, char** argv, int argc);
static int cli_handle_misc_options(char** argv, int argc, int *pargi, cli_opts_t * popts); static int cli_handle_misc_options(char** argv, int argc, int *pargi, cli_opts_t * popts);
static lhmss_t* get_desc_to_chars_map(); static lhmss_t* get_desc_to_chars_map();
static lhmsll_t* get_default_repeat_ifses(); static lhmsll_t* get_default_repeat_ifses();
static lhmsll_t* get_default_repeat_ipses(); static lhmsll_t* get_default_repeat_ipses();
skipping to change at line 181 skipping to change at line 181
// Set defaults for options // Set defaults for options
cli_opts_init(popts); cli_opts_init(popts);
// Try .mlrrc overrides (then command-line on top of that). // Try .mlrrc overrides (then command-line on top of that).
// A --norc flag (if provided) must come before all other options. // A --norc flag (if provided) must come before all other options.
// Or, they can set the environment variable MLRRC="__none__". // Or, they can set the environment variable MLRRC="__none__".
if (argc >= 2 && streq(argv[1], "--norc")) { if (argc >= 2 && streq(argv[1], "--norc")) {
argi++; argi++;
} else { } else {
cli_load_mlrrc_or_die(popts); cli_load_mlrrc(popts);
} }
for (; argi < argc; /* variable increment: 1 or 2 depending on flag */) { for (; argi < argc; /* variable increment: 1 or 2 depending on flag */) {
if (argv[argi][0] != '-') { if (argv[argi][0] != '-') {
break; // No more flag options to process break; // No more flag options to process
} else if (handle_terminal_usage(argv, argc, argi)) { } else if (handle_terminal_usage(argv, argc, argi)) {
exit(0); exit(0);
} else if (cli_handle_reader_options(argv, argc, &argi, &popts->r eader_opts)) { } else if (cli_handle_reader_options(argv, argc, &argi, &popts->r eader_opts)) {
// handled // handled
skipping to change at line 874 skipping to change at line 874
fprintf(o, " --p2c --p2t --p2d --p2n --p2j --p2x --p2m\n"); fprintf(o, " --p2c --p2t --p2d --p2n --p2j --p2x --p2m\n");
fprintf(o, "The letters c t d n j x p m refer to formats CSV, TSV, DKVP, NIDX, JSON, XTAB,\n"); fprintf(o, "The letters c t d n j x p m refer to formats CSV, TSV, DKVP, NIDX, JSON, XTAB,\n");
fprintf(o, "PPRINT, and markdown, respectively. Note that markdown format is available for\n"); fprintf(o, "PPRINT, and markdown, respectively. Note that markdown format is available for\n");
fprintf(o, "output only.\n"); fprintf(o, "output only.\n");
} }
static void main_usage_compressed_data_options(FILE* o, char* argv0) { static void main_usage_compressed_data_options(FILE* o, char* argv0) {
fprintf(o, " --prepipe {command} This allows Miller to handle compressed inputs. You can do\n"); fprintf(o, " --prepipe {command} This allows Miller to handle compressed inputs. You can do\n");
fprintf(o, " without this for single input files, e.g. \"gunzip < myfile .csv.gz | %s ...\".\n", fprintf(o, " without this for single input files, e.g. \"gunzip < myfile .csv.gz | %s ...\".\n",
argv0); argv0);
fprintf(o, "\n");
fprintf(o, " However, when multiple input files are present, between-fil e separations are\n"); fprintf(o, " However, when multiple input files are present, between-fil e separations are\n");
fprintf(o, " lost; also, the FILENAME variable doesn't iterate. Using -- prepipe you can\n"); fprintf(o, " lost; also, the FILENAME variable doesn't iterate. Using -- prepipe you can\n");
fprintf(o, " specify an action to be taken on each input file. This pre- pipe command must\n"); fprintf(o, " specify an action to be taken on each input file. This pre- pipe command must\n");
fprintf(o, " be able to read from standard input; it will be invoked wit h\n"); fprintf(o, " be able to read from standard input; it will be invoked wit h\n");
fprintf(o, " {command} < {filename}.\n"); fprintf(o, " {command} < {filename}.\n");
fprintf(o, " Examples:\n"); fprintf(o, " Examples:\n");
fprintf(o, " %s --prepipe 'gunzip'\n", argv0); fprintf(o, " %s --prepipe 'gunzip'\n", argv0);
fprintf(o, " %s --prepipe 'zcat -cf'\n", argv0); fprintf(o, " %s --prepipe 'zcat -cf'\n", argv0);
fprintf(o, " %s --prepipe 'xz -cd'\n", argv0); fprintf(o, " %s --prepipe 'xz -cd'\n", argv0);
fprintf(o, " %s --prepipe cat\n", argv0); fprintf(o, " %s --prepipe cat\n", argv0);
fprintf(o, " %s --prepipe-gunzip\n", argv0);
fprintf(o, " %s --prepipe-zcat\n", argv0);
fprintf(o, " Note that this feature is quite general and is not limited to decompression\n"); fprintf(o, " Note that this feature is quite general and is not limited to decompression\n");
fprintf(o, " utilities. You can use it to apply per-file filters of your choice.\n"); fprintf(o, " utilities. You can use it to apply per-file filters of your choice.\n");
fprintf(o, " For output compression (or other) utilities, simply pipe th e output:\n"); fprintf(o, " For output compression (or other) utilities, simply pipe th e output:\n");
fprintf(o, " %s ... | {your compression command}\n", argv0); fprintf(o, " %s ... | {your compression command}\n", argv0);
fprintf(o, "\n");
fprintf(o, " There are shorthands --prepipe-zcat and --prepipe-gunzip wh
ich are\n");
fprintf(o, " valid in .mlrrc files. The --prepipe flag is not valid in .
mlrrc\n");
fprintf(o, " files since that would put execution of the prepipe command
under \n");
fprintf(o, " control of the .mlrrc file.\n");
} }
static void main_usage_separator_options(FILE* o, char* argv0) { static void main_usage_separator_options(FILE* o, char* argv0) {
fprintf(o, " --rs --irs --ors Record separators, e. g. 'lf' or '\\r\\n'\n"); fprintf(o, " --rs --irs --ors Record separators, e. g. 'lf' or '\\r\\n'\n");
fprintf(o, " --fs --ifs --ofs --repifs Field separators, e.g . comma\n"); fprintf(o, " --fs --ifs --ofs --repifs Field separators, e.g . comma\n");
fprintf(o, " --ps --ips --ops Pair separators, e.g. equals sign\n"); fprintf(o, " --ps --ips --ops Pair separators, e.g. equals sign\n");
fprintf(o, "\n"); fprintf(o, "\n");
fprintf(o, " Notes about line endings:\n"); fprintf(o, " Notes about line endings:\n");
fprintf(o, " * Default line endings (--irs and --ors) are \"auto\" which means autodetect from\n"); fprintf(o, " * Default line endings (--irs and --ors) are \"auto\" which means autodetect from\n");
fprintf(o, " the input file format, as long as the input file(s) have lines ending in either\n"); fprintf(o, " the input file format, as long as the input file(s) have lines ending in either\n");
skipping to change at line 1113 skipping to change at line 1121
popts->no_input = FALSE; popts->no_input = FALSE;
popts->have_rand_seed = FALSE; popts->have_rand_seed = FALSE;
popts->rand_seed = 0; popts->rand_seed = 0;
} }
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// * If $MLRRC is set, use it and only it. // * If $MLRRC is set, use it and only it.
// * Otherwise try first $HOME/.mlrrc and then ./.mlrrc but let them // * Otherwise try first $HOME/.mlrrc and then ./.mlrrc but let them
// stack: e.g. $HOME/.mlrrc is lots of settings and maybe in one // stack: e.g. $HOME/.mlrrc is lots of settings and maybe in one
// subdir you want to override just a setting or two. // subdir you want to override just a setting or two.
static void cli_load_mlrrc_or_die(cli_opts_t* popts) { static void cli_load_mlrrc(cli_opts_t* popts) {
char* env_mlrrc = getenv("MLRRC"); char* env_mlrrc = getenv("MLRRC");
if (env_mlrrc != NULL) { if (env_mlrrc != NULL) {
if (streq(env_mlrrc, "__none__")) { if (streq(env_mlrrc, "__none__")) {
return; return;
} }
if (cli_try_load_mlrrc(popts, env_mlrrc)) { cli_try_load_mlrrc(popts, env_mlrrc);
return; return;
}
} }
char* env_home = getenv("HOME"); char* env_home = getenv("HOME");
if (env_home != NULL) { if (env_home != NULL) {
char* path = mlr_paste_2_strings(env_home, "/.mlrrc"); char* path = mlr_paste_2_strings(env_home, "/.mlrrc");
(void)cli_try_load_mlrrc(popts, path); cli_try_load_mlrrc(popts, path);
free(path); free(path);
} }
(void)cli_try_load_mlrrc(popts, "./.mlrrc"); cli_try_load_mlrrc(popts, "./.mlrrc");
} }
static int cli_try_load_mlrrc(cli_opts_t* popts, char* path) { static void cli_try_load_mlrrc(cli_opts_t* popts, char* path) {
FILE* fp = fopen(path, "r"); FILE* fp = fopen(path, "r");
if (fp == NULL) { if (fp == NULL) {
return FALSE; return;
} }
char* line = NULL; char* line = NULL;
size_t linecap = 0; size_t linecap = 0;
int rc; int rc;
int lineno = 0; int lineno = 0;
while ((rc = getline(&line, &linecap, fp)) != -1) { while ((rc = getline(&line, &linecap, fp)) != -1) {
lineno++; lineno++;
char* line_to_destroy = strdup(line); char* line_to_destroy = strdup(line);
skipping to change at line 1160 skipping to change at line 1167
path, lineno, line); path, lineno, line);
exit(1); exit(1);
} }
free(line_to_destroy); free(line_to_destroy);
} }
fclose(fp); fclose(fp);
if (line != NULL) { if (line != NULL) {
free(line); free(line);
} }
return TRUE;
} }
// Chomps trailing CR, LF, or CR/LF; comment-strips; left-right trims. // Chomps trailing CR, LF, or CR/LF; comment-strips; left-right trims.
static int handle_mlrrc_line_1(cli_opts_t* popts, char* line) { static int handle_mlrrc_line_1(cli_opts_t* popts, char* line) {
// chomp // chomp
size_t len = strlen(line); size_t len = strlen(line);
if (len >= 2 && line[len-2] == '\r' && line[len-1] == '\n') { if (len >= 2 && line[len-2] == '\r' && line[len-1] == '\n') {
line[len-2] = 0; line[len-2] = 0;
} else if (len >= 1 && (line[len-1] == '\r' || line[len-1] == '\n')) { } else if (len >= 1 && (line[len-1] == '\r' || line[len-1] == '\n')) {
line[len-1] = 0; line[len-1] = 0;
skipping to change at line 1251 skipping to change at line 1256
argv[0] = line; argv[0] = line;
argv[1] = p; argv[1] = p;
argv[2] = NULL; argv[2] = NULL;
argc = 2; argc = 2;
} }
return handle_mlrrc_line_4(popts, argv, argc); return handle_mlrrc_line_4(popts, argv, argc);
} }
static int handle_mlrrc_line_4(cli_opts_t* popts, char** argv, int argc) { static int handle_mlrrc_line_4(cli_opts_t* popts, char** argv, int argc) {
int argi = 0; int argi = 0;
if (streq(argv[0], "--prepipe")) {
// Don't allow code execution via .mlrrc
return FALSE;
}
if (cli_handle_reader_options(argv, argc, &argi, &popts->reader_opts)) { if (cli_handle_reader_options(argv, argc, &argi, &popts->reader_opts)) {
// handled // handled
} else if (cli_handle_writer_options(argv, argc, &argi, &popts->writer_op ts)) { } else if (cli_handle_writer_options(argv, argc, &argi, &popts->writer_op ts)) {
// handled // handled
} else if (cli_handle_reader_writer_options(argv, argc, &argi, &popts->re ader_opts, &popts->writer_opts)) { } else if (cli_handle_reader_writer_options(argv, argc, &argi, &popts->re ader_opts, &popts->writer_opts)) {
// handled // handled
} else if (cli_handle_misc_options(argv, argc, &argi, popts)) { } else if (cli_handle_misc_options(argv, argc, &argi, popts)) {
// handled // handled
} else { } else {
// unhandled // unhandled
skipping to change at line 1786 skipping to change at line 1795
} else if (streq(argv[argi], "--no-mmap")) { } else if (streq(argv[argi], "--no-mmap")) {
// No-op as of 5.6.3 (mmap is being abandoned) but don't break // No-op as of 5.6.3 (mmap is being abandoned) but don't break
// the command-line user experience. // the command-line user experience.
argi += 1; argi += 1;
} else if (streq(argv[argi], "--prepipe")) { } else if (streq(argv[argi], "--prepipe")) {
check_arg_count(argv, argi, argc, 2); check_arg_count(argv, argi, argc, 2);
preader_opts->prepipe = argv[argi+1]; preader_opts->prepipe = argv[argi+1];
argi += 2; argi += 2;
} else if (streq(argv[argi], "--prepipe-gunzip")) {
preader_opts->prepipe = "gunzip";
argi += 1;
} else if (streq(argv[argi], "--prepipe-zcat")) {
preader_opts->prepipe = "zcat";
argi += 1;
} else if (streq(argv[argi], "--skip-comments")) { } else if (streq(argv[argi], "--skip-comments")) {
preader_opts->comment_string = DEFAULT_COMMENT_STRING; preader_opts->comment_string = DEFAULT_COMMENT_STRING;
preader_opts->comment_handling = SKIP_COMMENTS; preader_opts->comment_handling = SKIP_COMMENTS;
argi += 1; argi += 1;
} else if (streq(argv[argi], "--skip-comments-with")) { } else if (streq(argv[argi], "--skip-comments-with")) {
check_arg_count(argv, argi, argc, 2); check_arg_count(argv, argi, argc, 2);
preader_opts->comment_string = argv[argi+1]; preader_opts->comment_string = argv[argi+1];
preader_opts->comment_handling = SKIP_COMMENTS; preader_opts->comment_handling = SKIP_COMMENTS;
argi += 2; argi += 2;
 End of changes. 14 change blocks. 
13 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)