Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
Home

[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]
To: Freeciv Developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
From: Justin Moore <justin@xxxxxxxxxxx>
Date: Fri, 5 Oct 2001 16:36:58 -0400 (EDT)

   Wow.  Ya disappear for a week or two and come back to a flamefest
between Ross and Raimar.  But I can't really say that I'm surprised. :)

> > >> split should treat the buffer it was handed as working memory, return
> > >> pointers into the parsed string elements, and let the caller deal with
> > >> ALL memory issues.
> > >
> > >Ok since there is so much resistance: we implement the strdup/free in
> > >split if it turns out that every caller of split will copy the string
> > >because it is needed later. Ok?
> >
> > A better way is to just implement split to take a buffer and do its
> > splitting thing in a reasonable and efficient manner.
>
> There should be a big fat comment about the lifetime of the result and
> memory issues if split() is be done this way.

   I'll comment split to indicate that is has strtok-like changing of the
buffer you pass to it.  As for the whitespace issue, for sake of speed and
coding simplicity, I'm going with Raimar's suggestion for enums that get
passed to split.  Hence, the current (final) API is:

int split(const char *toks, char *buf, char *args[], int max_args,
          int handle_whitespace);

where handle_whitespace could be

#define REMOVE_NO_WHITESPACE      0x0
#define REMOVE_PADDING_WHITESPACE 0x1
#define REMOVE_SPLIT_WHITESPACE   0x2

unless someone has better ideas for names. (And, no, I can't believe I
just asked an open question like that.)

   I'll work on the server parsing stuff when I get a chance.  I plan to
overhaul the basic framework, and people can take it from there as to how
specific functions will be implemented.

-jdm

Department of Computer Science, Duke University, Durham, NC 27708-0129
Email:  justin@xxxxxxxxxxx



[Prev in Thread] Current Thread [Next in Thread]