Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2003:
[Freeciv-Dev] (PR#6410) make helpdata.c use speclist
Home

[Freeciv-Dev] (PR#6410) make helpdata.c use speclist

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6410) make helpdata.c use speclist
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 6 Oct 2003 08:19:18 -0700
Reply-to: rt@xxxxxxxxxxxxxx

One of the last holdouts of direct use of the genlist, the ugly helpdata
list implementation, is here transformed into a speclist. Much nicer.

  - Per

Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.64
diff -u -r1.64 helpdata.c
--- client/helpdata.c   1 Sep 2003 15:22:42 -0000       1.64
+++ client/helpdata.c   6 Oct 2003 15:16:32 -0000
@@ -39,27 +39,26 @@
 
 #include "helpdata.h"
 
-
 static const char * const help_type_names[] = {
   "(Any)", "(Text)", "Units", "Improvements", "Wonders",
   "Techs", "Terrain", "Governments", NULL
 };
 
-
 #define MAX_LAST (MAX(MAX(MAX(A_LAST,B_LAST),U_LAST),T_COUNT))
 
+#define SPECLIST_TAG help
+#define SPECLIST_TYPE struct help_item
+#include "speclist.h"
+#define SPECLIST_TAG help
+#define SPECLIST_TYPE struct help_item
+#include "speclist_c.h"
+
+#define help_list_iterate(helplist, phelp) \
+    TYPED_LIST_ITERATE(struct help_item, helplist, phelp)
+#define help_list_iterate_end  LIST_ITERATE_END
 
-/* speclist? */
-#define help_list_iterate(helplist, pitem) { \
-  struct genlist_iterator myiter; \
-  struct help_item *pitem; \
-  for( genlist_iterator_init(&myiter, &helplist, 0); \
-       (pitem=ITERATOR_PTR(myiter)); \
-       ITERATOR_NEXT(myiter) ) {
-#define help_list_iterate_end }}
-
-static struct genlist help_nodes;
-static struct genlist_iterator help_nodes_iterator;
+static struct genlist_link *help_nodes_iterator;
+static struct help_list help_nodes;
 static bool help_nodes_init = FALSE;
 /* helpnodes_init is not quite the same as booted in boot_help_texts();
    latter can be 0 even after call, eg if couldn't find helpdata.txt.
@@ -76,7 +75,7 @@
 static void check_help_nodes_init(void)
 {
   if (!help_nodes_init) {
-    genlist_init(&help_nodes);
+    help_list_init(&help_nodes);
     help_nodes_init = TRUE;    /* before help_iter_start to avoid recursion! */
     help_iter_start();
   }
@@ -92,10 +91,8 @@
     free(ptmp->topic);
     free(ptmp->text);
     free(ptmp);
-  }
-  help_list_iterate_end;
-  genlist_unlink_all(&help_nodes);
-  help_iter_start();
+  } help_list_iterate_end;
+  help_list_unlink_all(&help_nodes);
 }
 
 /****************************************************************
@@ -154,7 +151,7 @@
 }
 
 /****************************************************************
- for genlist_sort(); sort by topic via compare_strings()
+ for help_list_sort(); sort by topic via compare_strings()
  (sort topics with more leading spaces after those with fewer)
 *****************************************************************/
 static int help_item_compar(const void *a, const void *b)
@@ -241,9 +238,9 @@
           to change that now.  --dwp
        */
        char name[MAX_LEN_NAME+2];
-       struct genlist category_nodes;
+       struct help_list category_nodes;
        
-       genlist_init(&category_nodes);
+       help_list_init(&category_nodes);
        if(current_type==HELP_UNIT) {
          unit_type_iterate(i) {
            if(unit_type_exists(i)) {
@@ -251,7 +248,7 @@
              my_snprintf(name, sizeof(name), " %s", unit_name(i));
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
-             genlist_insert(&category_nodes, pitem, -1);
+             help_list_insert_back(&category_nodes, pitem);
            }
          } unit_type_iterate_end;
        } else if(current_type==HELP_TECH) {
@@ -261,7 +258,7 @@
              my_snprintf(name, sizeof(name), " %s", advances[i].name);
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
-             genlist_insert(&category_nodes, pitem, -1);
+             help_list_insert_back(&category_nodes, pitem);
            }
          } tech_type_iterate_end;
        } else if(current_type==HELP_TERRAIN) {
@@ -271,7 +268,7 @@
              my_snprintf(name, sizeof(name), " %s", 
tile_types[i].terrain_name);
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
-             genlist_insert(&category_nodes, pitem, -1);
+             help_list_insert_back(&category_nodes, pitem);
            }
          }
          /* Add special Civ2-style river help text if it's supplied. */
