--- options.c.orig	Thu Dec  6 17:53:03 2001
+++ options.c	Thu Dec  6 19:13:54 2001
@@ -245,35 +245,6 @@
 }
   
 /****************************************************************
-...								
-*****************************************************************/
-static FILE *open_option_file(char *mode)
-{
-  char *name;
-  FILE *f;
-
-  name = option_file_name();
-  if (name==NULL) {
-    return NULL;
-  }
-  f = fopen(name, mode);
-
-  if(mode[0]=='w') {
-    char output_buffer[256];
-    if (f) {
-      my_snprintf(output_buffer, sizeof(output_buffer),
-		  _("Settings file is %s"), name);
-    } else {
-      my_snprintf(output_buffer, sizeof(output_buffer),
-		  _("Cannot write to file %s"), name);
-    }
-    append_output_window(output_buffer);
-  }
-  
-  return f;
-}
-
-/****************************************************************
 ... 
 *****************************************************************/
 void load_options(void)
@@ -323,38 +294,46 @@
 *****************************************************************/
 void save_options(void)
 {
-  FILE *option_file;
+  struct section_file sf;
   client_option *o;
+  char *name;
+  char output_buffer[256];
   view_option *v;
   int i;
 
-  option_file = open_option_file("w");
-  if (option_file==NULL) {
-    append_output_window(_("Cannot save settings."));
+  name = option_file_name();
+  if(name == NULL) {
+    append_output_window(_("Save failed, cannot find a filename."));
     return;
   }
 
-  fprintf(option_file, "# settings file for freeciv client version %s\n#\n",
-	 VERSION_STRING);
-  
-  fprintf(option_file, "[client]\n");
+  section_file_init(&sf);
 
-  for (o=options; o->name; o++) {
-    fprintf(option_file, "%s = %d\n", o->name, *(o->p_value));
-  }
-  for (v=view_options; v->name; v++) {
-    fprintf(option_file, "%s = %d\n", v->name, *(v->p_value));
+  for(o=options; o->name; o++)
+    secfile_insert_int(&sf, *(o->p_value), "client.%s", o->name);
+
+  for(v=view_options; v->name; v++)
+    secfile_insert_int(&sf, *(v->p_value), "client.%s", v->name);
+
+  for(i=0; i < E_LAST; i++) {
+    /* this next line puts a comment into the file. yep, it's ugly. */
+    secfile_insert_int(&sf, 0, "client.# 0=== %s ==", message_text[i]);
+    secfile_insert_int(&sf, messages_where[i],"client.message_where_%02d", i);
   }
-  for (i=0; i<E_LAST; i++) {
-    fprintf(option_file, "message_where_%02d = %d  # %s\n",
-	   i, messages_where[i], message_text[i]);
+
+  for(i=1; i < num_city_report_spec(); i++) {
+    secfile_insert_int(&sf, *(city_report_spec_show_ptr(i)),
+                       "client.city_report_%s", city_report_spec_tagname(i));
   }
-  for (i=1; i<num_city_report_spec(); i++) {
-    fprintf(option_file, "city_report_%s = %d\n",
-	   city_report_spec_tagname(i), *(city_report_spec_show_ptr(i)));
+
+  if(!section_file_save(&sf, name, 0)) {
+    my_snprintf(output_buffer, sizeof(output_buffer),
+                _("Save failed, cannot write to file %s"), name);
+  } else {
+    my_snprintf(output_buffer, sizeof(output_buffer),
+                _("Saved setttings to file %s"), name);
   }
 
-  fclose(option_file);
-  
-  append_output_window(_("Saved settings."));
+  append_output_window(output_buffer);
+  section_file_free(&sf);
 }