mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-26 17:28:13 +00:00
miller-in-place iterate
This commit is contained in:
parent
57d58a261d
commit
4d5b3f2d16
5 changed files with 15 additions and 21 deletions
|
|
@ -119,7 +119,7 @@ static char* lhmss_get_or_die(lhmss_t* pmap, char* key, char* argv0);
|
|||
static int lhmsll_get_or_die(lhmsll_t* pmap, char* key, char* argv0);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
cli_opts_t* parse_command_line(int argc, char** argv) {
|
||||
cli_opts_t* parse_command_line(int argc, char** argv, sllv_t** ppmapper_list) {
|
||||
cli_opts_t* popts = mlr_malloc_or_die(sizeof(cli_opts_t));
|
||||
|
||||
cli_opts_init(popts);
|
||||
|
|
@ -240,7 +240,7 @@ cli_opts_t* parse_command_line(int argc, char** argv) {
|
|||
popts->mapper_argb = argi;
|
||||
popts->argv = argv;
|
||||
popts->argc = argc;
|
||||
popts->pmapper_list = cli_parse_mappers(argv, &argi, argc, popts, &no_input);
|
||||
*ppmapper_list = cli_parse_mappers(argv, &argi, argc, popts, &no_input);
|
||||
|
||||
for ( ; argi < argc; argi++) {
|
||||
slls_append(popts->filenames, argv[argi], NO_FREE);
|
||||
|
|
@ -330,16 +330,12 @@ sllv_t* cli_parse_mappers(char** argv, int* pargi, int argc, cli_opts_t* popts,
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void cli_opts_free(cli_opts_t* popts, context_t* pctx) { // xxx rm ctx arg when mapper-free move
|
||||
void cli_opts_free(cli_opts_t* popts) { // xxx rm ctx arg when mapper-free move
|
||||
if (popts == NULL)
|
||||
return;
|
||||
|
||||
mapper_chain_free(popts->pmapper_list, pctx);
|
||||
|
||||
slls_free(popts->filenames);
|
||||
|
||||
free(popts);
|
||||
|
||||
free_opt_singletons();
|
||||
}
|
||||
|
||||
|
|
@ -962,7 +958,6 @@ void cli_opts_init(cli_opts_t* popts) {
|
|||
cli_reader_opts_init(&popts->reader_opts);
|
||||
cli_writer_opts_init(&popts->writer_opts);
|
||||
|
||||
popts->pmapper_list = sllv_alloc();
|
||||
popts->mapper_argb = 0;
|
||||
popts->filenames = slls_alloc();
|
||||
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ typedef struct _cli_opts_t {
|
|||
cli_reader_opts_t reader_opts;
|
||||
cli_writer_opts_t writer_opts;
|
||||
|
||||
sllv_t* pmapper_list; // xxx pull out of popts
|
||||
|
||||
// These are used to construct the mapper list. In particular,
|
||||
// for in-place mode they're reconstructed for each file.
|
||||
char** argv;
|
||||
|
|
@ -78,7 +76,7 @@ typedef struct _cli_opts_t {
|
|||
} cli_opts_t;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
cli_opts_t* parse_command_line(int argc, char** argv);
|
||||
cli_opts_t* parse_command_line(int argc, char** argv, sllv_t** ppmapper_list);
|
||||
|
||||
// xxx cmt
|
||||
sllv_t* cli_parse_mappers(char** argv, int* pargi, int argc, cli_opts_t* popts, int* pno_input);
|
||||
|
|
@ -106,7 +104,7 @@ void cli_merge_writer_opts(cli_writer_opts_t* pfunc_opts, cli_writer_opts_t* pma
|
|||
// output. E.g. pretty-print output has column widths which are only computable
|
||||
// after all output records have been retained. The free methods are used as
|
||||
// drain triggers.
|
||||
void cli_opts_free(cli_opts_t* popts, context_t* pctx);
|
||||
void cli_opts_free(cli_opts_t* popts);
|
||||
|
||||
// The caller can unconditionally free the return value
|
||||
char* cli_sep_from_arg(char* arg);
|
||||
|
|
|
|||
|
|
@ -22,15 +22,17 @@ int main(int argc, char** argv) {
|
|||
// the handler instead.
|
||||
do_aux_entries(argc, argv);
|
||||
|
||||
cli_opts_t* popts = parse_command_line(argc, argv);
|
||||
sllv_t* pmapper_list = NULL;
|
||||
cli_opts_t* popts = parse_command_line(argc, argv, &pmapper_list);
|
||||
mlr_global_init(argv[0], popts->ofmt);
|
||||
|
||||
context_t ctx;
|
||||
context_init_from_opts(&ctx, popts);
|
||||
|
||||
int ok = do_stream_chained(&ctx, popts);
|
||||
int ok = do_stream_chained(&ctx, pmapper_list, popts);
|
||||
|
||||
cli_opts_free(popts, &ctx);
|
||||
mapper_chain_free(pmapper_list, &ctx);
|
||||
cli_opts_free(popts);
|
||||
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
static int do_stream_chained_in_place(context_t* pctx, cli_opts_t* popts);
|
||||
|
||||
static int do_stream_chained_to_stdout(context_t* pctx, cli_opts_t* popts);
|
||||
static int do_stream_chained_to_stdout(context_t* pctx, sllv_t* pmapper_list, cli_opts_t* popts);
|
||||
|
||||
static int do_file_chained(char* filename, context_t* pctx,
|
||||
lrec_reader_t* plrec_reader, sllv_t* pmapper_list, lrec_writer_t* plrec_writer, FILE* output_stream,
|
||||
|
|
@ -28,11 +28,11 @@ static void null_progress_indicator(context_t* pctx, long long nr_progress_mod);
|
|||
static void stderr_progress_indicator(context_t* pctx, long long nr_progress_mod);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
int do_stream_chained(context_t* pctx, cli_opts_t* popts) {
|
||||
int do_stream_chained(context_t* pctx, sllv_t* pmapper_list, cli_opts_t* popts) {
|
||||
if (popts->do_in_place) {
|
||||
return do_stream_chained_in_place(pctx, popts);
|
||||
} else {
|
||||
return do_stream_chained_to_stdout(pctx, popts);
|
||||
return do_stream_chained_to_stdout(pctx, pmapper_list, popts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +107,11 @@ static int do_stream_chained_in_place(context_t* pctx, cli_opts_t* popts) {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static int do_stream_chained_to_stdout(context_t* pctx, cli_opts_t* popts) {
|
||||
static int do_stream_chained_to_stdout(context_t* pctx, sllv_t* pmapper_list, cli_opts_t* popts) {
|
||||
FILE* output_stream = stdout;
|
||||
|
||||
lrec_reader_t* plrec_reader = lrec_reader_alloc_or_die(&popts->reader_opts);
|
||||
lrec_writer_t* plrec_writer = lrec_writer_alloc_or_die(&popts->writer_opts);
|
||||
sllv_t* pmapper_list = popts->pmapper_list;
|
||||
|
||||
MLR_INTERNAL_CODING_ERROR_IF(pmapper_list->length < 1); // Should not have been allowed by the CLI parser.
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@
|
|||
#include "mapping/mappers.h"
|
||||
#include "output/lrec_writers.h"
|
||||
|
||||
int do_stream_chained(context_t* pctx, cli_opts_t* popts);
|
||||
int do_stream_chained(context_t* pctx, sllv_t* pmapper_list, cli_opts_t* popts);
|
||||
|
||||
#endif // STREAM_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue