From 88a53de03c816b39dedc9f4ef3e5e2ecff6595d4 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 10 Nov 2015 08:07:57 -0500 Subject: [PATCH] neaten --- c/mapping/mapper_filter.c | 3 ++- c/mapping/mapper_sec2gmt.c | 20 +++++++++++------- c/reg_test/expected/out | 38 ++++++++++++++++++++++++++++++++++ c/reg_test/run | 6 ++++++ c/todo.txt | 10 ++++----- doc/content-for-reference.html | 2 ++ doc/mlr.1.premade | 5 +++-- doc/reference.html | 5 ++++- 8 files changed, 71 insertions(+), 18 deletions(-) diff --git a/c/mapping/mapper_filter.c b/c/mapping/mapper_filter.c index ed425e215..17b361709 100644 --- a/c/mapping/mapper_filter.c +++ b/c/mapping/mapper_filter.c @@ -41,7 +41,8 @@ static void mapper_filter_usage(FILE* o, char* argv0, char* verb) { fprintf(o, " %s %s '($x<.5 && $y<.5) || ($x>.5 && $y>.5)'\n", argv0, verb); fprintf(o, " %s %s '($name =~ \"^sys.*east$\") || ($name =~ \"^dev.[0-9]+\"i)'\n", argv0, verb); fprintf(o, "Please see http://johnkerl.org/miller/doc/reference.html for more information\n"); - fprintf(o, "including function list.\n"); + fprintf(o, "including function list. Or \"%s -f\". Please also also \"%s grep\" which is\n", argv0, argv0); + fprintf(o, "useful when you don't yet know which field name(s) you're looking for.\n"); } // ---------------------------------------------------------------- diff --git a/c/mapping/mapper_sec2gmt.c b/c/mapping/mapper_sec2gmt.c index 6bd11a021..9c88ae542 100644 --- a/c/mapping/mapper_sec2gmt.c +++ b/c/mapping/mapper_sec2gmt.c @@ -79,16 +79,20 @@ static sllv_t* mapper_sec2gmt_process(lrec_t* pinrec, context_t* pctx, void* pvs if (sval == NULL) continue; - double dval = mlr_double_from_string_or_die(sval); + if (*sval == 0) { + lrec_put_no_free(pinrec, name, ""); + } else { + double dval = mlr_double_from_string_or_die(sval); - // xxx make mlrutil func - time_t clock = (time_t) dval; - struct tm tm; - struct tm *ptm = gmtime_r(&clock, &tm); - char* stamp = mlr_malloc_or_die(32); - (void)strftime(stamp, 32, "%Y-%m-%dT%H:%M:%SZ", ptm); + // xxx make mlrutil func + time_t clock = (time_t) dval; + struct tm tm; + struct tm *ptm = gmtime_r(&clock, &tm); + char* stamp = mlr_malloc_or_die(32); + (void)strftime(stamp, 32, "%Y-%m-%dT%H:%M:%SZ", ptm); - lrec_put_no_free(pinrec, name, stamp); + lrec_put(pinrec, name, stamp, LREC_FREE_ENTRY_VALUE); + } } return sllv_single(pinrec); } diff --git a/c/reg_test/expected/out b/c/reg_test/expected/out index b4504e24f..3a12735b8 100644 --- a/c/reg_test/expected/out +++ b/c/reg_test/expected/out @@ -16,6 +16,30 @@ a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864 mlr cat /dev/null +mlr cat -n ./reg_test/input/abixy +n=0,a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533 +n=1,a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797 +n=2,a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776 +n=3,a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463 +n=4,a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729 +n=5,a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697 +n=6,a=eks,b=zee,i=7,x=0.6117840605678454,y=0.1878849191181694 +n=7,a=zee,b=wye,i=8,x=0.5985540091064224,y=0.976181385699006 +n=8,a=hat,b=wye,i=9,x=0.03144187646093577,y=0.7495507603507059 +n=9,a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864 + +mlr cat -N counter ./reg_test/input/abixy +counter=0,a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533 +counter=1,a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797 +counter=2,a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776 +counter=3,a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463 +counter=4,a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729 +counter=5,a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697 +counter=6,a=eks,b=zee,i=7,x=0.6117840605678454,y=0.1878849191181694 +counter=7,a=zee,b=wye,i=8,x=0.5985540091064224,y=0.976181385699006 +counter=8,a=hat,b=wye,i=9,x=0.03144187646093577,y=0.7495507603507059 +counter=9,a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864 + mlr cut -f a,x ./reg_test/input/abixy a=pan,x=0.3467901443380824 a=eks,x=0.7586799647899636 @@ -582,6 +606,20 @@ a=zee,b=wye,count=2 a=hat,b=wye,count=2 a=pan,b=wye,count=2 +mlr grep pan ./reg_test/input/abixy-het +a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533 +a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797 +a=wye,b=pan,i=5,xxx=0.5732889198020006,y=0.8636244699032729 +a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697 +a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864 + +mlr grep -v pan ./reg_test/input/abixy-het +aaa=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776 +a=eks,bbb=wye,i=4,x=0.38139939387114097,y=0.13418874328430463 +a=eks,b=zee,iii=7,x=0.6117840605678454,y=0.1878849191181694 +a=zee,b=wye,i=8,x=0.5985540091064224,yyy=0.976181385699006 +aaa=hat,bbb=wye,i=9,x=0.03144187646093577,y=0.7495507603507059 + ================================================================ SORT diff --git a/c/reg_test/run b/c/reg_test/run index b9468de50..c67a3fe56 100755 --- a/c/reg_test/run +++ b/c/reg_test/run @@ -76,6 +76,9 @@ announce STATELESS MAPPERS run_mlr cat $indir/abixy run_mlr cat /dev/null +run_mlr cat -n $indir/abixy +run_mlr cat -N counter $indir/abixy + run_mlr cut -f a,x $indir/abixy run_mlr cut --complement -f a,x $indir/abixy @@ -165,6 +168,9 @@ run_mlr uniq -c -g a,b $indir/abixy-het run_mlr count-distinct -f a $indir/small $indir/abixy run_mlr count-distinct -f a,b $indir/small $indir/abixy +run_mlr grep pan $indir/abixy-het +run_mlr grep -v pan $indir/abixy-het + # ---------------------------------------------------------------- announce SORT diff --git a/c/todo.txt b/c/todo.txt index 93f80b9a1..cfc20071b 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -17,17 +17,13 @@ TOP OF LIST - brew version bump?!? - cut a release w/ manpage -! formats @ mlrdoc -- note default iidx for ps-less dkvp fields. also @ mlr -h? +! mlrdoc/formats -- note default iidx for ps-less dkvp fields. also @ mlr -h? ! split mlrdoc into master & releases -- ? * new UT: o sec2gmt - o cat -n/-N - o grep -! grep to mld regex section -! mlr grep -h {pattern} -> {regex} -! need mlr --regex-help re //, "...", "..."i, "\(..\)" vs. "(..)", etc. +* sec2gmt verb&fcn null-handling & UT both * R: ! xref @ covers x 2 @@ -52,6 +48,8 @@ TOP OF LIST - out-of-place bar -- preserving count as separate column? - fix # for just-above-lo bar: "[...]" & "<...]" & "[...>" ? +! need mlr --regex-help re //, "...", "..."i, "\(..\)" vs. "(..)", etc. + * faqents: ! some of these putative faqents (and maybe some of the existing ones) should be in a cookbook page - csv/csvlite compare/contrast @ mld formats diff --git a/doc/content-for-reference.html b/doc/content-for-reference.html index 8953331ac..72d91cfac 100644 --- a/doc/content-for-reference.html +++ b/doc/content-for-reference.html @@ -244,6 +244,8 @@ filter '$url =~ "http.*com"'
  • In mlr rename, e.g. mlr rename -r '^(sda[0-9]).*$,dev/\1' +
  • In mlr grep, e.g. mlr --csv grep 00188555487 myfiles*.csv +

    The i after the double-quoted regular-expression string is used to diff --git a/doc/mlr.1.premade b/doc/mlr.1.premade index f6ec312a7..a6a1e4b00 100644 --- a/doc/mlr.1.premade +++ b/doc/mlr.1.premade @@ -1,7 +1,7 @@ '\" t .\" Title: mlr .\" Author: [see the "AUTHOR" section] -.\" Generator: mkman.rb +.\" Generator: ./mkman.rb .\" Date: 2015-11-10 .\" Manual: \ \& .\" Source: \ \& @@ -371,7 +371,8 @@ Examples: mlr filter '($x<.5 && $y<.5) || ($x>.5 && $y>.5)' mlr filter '($name =~ "^sys.*east$") || ($name =~ "^dev.[0-9]+"i)' Please see http://johnkerl.org/miller/doc/reference.html for more information -including function list. +including function list. Or "mlr -f". Please also also "mlr grep" which is +useful when you don't yet know which field name(s) you're looking for. .fi .if n \{\ .RE diff --git a/doc/reference.html b/doc/reference.html index a6160628c..0d4b1ce88 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -651,6 +651,8 @@ filter '$url =~ "http.*com"'

  • In mlr rename, e.g. mlr rename -r '^(sda[0-9]).*$,dev/\1' +
  • In mlr grep, e.g. mlr --csv grep 00188555487 myfiles*.csv +

    The i after the double-quoted regular-expression string is used to @@ -989,7 +991,8 @@ Examples: mlr filter '($x<.5 && $y<.5) || ($x>.5 && $y>.5)' mlr filter '($name =~ "^sys.*east$") || ($name =~ "^dev.[0-9]+"i)' Please see http://johnkerl.org/miller/doc/reference.html for more information -including function list. +including function list. Or "mlr -f". Please also also "mlr grep" which is +useful when you don't yet know which field name(s) you're looking for.