Re: [Parser-devel] [token.c] A new functionality
Status: Beta
Brought to you by:
jineshkj
From: Noam P. <npo...@uw...> - 2006-10-03 03:33:46
|
Jinesh K J wrote: > Hi Noam, > > As I've mentioned in the previous mail, I'm working on integrating > gettoken() and puttoken() into the trunk. Mean while I would like to > have one more functionality as given below: > > char *groupname(char *input) > > Here, input would be a string which containts a group name within > '[]'. Examples for input are given below: > > @[group1]@ -> @group1@ > @[group 1]@ -> @group 1@ > > Please note that '[' and ']' are included in the input(so that i've > used '@' as cover). ie, What ever that comes in between those square > brackets are to be extracted as a single token. But, even inside the > square brackets, quoted values must be possible. For example: > > @["group"]@ -> @group@ > @["group 1"]@ -> @group 1@ > @["group [H]"]@ -> @group [H]@ > @[group "[H]"]@ -> @group [H]@ > @[group "[H\\T]"]@ -> @group [H\T]@ > ... > > All the rules for quoted values we used for gettoken() are valid here > also. So, I wish if we could use gettoken here too. > Ok, I uploaded my first attempt, but I'm wondering whether the input always has '[' and ']'? Can there be stuff outside the brackets? eg @[group 1] hello@ -> @group 1@ > Also, in token.c, all the memory allocation functions' return value > are unchecked. For example, in puttoken() after calling calloc(), str > is not checked for NULL. > > char *str = calloc(2+1, sizeof(char)); > str[0] = str[1] = '"'; > str[2] = '\0'; > return str; > > > I wish if we can just do an exit(-1), whenever such an error occurs. > I put that in, but isn't there any better way to signal errors? Noam |