mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-22 07:30:43 +00:00
comment-strip neaten
This commit is contained in:
parent
a5ce769cf7
commit
dff708634c
5 changed files with 3 additions and 69 deletions
|
|
@ -515,30 +515,3 @@ char* read_fp_into_memory(FILE* fp, size_t* psize) {
|
|||
*psize = file_size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
char* alloc_comment_strip(char* input) {
|
||||
char* output = mlr_strdup_or_die(input);
|
||||
char* q = output;
|
||||
int copying = TRUE;
|
||||
|
||||
for (char* p = input; *p; p++) {
|
||||
if (copying) {
|
||||
if (*p == '#') {
|
||||
copying = FALSE;
|
||||
} else {
|
||||
*q = *p;
|
||||
q++;
|
||||
}
|
||||
} else {
|
||||
if (*p == '\n') {
|
||||
copying = TRUE;
|
||||
*q = *p;
|
||||
q++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*q = 0;
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,8 +159,4 @@ char* read_file_into_memory(char* filename, size_t* psize);
|
|||
// The caller should free the return value.
|
||||
char* read_fp_into_memory(FILE* fp, size_t* psize);
|
||||
|
||||
// Returns a copy of the input string with pound-sign to newline elided.
|
||||
// Does not modify the input. The caller should free the output.
|
||||
char* alloc_comment_strip(char* input);
|
||||
|
||||
#endif // MLRUTIL_H
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
// ----------------------------------------------------------------
|
||||
typedef struct _mapper_put_or_filter_state_t {
|
||||
char* mlr_dsl_expression;
|
||||
char* comment_stripped_mlr_dsl_expression;
|
||||
|
||||
mlr_dsl_ast_t* past;
|
||||
mlr_dsl_cst_t* pcst;
|
||||
|
|
@ -55,7 +54,6 @@ static mapper_t* mapper_put_or_filter_alloc(
|
|||
char* mlr_dsl_expression,
|
||||
int print_ast,
|
||||
int trace_stack_allocation,
|
||||
char* comment_stripped_mlr_dsl_expression,
|
||||
mlr_dsl_ast_t* past,
|
||||
int put_output_disabled, // mlr put -q
|
||||
int do_final_filter, // mlr filter
|
||||
|
|
@ -227,7 +225,6 @@ static mapper_t* shared_parse_cli(int* pargi, int argc, char** argv,
|
|||
slls_t* expression_filenames = slls_alloc();
|
||||
slls_t* expression_strings = slls_alloc();
|
||||
char* mlr_dsl_expression = NULL;
|
||||
char* comment_stripped_mlr_dsl_expression = NULL;
|
||||
int put_output_disabled = FALSE;
|
||||
int do_final_filter = FALSE;
|
||||
int negate_final_filter = FALSE;
|
||||
|
|
@ -343,14 +340,11 @@ static mapper_t* shared_parse_cli(int* pargi, int argc, char** argv,
|
|||
slls_free(expression_filenames);
|
||||
slls_free(expression_strings);
|
||||
|
||||
//comment_stripped_mlr_dsl_expression = alloc_comment_strip(mlr_dsl_expression);
|
||||
comment_stripped_mlr_dsl_expression = mlr_strdup_or_die(mlr_dsl_expression);
|
||||
|
||||
// Linked list of mlr_dsl_ast_node_t*.
|
||||
mlr_dsl_ast_t* past = mlr_dsl_parse(comment_stripped_mlr_dsl_expression, trace_parse);
|
||||
mlr_dsl_ast_t* past = mlr_dsl_parse(mlr_dsl_expression, trace_parse);
|
||||
if (past == NULL) {
|
||||
fprintf(stderr, "%s %s: syntax error on DSL parse of '%s'\n",
|
||||
argv[0], verb, comment_stripped_mlr_dsl_expression);
|
||||
argv[0], verb, mlr_dsl_expression);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -364,7 +358,6 @@ static mapper_t* shared_parse_cli(int* pargi, int argc, char** argv,
|
|||
|
||||
*pargi = argi;
|
||||
return mapper_put_or_filter_alloc(mlr_dsl_expression, print_ast, trace_stack_allocation,
|
||||
comment_stripped_mlr_dsl_expression,
|
||||
past, put_output_disabled, do_final_filter, negate_final_filter,
|
||||
type_inferencing, oosvar_flatten_separator, flush_every_record,
|
||||
pwriter_opts, pmain_writer_opts);
|
||||
|
|
@ -375,7 +368,6 @@ static mapper_t* mapper_put_or_filter_alloc(
|
|||
char* mlr_dsl_expression,
|
||||
int print_ast,
|
||||
int trace_stack_allocation,
|
||||
char* comment_stripped_mlr_dsl_expression,
|
||||
mlr_dsl_ast_t* past,
|
||||
int put_output_disabled, // mlr put -q
|
||||
int do_final_filter, // mlr filter
|
||||
|
|
@ -389,7 +381,6 @@ static mapper_t* mapper_put_or_filter_alloc(
|
|||
mapper_put_or_filter_state_t* pstate = mlr_malloc_or_die(sizeof(mapper_put_or_filter_state_t));
|
||||
// Retain the string contents along with any in-pointers from the AST/CST
|
||||
pstate->mlr_dsl_expression = mlr_dsl_expression;
|
||||
pstate->comment_stripped_mlr_dsl_expression = comment_stripped_mlr_dsl_expression;
|
||||
pstate->past = past;
|
||||
pstate->pcst = mlr_dsl_cst_alloc(past, print_ast, trace_stack_allocation,
|
||||
type_inferencing, flush_every_record, do_final_filter, negate_final_filter);
|
||||
|
|
@ -416,7 +407,6 @@ static void mapper_put_or_filter_free(mapper_t* pmapper) {
|
|||
mapper_put_or_filter_state_t* pstate = pmapper->pvstate;
|
||||
|
||||
free(pstate->mlr_dsl_expression);
|
||||
free(pstate->comment_stripped_mlr_dsl_expression);
|
||||
mlhmmv_free(pstate->poosvars);
|
||||
bind_stack_free(pstate->pbind_stack);
|
||||
loop_stack_free(pstate->ploop_stack);
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ DSL:
|
|||
* variadic min & max
|
||||
* substr func
|
||||
* ENV @ LHS (putenv), and why (popens)
|
||||
* # in the lexer so #-strings are OK now (show an example)
|
||||
|
||||
VERBS:
|
||||
* most-frequent/least-frequent
|
||||
|
|
|
|||
|
|
@ -141,31 +141,6 @@ static char * test_unbackslash() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static char * test_alloc_comment_strip() {
|
||||
mu_assert_lf(streq(alloc_comment_strip(""), ""));
|
||||
mu_assert_lf(streq(alloc_comment_strip("hello"), "hello"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("#"), ""));
|
||||
mu_assert_lf(streq(alloc_comment_strip("######"), ""));
|
||||
mu_assert_lf(streq(alloc_comment_strip("#hello"), ""));
|
||||
mu_assert_lf(streq(alloc_comment_strip("#hello\n"), "\n"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("hello#there"), "hello"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("hello#there\n"), "hello\n"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthree\nfour"), "one\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("#one\ntwo\nthree\nfour"), "\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("on#e\ntwo\nthree\nfour"), "on\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one#\ntwo\nthree\nfour"), "one\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\n#two\nthree\nfour"), "one\n\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo#\nthree\nfour"), "one\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthr#ee\nfour"), "one\ntwo\nthr\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthree#\nfour"), "one\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthree\n#four"), "one\ntwo\nthree\n"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthree\nfo#ur"), "one\ntwo\nthree\nfo"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("one\ntwo\nthree\nfour#"), "one\ntwo\nthree\nfour"));
|
||||
mu_assert_lf(streq(alloc_comment_strip("#one\nt#wo\nth#ree\nfou#r#"), "\nt\nth\nfou"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
static char * all_tests() {
|
||||
mu_run_test(test_canonical_mod);
|
||||
|
|
@ -175,7 +150,6 @@ static char * all_tests() {
|
|||
mu_run_test(test_scanners);
|
||||
mu_run_test(test_paste);
|
||||
mu_run_test(test_unbackslash);
|
||||
mu_run_test(test_alloc_comment_strip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue