aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-02-15 15:00:31 +0000
committerWillem Jan Palenstijn2009-02-15 15:00:31 +0000
commita988ed0d0fcec9f7d2556400a9d39f0938c0bc87 (patch)
tree1681734b35665178ddb04012934e06e73fbfc0f6 /engines
parente1b36cf2cd8a78782c9e177cb6f06c290bfeb585 (diff)
downloadscummvm-rg350-a988ed0d0fcec9f7d2556400a9d39f0938c0bc87.tar.gz
scummvm-rg350-a988ed0d0fcec9f7d2556400a9d39f0938c0bc87.tar.bz2
scummvm-rg350-a988ed0d0fcec9f7d2556400a9d39f0938c0bc87.zip
moving towards const-correctness of files generating savegame.cpp.
svn-id: r38250
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/cfsml.pl36
-rw-r--r--engines/sci/engine/savegame.cfsml40
2 files changed, 38 insertions, 38 deletions
diff --git a/engines/sci/engine/cfsml.pl b/engines/sci/engine/cfsml.pl
index bc2cc5c762..75522c9b92 100644
--- a/engines/sci/engine/cfsml.pl
+++ b/engines/sci/engine/cfsml.pl
@@ -117,7 +117,7 @@ sub create_string_functions
#endif
static void
-_cfsml_error(char *fmt, ...)
+_cfsml_error(const char *fmt, ...)
{
va_list argp;
@@ -196,9 +196,9 @@ static void _cfsml_register_pointer(void *ptr)
static char *
-_cfsml_mangle_string(char *s)
+_cfsml_mangle_string(const char *s)
{
- char *source = s;
+ const char *source = s;
char c;
char *target = (char *) sci_malloc(1 + strlen(s) * 2); /* We will probably need less than that */
char *writer = target;
@@ -220,14 +220,15 @@ _cfsml_mangle_string(char *s)
static char *
-_cfsml_unmangle_string(char *s)
+_cfsml_unmangle_string(const char *s, unsigned int length)
{
char *target = (char *) sci_malloc(1 + strlen(s));
char *writer = target;
- char *source = s;
+ const char *source = s;
+ const char *end = s + length;
char c;
- while ((c = *source++) && (c > 31)) {
+ while ((source != end) && (c = *source++) && (c > 31)) {
if (c == '\\') { /* Escaped character? */
c = *source++;
if ((c != '\\') && (c != '"')) /* Un-escape 0-31 only */
@@ -430,7 +431,7 @@ sub create_declaration
$types{$type}{'reader'} = "_cfsml_read_" . $typename;
write_line_pp(__LINE__, 0);
print "static void\n$types{$type}{'writer'}(FILE *fh, $ctype* save_struc);\n";
- print "static int\n$types{$type}{'reader'}(FILE *fh, $ctype* save_struc, char *lastval,".
+ print "static int\n$types{$type}{'reader'}(FILE *fh, $ctype* save_struc, const char *lastval,".
" int *line, int *hiteof);\n\n";
};
@@ -455,7 +456,7 @@ sub create_writer
print " if (!(*save_struc))\n";
print " fprintf(fh, \"\\\\null\\\\\");\n";
print " else {\n";
- print " char *token = _cfsml_mangle_string((char *) *save_struc);\n";
+ print " char *token = _cfsml_mangle_string((const char *) *save_struc);\n";
print " fprintf(fh, \"\\\"%s\\\"\", token);\n";
print " free(token);\n";
print " }\n";
@@ -537,7 +538,7 @@ sub create_reader
write_line_pp(__LINE__, 0);
print "static int\n_cfsml_read_$typename";
- print "(FILE *fh, $ctype* save_struc, char *lastval, int *line, int *hiteof)\n{\n";
+ print "(FILE *fh, $ctype* save_struc, const char *lastval, int *line, int *hiteof)\n{\n";
print " char *token;\n";
if ($types{$type}{'type'} eq $type_record) {
@@ -577,18 +578,17 @@ sub create_reader
write_line_pp(__LINE__, 0);
print "\n";
print " if (strcmp(lastval, \"\\\\null\\\\\")) { /* null pointer? */\n";
+ print " unsigned int length = strlen(lastval);\n";
print " if (*lastval == '\"') { /* Quoted string? */\n";
- print " int seeker = strlen(lastval);\n\n";
- print " while (lastval[seeker] != '\"')\n";
- print " --seeker;\n\n";
- print " if (!seeker) { /* No matching double-quotes? */\n";
+ print " while (lastval[length] != '\"')\n";
+ print " --length;\n\n";
+ print " if (!length) { /* No matching double-quotes? */\n";
print " _cfsml_error(\"Unbalanced quotes at line %d\\n\", *line);\n";
print " return CFSML_FAILURE;\n";
print " }\n\n";
- print " lastval[seeker] = 0; /* Terminate string at closing quotes... */\n";
print " lastval++; /* ...and skip the opening quotes locally */\n";
print " }\n";
- print " *save_struc = _cfsml_unmangle_string(lastval);\n";
+ print " *save_struc = _cfsml_unmangle_string(lastval, length);\n";
print " _cfsml_register_pointer(*save_struc);\n";
print " return CFSML_SUCCESS;\n";
print " } else {\n";
@@ -605,7 +605,7 @@ sub create_reader
print " };\n";
print " closed = 0;\n";
print " do {\n";
- print " char *value;\n";
+ print " const char *value;\n";
print " token = _cfsml_get_identifier(fh, line, hiteof, &assignment);\n\n";
print " if (!token) {\n";
print " _cfsml_error(\"Expected token at line %d\\n\", *line);\n";
@@ -837,10 +837,10 @@ sub insert_reader_code {
if ($firsttoken) {
write_line_pp(__LINE__, 0);
- print " char *_cfsml_inp = $firsttoken;\n";
+ print " const char *_cfsml_inp = $firsttoken;\n";
} else {
write_line_pp(__LINE__, 0);
- print " char *_cfsml_inp =".
+ print " const char *_cfsml_inp =".
" _cfsml_get_identifier($fh, &($linecounter), &_cfsml_eof, &dummy);\n\n";
}
diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml
index 5b3abafb13..4c18fb1131 100644
--- a/engines/sci/engine/savegame.cfsml
+++ b/engines/sci/engine/savegame.cfsml
@@ -64,7 +64,7 @@ write_reg_t(FILE *fh, reg_t *foo)
}
int
-read_reg_t(FILE *fh, reg_t *foo, char *lastval, int *line, int *hiteof)
+read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof)
{
int segment, offset;
@@ -86,7 +86,7 @@ write_sci_version(FILE *fh, sci_version_t *foo)
}
int
-read_sci_version(FILE *fh, sci_version_t *foo, char *lastval, int *line, int *hiteof)
+read_sci_version(FILE *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof)
{
return version_parse(lastval, foo);
}
@@ -101,10 +101,10 @@ write_PTN(FILE *fh, parse_tree_node_t *foo)
}
int
-read_PTN(FILE *fh, parse_tree_node_t *foo, char *lastval, int *line, int *hiteof)
+read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof)
{
if (lastval[0] == 'L') {
- char *c = lastval + 1;
+ const char *c = lastval + 1;
char *strend;
while (*c && isspace(*c))
@@ -119,7 +119,7 @@ read_PTN(FILE *fh, parse_tree_node_t *foo, char *lastval, int *line, int *hiteof
return 0;
} else if (lastval[0] == 'B') {
- char *c = lastval + 1;
+ const char *c = lastval + 1;
char *strend;
while (*c && isspace(*c)) ++c;
@@ -153,30 +153,30 @@ read_PTN(FILE *fh, parse_tree_node_t *foo, char *lastval, int *line, int *hiteof
void
write_menubar_tp(FILE *fh, menubar_t **foo);
int
-read_menubar_tp(FILE *fh, menubar_t **foo, char *lastval, int *line, int *hiteof);
+read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof);
void
write_mem_obj_tp(FILE *fh, mem_obj_t **foo);
int
-read_mem_obj_tp(FILE *fh, mem_obj_t **foo, char *lastval, int *line, int *hiteof);
+read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof);
void
write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo);
int
-read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, char *lastval, int *line, int *hiteof);
+read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof);
void
write_songlib_t(FILE *fh, songlib_t *foo);
int
-read_songlib_t(FILE *fh, songlib_t *foo, char *lastval, int *line, int *hiteof);
+read_songlib_t(FILE *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof);
void
write_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo);
int
-read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, char *lastval, int *line, int *hiteof);
+read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, const char *lastval, int *line, int *hiteof);
int
-read_song_tp(FILE *fh, song_t **foo, char *lastval, int *line, int *hiteof);
+read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof);
typedef mem_obj_t *mem_obj_ptr;
@@ -421,7 +421,7 @@ write_songlib_t(FILE *fh, songlib_t *songlib)
}
int
-read_songlib_t(FILE *fh, songlib_t *songlib, char *lastval, int *line, int *hiteof)
+read_songlib_t(FILE *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof)
{
int songcount;
int i;
@@ -447,7 +447,7 @@ read_songlib_t(FILE *fh, songlib_t *songlib, char *lastval, int *line, int *hite
struct {
int type;
- char *name;
+ const char *name;
} mem_obj_string_names[] = {
{MEM_OBJ_INVALID, "INVALID"},
{MEM_OBJ_SCRIPT, "SCRIPT"},
@@ -461,7 +461,7 @@ struct {
{MEM_OBJ_DYNMEM,"DYNMEM"}};
int
-mem_obj_string_to_enum(char *str)
+mem_obj_string_to_enum(const char *str)
{
int i;
@@ -491,7 +491,7 @@ song_iterator_t *
build_iterator(state_t *s, int song_nr, int type, songit_id_t id);
int
-read_song_tp(FILE *fh, song_t **foo, char *lastval, int *line, int *hiteof)
+read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof)
{
char *token;
int assignment;
@@ -504,7 +504,7 @@ read_song_tp(FILE *fh, song_t **foo, char *lastval, int *line, int *hiteof)
return 0;
}
int
-read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, char *lastval, int *line, int *hiteof)
+read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof)
{
*foo = (int_hash_map_t*)malloc(sizeof(int_hash_map_t));
%CFSMLREAD int_hash_map_t (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
@@ -530,7 +530,7 @@ write_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo)
}
int
-read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, char *lastval, int *line, int *hiteof)
+read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, const char *lastval, int *line, int *hiteof)
{
static char buffer[80];
@@ -586,7 +586,7 @@ write_menubar_tp(FILE *fh, menubar_t **foo)
int
-read_menubar_tp(FILE *fh, menubar_t **foo, char *lastval, int *line, int *hiteof)
+read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof)
{
if (lastval[0] == '\\') {
@@ -637,7 +637,7 @@ write_mem_obj_t(FILE *fh, mem_obj_t *foo)
}
int
-read_mem_obj_t(FILE *fh, mem_obj_t *foo, char *lastval, int *line, int *hiteof)
+read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof)
{
char buffer[80];
foo->type = mem_obj_string_to_enum(lastval);
@@ -696,7 +696,7 @@ write_mem_obj_tp(FILE *fh, mem_obj_t **foo)
}
int
-read_mem_obj_tp(FILE *fh, mem_obj_t **foo, char *lastval, int *line, int *hiteof)
+read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof)
{
if (lastval[0] == '\\') {