diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-02-19 03:04:39 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-02-19 03:08:16 +0100 |
commit | 2702a61b0e22ddcbd0b23c1765fac90fe766802a (patch) | |
tree | cb10887ccd29796673fc08bf8066c803add195a8 | |
parent | 136e5bc4f7095aef80e55c5e329de5e04bd85886 (diff) | |
download | calcurse-2702a61b0e22ddcbd0b23c1765fac90fe766802a.zip |
Fix hash table issues with ISO C99
ISO C99 forbids unnamed structs/unions and nested functions. Move the
"HTABLE_HEAD" and "HTABLE_GENERATE" parts out of the function body and
place them at the very top of the file (where function definitions are
allowed). Also, remove the unnamed struct from "htable.h" (which was
useless anyway).
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/htable.h | 4 | ||||
-rw-r--r-- | src/io.c | 17 | ||||
-rw-r--r-- | src/note.c | 10 |
3 files changed, 18 insertions, 13 deletions
diff --git a/src/htable.h b/src/htable.h index 10d04c1..efd7cac 100644 --- a/src/htable.h +++ b/src/htable.h @@ -69,9 +69,7 @@ struct name { \ } #define HTABLE_ENTRY(type) \ -struct { \ - struct type *next; /* To build the bucket chain list. */ \ -} +struct type *next /* To build the bucket chain list. */ #define HTABLE_SIZE(head) \ (sizeof (*(head)->bkts) ? sizeof ((head)->bkts) / sizeof (*(head)->bkts) : 0) @@ -72,6 +72,15 @@ struct ht_keybindings_s { HTABLE_ENTRY (ht_keybindings_s); }; +static void load_keys_ht_getkey (struct ht_keybindings_s *, char **, int *); +static int load_keys_ht_compare (struct ht_keybindings_s *, + struct ht_keybindings_s *); + +#define HSIZE 256 +HTABLE_HEAD (ht_keybindings, HSIZE, ht_keybindings_s); +HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey, + load_keys_ht_compare) + /* Draw a progress bar while saving, loading or exporting data. */ static void progress_bar (progress_bar_t type, int progress) @@ -752,12 +761,7 @@ io_load_keys (char *pager) keys_init (); -#define HSIZE 256 - HTABLE_HEAD (ht_keybindings, HSIZE, ht_keybindings_s) ht_keys = - HTABLE_INITIALIZER (&ht_keys); - - HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey, - load_keys_ht_compare); + struct ht_keybindings ht_keys = HTABLE_INITIALIZER (&ht_keys); for (i = 0; i < NBKEYS; i++) { @@ -874,7 +878,6 @@ io_load_keys (char *pager) keys_fill_missing (); if (keys_check_missing_bindings ()) WARN_MSG (_("Some actions do not have any associated key bindings!")); -#undef HSIZE } void @@ -46,6 +46,12 @@ struct note_gc_hash { HTABLE_ENTRY (note_gc_hash); }; +static void note_gc_extract_key (struct note_gc_hash *, char **, int *); +static int note_gc_cmp (struct note_gc_hash *, struct note_gc_hash *); + +HTABLE_HEAD (htp, NOTE_GC_HSIZE, note_gc_hash); +HTABLE_GENERATE (htp, note_gc_hash, note_gc_extract_key, note_gc_cmp) + /* Create note file from a string and return a newly allocated string that * contains its name. */ char * @@ -164,8 +170,7 @@ note_gc_cmp (struct note_gc_hash *a, struct note_gc_hash *b) void note_gc (void) { - HTABLE_HEAD (htp, NOTE_GC_HSIZE, note_gc_hash) gc_htable = - HTABLE_INITIALIZER (&gc_htable); + struct htp gc_htable = HTABLE_INITIALIZER (&gc_htable); struct note_gc_hash *hp; DIR *dirp; struct dirent *dp; @@ -177,7 +182,6 @@ note_gc (void) return; /* Insert all note file names into a hash table. */ - HTABLE_GENERATE (htp, note_gc_hash, note_gc_extract_key, note_gc_cmp); do { if ((dp = readdir (dirp)) && *(dp->d_name) != '.') |