diff options
author | Bardur Arantsson <bardur@scientician.net> | 2013-03-27 08:26:51 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2013-09-27 14:46:42 +0200 |
commit | 45d2d5c39869cce42d0f2b7b5fc65c5a0d7014bb (patch) | |
tree | 5350ee89bcbe3b29069e671395039ec85134a6d9 /src | |
parent | 67dd3b38ff1311dbd3a37895f6bf0e81b0341bbf (diff) |
Constness fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/init2.c | 2 | ||||
-rw-r--r-- | src/loadsave.c | 85 |
2 files changed, 51 insertions, 36 deletions
diff --git a/src/init2.c b/src/init2.c index 50329509..f5001e0d 100644 --- a/src/init2.c +++ b/src/init2.c @@ -2398,7 +2398,7 @@ void init_angband(void) FILE *fp; - char *news_file; + const char *news_file; char buf[1024]; diff --git a/src/loadsave.c b/src/loadsave.c index f68d974c..818cbb62 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -34,7 +34,7 @@ static void morejunk(void); static bool_ do_inventory(int); static bool_ do_dungeon(int, bool_); static void do_grid(int); -static void my_sentinel(char *, u16b, int); +static void my_sentinel(const char *, u16b, int); static void do_ver_s16b(s16b *, u32b, s16b, int); @@ -1138,39 +1138,49 @@ static void do_s32b(s32b *ip, int flag) do_u32b((u32b *)ip, flag); } -static void do_string(char *str, int max, int flag) -/* Max is ignored for writing */ +static void save_string(const char *str) { - if (flag == LS_LOAD) + while (*str) { - int i; + do_byte((byte*)str, LS_SAVE); + str++; + } + do_byte((byte*)str, LS_SAVE); +} - /* Read the string */ - for (i = 0; TRUE; i++) - { - byte tmp8u; +static void load_string(char *str, int max) +{ + int i; - /* Read a byte */ - do_byte(&tmp8u, LS_LOAD); + /* Read the string */ + for (i = 0; TRUE; i++) + { + byte tmp8u; - /* Collect string while legal */ - if (i < max) str[i] = tmp8u; + /* Read a byte */ + do_byte(&tmp8u, LS_LOAD); - /* End of string */ - if (!tmp8u) break; - } - /* Terminate */ - str[max - 1] = '\0'; + /* Collect string while legal */ + if (i < max) str[i] = tmp8u; + + /* End of string */ + if (!tmp8u) break; + } + /* Terminate */ + str[max - 1] = '\0'; +} + +static void do_string(char *str, int max, int flag) +/* Max is ignored for writing */ +{ + if (flag == LS_LOAD) + { + load_string(str, max); return; } if (flag == LS_SAVE) { - while (*str) - { - do_byte((byte*)str, flag); - str++; - } - do_byte((byte*)str, flag); /* Output a terminator */ + save_string(str); return; } printf("FATAL: do_string passed flag %d\n", flag); @@ -1377,31 +1387,36 @@ static void do_item(object_type *o_ptr, int flag) { char buf[128]; /* Inscription */ - do_string(buf, 128, LS_LOAD); - /* Save the inscription */ - if (buf[0]) o_ptr->note = quark_add(buf); - - do_string(buf, 128, LS_LOAD); - if (buf[0]) o_ptr->art_name = quark_add(buf); + load_string(buf, 128); + if (buf[0]) + { + o_ptr->note = quark_add(buf); + } + /* Artifact name */ + load_string(buf, 128); + if (buf[0]) + { + o_ptr->art_name = quark_add(buf); + } } if (flag == LS_SAVE) { /* Save the inscription (if any) */ if (o_ptr->note) { - do_string((char *)quark_str(o_ptr->note), 0, LS_SAVE); + save_string(quark_str(o_ptr->note)); } else { - do_string("", 0, LS_SAVE); + save_string(""); } if (o_ptr->art_name) { - do_string((char *)quark_str(o_ptr->art_name), 0, LS_SAVE); + save_string(quark_str(o_ptr->art_name)); } else { - do_string("", 0, LS_SAVE); + save_string(""); } } @@ -3137,7 +3152,7 @@ static void do_grid(int flag) } } -static void my_sentinel(char *place, u16b value, int flag) +static void my_sentinel(const char *place, u16b value, int flag) /* This function lets us know exactly where a savefile is broken by reading/writing conveniently a sentinel at this spot */ |