Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8504) Add function to get all section entries
Home

[Freeciv-Dev] (PR#8504) Add function to get all section entries

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8504) Add function to get all section entries
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Tue, 13 Apr 2004 09:12:08 -0700
Reply-to: rt@xxxxxxxxxxx

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


For things like

[key_bindings]
c="center_unit"
C="center_capital"

Kp8="move_unit(n)"
Kp6="move_unit(e)"
Kp2="move_unit(s)"
Kp4="move_unit(w)"

Kp7="move_unit(nw)"
Kp9="move_unit(ne)"
Kp3="move_unit(se)"
Kp1="move_unit(sw)"

Left="scroll(left,1,tile)"
Right="scroll(right,1,tile)"
Up="scroll(up,1,tile)"
Down="scroll(down,1,tile)"

Shift-Left="scroll(left,0.5,screen)"
Shift-Right="scroll(right,0.5,screen)"
Shift-Up="scroll(up,0.5,screen)"
Shift-Down="scroll(down,0.5,screen)"

Alt-Left="scroll(left,1,pixel)"
Alt-Right="scroll(right,1,pixel)"
Alt-Up="scroll(up,1,pixel)"
Alt-Down="scroll(down,1,pixel)"

I need a way to iterate over all keys of the given section. The
attached patch add such a function.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "These download files are in Microsoft Word 6.0 format. After
  unzipping, these files can be viewed in any text editor, including
  all versions of Microsoft Word, WordPad, and Microsoft Word Viewer."
    -- http://www.microsoft.com/hwdev/pc99.htm

Index: common/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/registry.c,v
retrieving revision 1.60
diff -u -u -r1.60 registry.c
--- common/registry.c   1 Nov 2003 01:02:38 -0000       1.60
+++ common/registry.c   13 Apr 2004 16:07:35 -0000
@@ -1540,5 +1540,50 @@
     }
   }
   section_list_iterate_end;
+  return ret;
+}
+
+/***************************************************************
+  Returns pointer to list of strings giving all key in the given
+  section and sets the number of such sections in (*num).  If there
+  are none such, returns NULL and sets (*num) to zero.  The returned
+  pointer is malloced, and it is the responsibilty of the caller to
+  free this pointer, but the actual strings pointed to are part of the
+  section_file data, and should not be freed by the caller (nor used
+  after the section_file has been freed or changed).  The order of the
+  returned names is undefined.
+***************************************************************/
+char **secfile_get_section_entries(struct section_file *my_section_file,
+                                  const char *section, int *num)
+{
+  char **ret;
+  struct section *psection = NULL;
+  int i;
+
+  section_list_iterate_rev(*my_section_file->sections, asection) {
+    if (strcmp(asection->name, section) == 0) {
+      psection = asection;
+      break;
+    }
+  } section_list_iterate_rev_end;
+
+  if(!psection) {
+      *num=0;
+      return NULL;
+  }
+
+  *num = entry_list_size(&psection->entries);
+
+  if (*num == 0) {
+    return NULL;
+  }
+
+  ret = fc_malloc((*num) * sizeof(char *));
+
+  i = 0;  
+  entry_list_iterate(psection->entries, pentry) {
+    ret[i++] = pentry->name;
+  } entry_list_iterate_end;
+
   return ret;
 }
Index: common/registry.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/registry.h,v
retrieving revision 1.23
diff -u -u -r1.23 registry.h
--- common/registry.h   6 Dec 2002 15:13:32 -0000       1.23
+++ common/registry.h   13 Apr 2004 16:07:35 -0000
@@ -106,6 +106,9 @@
 char **secfile_get_secnames_prefix(struct section_file *my_section_file,
                                   const char *prefix, int *num);
 
+char **secfile_get_section_entries(struct section_file *my_section_file,
+                                  const char *section, int *num);
+
 /* Only need use these explicitly on section_files constructed,
    not for ones generated by section_file_load:
 */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8504) Add function to get all section entries, Raimar Falke <=