From: James Turner Subject: Circlemud design issues Sammy writes: > I hate to be rude, but rather than argue till you're blue in the face that > these are wasteful functions that would be better off replaced by a "pair > of functions", why not show us those two functions? One of the pair is the standard one_argument (and its variation one_word, which I plan on incorporating into one single function). Below is the function that I described before. Basically, it takes a string and breaks it up into words. It respects single and double quotes, though it probably needs a parameter to specify whether to only break on whitespaces. The macro VALID_STRING I define elsewhere (gasp, yes a macro, the reasoning being that it is very type independant and doesn't depend on the internals of any data structure). The function as-is is not thread safe; however, that can be changed without too much work. After split_argument is the an example of its use. The function itself isn't important (it is part of my quest tracking code for autoquests, which interfaces with DG scripts). Also, note I use send_to_charf from George's site, but only in the do_showquests function. The split_argument function should work on any system, provided the defines and structure are in place. #define VALID_STRING(s) ((s) && *(s)) #define MAX_PARAMS 128 char split_results[MAX_PARAMS][MAX_INPUT_LENGTH]; int split_argument(char *arg) { int i, j, n; char stopchar; for (i = 0; i < MAX_PARAMS; i++) split_results[i][0] = 0; if (!VALID_STRING(arg)) return 0; while(*arg && isspace(*arg)) arg++; if (!VALID_STRING(arg)) return 0; n = 0; for(i = 0; arg[i] != 0; i++) { while(arg[i] && isspace(arg[i])) i++; if (arg[i] == '"' || arg[i] == '\'') { stopchar = arg[i]; i++; } else stopchar = ' '; for (j = 0; arg[i+j] && (arg[i+j] != stopchar); j++) split_results[n][j] = arg[i+j]; if (arg[i+j] == stopchar) i++; split_results[n][j] = 0; i += j; n++; } return n; } void do_setquests(CHAR_DATA *ch, char *argument, int cmd, int subcmd) { CHAR_DATA *vict; int n, quest, val; n = split_argument(argument); if (n < 3) { send_to_charf(ch, "Usage: setquests \r\n"); return; } vict = get_char_vis(ch, split_results[0]); quest = atoi(split_results[1]); val = atoi(split_results[2]); if (!vict || IS_NPC(vict)) { send_to_char("No such player is online.\r\n", ch); return; } if ((quest < 1) || (quest > NUM_QUESTS)) { send_to_charf(ch, "The quest number should be between 1 and %d.\r\n", NUM_Q UESTS); return; } setQuestStatus(vict, quest - 1, val); send_to_charf(ch, "%s's quest %d now is %d.\r\n", GET_NAME(vict), quest, val) ; } -- James Turner turnerjh@xtn.net http://www.vuse.vanderbilt.edu/~turnerj1/