Skip to content

Commit

Permalink
Move various io-related source files to src/io/ (#221)
Browse files Browse the repository at this point in the history
* Move various io-related source files to src/io/

* Move string search functions out of util.c

* Fix emzip builds

* Move non-IO stuff back out of io/

* Fix hashtable.h/memcasecmp.h include guards
  • Loading branch information
AliceLR committed Apr 4, 2020
1 parent 0b0d153 commit 8fe56e0
Show file tree
Hide file tree
Showing 56 changed files with 383 additions and 271 deletions.
14 changes: 9 additions & 5 deletions arch/emscripten/Makefile.in
Expand Up @@ -62,18 +62,22 @@ clean:

all: emzip.js

# NOTE: hack, core_obj isn't defined yet...
emzip.js: arch/emscripten/emzip.c src/.build/zip.o src/.build/vfs.o src/.build/util.o
# NOTE: hack, core_obj and io_obj aren't defined yet...
emzip_objs := \
src/.build/util.o \
src/io/.build/vfile.o \
src/io/.build/zip.o \
src/io/.build/zip_stream.o

emzip.js: arch/emscripten/emzip.c ${emzip_objs}
$(if ${V},,@echo " LINK " $@)
${CC} -O3 \
-s ENVIRONMENT=web \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s EXPORT_NAME="'emzip'" \
-s "EXPORTED_RUNTIME_METHODS=['_main', 'UTF8ToString']" \
arch/emscripten/emzip.c \
${core_obj}/zip.o ${core_obj}/vfs.o ${core_obj}/util.o \
${ZLIB_LDFLAGS} -o emzip.js
$< ${emzip_objs} ${ZLIB_LDFLAGS} -o $@

# Normally not defined yet...
build := build/${SUBPLATFORM}
Expand Down
2 changes: 1 addition & 1 deletion arch/emscripten/emzip.c
Expand Up @@ -23,7 +23,7 @@
* copied into module memory, but supports more decompression methods than UZIP.
*/

#include "../../src/zip.h"
#include "../../src/io/zip.h"
#include <stdlib.h>
#include <emscripten.h>

Expand Down
25 changes: 15 additions & 10 deletions src/Makefile.in
Expand Up @@ -17,6 +17,9 @@ core_obj = src/.build
audio_src = src/audio
audio_obj = src/audio/.build

io_src = src/io
io_obj = src/io/.build

network_src = src/network
network_obj = src/network/.build

Expand Down Expand Up @@ -55,6 +58,10 @@ ${audio_obj}/%.o: ${audio_src}/%.cpp
$(if ${V},,@echo " CXX " $<)
${CC} -MD ${core_cxxflags} ${core_flags} ${core_spec} -c $< -o $@

${io_obj}/%.o: ${io_src}/%.c
$(if ${V},,@echo " CC " $<)
${CC} -MD ${core_cflags} ${core_flags} ${core_spec} -c $< -o $@

${network_obj}/%.o: ${network_src}/%.c
$(if ${V},,@echo " CC " $<)
${CC} -MD ${core_cflags} ${core_flags} ${core_spec} -c $< -o $@
Expand All @@ -79,11 +86,9 @@ core_cobjs := \
${core_obj}/core.o \
${core_obj}/counter.o \
${core_obj}/data.o \
${core_obj}/dir.o \
${core_obj}/error.o \
${core_obj}/event.o \
${core_obj}/expr.o \
${core_obj}/fsafeopen.o \
${core_obj}/game.o \
${core_obj}/game_menu.o \
${core_obj}/game_ops.o \
Expand All @@ -108,10 +113,13 @@ core_cobjs := \
${core_obj}/sprite.o \
${core_obj}/str.o \
${core_obj}/util.o \
${core_obj}/vfs.o \
${core_obj}/window.o \
${core_obj}/world.o \
${core_obj}/zip.o
${io_obj}/dir.o \
${io_obj}/fsafeopen.o \
${io_obj}/vfile.o \
${io_obj}/zip.o \
${io_obj}/zip_stream.o

#
# Lists mandatory C++ language sources (mangled to object names) required
Expand Down Expand Up @@ -289,10 +297,6 @@ core_ldflags := $(LIBPNG_LDFLAGS) ${core_ldflags}
core_cobjs += ${core_obj}/pngops.o
endif

ifeq (${BUILD_COUNTER_HASH_TABLES},1)
core_flags += -Icontrib/khash/
endif

ifeq (${BUILD_AUDIO},1)
audio_cobjs := \
${audio_obj}/audio.o \
Expand Down Expand Up @@ -381,6 +385,7 @@ core_objs := ${core_cobjs} ${core_cxxobjs}

${core_objs}: | $(filter-out $(wildcard ${core_obj}), ${core_obj})
${core_objs}: | $(filter-out $(wildcard ${audio_obj}), ${audio_obj})
${core_objs}: | $(filter-out $(wildcard ${io_obj}), ${io_obj})
${core_objs}: | $(filter-out $(wildcard ${network_obj}), ${network_obj})

ifeq (${BUILD_MODULAR},1)
Expand Down Expand Up @@ -475,8 +480,8 @@ ${mzxrun}.debug:
endif

mzx_clean: core_target_clean gdm2s3m_clean icons_clean libmodplug_clean libxmp_clean
$(if ${V},,@echo " RM " ${core_obj} ${audio_obj} ${network_obj})
${RM} -r ${core_obj} ${audio_obj} ${network_obj}
$(if ${V},,@echo " RM " ${core_obj} ${audio_obj} ${io_obj} ${network_obj})
${RM} -r ${core_obj} ${audio_obj} ${io_obj} ${network_obj}
$(if ${V},,@echo " RM " ${mzxrun} ${mzxrun}.debug)
${RM} ${mzxrun} ${mzxrun}.debug
$(if ${V},,@echo " RM " ${mzx} ${mzx}.debug)
Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio.c
Expand Up @@ -35,9 +35,9 @@

#include "../configure.h"
#include "../data.h"
#include "../fsafeopen.h"
#include "../platform.h"
#include "../util.h"
#include "../io/fsafeopen.h"

#if defined(CONFIG_MODPLUG) + defined(CONFIG_MIKMOD) + \
defined(CONFIG_XMP) + defined(CONFIG_OPENMPT) > 1
Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio_modplug.cpp
Expand Up @@ -30,8 +30,8 @@
#include "sampled_stream.h"

#include "../const.h"
#include "../fsafeopen.h"
#include "../util.h"
#include "../io/fsafeopen.h"

struct _ModPlugFile
{
Expand Down
4 changes: 2 additions & 2 deletions src/board.c
Expand Up @@ -25,14 +25,14 @@
#include "board.h"
#include "const.h"
#include "error.h"
#include "memfile.h"
#include "legacy_board.h"
#include "robot.h"
#include "world.h"
#include "world_format.h"
#include "util.h"
#include "world_struct.h"
#include "zip.h"
#include "io/memfile.h"
#include "io/zip.h"


static int save_board_info(struct board *cur_board, struct zip_archive *zp,
Expand Down
6 changes: 3 additions & 3 deletions src/configure.c
Expand Up @@ -21,18 +21,18 @@
// Config file options, which can be given either through config.txt
// or at the command line.

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>

#include "configure.h"
#include "counter.h"
#include "event.h"
#include "rasm.h"
#include "fsafeopen.h"
#include "util.h"
#include "sys/stat.h"
#include "io/fsafeopen.h"

// Arch-specific config.
#ifdef CONFIG_NDS
Expand Down
5 changes: 3 additions & 2 deletions src/counter.c
Expand Up @@ -40,7 +40,6 @@
#include "data.h"
#include "error.h"
#include "event.h"
#include "fsafeopen.h"
#include "game_ops.h"
#include "graphics.h"
#include "idarray.h"
Expand All @@ -52,6 +51,8 @@
#include "util.h"
#include "world.h"
#include "world_struct.h"
#include "io/dir.h"
#include "io/fsafeopen.h"

#include "audio/audio.h"

Expand All @@ -62,7 +63,7 @@
*/

#ifdef CONFIG_COUNTER_HASH_TABLES
#include <khashmzx.h>
#include "hashtable.h"
HASH_SET_INIT(COUNTER, struct counter *, name, name_length)
#endif

Expand Down
1 change: 1 addition & 0 deletions src/editor/Makefile.in
Expand Up @@ -39,6 +39,7 @@ editor_objs := \
${editor_obj}/robot.o \
${editor_obj}/select.o \
${editor_obj}/sfx_edit.o \
${editor_obj}/stringsearch.o \
${editor_obj}/undo.o \
${editor_obj}/window.o \
${editor_obj}/world.o
Expand Down
2 changes: 1 addition & 1 deletion src/editor/board.c
Expand Up @@ -27,7 +27,7 @@
#include "../world.h"
#include "../world_format.h"
#include "../util.h"
#include "../zip.h"
#include "../io/zip.h"

#include "world.h"
#include "configure.h"
Expand Down
23 changes: 12 additions & 11 deletions src/editor/debug.c
Expand Up @@ -24,6 +24,7 @@
#include "char_ed.h"
#include "pal_ed.h"
#include "robo_debug.h"
#include "stringsearch.h"
#include "window.h"

#include "../core.h"
Expand Down Expand Up @@ -1240,8 +1241,8 @@ static boolean select_debug_var(struct debug_node *node, char *var_name,
/******************/

static boolean search_match(const char *var_text, const size_t var_text_length,
const char *match_text, const int *match_text_index, const size_t match_length,
int search_flags)
const char *match_text, const struct string_search_data *match_text_index,
const size_t match_length, int search_flags)
{
boolean ignore_case = (search_flags & VAR_SEARCH_CASESENS) == 0;

Expand All @@ -1262,7 +1263,7 @@ static boolean search_match(const char *var_text, const size_t var_text_length,
}
else
{
if(boyer_moore_search(var_text, var_text_length, match_text, match_length,
if(string_search(var_text, var_text_length, match_text, match_length,
match_text_index, ignore_case))
return true;
}
Expand All @@ -1272,8 +1273,8 @@ static boolean search_match(const char *var_text, const size_t var_text_length,

static boolean search_vars(struct world *mzx_world, struct debug_node *node,
struct debug_var **res_var, struct debug_node **res_node, int *res_pos,
const char *match_text, const int *match_text_index, const size_t match_length,
int search_flags, struct debug_var **stop_var)
const char *match_text, const struct string_search_data *match_text_index,
const size_t match_length, int search_flags, struct debug_var **stop_var)
{
boolean matched = false;
struct debug_var *current;
Expand Down Expand Up @@ -1369,8 +1370,8 @@ static boolean search_vars(struct world *mzx_world, struct debug_node *node,

static boolean search_node(struct world *mzx_world, struct debug_node *node,
struct debug_var **res_var, struct debug_node **res_node, int *res_pos,
const char *match_text, const int *match_text_index, const size_t match_length,
int search_flags, struct debug_var **stop_var)
const char *match_text, const struct string_search_data *match_text_index,
const size_t match_length, int search_flags, struct debug_var **stop_var)
{
boolean r = false;
int i;
Expand Down Expand Up @@ -1467,12 +1468,12 @@ static boolean search_debug(struct world *mzx_world, struct debug_node *node,
struct debug_var *stop_var = NULL;
boolean matched = false;

int match_text_index[256] = { 0 };
struct string_search_data match_text_index;
boolean ignore_case = (search_flags & VAR_SEARCH_CASESENS) == 0;

// Generate an index to help speed up substring searches.
if(!(search_flags & VAR_SEARCH_EXACT))
boyer_moore_index(match_text, match_length, match_text_index, ignore_case);
string_search_index(match_text, match_length, &match_text_index, ignore_case);

if(search_flags & VAR_SEARCH_WRAP)
{
Expand All @@ -1492,12 +1493,12 @@ static boolean search_debug(struct world *mzx_world, struct debug_node *node,
}

matched = search_node(mzx_world, node, res_var, res_node, res_pos,
match_text, match_text_index, match_length, search_flags, &stop_var);
match_text, &match_text_index, match_length, search_flags, &stop_var);

// Wrap? Try again from the start
if(!matched && (search_flags & VAR_SEARCH_WRAP))
matched = search_node(mzx_world, node, res_var, res_node, res_pos,
match_text, match_text_index, match_length, search_flags, &stop_var);
match_text, &match_text_index, match_length, search_flags, &stop_var);

// If we stopped on a non-match, return false.
if(*res_var == NULL)
Expand Down
15 changes: 8 additions & 7 deletions src/editor/robo_debug.c
Expand Up @@ -25,6 +25,7 @@
#include "debug.h"
#include "robot.h"
#include "robo_debug.h"
#include "stringsearch.h"
#include "window.h"

#include "../core.h"
Expand All @@ -41,7 +42,7 @@ struct breakpoint
{
char match_name[ROBOT_NAME_SIZE];
char match_string[61];
int index[256];
struct string_search_data index;
int line_number;
int match_name_len;
int match_string_len;
Expand Down Expand Up @@ -242,8 +243,8 @@ static void new_breakpoint(struct world *mzx_world)
num_breakpoints_allocated * sizeof(struct breakpoint *));
}

boyer_moore_index(br->match_string, br->match_string_len,
br->index, true);
string_search_index(br->match_string, br->match_string_len,
&(br->index), true);

breakpoints[num_breakpoints] = br;
num_breakpoints++;
Expand Down Expand Up @@ -457,8 +458,8 @@ void __debug_robot_config(struct world *mzx_world)

if(!edit_breakpoint_dialog(mzx_world, br, "Edit Breakpoint"))
{
boyer_moore_index(br->match_string, br->match_string_len,
br->index, true);
string_search_index(br->match_string, br->match_string_len,
&(br->index), true);
}
}
else
Expand Down Expand Up @@ -1205,8 +1206,8 @@ int __debug_robot_break(context *ctx, struct robot *cur_robot,

// Try to find the match pattern in the line
if(b->match_string_len)
if(!boyer_moore_search((void *)src_ptr, src_length,
(void *)b->match_string, b->match_string_len, b->index, true))
if(!string_search((void *)src_ptr, src_length,
(void *)b->match_string, b->match_string_len, &(b->index), true))
continue;

action = ACTION_MATCHED;
Expand Down

0 comments on commit 8fe56e0

Please sign in to comment.