Index: stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.188 diff -u -r1.188 stdinhand.c --- stdinhand.c 2001/08/27 06:41:21 1.188 +++ stdinhand.c 2001/08/30 22:00:00 @@ -65,6 +65,7 @@ static void show_list(struct connection *caller, char *arg); static void show_connections(struct connection *caller); static void set_ai_level(struct connection *caller, char *name, int level); +static int split(char *buf, int len, char **args, int max_args, char *toks); static const char horiz_line[] = "------------------------------------------------------------------------------"; @@ -2404,6 +2405,61 @@ } else { cmd_reply_no_such_player(cmd, caller, name, match_result); } +} + +/****************************************************************** + Generic split function. Takes a buffer, and buffer length, and + returns the number of arguments found. To be backwards compatible + it will split on either whitespace or a '=' sign. Will split on any + characters in 'toks'. + + NOTE: The array of char ptrs must be allocated by the caller. + NOTE: This will insert \0's into the original string. Don't call + this function unless it's ok if the original string changes. +******************************************************************/ +static int split(char *buf, int len, char **args, int max_args, char *toks) +{ + int i; + int nfound; + char *my_toks; + + if((buf[0] == '#') || (buf[0] == '\n')) /* Comment or blank line */ + return 0; + + /* Remove all leading whitespace and toks. + * Make sure it doesn't segfault if we were passed a NULL toks. */ + i = 0; + my_toks = toks ? toks : ""; + while((i < len) && (isspace(buf[i]) || strchr(my_toks, buf[i]))) + i++; + + /* Are we at the end? */ + if(i == len) + return 0; + + /* Split this puppy up. */ + nfound = 0; + args[nfound++] = buf+i; + while(nfound < max_args) { + /* Get through this word */ + while((i < len) && !isspace(buf[i]) && !strchr(my_toks, buf[i])) + i++; + + if(i == len) /* Are we done? */ + return nfound; + + /* Get rid of any whitespace or characters in my_toks */ + while((i < len) && (isspace(buf[i]) || strchr(my_toks, buf[i]))) + buf[i++] = '\0'; + + /* Are we done, or are we at a new word? */ + if(i == len) + return nfound; + else + args[nfound++] = buf+i; + } + + return nfound; } static void crash_and_burn(struct connection *caller)