home · contact · privacy
Server: Read in former "config" data as normal server god commands.
[plomrogue] / src / client / interface_conf.c
index f5a05973d6dacceb4d8a50c2d6e7e5e988dec82e..aba5e3bf5927f3be950a26d6d190e661804707e4 100644 (file)
@@ -9,15 +9,9 @@
 #include <stdio.h> /* FILE, sprintf() */
 #include <string.h> /* strchr(), strcmp(), strdup(), strlen() */
 #include <unistd.h> /* optarg, getopt() */
-#include "../common/parse_file.h" /* EDIT_STARTED, parse_file(), parse_val(),
-                                   * token_from_line(), parsetest_singlechar(),
-                                   * parse_and_reduce_to_readyflag(),
-                                   * parsetest_defcontext(),parse_unknown_arg(),
-                                   * parsetest_too_many_values(),
-                                   * parse_id_uniq(), parse_init_entry()
-                                   */
-#include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(),
-                                  * try_fwrite()
+#include "../common/parse_file.h" /* token_from_line(),parsetset_singlechar() */
+#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish(),
+                                  * detect_atomic_leftover(), try_fwrite()
                                   */
 #include "../common/rexit.h" /* exit_err(), exit_trouble() */
 #include "../common/try_malloc.h" /* try_malloc() */
 #include "command_db.h" /* get_command() */
 #include "keybindings.h" /* KeyBinding, KeyBindingDB, get_command_to_keycode()*/
 #include "map.h" /* map_center() */
+#include "parse.h" /* EDIT_STARTED, parse_file(), parse_flagval(),
+                    * parse_and_reduce_to_readyflag(), parse_id_uniq()
+                    * parsetest_defcontext(), parse_unknown_arg(),
+                    * parsetest_too_many_values(), parse_init_entry()
+                    */
 #include "wincontrol.h" /* toggle_window() */
 #include "windows.h" /* Win, free_winDB(), make_v_screen_and_init_win_sizes() */
 #include "world.h" /* global world */
@@ -143,7 +142,7 @@ static void write_def(FILE * file, char * prefix, uint8_t quotes, char * val,
                       char type)
 {
     char * f_name = "write_def()";
-    char * val_str;
+    char * val_str = NULL;
     int test_val_str = 1;
     if      ('s' == type)
     {
@@ -311,19 +310,19 @@ static uint8_t set_members(char * token0, char * token1, uint8_t * win_flags,
                            uint8_t * ord_flags,uint8_t kbd_flags,char * str_key,
                            struct Win * win, struct KeyBindingDB * kbdb)
 {
-    if (   parse_val(token0, token1, "NAME", win_flags,
-                     NAME_SET, 's', (char *) &win->title)
-        || parse_val(token0, token1, "WIDTH", win_flags,
-                     WIDTH_SET, 'i', (char *) &win->target_width)
-        || parse_val(token0, token1, "HEIGHT", win_flags,
-                     HEIGHT_SET, 'i', (char *) &win->target_height));
-    else if (parse_val(token0, token1, "BREAK", win_flags,
-                       BREAK_SET, '8', (char *) &win->linebreak))
+    if (   parse_flagval(token0, token1, "NAME", win_flags,
+                         NAME_SET, 's', (char *) &win->title)
+        || parse_flagval(token0, token1, "WIDTH", win_flags,
+                         WIDTH_SET, 'i', (char *) &win->target_width)
+        || parse_flagval(token0, token1, "HEIGHT", win_flags,
+                         HEIGHT_SET, 'i', (char *) &win->target_height));
+    else if (parse_flagval(token0, token1, "BREAK", win_flags,
+                           BREAK_SET, '8', (char *) &win->linebreak))
     {
         err_line(2 < win->linebreak, "Value must be 0, 1 or 2.");
     }
-    else if (parse_val(token0, token1, "WIN_FOCUS", ord_flags,
-                       FOCUS_SET, 'c', &tmp_active))
+    else if (parse_flagval(token0, token1, "WIN_FOCUS", ord_flags,
+                           FOCUS_SET, 'c', &tmp_active))
     {
         char * err_null = "Value not empty as it should be.";
         char * err_outside = "ID not found in WIN_ORDER ID series.";
@@ -401,13 +400,8 @@ extern void obey_argv(int argc, char * argv[])
 
 extern void save_interface_conf()
 {
-    char * f_name = "save_interface_conf()";
-    char * path = world.path_interface;
-    size_t size = strlen(path) + 4 + 1;
-    char * path_tmp = try_malloc(size, f_name);
-    int test = snprintf(path_tmp, size, "%s_tmp", path);
-    exit_trouble(test < 0, f_name, "snprintf()");
-    FILE * file = try_fopen(path_tmp, "w", f_name);
+    char * path_tmp;
+    FILE * file = atomic_write_start(world.path_interface, &path_tmp);
     char * str_keybs = "\nKEYBINDINGS ";
     write_def(file, str_keybs, 1, "global", 's');
     write_keybindings(file, &world.kb_global);
@@ -431,8 +425,7 @@ extern void save_interface_conf()
         write_def(file, "HEIGHT ", 0, (char *) &win->target_height, 'i');
         write_keybindings(file, &win->kb);
     }
-    try_fclose_unlink_rename(file, path_tmp, path, f_name);
-    free(path_tmp);
+    atomic_write_finish(file, world.path_interface, path_tmp);
 }
 
 
@@ -446,6 +439,7 @@ extern void load_interface_conf()
     tmp_order    = try_malloc(1, f_name);
     tmp_order[0] = '\0';
     tmp_active   = '\0';
+    detect_atomic_leftover(world.path_interface);
     parse_file(world.path_interface, tokens_into_entries);
     char * err = "Not all expected windows defined in config file.";
     exit_err(strlen(world.winDB.legal_ids) != strlen(world.winDB.ids), err);