From 41974ae5265fbc23a06f276f9e008d5dad020e0b Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 30 Aug 2012 16:16:25 -0700 Subject: Rename files for C++ conversion. Does not compile. After updating, you can remove these files, as shown in 'git status': Untracked files: (use "git add ..." to include in what will be committed) src/map/magic-interpreter-lexer.c src/map/magic-interpreter-parser.c src/map/magic-interpreter-parser.h --- src/tool/mapfrob.cpp | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/tool/mapfrob.cpp (limited to 'src/tool/mapfrob.cpp') diff --git a/src/tool/mapfrob.cpp b/src/tool/mapfrob.cpp new file mode 100644 index 0000000..8663ae0 --- /dev/null +++ b/src/tool/mapfrob.cpp @@ -0,0 +1,129 @@ +// Compile with +// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o + +#include +#include +#include "../common/mmo.hpp" +// Yes, this is intentional +#include "../char/char.cpp" + +// Well, this is not terribly elegant, but I don't have that much time. +#define MAX_MAP 1024 +#define MAP_NAME_SIZE 32 +int maps_nr = 0; +struct +{ + char old[MAP_NAME_SIZE], new[MAP_NAME_SIZE]; +} maps[MAX_MAP]; + +void transform_point (struct point *p) +{ + int k; + + if (!p->map[0]) + return; + + for (k = 0; k < maps_nr; k++) + if (!strcmp (p->map, maps[k].old)) + { + strcpy (p->map, maps[k].new); + return; + } + + fprintf (stderr, "Warning: untranslated map `%s'\n", p->map); +} + +void transform_char (struct mmo_charstatus *p) +{ + int i; + + transform_point (&p->last_point); + transform_point (&p->save_point); + + for (i = 0; i < 10; i++) + transform_point (&p->memo_point[i]); +} + +int mmo_char_convert () +{ + char line[965536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp, *ofp; + + ifp = stdin; + ofp = stdout; + while (fgets (line, 65535, ifp)) + { + memset (&char_dat, 0, sizeof (struct mmo_charstatus)); + ret = mmo_char_fromstr (line, &char_dat); + if (ret) + { + transform_char (&char_dat); + mmo_char_tostr (line, &char_dat); + fprintf (ofp, "%s\n", line); + } + } + return 0; +} + +#define PARSE_MODE_NEXTNUM 0 +#define PARSE_MODE_RANGE 1 + +int init (int count, char **translates) +{ + int i; + char *suffix = ".gat"; + + for (i = 0; i < count; i++) + { + char *src = translates[i]; + char *dest = strchr (src, ':'); + + if (!dest) + { + fprintf (stderr, "Missing colon in: `%s'\n", src); + return 1; + } + + *dest++ = 0; + + if (strlen (src) + strlen (suffix) >= MAP_NAME_SIZE) + { + fprintf (stderr, "Map name prefix too long: `%s'\n", src); + return 1; + } + + if (strlen (dest) + strlen (suffix) >= MAP_NAME_SIZE) + { + fprintf (stderr, "Map name prefix too long: `%s'\n", dest); + return 1; + } + + strncpy (maps[maps_nr].old, src, MAP_NAME_SIZE); + strcat (maps[maps_nr].old, suffix); + strncpy (maps[maps_nr].new, dest, MAP_NAME_SIZE); + strcat (maps[maps_nr].new, suffix); + + ++maps_nr; + } + + return 0; +} + +int main (int argc, char *argv[]) +{ + if (argc < 2) + { + printf ("Usage: %s oldmap0:newmap0 oldmap1:newmap1 ...\n", argv[0]); + printf ("e.g., %s new_1-1:001-2 new_2-1:001-1\n", argv[0]); + puts ("The extension `.gat' is appended implicitly."); + exit (0); + } + if (init (argc - 1, argv + 1)) + return 1; + + mmo_char_convert (); + + return 0; +} -- cgit v1.2.3-70-g09d2