From d769b7b4ad0aee07b9dddcb517ea85f93543ba12 Mon Sep 17 00:00:00 2001 From: tobiasb Date: Sun, 25 Jul 2004 14:21:13 +0000 Subject: [PATCH] New isdnrep option -m [*|/]number. It multiplies or divide the cost of each call by the given number. `-m/1.16' for example displays the costs without the German `Umsatzsteuer'. --- isdnlog/isdnrep/ChangeLog | 7 +++++++ isdnlog/isdnrep/isdnrep.1.in | 10 ++++++++-- isdnlog/isdnrep/isdnrep.c | 20 +++++++++++++++++++- isdnlog/isdnrep/isdnrep.h | 16 +++++++++++++++- isdnlog/isdnrep/rep_main.c | 32 ++++++++++++++++++++++++++++++-- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/isdnlog/isdnrep/ChangeLog b/isdnlog/isdnrep/ChangeLog index c02a468c..4e9677a8 100644 --- a/isdnlog/isdnrep/ChangeLog +++ b/isdnlog/isdnrep/ChangeLog @@ -1,3 +1,10 @@ +2004-07-25 Tobias Becker + + * rep_main.c (parse_options): New option `-m', multiplies or divides + connection costs before displaying + * isdnrep.h (modcost): New global variable for `-m' option. + * isdnrep.c (print_header, set_caller_infos): Apply `-m' option. + 2004-07-24 Tobias Becker * rep_main.c (parse_options): New option `-x', selects calls by hour diff --git a/isdnlog/isdnrep/isdnrep.1.in b/isdnlog/isdnrep/isdnrep.1.in index 43c77745..03cc10f5 100644 --- a/isdnlog/isdnrep/isdnrep.1.in +++ b/isdnlog/isdnrep/isdnrep.1.in @@ -1,5 +1,5 @@ -.\" $Id: isdnrep.1.in,v 1.7 2004/07/24 17:58:06 tobiasb Exp $ -.\" CHECKIN $Date: 2004/07/24 17:58:06 $ +.\" $Id: isdnrep.1.in,v 1.8 2004/07/25 14:21:13 tobiasb Exp $ +.\" CHECKIN $Date: 2004/07/25 14:21:13 $ .TH isdnrep 1 "@MANDATE_ISDNREP@" "ISDN 4 Linux @I4LVERSION@" "Linux System Commands" .PD 0 @@ -241,6 +241,12 @@ B Like b but allow all providers, not only the booked. .RE +.TP +\fB\-m\fR[\fB*\fR|\fB/\fR]\fInumber\fB modify call costs\fR +Multiply (*) or divide (/) the stored or recalculated call costs +by number before displaying them. If neither * nor / is given, +multiply. + .TP .B \-wX WWW isdnrep can give its output in HTML format; this is switched on with diff --git a/isdnlog/isdnrep/isdnrep.c b/isdnlog/isdnrep/isdnrep.c index bbc61266..1973b85a 100644 --- a/isdnlog/isdnrep/isdnrep.c +++ b/isdnlog/isdnrep/isdnrep.c @@ -1,4 +1,4 @@ -/* $Id: isdnrep.c,v 1.100 2004/07/24 17:58:06 tobiasb Exp $ +/* $Id: isdnrep.c,v 1.101 2004/07/25 14:21:13 tobiasb Exp $ * * ISDN accounting for isdn4linux. (Report-module) * @@ -24,6 +24,11 @@ * * * $Log: isdnrep.c,v $ + * Revision 1.101 2004/07/25 14:21:13 tobiasb + * New isdnrep option -m [*|/]number. It multiplies or divide the cost of + * each call by the given number. `-m/1.16' for example displays the costs + * without the German `Umsatzsteuer'. + * * Revision 1.100 2004/07/24 17:58:06 tobiasb * New isdnrep options: `-L:' controls the displayed call summaries in the * report footer. `-x' displays only call selected or not deselected by @@ -2200,6 +2205,11 @@ static int print_header(int lday) } print_line2(F_TEXT_LINE, "%s", s); } + + /* TODO: consistent terminology. fees vs. costs (tobiasb|200407) */ + if (modcost.mode) + print_line2(F_TEXT_LINE, "All displayed costs have been %s by %s.", + modcost.mode == 2 ? "divided" : "multiplied", modcost.numstr); } else @@ -2724,6 +2734,14 @@ static int set_caller_infos(one_call *cur_call, char *string, time_t from) */ repair(cur_call); + if (cur_call->pay != 0.0 && modcost.mode) + { + if (modcost.mode == 1) + cur_call->pay *= modcost.number; + else if (modcost.mode == 2) + cur_call->pay /= modcost.number; + } + return(rc); } diff --git a/isdnlog/isdnrep/isdnrep.h b/isdnlog/isdnrep/isdnrep.h index 31a099ed..c9fb4579 100644 --- a/isdnlog/isdnrep/isdnrep.h +++ b/isdnlog/isdnrep/isdnrep.h @@ -1,4 +1,4 @@ -/* $Id: isdnrep.h,v 1.23 2004/07/24 17:58:06 tobiasb Exp $ +/* $Id: isdnrep.h,v 1.24 2004/07/25 14:21:13 tobiasb Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnrep.h,v $ + * Revision 1.24 2004/07/25 14:21:13 tobiasb + * New isdnrep option -m [*|/]number. It multiplies or divide the cost of + * each call by the given number. `-m/1.16' for example displays the costs + * without the German `Umsatzsteuer'. + * * Revision 1.23 2004/07/24 17:58:06 tobiasb * New isdnrep options: `-L:' controls the displayed call summaries in the * report footer. `-x' displays only call selected or not deselected by @@ -218,6 +223,14 @@ typedef struct { char *input; /* input from command line after -r[vp] */ } RECALC; +/*****************************************************************************/ + +typedef struct { + int mode; /* 0 no action, 1 multiply, 2 divide */ + char *numstr; /* number as string, part of given option */ + double number; /* number for multiplication or division */ +} MODCOST; + /*****************************************************************************/ /* isdnrep.c defines _REP_FUNC_C_, rep_main.c defines _ISDNREP_C_, ... */ #ifdef _REP_FUNC_C_ @@ -270,6 +283,7 @@ _EXTERN int preselect _SET_33; #endif _EXTERN int summary _SET_0; _EXTERN RECALC recalc; /* initiation done in main */ +_EXTERN MODCOST modcost; /* initiation done in main */ _EXTERN int sel_sums[3] _SET_ARRAY_0; _EXTERN bitfield days[2] _SET_ARRAY_0; _EXTERN bitfield hours[2] _SET_ARRAY_0; diff --git a/isdnlog/isdnrep/rep_main.c b/isdnlog/isdnrep/rep_main.c index 28a6f318..cb72f116 100644 --- a/isdnlog/isdnrep/rep_main.c +++ b/isdnlog/isdnrep/rep_main.c @@ -1,4 +1,4 @@ -/* $Id: rep_main.c,v 1.18 2004/07/24 17:58:06 tobiasb Exp $ +/* $Id: rep_main.c,v 1.19 2004/07/25 14:21:13 tobiasb Exp $ * * ISDN accounting for isdn4linux. (Report-module) * @@ -20,6 +20,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: rep_main.c,v $ + * Revision 1.19 2004/07/25 14:21:13 tobiasb + * New isdnrep option -m [*|/]number. It multiplies or divide the cost of + * each call by the given number. `-m/1.16' for example displays the costs + * without the German `Umsatzsteuer'. + * * Revision 1.18 2004/07/24 17:58:06 tobiasb * New isdnrep options: `-L:' controls the displayed call summaries in the * report footer. `-x' displays only call selected or not deselected by @@ -306,7 +311,7 @@ static char fnbuff[512] = ""; static char usage[] = "%s: usage: %s [ -%s ]\n"; static char wrongdate[] = "unknown date: %s\n"; static char wrongxopt[] = "error in -x option starting at: %s\n"; -static char options[] = "abcd:f:hinop:r:s:t:uvw:x:EF:L:M:NR:SV"; +static char options[] = "abcd:f:him:nop:r:s:t:uvw:x:EF:L:M:NR:SV"; static char *linefmt = ""; static char *htmlreq = NULL; static char *phonenumberarg = NULL; @@ -326,6 +331,7 @@ int main(int argc, char *argv[], char *envp[]) recalc.mode = '\0'; recalc.prefix = UNKNOWN; recalc.input = NULL; recalc.count = recalc.unknown = recalc.cheaper = 0; + modcost.mode = 0; select_summaries(sel_sums, NULL); /* default: all summaries */ /* we don't need this at the moment: @@ -340,6 +346,8 @@ int main(int argc, char *argv[], char *envp[]) * set_msnlist after readconfig. */ + /* TODO: parse_options may print to stdout regardless a missing + * Content-Type header. (tobiasb|200407) */ if ((c=parse_options(argc, argv, myname) > 0)) return c; @@ -532,6 +540,26 @@ static int parse_options(int argc, char *argv[], char *myname) case 'c' : do_defopts = 0; break; + case 'm' : modcost.mode = (*optarg =='/') ? 2 : 1; + modcost.numstr = strdup(optarg); + if (*optarg == '*' || *optarg == '/') + modcost.numstr++; + ptr = NULL; + modcost.number = strtod(modcost.numstr, &ptr); + if (modcost.numstr == ptr) + { + printf("no number in -m option: %s\n", modcost.numstr); + return 1; + } + if (modcost.mode == 2 && modcost.number == 0.0) + { + printf("division by 0 as requested in -m option not allowed.\n"); + return 1; + } + if (ptr && *ptr) + *ptr = 0; + break; + case '?' : printf(usage, argv[0], argv[0], options); return(1); } /* switch */