summaryrefslogtreecommitdiffstats
path: root/dive.h
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-10 10:18:13 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-10 11:36:17 -0700
commiteb47b2a8d8764778697ac2fdb342c976cd487ca3 (patch)
tree99d51da8bb2a1cfc4ef9325258f22394630c28db /dive.h
parente8ee701d3573c860b09c2634647e9d00a0bb111c (diff)
downloadsubsurface-eb47b2a8d8764778697ac2fdb342c976cd487ca3.tar.gz
Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for the fact that I noticed it while writing the git saving code. The subsurface divetag list handling is being stupid, and has a initial dummy entry at the head of the list for no good reason. I say "no good reason", because there *is* a reason for it: it allows code to avoid the special case of empty list and adding entries to before the first entry etc etc. But that reason is a really *bad* reason, because it's valid only because people don't understand basic list manipulation and pointers to pointers. So get rid of the dummy element, and do things right instead - by passing a *pointer* to the list, instead of the list. And then when traversing the list and looking for a place to insert things, don't go to the next entry - just update the "pointer to pointer" to point to the address of the next entry. Each entry in a C linked list is no different than the list itself, so you can use the pointer to the pointer to the next entry as a pointer to the list. This is a pet peeve of mine. The real beauty of pointers can never be understood unless you understand the indirection they allow. People who grew up with Pascal and were corrupted by that mindset are mentally stunted. Niklaus Wirth has a lot to answer for! But never fear. You too can overcome that mental limitation, it just needs some brain exercise. Reading this patch may help. In particular, contemplate the new "taglist_add_divetag()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.h')
-rw-r--r--dive.h6
1 files changed, 2 insertions, 4 deletions
diff --git a/dive.h b/dive.h
index 6d6edaae9..febc6080c 100644
--- a/dive.h
+++ b/dive.h
@@ -315,7 +315,7 @@ struct tag_entry {
extern struct tag_entry *g_tag_list;
-struct divetag *taglist_add_tag(struct tag_entry *tag_list, const char *tag);
+struct divetag *taglist_add_tag(struct tag_entry **tag_list, const char *tag);
/*
* Writes all divetags in tag_list to buffer, limited by the buffer's (len)gth.
@@ -323,10 +323,8 @@ struct divetag *taglist_add_tag(struct tag_entry *tag_list, const char *tag);
*/
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len);
-void taglist_init(struct tag_entry **tag_list);
-void taglist_clear(struct tag_entry *tag_list);
void taglist_init_global();
-
+void taglist_free(struct tag_entry *tag_list);
/*
* Events are currently pretty meaningless. This is