[srvx-commits] CVS: services/src common.h,1.92,1.93 tools.c,1.127,1.128
Brought to you by:
entrope
From: Entrope <en...@us...> - 2003-10-10 02:40:30
|
Update of /cvsroot/srvx/services/src In directory sc8-pr-cvs1:/tmp/cvs-serv9917/src Modified Files: common.h tools.c Log Message: add intervalString2(): returns output buffer, allows brief output Index: common.h =================================================================== RCS file: /cvsroot/srvx/services/src/common.h,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -r1.92 -r1.93 *** common.h 1 Sep 2003 14:43:22 -0000 1.92 --- common.h 10 Oct 2003 02:40:25 -0000 1.93 *************** *** 168,172 **** #define INTERVALLEN 32 ! void intervalString(char *output, time_t interval); int getipbyname(const char *name, unsigned long *ip); --- 168,173 ---- #define INTERVALLEN 32 ! char *intervalString2(char *output, time_t interval, int brief); ! #define intervalString(OUTPUT, INTERVAL) intervalString2((OUTPUT), (INTERVAL), 0) int getipbyname(const char *name, unsigned long *ip); Index: tools.c =================================================================== RCS file: /cvsroot/srvx/services/src/tools.c,v retrieving revision 1.127 retrieving revision 1.128 diff -C2 -r1.127 -r1.128 *** tools.c 26 Sep 2003 15:16:58 -0000 1.127 --- tools.c 10 Oct 2003 02:40:25 -0000 1.128 *************** *** 605,610 **** } ! void ! intervalString(char *output, time_t interval) { static const struct { --- 605,610 ---- } ! char * ! intervalString2(char *output, time_t interval, int brief) { static const struct { *************** *** 619,629 **** { "second", 1 } }; ! int words, pos, count; ! unsigned int type; if(!interval) { ! strcpy(output, "0 seconds"); ! return; } --- 619,628 ---- { "second", 1 } }; ! unsigned int type, words, pos, count; if(!interval) { ! strcpy(output, brief ? "0s" : "0 seconds"); ! return output; } *************** *** 631,649 **** interval && (words < 2) && (type < ArrayLength(unit)); type++) { ! if(interval < unit[type].length) continue; count = interval / unit[type].length; interval = interval % unit[type].length; ! if(words == 1) ! { ! memcpy(output + pos, " and ", 5); ! pos += 5; ! } ! pos += sprintf(output + pos, "%d %s", count, unit[type].name); ! if(count != 1) output[pos++] = 's'; words++; } output[pos] = 0; } --- 630,651 ---- interval && (words < 2) && (type < ArrayLength(unit)); type++) { ! if (interval < unit[type].length) ! continue; count = interval / unit[type].length; interval = interval % unit[type].length; ! if (brief) ! pos += sprintf(output + pos, "%d%c", count, unit[type].name[0]); ! else if (words == 1) ! pos += sprintf(output + pos, " and %d %s", count, unit[type].name); ! else ! pos += sprintf(output + pos, "%d %s", count, unit[type].name); ! if (count != 1) ! output[pos++] = 's'; words++; } output[pos] = 0; + return output; } |