Re: constified parse_duration()

2008-11-17 Thread Bruno Haible
Hi Bruce, > > So, it took 20 minutes to clean up. Attached. > > I should have tested better. I've included a test program and script now. Thanks. I have committed it into gnulib, after adding module descriptions and removing a "Written by Bruno Haible" comment from the test. 2008-11-17 Bruce

Re: parse_duration()

2008-11-17 Thread Bruno Haible
Bruce Korb wrote: > I found my round tuit: The problem with "char const" is that > strtoul takes a "char **" as its second argument. So it is > rather a bother to recast a "char const **" address to "char **" > all the time. Yes, it is a bit of a problem. You can work around it by declaring the

Re: constified parse_duration()

2008-11-16 Thread Bruce Korb
} int main (int argc, char *argv[]) { if (--argc <= 0) { fprintf (stderr, "USAGE: %s [...]", argv[0]); return 1; } do { char const * arg = *++argv; time_t res = parse_duration (arg); if (errno != 0) { fprintf (stderr, &qu

constified parse_duration()

2008-11-16 Thread Bruce Korb
f these formats: hhmmss hh:mm:ss hh H mm M ss S For the final format: * Embedded white space is allowed, but it is optional. * All of the terms are optional. Any or all-but-one may be omitted. * The terms must appear in this order. */ #ifndef GNULIB_PARSE_DURATION_H #defi

Re: parse_duration()

2008-11-16 Thread Bruce Korb
Bruce Korb wrote: Bruno Haible wrote: For this context, the right, proper and easiest solution is to say that months are 30 days and leave it at that. Hi Bruno, I found my round tuit: The problem with "char const" is that strtoul takes a "char **" as its second argument. So it is rather a

Re: parse_duration()

2008-11-05 Thread Bruce Korb
ointers as pointing to 'const' not only helps the reader > to understand that no dirty tricks are being played to the string, but > also helps avoiding bugs through typos when someone writes (*ps = 'x') > when he means (*ps == 'x'). Yep -- we're agreed. It's a Good Thing. Is it worth the bother in this context? Maybe. The answer, to me, is not completely obvious. Certainly, the entry point to parse_duration() needs to be ``char const *''. Cheers - Bruce

Re: parse_duration()

2008-11-05 Thread Bruno Haible
cter. - If locale independent, use "c-ctype.h" instead of . > >> parse_YMD(char const * pz) > >> { > >> time_t res = 0, val; > >> char * ps = strchr(pz, 'Y'); > > > > 'ps' should be declared as 'char const *&

Re: parse_duration()

2008-11-04 Thread Bruce Korb
form issues. (An old Solaris, if I remember correctly.) So, it's habit now. Changed. parse_YMD(char const * pz) { time_t res = 0, val; char * ps = strchr(pz, 'Y'); 'ps' should be declared as 'char const *', because 'pz' has const. The

Re: parse_duration()

2008-11-03 Thread Bruno Haible
Hi Bruce, > I think that there lies madness. Is the duration that someone is trying to > express necessarily starting from now? The primary intent was for stuff > like: > > timeout --duration='' some-command > > which is, indeed, meaning "from now". So, if this were to somehow b

Re: parse_duration()

2008-11-02 Thread Bruce Korb
Bruno Haible wrote: The little question remaining though is "how many seconds in a year" and, more importantly, "how many seconds in a month"? In other words, if some one in February were expecting P1M to represent a 28 day duration and a 31 day duration had it been March, um, well, Very good