[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Fri, Oct 05, 2001 at 04:55:18PM -0400, Daniel L Speyer wrote:
> I suppose I'm duplicating effort a little, but what do people think of
> this split function?
>
> char ** splitprotect(char* string,char* on){
> int i,j,n=0,l=strlen(string),q=0,b=0;
I agree with Raimar: i could be 'c_from', j 'c_to', l is at least 'len',
q is 'within_quotes', b is 'bracket_level'.
> char** out;
> for(i=0;i<l;i++){
> if (string[i]=='"')
> q=!q;
> if (q)
> continue;
There's no way to use a " within a quotes?
I'm not sure we need it (directory names may contain "s) but if we do,
the "" convention or support for \ must be added.
> if (string[i]=='{'){
> b++;
> continue;
> }
What's the assumption on bracket matching vs. next line continuation?
Do you assume the entire command is already in the buffer? How do
yopu know how many lines to fetch before parsing the brackets?
> if (string[i]=='}'){
> b--;
> continue;
> }
> if (!b){
> for(j=0;j<strlen(on);j++){
> if (string[i]==on[j]){
> string[i]=0;
> n++;
> }
(Using char*s instead of char[] indexes is fine with me.)
> }
> }
> }
> out=(char**)malloc((n+2)*sizeof(char*));
I thought the list agreed not to do this. Return the modified input buffer.
> *out=string;
> j=1;
> for(i=0;i<l;i++){
> if (!string[i])
> out[j++]=string+i+1;
> }
> out[n+1]=0;
> return(out);
> }
>
> It doesn't do regexps, but I don't think we'll need them.
Agreed.
> It does handle
> multiple split characters.
So '=' could be used - nice, except you'll lose the information in error
messages, so I'm not sure this is desirable.
> It only allocates memory for the specific
> array it returns, and it does mangle the input string.
If you mangle it, might as well use it to rturn the result.
> I think this is
> the function I would want if I were writing the entire parser. If not,
> well, I didn't put all that much work into it anayway :)
>
> --Daniel Speyer
> "May the /src be with you, always"
Shouldn't that be the /usr/src ?
--
Reinier
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), (continued)
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Arien Malec, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Arien Malec, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Daniel L Speyer, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Daniel L Speyer, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Justin Moore, 2001/10/22
[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Daniel L Speyer, 2001/10/05
|
|