home · contact · privacy
Minor refactoring in file parsing.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 6 Apr 2014 22:04:47 +0000 (00:04 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 6 Apr 2014 22:04:47 +0000 (00:04 +0200)
src/client/command_db.c
src/client/interface_conf.c
src/common/parse_file.c
src/common/parse_file.h
src/server/configfile.c

index ef84c493fb42f1f04c886d323c61d0bfafd67388..9e99f5e6e93fb5aeb43b2910865999f27ed3bfc9 100644 (file)
@@ -7,7 +7,8 @@
 #include <stdlib.h> /* free() */
 #include <string.h> /* memset(), strcmp(), strdup() */
 #include "../common/parse_file.h" /* EDIT_STARTED, parse_file(), set_val(),
-                                   * token_from_line(), err_line()
+                                   * token_from_line(), err_line(),
+                                   * finalize_by_readyflag()
                                    */
 #include "../common/try_malloc.h" /* try_malloc() */
 #include "array_append.h" /* array_append() */
@@ -48,8 +49,7 @@ static void tokens_into_entries(char * token0, char * token1)
     static struct Command * cmd = NULL;
     if (!token0 || !strcmp(token0, str_cmd))
     {
-        char * err_fin = "Last definition block not finished yet.";
-        err_line((cmd_flags & READY_CMD) ^ READY_CMD, err_fin);
+        finalize_by_readyflag(&cmd_flags, READY_CMD);
         if (cmd)
         {
             array_append(world.commandDB.n, sizeof(struct Command),
index 69ef9eb54675fe2f009359e0de502727103801df..afc3ede3f75d808c90e0121f827a961a97db84e1 100644 (file)
@@ -10,7 +10,7 @@
 #include <string.h> /* memset(), strchr(), strcmp(), strdup(), strlen() */
 #include <unistd.h> /* optarg, getopt() */
 #include "../common/parse_file.h" /* EDIT_STARTED, parse_file(), set_val(),
-                                   * token_from_line()
+                                   * token_from_line(), finalize_by_readyflag()
                                    */
 #include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(),
                                   * try_fwrite()
@@ -187,14 +187,10 @@ static void tokens_into_entries(char * token0, char * token1)
     if (!token0 || !strcmp(token0, str_win) || !strcmp(token0, str_ord)
                 || !strcmp(token0, str_kbd))
     {
-        err_line(   ((win_flags & READY_WIN) ^ READY_WIN)
-                 || ((ord_flags & READY_ORD) ^ READY_ORD)
-                 || ((kbd_flags & READY_KBD) ^ READY_KBD),
-                 "Last definition block not yet finished yet.");
+        finalize_by_readyflag(&win_flags, READY_WIN);
+        finalize_by_readyflag(&ord_flags, READY_ORD);
+        finalize_by_readyflag(&kbd_flags, READY_KBD);
         write_if_win(&win);
-        ord_flags = READY_ORD;
-        win_flags = READY_WIN;
-        kbd_flags = READY_KBD;
     }
     if (!token0)
     {
index 9e55d16fa8eb53aa326d70220d34cbc683ec0df9..3632f401a0f9c91eada3818e1019954dd7baa4f7 100644 (file)
@@ -208,3 +208,12 @@ extern uint8_t set_val(char * token0, char * token1, char * comparand,
     }
     return 0;
 }
+
+
+
+extern void finalize_by_readyflag(uint8_t * flags, uint8_t ready_flag)
+{
+    char * err_fin = "Last definition block not finished yet.";
+    err_line((*flags & ready_flag) ^ ready_flag, err_fin);
+    *flags = ready_flag;
+}
index b10f3f36b284e3efc156565b406daa71e9e7e08d..5c002fc199e6229457d05d40160ff710797afbae 100644 (file)
@@ -52,6 +52,9 @@ extern uint8_t set_val(char * token0, char * token1, char * comparand,
                        uint8_t * flags, uint8_t set_flag, char type,
                        char * element);
 
+/* Check "ready_flag" is set in "flags", re-set "flags" to "ready_flag" only. */
+extern void finalize_by_readyflag(uint8_t * flags, uint8_t ready_flag);
+
 
 
 #endif
index 38404bd3a82b9306989d6dce7454d918b10f53ab..026f658346b6308270c71682a623b3a1427620ce 100644 (file)
@@ -6,7 +6,8 @@
 #include <stdlib.h> /* atoi(), free() */
 #include <string.h> /* strcmp() */
 #include "../common/parse_file.h" /* EDIT_STARTED, set_val(), test_for_int(),
-                                   * err_line(), parse_file(),token_from_line()
+                                   * err_line(), parse_file(),token_from_line(),
+                                   * finalize_by_readyflag()
                                    */
 #include "../common/rexit.h" /* exit_err(), exit_trouble() */
 #include "../common/try_malloc.h" /* try_malloc() */
@@ -110,13 +111,10 @@ static void tokens_into_entries(char * token0, char * token1)
     static struct EntryHead * mod = NULL;
     if (!token0 || !strcmp(token0,str_act) || !strcmp(token0,str_obj))
     {
-        err_line(   ((action_flags & READY_ACT) ^ READY_ACT)
-                 || ((object_flags & READY_OBJ) ^ READY_OBJ),
-                 "Last definitino block not finished yet.");
+        finalize_by_readyflag(&action_flags, READY_ACT);
+        finalize_by_readyflag(&object_flags, READY_OBJ);
         write_if_entry(&moa, (struct EntryHead ***) &moa_p_p);
         write_if_entry(&mod, (struct EntryHead ***) &mod_p_p);
-        action_flags = READY_ACT;
-        object_flags = READY_OBJ;
     }
     err_line(token0 && NULL != token_from_line(NULL), "Too many values.");
     if (   token0