mirror of
https://github.com/tbamud/tbamud.git
synced 2026-01-23 01:16:09 +01:00
code cleanup. Remove inline block, make variable names more understandable.
Ref https://www.tbamud.com/forum/4-development/4525-confused-over-piece-of-code-in-parse-room
This commit is contained in:
parent
4967f744d4
commit
1af3c68d5c
1 changed files with 20 additions and 11 deletions
31
src/db.c
31
src/db.c
|
|
@ -1239,6 +1239,24 @@ static bitvector_t asciiflag_conv_aff(char *flag)
|
|||
return (flags);
|
||||
}
|
||||
|
||||
/* Fix for crashes in the editor when formatting. E-descs are assumed to
|
||||
* end with a \r\n. -Welcor */
|
||||
void ensure_newline_terminated(struct extra_descr_data* new_descr) {
|
||||
char *with_term, *end;
|
||||
|
||||
if (new_descr->description == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
end = strchr(new_descr->description, '\0');
|
||||
if (end > new_descr->description && *(end - 1) != '\n') {
|
||||
CREATE(with_term, char, strlen(new_descr->description) + 3);
|
||||
sprintf(with_term, "%s\r\n", new_descr->description); /* snprintf ok : size checked above*/
|
||||
free(new_descr->description);
|
||||
new_descr->description = with_term;
|
||||
}
|
||||
}
|
||||
|
||||
/* load the rooms */
|
||||
void parse_room(FILE *fl, int virtual_nr)
|
||||
{
|
||||
|
|
@ -1346,17 +1364,8 @@ void parse_room(FILE *fl, int virtual_nr)
|
|||
CREATE(new_descr, struct extra_descr_data, 1);
|
||||
new_descr->keyword = fread_string(fl, buf2);
|
||||
new_descr->description = fread_string(fl, buf2);
|
||||
/* Fix for crashes in the editor when formatting. E-descs are assumed to
|
||||
* end with a \r\n. -Welcor */
|
||||
{
|
||||
char *end = strchr(new_descr->description, '\0');
|
||||
if (end > new_descr->description && *(end-1) != '\n') {
|
||||
CREATE(end, char, strlen(new_descr->description)+3);
|
||||
sprintf(end, "%s\r\n", new_descr->description); /* snprintf ok : size checked above*/
|
||||
free(new_descr->description);
|
||||
new_descr->description = end;
|
||||
}
|
||||
}
|
||||
ensure_newline_terminated(new_descr);
|
||||
|
||||
new_descr->next = world[room_nr].ex_description;
|
||||
world[room_nr].ex_description = new_descr;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue