[PATCH 2/3] Simplify tripflags: remove tripflag_names[]

Linus Torvalds torvalds at linux-foundation.org
Mon Nov 26 15:21:32 PST 2012


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 26 Nov 2012 14:52:07 -0800
Subject: [PATCH 2/3] Simplify tripflags: remove tripflag_names[]

This removes the tripflag name array, since it's not actually useful.
The only information we ever save in the XML file is whether a dive is
explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and
everything else is implicit.

I'm going to simplify the trip flags further (possibly removing it
entirely - like I did for dive trips already), and don't like having to
maintain the tripflag_names[] array logic.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This just removes a bit of code, but more importantly it will make it 
easier to eventually change/remove the tripflag thing.

 dive.h      |  1 -
 divelist.c  |  5 -----
 parse-xml.c | 10 ++--------
 save-xml.c  | 10 ++--------
 4 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/dive.h b/dive.h
index abe852508b69..4eb81752f83f 100644
--- a/dive.h
+++ b/dive.h
@@ -270,7 +270,6 @@ struct divecomputer {
 #define W_IDX_SECONDARY 1
 
 typedef enum { TF_NONE, NO_TRIP, IN_TRIP, ASSIGNED_TRIP, NUM_TRIPFLAGS } tripflag_t;
-extern const char *tripflag_names[NUM_TRIPFLAGS];
 
 typedef struct dive_trip {
 	timestamp_t when;
diff --git a/divelist.c b/divelist.c
index 2d759a606ab2..566cf0bf9841 100644
--- a/divelist.c
+++ b/divelist.c
@@ -43,11 +43,6 @@ static struct DiveList dive_list;
 dive_trip_t *dive_trip_list;
 gboolean autogroup = FALSE;
 
-/* this duplicate assignment of "INTRIP" causes the save_xml code
- * to convert an ASSIGNED_TRIP (which is temporary in memory) to
- * a statically assigned trip (INTRIP) in file */
-const char *tripflag_names[NUM_TRIPFLAGS] = { "TF_NONE", "NOTRIP", "INTRIP", "INTRIP" };
-
 /*
  * The dive list has the dive data in both string format (for showing)
  * and in "raw" format (for sorting purposes)
diff --git a/parse-xml.c b/parse-xml.c
index 1d08ca009165..35e87a2d5652 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -533,14 +533,8 @@ static void hex_value(char *buffer, void *_i)
 static void get_tripflag(char *buffer, void *_tf)
 {
 	tripflag_t *tf = _tf;
-	tripflag_t i;
-
-	*tf = TF_NONE;
-	for (i = NO_TRIP; i < NUM_TRIPFLAGS; i++)
-		if(! strcmp(buffer, tripflag_names[i])) {
-			*tf = i;
-			break;
-		}
+	*tf = strcmp(buffer, "NOTRIP") ? TF_NONE : NO_TRIP;
+	free(buffer);
 }
 
 static void centibar(char *buffer, void *_pressure)
diff --git a/save-xml.c b/save-xml.c
index 58faf6aeb3ab..8d7d7f889766 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -373,14 +373,8 @@ static void save_dive(FILE *f, struct dive *dive)
 	fputs("<dive", f);
 	if (dive->number)
 		fprintf(f, " number='%d'", dive->number);
-	/*
-	 * TF_NONE is the default for dives with no trips
-	 * IN_TRIP is the default for dives with trips
-	 * ASSIGNED_TRIP is an in-memory thing and gets converted
-	 *    to IN_TRIP by the save code.
-	 */
-	if (dive->tripflag != TF_NONE && dive->tripflag != IN_TRIP && dive->tripflag != ASSIGNED_TRIP)
-		fprintf(f, " tripflag='%s'", tripflag_names[dive->tripflag]);
+	if (dive->tripflag == NO_TRIP)
+		fprintf(f, " tripflag='NOTRIP'");
 	if (dive->rating)
 		fprintf(f, " rating='%d'", dive->rating);
 	if (dive->visibility)
-- 
1.8.0.dirty



More information about the subsurface mailing list