Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9685) Make server create a wiki server manual
Home

[Freeciv-Dev] (PR#9685) Make server create a wiki server manual

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9685) Make server create a wiki server manual
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Thu, 12 Aug 2004 04:30:28 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9685 >

This is a first, experimental patch to make the server output its own
manual. Use the command "/manual" to write the files "manual1.txt" and
"manual2.txt". The latter is currently empty, the former contains all
server options described in the wiki format.

Problem: The resulting file is long (22kb), and cut'n'paste into the wiki
edit box is extremely tedious. We cannot upload whole pages into the wiki
either. Any suggestions?

  - Per

Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.335
diff -u -r1.335 stdinhand.c
--- server/stdinhand.c  9 Aug 2004 15:45:49 -0000       1.335
+++ server/stdinhand.c  12 Aug 2004 11:27:07 -0000
@@ -1163,6 +1163,7 @@
   CMD_LOAD,
   CMD_READ_SCRIPT,
   CMD_WRITE_SCRIPT,
+  CMD_WRITE_MANUAL,
 
   /* undocumented */
   CMD_RFCSTYLE,
@@ -1490,6 +1491,11 @@
    N_("write <file-name>"),
    N_("Write current settings as server commands to file."), NULL
   },
+  {"manual",   ALLOW_HACK,
+   /* TRANS: translate text between <> only */
+   N_("manual"),
+   N_("Write the server manual."), NULL
+  },
   {"rfcstyle", ALLOW_HACK,
    "rfcstyle",
    N_("Switch server output between 'RFC-style' and normal style."), NULL
@@ -2264,6 +2270,66 @@
 }
 
 /**************************************************************************
+  Write a server manual in wiki format.
+**************************************************************************/
+static bool manual_command(struct connection *caller, bool check)
+{
+  FILE *doc1;
+  FILE *doc2;
+
+  if (check) {
+    return TRUE; /* Always */
+  }
+  if (is_reg_file_for_access("manual1.txt", TRUE)
+      && is_reg_file_for_access("manual2.txt", TRUE)
+      && (doc1 = fopen("manual1.txt", "w"))
+      && (doc2 = fopen("manual2.txt", "w"))) {
+    int i;
+
+    fprintf(doc1, "<h1>Freeciv %s server commands</h1>\n\n", VERSION_STRING);
+
+    for (i = 0; settings[i].name; i++) {
+      struct settings_s *op = &settings[i];
+
+      assert(op->short_help != NULL);
+      assert(op->extra_help != NULL);
+      fprintf(doc1, "=== %s ===\n\n", op->name);
+      fprintf(doc1, "%s\n\n", _(op->short_help));
+      if (strlen(op->extra_help) > 0) {
+        fprintf(doc1, "%s\n\n", _(op->extra_help));
+      }
+      fprintf(doc1, "Status: %s\n\n", (sset_is_changeable(i)
+                                      ? _("changeable") : _("fixed")));
+      switch (op->type) {
+      case SSET_BOOL:
+        fprintf(doc1,
+               _("Value: %d, Minimum: 0, Default: %d, Maximum: 1\n\n"),
+               (*(op->bool_value)) ? 1 : 0, op->bool_default_value ? 1 : 0);
+        break;
+      case SSET_INT:
+        fprintf(doc1,
+               _("Value: %d, Minimum: %d, Default: %d, Maximum: %d\n\n"),
+               *(op->int_value), op->int_min_value, op->int_default_value,
+               op->int_max_value);
+        break;
+      case SSET_STRING:
+        fprintf(doc1,
+               _("Value: \"%s\", Default: \"%s\"\n\n"), op->string_value,
+               op->string_default_value);
+        break;
+      }
+    }
+
+    fclose(doc1);
+    fclose(doc2);
+    return TRUE;
+  } else {
+    freelog(LOG_ERROR, _("Could not write manual files."));
+    return FALSE;
+  }
+}
+
+/**************************************************************************
 ...
 (Should this take a 'caller' argument for output? --dwp)
 **************************************************************************/
@@ -4479,6 +4545,8 @@
     return save_command(caller,arg, check);
   case CMD_LOAD:
     return load_command(caller, arg, check);
+  case CMD_WRITE_MANUAL:
+    return manual_command(caller, check);
   case CMD_METAINFO:
     return metainfo_command(caller, arg, check);
   case CMD_METACONN:

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9685) Make server create a wiki server manual, Per I. Mathisen <=