"Fossies" - the Fresh Open Source Software Archive

Member "mlr-5.9.1/c/mapping/mapper_nothing.c" (3 Sep 2020, 2088 Bytes) of package /linux/misc/mlr-5.9.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mapper_nothing.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.9.0_vs_5.9.1.

    1 #include "cli/argparse.h"
    2 #include "mapping/mappers.h"
    3 #include "lib/mlrutil.h"
    4 #include "containers/sllv.h"
    5 
    6 static void      mapper_nothing_usage(FILE* o, char* argv0, char* verb);
    7 static mapper_t* mapper_nothing_parse_cli(int* pargi, int argc, char** argv,
    8     cli_reader_opts_t* _, cli_writer_opts_t* __);
    9 static mapper_t* mapper_nothing_alloc();
   10 static void      mapper_nothing_free(mapper_t* pmapper, context_t* _);
   11 static sllv_t*   mapper_nothing_process(lrec_t* pinrec, context_t* pctx, void* pvstate);
   12 
   13 // ----------------------------------------------------------------
   14 mapper_setup_t mapper_nothing_setup = {
   15     .verb = "nothing",
   16     .pusage_func = mapper_nothing_usage,
   17     .pparse_func = mapper_nothing_parse_cli,
   18     .ignores_input = FALSE,
   19 };
   20 
   21 // ----------------------------------------------------------------
   22 static mapper_t* mapper_nothing_parse_cli(int* pargi, int argc, char** argv,
   23     cli_reader_opts_t* _, cli_writer_opts_t* __)
   24 {
   25     if ((argc - *pargi) < 1) {
   26         mapper_nothing_usage(stderr, argv[0], argv[*pargi]);
   27         return NULL;
   28     }
   29     *pargi += 1;
   30     mapper_t* pmapper = mapper_nothing_alloc();
   31     return pmapper;
   32 }
   33 
   34 static void mapper_nothing_usage(FILE* o, char* argv0, char* verb) {
   35     fprintf(o, "Usage: %s %s\n", argv0, verb);
   36     fprintf(o, "Drops all input records. Useful for testing, or after tee/print/etc. have\n");
   37     fprintf(o, "produced other output.\n");
   38 }
   39 
   40 // ----------------------------------------------------------------
   41 static mapper_t* mapper_nothing_alloc(ap_state_t* pargp, int do_counters, char* counter_field_name) {
   42     mapper_t* pmapper = mlr_malloc_or_die(sizeof(mapper_t));
   43     pmapper->pvstate       = NULL;
   44     pmapper->pprocess_func = mapper_nothing_process;
   45     pmapper->pfree_func    = mapper_nothing_free;
   46     return pmapper;
   47 }
   48 static void mapper_nothing_free(mapper_t* pmapper, context_t* _) {
   49     free(pmapper);
   50 }
   51 
   52 // ----------------------------------------------------------------
   53 static sllv_t* mapper_nothing_process(lrec_t* pinrec, context_t* pctx, void* pvstate) {
   54     if (pinrec != NULL) {
   55         lrec_free(pinrec);
   56         return NULL;
   57     } else {
   58         return sllv_single(NULL);
   59     }
   60 }