Browse Source

Script with cproto to generate function prototypes.

Beoran 6 years ago
parent
commit
fc03683ed6

+ 4 - 0
CMakeLists.txt

@@ -51,6 +51,10 @@ set(ERUTA_LIBS ${LIBS} ${OBJC_LIBRARIES} ${ALLEGRO_LIBRARIES} ${PNG_LIBRARY} ${J
 include_directories("include")
 include_directories("include/zori")
 include_directories("include/tr")
+include_directories("include/proto")
+include_directories("include/zori/proto")
+include_directories("include/tr/proto")
+
 # add_subdirectory("src")
 include(ErutaFiles)
 set_source_files_properties(${ERUTA_SRC_FILES} PROPERTIES LANGUAGE C)

+ 5 - 4
README

@@ -19,6 +19,7 @@ Requirements:
   `cd <directory_where_mruby_is> ; make ; sudo bin/install_mruby`
   to compile and install mruby into /usr/local
 * For compilation: cmake 2.8.10.2 or later (see vendor directory), make or ninja.
+* For development: cproto to generate header files.
 * For testing and debugging: gdb, ddd, valgrind.
 * For map editing: tiled (www.mapeditor.org)
 * For some of the tools and continuous testing: Ruby, watchr.
@@ -57,7 +58,7 @@ Use naturaldocs.
 License:
 
 Eruta is copyright (C)
-2007-2015 Beoran beoran@rubyforge.org.
+2007-2017 Beoran beoran@rubyforge.org.
 2012 com64 (music files in data/music/*_com64.ogg)
 
 Redistribution and use in source and binary forms, with or without modification,
@@ -191,8 +192,8 @@ Alexbond45, LunarKnite, Mikka, Sagephoenix.
 
 Remarks for developers:
 
-bin/mkproto is an automatic function prototype extraction tool that is
-no longer used due to it being more hassle than help.
+The header files are partially automatically generated using the cproto tool.
+The documentation should therefore be written in the C files.
 
 When a new .c file is needed, use the bin/newmodule tool like this
 bin/newmodule bar
@@ -267,7 +268,7 @@ src/tr_thing.c    : MRuby script bindings for physical thing functionality.
 src/ui.c          : User interface functionality.
 src/widget.c      : UI widgets, currently only script console.
 src/xml.c         : Libxml helper functions.
-src/zori.c        : UI functions, currently empty.
+src/zori/*.c      : UI engine.
 
 Since I try out a lot of things, ther are quite a few unused C fils in
 the project. Perhaps I will clean them out some day.. :)

+ 38 - 0
bin/runcprotoall

@@ -0,0 +1,38 @@
+#!/bin/sh
+
+CPROTO=cproto 
+CPROTO_FLAGS="-I. -I./include -I./include/zori -I./include/tr -D CPROTO"
+c_files=$(find src -iname "*.c" | tr "\n" ' ')
+
+for each in $c_files
+do
+  dir=$(dirname "$each")
+  cfile=$(basename "$each")
+  hdir=include${dir#src}
+  bfile="${cfile%.c}"
+  haid="${bfile}_proto.h"
+  guard="${bfile}_proto_included"
+  hfile="$hdir/$haid"
+  # printf "%s: %s->%s\n" "$each" "$dir" "$hfile $guard"
+
+  if grep -q '@generate_cproto@' $each
+  then 
+    mkdir -p "$hdir"
+    temp=$(mktemp)
+    printf "Generating $hfile from $each. ${CPROTO_PATH} \n"
+    # create file if it doesn't exist to avoid chicken and egg problems. 
+    touch "$hfile" 
+    
+    printf "/* This file was generated by runcprotoall */\n" > "$temp"
+    printf "\n#ifndef CPROTO /* Needed to protect cproto from itself. */\n#ifndef ${guard}\n" >> "$temp"
+    if cproto $CPROTO_FLAGS -I"$hdir" "$each" >> "$temp" 
+    then
+      printf "\n#endif /* ${guard} */ \n#endif /* CPROTO */" >> "$temp"
+      mv -f "$temp" "$hfile" 
+    else
+      printf "cproto failed\n"
+      exit 1
+    fi
+  fi
+done
+

+ 7 - 0
include/store_proto.h

@@ -1,3 +1,7 @@
+/* This file was generated by runcprotoall */
+
+#ifndef CPROTO /* Needed to protect cproto from itself. */
+#ifndef store_proto_included
 /* src/store.c */
 _Bool store_init(void);
 _Bool store_index_ok(int index);
@@ -47,3 +51,6 @@ int store_load_bitmap_flags_id(int min, const char *vpath, int flags);
 int store_load_bitmap_id(int min, const char *vpath);
 int store_load_other_id(int min, const char *vpath, ResorKind kind, ResorLoader *loader, ResorDestructor *destroy, void *extra);
 int store_load_tilemap_id(int min, const char *vpath);
+
+#endif /* store_proto_included */ 
+#endif /* CPROTO */

+ 1 - 39
include/zori/zori_longtext.h

@@ -21,45 +21,7 @@ struct zori_longtext {
 };
  
 
-struct zori_longtext *zori_widget_to_longtext(struct zori_widget *widget);
-struct zori_longtext *zori_longtext_set(struct zori_longtext *longtext, const zori_string *text);
-struct zori_longtext *zori_longtext_set_cstr(struct zori_longtext *longtext, const char *cstr);
-struct zori_longtext *zori_longtext_init_cstr(struct zori_longtext *longtext, const char *cstr);
-void zori_longtext_done(struct zori_longtext *longtext);
-int zori_longtext_page(struct zori_longtext *longtext);
-int zori_longtext_last_page(struct zori_longtext *longtext);
-int zori_longtext_page_(struct zori_longtext *longtext, int page);
-int zori_longtext_at_end(struct zori_longtext *longtext);
-void zori_longtext_update_longtext(struct zori_longtext *longtext, double dt);
-int zori_longtext_longtext_at_end(struct zori_longtext *longtext);
-void zori_longtext_draw_text(struct zori_longtext *longtext);
-void zori_longtext_draw_partial_text(struct zori_longtext *longtext);
-void zori_draw_longtext(struct zori_longtext *longtext);
-zori_id zori_set_line_stop(zori_id index, int stop);
-zori_id zori_line_start_(zori_id index, int start);
-int zori_delay_(zori_id index, double delay);
-int zori_line_stop(int index);
-int zori_line_start(int index);
-double zori_delay(int index);
-int zori_page_lines_(zori_id index, int lines);
-int zori_page_lines(int index);
-int zori_paused_(zori_id index, int paused);
-int zori_paused(zori_id index);
-int zori_page(zori_id index);
-int zori_last_page(zori_id index);
-int zori_at_end(zori_id index);
-int zori_page_(zori_id index, int page);
-int zori_next_page(zori_id index);
-int zori_previous_page(int index);
-int zori_longtext_on_mouse_axes(union zori_event *event);
-int zori_longtext_on_mouse_click(union zori_event *event);
-int zori_longtext_on_draw(union zori_event *event);
-struct zori_longtext *zori_longtext_init(struct zori_longtext *longtext, const char *text);
-struct zori_longtext *zori_longtext_new(zori_id id, zori_id parent_id, zori_box *box, const char *text);
-zori_id zori_new_longtext(zori_id id, zori_id parent, zori_box *box, const char *text);
-
-
- 
+#include "zori_longtext_proto.h" 
  
 
 #endif

+ 44 - 0
include/zori/zori_longtext_proto.h

@@ -0,0 +1,44 @@
+/* This file was generated by runcprotoall */
+
+#ifndef CPROTO /* Needed to protect cproto from itself. */
+#ifndef zori_longtext_proto_included
+/* src/zori/zori_longtext.c */
+struct zori_longtext *zori_widget_to_longtext(struct zori_widget *widget);
+struct zori_longtext *zori_longtext_set(struct zori_longtext *longtext, const zori_string *text);
+struct zori_longtext *zori_longtext_set_cstr(struct zori_longtext *longtext, const char *cstr);
+struct zori_longtext *zori_longtext_init_cstr(struct zori_longtext *longtext, const char *cstr);
+void zori_longtext_done(struct zori_longtext *longtext);
+int zori_longtext_page(struct zori_longtext *longtext);
+int zori_longtext_last_page(struct zori_longtext *longtext);
+int zori_longtext_page_(struct zori_longtext *longtext, int page);
+int zori_longtext_at_end(struct zori_longtext *longtext);
+void zori_longtext_update_longtext(struct zori_longtext *longtext, double dt);
+int zori_longtext_longtext_at_end(struct zori_longtext *longtext);
+void zori_longtext_draw_text(struct zori_longtext *longtext);
+void zori_longtext_draw_partial_text(struct zori_longtext *longtext);
+void zori_draw_longtext(struct zori_longtext *longtext);
+zori_id zori_set_line_stop(zori_id index, int stop);
+zori_id zori_line_start_(zori_id index, int start);
+int zori_delay_(zori_id index, double delay);
+int zori_line_stop(int index);
+int zori_line_start(int index);
+double zori_delay(int index);
+int zori_page_lines_(zori_id index, int lines);
+int zori_page_lines(int index);
+int zori_paused_(zori_id index, int paused);
+int zori_paused(zori_id index);
+int zori_page(zori_id index);
+int zori_last_page(zori_id index);
+int zori_at_end(zori_id index);
+int zori_page_(zori_id index, int page);
+int zori_next_page(zori_id index);
+int zori_previous_page(int index);
+int zori_longtext_on_mouse_axes(union zori_event *event);
+int zori_longtext_on_mouse_click(union zori_event *event);
+int zori_longtext_on_draw(union zori_event *event);
+struct zori_longtext *zori_longtext_init(struct zori_longtext *longtext, const char *text);
+struct zori_longtext *zori_longtext_new(zori_id id, zori_id parent_id, zori_box *box, const char *text);
+zori_id zori_new_longtext(zori_id id, zori_id parent, zori_box *box, const char *text);
+
+#endif /* zori_longtext_proto_included */ 
+#endif /* CPROTO */

+ 1 - 0
include/zori/zori_menu.h

@@ -9,6 +9,7 @@ struct zori_menu {
   int selected_index;
 };
 
+#include "zori_menu_proto.h"
 
 #endif
 

+ 22 - 0
include/zori/zori_menu_proto.h

@@ -0,0 +1,22 @@
+/* This file was generated by runcprotoall */
+
+#ifndef CPROTO /* Needed to protect cproto from itself. */
+#ifndef zori_menu_proto_included
+/* src/zori/zori_menu.c */
+struct zori_menu *zori_widget_to_menu(struct zori_widget *widget);
+struct zori_widget *zori_menu_get_selected(struct zori_menu *menu);
+int zori_menu_select_index(struct zori_menu *menu, int index);
+int zori_menu_select_previous(struct zori_menu *menu);
+int zori_menu_select_next(struct zori_menu *menu);
+int zori_menu_select_first(struct zori_menu *menu);
+int zori_menu_activate_selected(struct zori_menu *menu);
+int zori_menu_close(struct zori_menu *menu);
+int zori_menu_on_child_close(union zori_event *event);
+int zori_menu_on_key_down(union zori_event *event);
+int zori_menu_on_draw(union zori_event *event);
+struct zori_menu *zori_menu_init(struct zori_menu *menu, zori_id id, zori_id parent_id, zori_rebox *box, struct zori_style *style);
+struct zori_menu *zori_menu_new(zori_id id, zori_id parent_id, zori_box *box);
+zori_id zori_new_menu(zori_id id, zori_id parent, zori_box *box);
+
+#endif /* zori_menu_proto_included */ 
+#endif /* CPROTO */

+ 7 - 36
include/zori/zori_proto.h

@@ -1,3 +1,7 @@
+/* This file was generated by runcprotoall */
+
+#ifndef CPROTO /* Needed to protect cproto from itself. */
+#ifndef zori_proto_included
 /* src/zori/zori.c */
 int zori_handler_compare(const void *v1, const void *v2);
 struct zori_handler *zori_handlers_add(struct zori_handlers *me, zori_event_type type, zori_handler_func *handler, void *data);
@@ -22,42 +26,6 @@ zori_id zori_set_style(zori_id id, struct zori_style *style);
 zori_id zori_get_style(zori_id id, struct zori_style *style);
 zori_id zori_set_background_color(zori_id id, zori_color color);
 zori_id zori_set_background_bitmap(zori_id id, zori_bitmap *bitmap);
-zori_id zori_set_foreground_color(zori_id id, zori_color color);
-zori_id zori_set_foreground_bitmap(zori_id id, zori_bitmap *bitmap);
-zori_id zori_set_border_color(zori_id id, zori_color color);
-zori_id zori_set_border_bitmap(zori_id id, zori_bitmap *bitmap);
-zori_id zori_set_text_font_flags(zori_id id, int flags);
-void zori_draw_all(void);
-int zori_handle_system_event(zori_system_event *sysev);
-void zori_update(double dt);
-int zori_result(zori_id id);
-int zori_get_result(zori_id id, struct zori_result *result);
-/* src/zori/zori.c */
-int zori_handler_compare(const void *v1, const void *v2);
-struct zori_handler *zori_handlers_add(struct zori_handlers *me, zori_event_type type, zori_handler_func *handler, void *data);
-void zori_handlers_done(struct zori_handlers *me);
-void zori_handlers_init(struct zori_handlers *me);
-struct zori_handler *zori_handlers_search(struct zori_handlers *me, zori_event_type type);
-int zori_handlers_handle(struct zori_handlers *me, union zori_event *event);
-struct zori_root *zori_get_root(void);
-struct zori_widget *zori_get_root_widget(void);
-struct zori_widget *zori_get_widget(zori_id id);
-zori_id zori_get_unused_id(void);
-zori_id zori_initialize_root(void);
-zori_id zori_start(struct zori_style *default_style);
-zori_id zori_set_margins(zori_id id, int left, int top, int right, int bottom);
-zori_id zori_set_margin(zori_id id, int size);
-zori_id zori_set_paddings(zori_id id, int left, int top, int right, int bottom);
-zori_id zori_set_padding(zori_id id, int size);
-zori_font *zori_text_font(zori_id id);
-void zori_destroy_root(void);
-zori_id zori_shutdown(void);
-zori_id zori_set_style(zori_id id, struct zori_style *style);
-zori_id zori_get_style(zori_id id, struct zori_style *style);
-zori_id zori_set_background_color(zori_id id, zori_color color);
-zori_id zori_set_background_bitmap(zori_id id, zori_bitmap *bitmap);
-zori_id zori_set_foreground_color(zori_id id, zori_color color);
-zori_id zori_set_foreground_bitmap(zori_id id, zori_bitmap *bitmap);
 zori_id zori_set_border_color(zori_id id, zori_color color);
 zori_id zori_set_border_bitmap(zori_id id, zori_bitmap *bitmap);
 zori_id zori_set_text_font(zori_id id, zori_font *font);
@@ -67,3 +35,6 @@ int zori_handle_system_event(zori_system_event *sysev);
 void zori_update(double dt);
 int zori_result(zori_id id);
 int zori_get_result(zori_id id, struct zori_result *result);
+
+#endif /* zori_proto_included */ 
+#endif /* CPROTO */

+ 1 - 0
src/store.c

@@ -2,6 +2,7 @@
 #include "eruta.h"
 #include "store.h"
 
+/* Magic comment for runcprotoall: @generate_cproto@ */
 
 /** 
  * Store is a "global" resource container. It's simply an array of STORE_MAX 

+ 2 - 1
src/ui.c

@@ -8,6 +8,7 @@
 #include "zori_button.h"
 #include "zori_page.h"
 #include "zori_menu.h"
+#include "zori_longtext.h"
 #include "draw.h"
 #include "monolog.h"
 #include "ui.h"
@@ -50,7 +51,7 @@ void ui_state_init_hud(struct ui_state * ui,
   ui->hud.page = zori_new_page(-1, ui->screen);
   LOG_NOTE("HUD page: %d\n", ui->hud.page);
   box = rebox_make(10, 300, 620, 200);
-  ui->hud.dialog = zori_new_longtext(-1, ui->hud.page, box, INTRO_TEXT);
+  ui->hud.dialog = zori_new_longtext(-1, ui->hud.page, &box, INTRO_TEXT);
 }
 
 /* Set up Zori GUI. */

+ 2 - 0
src/zori/zori.c

@@ -1,4 +1,6 @@
 
+/* Magic comment for runcprotoall: @generate_cproto@ */
+
 #include "zori.h"
 #include "zori_registry.h"
 #include "zori_style.h"

+ 2 - 0
src/zori/zori_longtext.c

@@ -1,4 +1,6 @@
 
+/* Magic comment for runcprotoall: @generate_cproto@ */
+
 #include "monolog.h"
 #include "zori.h"
 #include "zori_widget.h"

+ 2 - 0
src/zori/zori_menu.c

@@ -4,6 +4,8 @@
 #include "zori_caption.h"
 #include "zori_menu.h"
 
+/* Magic comment for runcprotoall: @generate_cproto@ */
+
 struct zori_menu * zori_widget_to_menu(struct zori_widget * widget) {
   if (!zori_widget_is_type(widget, ZORI_WIDGET_TYPE_MENU)) return NULL;
   return ZORI_CONTAINER_OF(widget, struct zori_menu, widget);