X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmap_objects.c;h=e35a88c49c01b692e10ea14998dc40d27d1cc591;hb=4ca4f2fc97bd592bcbbef5ed2b21b320c7336425;hp=8cb1fca18b73f41926db759dc17cf7deae66a2b6;hpb=e9282787cecf5439513dbfaedeac235cdc841e91;p=plomrogue diff --git a/src/map_objects.c b/src/map_objects.c index 8cb1fca..e35a88c 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -4,7 +4,7 @@ #include /* for malloc(), calloc(), free(), atoi() */ #include /* for uint8_t */ #include /* for FILE typedef */ -#include /* for strchr(), strlen(), memcpy() */ +#include /* for strchr(), strlen(), memcpy(), strtok() */ #include "readwrite.h" /* for [read/write]_uint[8/16/23][_bigendian]() */ #include "misc.h" /* for textfile_sizes(), find_passable_pos() */ #include "main.h" /* for World struct */ @@ -99,25 +99,25 @@ extern void init_map_object_defs(struct World * world, char * filename) struct MonsterDef * * p_p_md = &world->monster_def; char * defline = malloc(linemax); char * line_p; + char * delim = " "; while (fgets(defline, linemax, file)) { mod.next = 0; - mod.id = atoi(defline); - line_p = strchr(defline, ' ') + 1; - mod.m_or_i = * line_p; - mod.mapchar = * (line_p + 2); + mod.id = atoi(strtok(defline, delim)); + mod.m_or_i = * strtok(NULL, delim); + mod.mapchar = * strtok(NULL, delim); if ('i' == mod.m_or_i) { - line_p = line_p + 5; + line_p = strtok(NULL, delim); } else { - md.corpse_id = atoi (line_p + 4); - md.hitpoints_start = atoi (line_p + 6); - line_p = strchr (line_p + 6, ' ') + 1; + md.corpse_id = atoi(strtok(NULL, delim)); + md.hitpoints_start = atoi(strtok(NULL, delim)); + line_p = strtok(NULL, delim); } - mod.desc = calloc (strlen (line_p), sizeof(char)); - memcpy (mod.desc, line_p, strlen(line_p) - 1); + mod.desc = calloc(strlen(line_p), sizeof(char)); + memcpy(mod.desc, line_p, strlen(line_p) - 1); if ('i' == mod.m_or_i) { id.map_obj_def = mod; @@ -135,7 +135,7 @@ extern void init_map_object_defs(struct World * world, char * filename) } free(defline); fclose(file); -}; +}