@@ -282,7 +279,7 @@
            strcpy(long_buffer, _(terrain_control.river_help_text));
            wordwrap_string(long_buffer, 68);
            pitem->text = mystrdup(long_buffer);
-           genlist_insert(&category_nodes, pitem, -1);
+           help_list_insert_back(&category_nodes, pitem);
          }
        } else if(current_type==HELP_GOVERNMENT) {
          government_iterate(gov) {
@@ -290,7 +287,7 @@
            my_snprintf(name, sizeof(name), " %s", gov->name);
            pitem->topic = mystrdup(name);
            pitem->text = mystrdup("");
-           genlist_insert(&category_nodes, pitem, -1);
+           help_list_insert_back(&category_nodes, pitem);
          } government_iterate_end;
        } else if(current_type==HELP_IMPROVEMENT) {
          impr_type_iterate(i) {
@@ -299,7 +296,7 @@
              my_snprintf(name, sizeof(name), " %s", improvement_types[i].name);
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
-             genlist_insert(&category_nodes, pitem, -1);
+             help_list_insert_back(&category_nodes, pitem);
            }
          } impr_type_iterate_end;
        } else if(current_type==HELP_WONDER) {
@@ -309,18 +306,18 @@
              my_snprintf(name, sizeof(name), " %s", improvement_types[i].name);
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
-             genlist_insert(&category_nodes, pitem, -1);
+             help_list_insert_back(&category_nodes, pitem);
            }
          } impr_type_iterate_end;
        } else {
          die("Bad current_type %d", current_type);
        }
-       genlist_sort(&category_nodes, help_item_compar);
+       help_list_sort(&category_nodes, help_item_compar);
        help_list_iterate(category_nodes, ptmp) {
-         genlist_insert(&help_nodes, ptmp, -1);
+         help_list_insert_back(&help_nodes, ptmp);
        }
        help_list_iterate_end;
-       genlist_unlink_all(&category_nodes);
+       help_list_unlink_all(&category_nodes);
        continue;
       }
     }
@@ -348,7 +345,7 @@
     paras = NULL;
     wordwrap_string(long_buffer, 68);
     pitem->text=mystrdup(long_buffer);
-    genlist_insert(&help_nodes, pitem, -1);
+    help_list_insert_back(&help_nodes, pitem);
   }
 
   free(sec);
@@ -372,7 +369,7 @@
 int num_help_items(void)
 {
   check_help_nodes_init();
-  return genlist_size(&help_nodes);
+  return help_list_size(&help_nodes);
 }
 
 /****************************************************************
@@ -385,7 +382,7 @@
   int size;
   
   check_help_nodes_init();
-  size = genlist_size(&help_nodes);
+  size = help_list_size(&help_nodes);
   if (pos < 0 || pos > size) {
     freelog(LOG_ERROR, "Bad index %d to get_help_item (size %d)", pos, size);
     return NULL;
@@ -393,7 +390,7 @@
   if (pos == size) {
     return NULL;
   }
-  return genlist_get(&help_nodes, pos);
+  return help_list_get(&help_nodes, pos);
 }
 
 /****************************************************************
@@ -457,7 +454,7 @@
 void help_iter_start(void)
 {
   check_help_nodes_init();
-  genlist_iterator_init(&help_nodes_iterator, &help_nodes, 0);
+  help_nodes_iterator = help_nodes.list.head_link;
 }
 
 /****************************************************************
@@ -469,8 +466,9 @@
   const struct help_item *pitem;
   
   check_help_nodes_init();
-  pitem = ITERATOR_PTR(help_nodes_iterator);
-  ITERATOR_NEXT(help_nodes_iterator);
+  pitem = help_nodes_iterator->dataptr;
+  help_nodes_iterator = help_nodes_iterator->next;
+
   return pitem;
 }
 

[Prev in Thread] Current Thread [Next in Thread]