On Wed, 29 May 1996, Ron Hensley wrote:
> [big snip]
>
> if (POOFIN(ch) != NULL) {
> fprintf(file,"|1\n");
> fprintf(file,"%s\n",POOFIN(ch));
> }
> if (POOFOUT(ch) != NULL) {
> fprintf(file,"|2\n");
> fprintf(file,"%s\n",POOFOUT(ch));
> }
In my opinion, it'd be nicer to use a scheme like:
<fieldname> <value>
So you'd have:
Poofin appears, levitating before you.~
Poofout rises into the air and vanishes.~
Easy to rewrite it like that, just make sure you smash_tilde the
string before writing it out and append a tilde (~) before the '\n'. Now
we have only one line in the if statement :)
if (POOFOUT(ch))
fprintf(file, "%-15s %s~", "Poofout", POOFOUT(ch));
> [snip]
>
> while (fgets(temp_buf,80,file)) {
> /* Yeah i was lazy at the time, this could be a strcmp()
> if (temp_buf[0] == '|' && temp_buf[1] == '1') {
> fgets(temp_buf,80,file);
> sprintf(buf,"poofin %s", temp_buf);
> command_interpreter(ch, buf);
> }
> if (temp_buf[0] == '|' && temp_buf[1] == '2') {
> fgets(temp_buf,80,file);
> sprintf(buf, "poofout %s", temp_buf);
> command_interpreter(ch, buf);
> }
> }
> fclose(file);
> }
I would rewrite this using the function to get strings ended with
a tilde (the name of which eludes me right now), do a one_argument, then
do:
char field [15];
tmp_buf = one_argument(tmp_buf, field);
skip_spaces(&tmp_buf);
if (!str_cmp(field, "poofin"))
GET_POOFIN(ch) = str_dup(tmp_buf);
else if (!str_cmp(field, "poofout"))
GET_POOFOUT(ch) = str_dup(tmp_buf);
/* add extra fields like:
else if (!str_cmp(field, "per")) {
ch->real_abils.per = atoi(tmp_buf);
ch->aff_abils = ch->real_abils;
} else if (!str_cmp(field, "prompt"))
GET_PROMPT(ch) = str_dup(tmp_buf);
.
.
.
*/
Makes it easier. Sorry I don't remember the name of the function
that gets strings from files terminated by a tilde (~), haven't looked at
the db.c file in a while, but it's used in a lot of places in there.
This archive was generated by hypermail 2b30 : 12/18/00 PST