diff --git a/changelog b/changelog index 561c0e9..bb47f03 100644 --- a/changelog +++ b/changelog @@ -45,6 +45,7 @@ Xlist (mlist, olist, rlist, zlist, slist, tlist, qlist) Minor IBT change to list 'in-progress' IBT's in yellow Bug Fix: Webster added to the util makefile for make all (wasn't compiling) Update to webster code to hopefully fix 'tell m-w' bug + IBT's no longer read preceding spaces (body and notes), which inserts spaces every copyover [Nov 01 2010] - Rumble Fixed do_scan crash due to exits to NOWHERE. (thanks Rhade) Changed do_score experience tnl to list only mortals since LVL_IMMORT showed negative EXP. diff --git a/src/db.c b/src/db.c index 78e5b05..1d71177 100644 --- a/src/db.c +++ b/src/db.c @@ -2784,6 +2784,61 @@ char *fread_string(FILE *fl, const char *error) return (strlen(buf) ? strdup(buf) : NULL); } +/* fread_clean_string is the same as fread_string, but skips preceding spaces */ +char *fread_clean_string(FILE *fl, const char *error) +{ + char buf[MAX_STRING_LENGTH], tmp[513]; + char *point, c; + int done = 0, length = 0, templength; + + *buf = '\0'; + + do + { + if( feof( fl ) ) + { + log( "%s", "fread_clean_string: EOF encountered on read." ); + return 0; + } + c = getc( fl ); + } + while( isspace( c ) ); + ungetc( c, fl ); + + do { + if (!fgets(tmp, 512, fl)) { + log("SYSERR: fread_clean_string: format error at or near %s", error); + exit(1); + } + /* If there is a '~', end the string; else put an "\r\n" over the '\n'. */ + /* now only removes trailing ~'s -- Welcor */ + point = strchr(tmp, '\0'); + for (point-- ; (*point=='\r' || *point=='\n'); point--); + if (*point=='~') { + *point='\0'; + done = 1; + } else { + *(++point) = '\r'; + *(++point) = '\n'; + *(++point) = '\0'; + } + + templength = point - tmp; + + if (length + templength >= MAX_STRING_LENGTH) { + log("SYSERR: fread_clean_string: string too large (db.c)"); + log("%s", error); + exit(1); + } else { + strcat(buf + length, tmp); /* strcat: OK (size checked above) */ + length += templength; + } + } while (!done); + + /* allocate space for the new string and copy it */ + return (strlen(buf) ? strdup(buf) : NULL); +} + /* Read a numerical value from a given file */ int fread_number(FILE *fp) { diff --git a/src/db.h b/src/db.h index 4c94492..5b537de 100644 --- a/src/db.h +++ b/src/db.h @@ -243,6 +243,7 @@ char *fread_action(FILE *fl, int nr); int create_entry(char *name); void zone_update(void); char *fread_string(FILE *fl, const char *error); +char *fread_clean_string(FILE *fl, const char *error); int fread_number(FILE *fp); char *fread_line(FILE *fp); int fread_flags(FILE *fp, int *fg, int fg_size); diff --git a/src/ibt.c b/src/ibt.c index 3212b7f..4f32389 100755 --- a/src/ibt.c +++ b/src/ibt.c @@ -148,7 +148,7 @@ static IBT_DATA *read_ibt( char *filename, FILE *fp ) { case 'B': if (!str_cmp(word, "Body")) STRFREE(ibtData->body); - KEY("Body", ibtData->body, fread_string( fp, buf )); + KEY("Body", ibtData->body, fread_clean_string( fp, buf )); break; case 'E': @@ -185,7 +185,7 @@ static IBT_DATA *read_ibt( char *filename, FILE *fp ) if (!str_cmp(word, "Name") && ibtData->name) STRFREE(ibtData->name); if (!str_cmp(word, "Notes") && ibtData->notes) STRFREE(ibtData->notes); TXT_KEY("Name", ibtData->name, fread_line( fp )); - KEY("Notes", ibtData->notes, fread_string( fp, buf )); + KEY("Notes", ibtData->notes, fread_clean_string( fp, buf )); break; case 'R':