update
authorPekka Riikonen <priikone@silcnet.org>
Sun, 25 Feb 2001 13:01:24 +0000 (13:01 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 25 Feb 2001 13:01:24 +0000 (13:01 +0000)
doc/CodingStyle

index 251deb918c967d66cd05e3dd1f5cb6a7928f0afe..3cd7c5937894c1e6d3f42c71832a374f642655fa 100644 (file)
@@ -570,6 +570,62 @@ ass sometimes.  But after the grand idea behind callback functions
 becomes clear they are a wonderful tool.
 
 
+Lists
+=====
+
+SILC has two different list API's.  The List API and the Dynamic List API.
+Both are based on the TRQ library.  For definitions of List API see
+lib/trq/silclist.h and for Dynamic List API see lib/trq/silcdlist.h. 
+Following short example of the List API.
+
+List API
+
+typedef struct SilcDummyStruct {
+  int dummy;
+  void *context;
+  struct SilcDummyStruct *next;
+} SilcDummy;
+
+int main()
+{
+  SilcList list;
+  SilcDummy *dummy;
+  SilcDummy *entry;
+
+  /* Initialize the list */
+  silc_list_init(list, struct SilcDummyStruct, next);
+
+  /* Allocate one list entry */        
+  dummy = silc_calloc(1, sizeof(*dummy));
+  dummy->dummy = 100;
+  dummy->context = NULL;
+
+  /* Add the entry to the list */
+  silc_list_add(list, dummy);
+
+  /* Allocate second list entry */     
+  dummy = silc_calloc(1, sizeof(*dummy));
+  dummy->dummy = 3000;
+  dummy->context = NULL;
+
+  /* Add the entry to the list */
+  silc_list_add(list, dummy);
+       
+  /* Then traverse the list, print the values, remove from list and free
+     memory */
+  silc_list_start(list)
+  while ((entry = silc_list_get(list)) != SILC_LIST_END) {
+    fprintf(stderr, "%d\n", entry->dummy);
+
+    /* Remove from list and free memory */
+    silc_list_del(list, entry);  
+    silc_free(entry);
+  }
+
+  return 0;
+}
+
+
 Copyrights of the Code
 ======================