diff --git a/src/core/handlers.c b/src/core/handlers.c index 1d2e0a7..bbb95aa 100644 --- a/src/core/handlers.c +++ b/src/core/handlers.c @@ -58,7 +58,11 @@ GString *command = g_string_new(""); GString *output = g_string_new(""); - g_string_printf(command, "%s %s 10 it %d", reportScript, csvfile, days); // TODO variable number of expenses, daily ecc + if(days > 0) { + g_string_printf(command, "%s %s 10 it %d", reportScript, csvfile, days); + } else { + g_string_printf(command, "%s %s 10 it", reportScript, csvfile); + } fp = popen(command->str,"r"); while( getline(&buf, &cap, fp) != -1 ){ diff --git a/src/expenses/grammar.y b/src/expenses/grammar.y index ca8b535..8863b52 100644 --- a/src/expenses/grammar.y +++ b/src/expenses/grammar.y @@ -88,14 +88,14 @@ ; /* convert a timestamp into num. of days. No calendar taken into account */ -days: /* empty */ { $$ = (BotReport) { .days = 1 }; } +days: /* empty */ { $$ = (BotReport) { .days = -1 }; } | TOK_TS_DAY tn { $$ = (BotReport) { .days = $2 }; } | TOK_TS_WEEK tn { $$ = (BotReport) { .days = 7*$2 }; } | TOK_TS_MONTH tn { $$ = (BotReport) { .days = 31*$2 }; } | TOK_TS_YEAR tn { $$ = (BotReport) { .days = 365*$2 }; } ; -tn: /* empty */ { $$ = 1; } +tn: /* empty */ { $$ = -1; } | TOK_INT { $$ = $1; } ; %% diff --git a/src/expenses/lex.l b/src/expenses/lex.l index 52097b3..8848bc0 100644 --- a/src/expenses/lex.l +++ b/src/expenses/lex.l @@ -22,10 +22,10 @@ del|storno yylval.cmd=BOT_CMD_DELETE; return TOK_CMD_DEL; reminder|ricordami yylval.cmd=BOT_CMD_REMINDER; return TOK_CMD_REMINDER; report yylval.cmd=BOT_CMD_REPORT; return TOK_CMD_REPORT; -day|giorno|giorni yylval.tsp=BOT_TS_DAY; return TOK_TS_DAY; -week|sett|settimana|settimane yylval.tsp=BOT_TS_WEEK; return TOK_TS_WEEK; -month|mese|mesi yylval.tsp=BOT_TS_MONTH; return TOK_TS_MONTH; -year|anno|anni yylval.tsp=BOT_TS_YEAR; return TOK_TS_YEAR; +day|days|giorno|giorni yylval.tsp=BOT_TS_DAY; return TOK_TS_DAY; +week|weeks|sett|settimana|settimane yylval.tsp=BOT_TS_WEEK; return TOK_TS_WEEK; +month|months|mese|mesi yylval.tsp=BOT_TS_MONTH; return TOK_TS_MONTH; +year|years|anno|anni yylval.tsp=BOT_TS_YEAR; return TOK_TS_YEAR; [a-zA-Z0-9_]+ yylval.str=g_string_new(yytext); return TOK_USER; /* user can't have special characters */ \"[^\n]+\" yylval.str=g_string_new(yytext); return TOK_STR; /* anything excepts '\n'; needs to be at the bottom of flex rules here */ [ \t]+ /* ignore whitespace */; diff --git a/src/expenses/task.c b/src/expenses/task.c index ce0ecaa..2b0988f 100644 --- a/src/expenses/task.c +++ b/src/expenses/task.c @@ -10,7 +10,7 @@ /* protected globals */ static BotCommand g_lastCommand = BOT_CMD_NONE; -static BotReport g_report = { 1 }; +static BotReport g_report = { -1 }; static BotReminder *g_tmp_lastReminder = NULL; /* store a thread per user */