Skip to content

Commit 91a5805

Browse files
committed
Merge branch 'bug/81'
* bug/81: minor, reactivate dgrepping for %c (count within month) test, add regression case for bug #81 chore, make dexpr(1) compile as standalone util again
2 parents d7bc6d0 + 4d8e8fa commit 91a5805

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

lib/date-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ dt_get_md(struct dt_d_s that)
251251
}
252252
}
253253

254-
/* too exotic to be public */
255-
static int
254+
/* too exotic to be public, nope bug #81 needs it */
255+
int
256256
dt_get_wcnt_mon(struct dt_d_s that)
257257
{
258258
if (LIKELY(that.typ == DT_YMCW)) {

lib/date-core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ extern unsigned int dt_get_yday(struct dt_d_s d);
462462
* Return N where N is the week within the year that THIS is in. */
463463
extern int dt_get_wcnt_year(struct dt_d_s this, unsigned int wkcnt_convention);
464464

465+
/**
466+
* Return N where N is the week within the month that THIS is in. */
467+
extern int dt_get_wcnt_mon(struct dt_d_s this);
468+
465469
/* converters */
466470
extern dt_daisy_t dt_conv_to_daisy(struct dt_d_s);
467471

src/dexpr-parser.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@
4343
#include <stdio.h>
4444
#include <errno.h>
4545
#include "token.h"
46+
#include "date-core.h"
4647
#include "date-core-strpf.h"
48+
#include "dt-locale.h"
4749
#include "dexpr.h"
50+
#include "dexpr-parser.h"
51+
#include "dt-io.h"
4852

4953
extern int yylex(YYSTYPE *yylval_param);
5054
extern int yyerror(dexpr_t *cur __attribute__((unused)), const char *errmsg);

src/dexpr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdio.h>
77
#include <stdbool.h>
88
#include "strops.h"
9+
#include "dt-locale.h"
910
#include "dexpr.h"
1011
#include "dexpr-parser.h"
1112

@@ -559,7 +560,7 @@ dexkv_matches_p(const_dexkv_t dkv, struct dt_dt_s d)
559560
break;
560561
case DT_SPFL_N_WCNT_MON:
561562
/* exotic function, needs extern'ing */
562-
cmp = /*dt_get_count(d)*/0;
563+
cmp = dt_get_wcnt_mon(d.d);
563564
break;
564565
case DT_SPFL_N_DCNT_YEAR:
565566
cmp = dt_get_yday(d.d);
@@ -639,6 +640,8 @@ dexpr_matches_p(const_dexpr_t dex, struct dt_dt_s d)
639640

640641

641642
#if defined STANDALONE
643+
const char *prog = "dexpr";
644+
642645
int
643646
main(int argc, char *argv[])
644647
{

test/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ dt_tests += dgrep.038.clit
464464
dt_tests += dgrep.039.clit
465465
dt_tests += dgrep.040.clit
466466
dt_tests += dgrep.041.clit
467+
dt_tests += dgrep.042.clit
468+
dt_tests += dgrep.043.clit
467469

468470
dt_tests += dround.001.clit
469471
dt_tests += dround.002.clit

test/dgrep.042.clit

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/clitoris ## -*- shell-script -*-
2+
3+
$ dseq 2018-03-05 2018-05-15 -f '%F %a %c %u' | dgrep '%c=04'
4+
2018-03-22 Thu 04 4
5+
2018-03-23 Fri 04 5
6+
2018-03-24 Sat 04 6
7+
2018-03-25 Sun 04 7
8+
2018-03-26 Mon 04 1
9+
2018-03-27 Tue 04 2
10+
2018-03-28 Wed 04 3
11+
2018-04-22 Sun 04 7
12+
2018-04-23 Mon 04 1
13+
2018-04-24 Tue 04 2
14+
2018-04-25 Wed 04 3
15+
2018-04-26 Thu 04 4
16+
2018-04-27 Fri 04 5
17+
2018-04-28 Sat 04 6
18+
$
19+
20+
## dgrep.042.clit ends here

test/dgrep.043.clit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/clitoris ## -*- shell-script -*-
2+
3+
$ dseq 2018-03-05 2018-05-15 -f '%F %a %c %u' | dgrep '%u=04'
4+
2018-03-08 Thu 02 4
5+
2018-03-15 Thu 03 4
6+
2018-03-22 Thu 04 4
7+
2018-03-29 Thu 05 4
8+
2018-04-05 Thu 01 4
9+
2018-04-12 Thu 02 4
10+
2018-04-19 Thu 03 4
11+
2018-04-26 Thu 04 4
12+
2018-05-03 Thu 01 4
13+
2018-05-10 Thu 02 4
14+
$
15+
16+
## dgrep.043.clit ends here

0 commit comments

Comments
 (0)