/* err_try_fgets.c */
-#include <stdint.h> /* uint8_t, uint32_t */
+#include <stdint.h> /* uint8_t, uint32_t, UINT8_MAX */
#include <stdio.h> /* FILE, sprintf() */
+#include <stdlib.h> /* atoi() */
#include <string.h> /* strlen(), strchr(), strcmp() */
#include "../common/readwrite.h" /* try_fgets() */
#include "../common/rexit.h" /* exit_err() */
char * err_int = "Expected valid positive or negative integer number.";
char * err_full = "Hit non-empty line where empty line was expected.";
char * err_delim = "Expected proper delimiter, found something else.";
+ char * err_uint8 = "Value is too large. Must be 255 or less.";
char * f_name = "err_try_fgets()";
line[0] = '\0';
try_fgets(line, linemax + 1, file, f_name);
err_line(strlen(line) < 2 && ('-' == line[i] || '+' == line[i]),
line, context, err_int);
}
+ err_line(strchr(test, '8') && atoi(line) > UINT8_MAX, line, context,
+ err_uint8);
}
#include "map_object_actions.h"
#include <stddef.h> /* NULL */
-#include <stdint.h> /* uint8_t, uint16_t, UINT8_MAx */
+#include <stdint.h> /* uint8_t, uint16_t */
#include <stdio.h> /* sprintf(), ungetc() */
#include <stdlib.h> /* free(), atoi() */
#include <string.h> /* strlen(), strcmp(), memcpy(), strncmp() */
char line[linemax + 1];
struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts;
char * context = "Failed reading map object actions config file. ";
- char * err_toolarge = "Value is too large.";
- char * err_uniq = "Declaration of ID already used.";
+ char * err_uniq = "Declaration of ID already used.";
reset_err_try_fgets_counter();
while (1)
{
}
exit_trouble(EOF == ungetc(test_for_end, file), f_name, "ungetc()");
struct MapObjAct * moa = try_malloc(sizeof(struct MapObjAct), f_name);
- err_try_fgets(line, linemax, file, context, "nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "nfi8");
moa->id = atoi(line);
struct MapObjAct * moa_test = world.map_obj_acts;
for (; NULL != moa_test; moa_test = moa_test->next)
{
err_line(moa->id == moa_test->id, line, context, err_uniq);
}
- err_try_fgets(line, linemax, file, context, "0nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "0nfi8");
moa->effort = atoi(line);
err_try_fgets(line, linemax, file, context, "0nf");
line[strlen(line) - 1] = '\0';
#include "map_objects.h"
#include <stddef.h> /* NULL */
#include <stdio.h> /* FILE typedef */
-#include <stdint.h> /* uint8_t, uint16_t, UINT8_MAX */
+#include <stdint.h> /* uint8_t, uint16_t */
#include <stdlib.h> /* free(), atoi() */
#include <string.h> /* strlen(), memcpy(), memset() */
#include "../common/err_try_fgets.h" /* err_try_fgets(), err_line(),
{
char * f_name = "init_map_object_defs()";
char * context = "Failed reading map object definitions file. ";
- char * err_toolarge = "Value is too large.";
- char * err_uniq = "Declaration of ID already used.";
+ char * err_uniq = "Declaration of ID already used.";
FILE * file = try_fopen(world.path_map_obj_defs, "r", f_name);
uint32_t linemax = textfile_width(file);
struct MapObjDef ** last_mod_ptr_ptr = &world.map_obj_defs;
exit_trouble(EOF == ungetc(test_for_end, file), f_name, "ungetc()");
struct MapObjDef * mod = try_malloc(sizeof(struct MapObjDef), f_name);
mod->next = NULL;
- err_try_fgets(line, linemax, file, context, "nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "nfi8");
mod->id = atoi(line);
struct MapObjDef * mod_test = world.map_obj_defs;
for (; NULL != mod_test; mod_test = mod_test->next)
{
err_line(mod->id == mod_test->id, line, context, err_uniq);
}
- err_try_fgets(line, linemax, file, context, "0nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "0nfi8");
mod->corpse_id = atoi(line);
err_try_fgets(line, linemax, file, context, "0nfs");
mod->char_on_map = line[0];
- err_try_fgets(line, linemax, file, context, "0nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "0nfi8");
mod->lifepoints = atoi(line);
err_try_fgets(line, linemax, file, context, "0nf");
line[strlen(line) - 1] = '\0';
mod->name = try_malloc(strlen(line) + 1, f_name);
memcpy(mod->name, line, strlen(line) + 1);
- err_try_fgets(line, linemax, file, context, "0nfi");
- err_line(atoi(line) > UINT8_MAX, line, context, err_toolarge);
+ err_try_fgets(line, linemax, file, context, "0nfi8");
mod->consumable = atoi(line);
* last_mod_ptr_ptr = mod;
last_mod_ptr_ptr = &mod->next;