[PATCH] revised attributes with no scope handling

Dennis Preiser <[email protected]> Sat, 17 Sep 2011 12:10:23 +0200
Newsgroups gmane.network.tin.devel
Message-ID <[email protected]>
The error message which is issued when ~/.tin/attributes contains
attributes with no scope is not helpful or contains garbage. Create an
attributes file which contains only

show_author=0
verbatim_handling=ON

and start tin to see what I mean.

With the attached patch the error message contains the full line as the
comment suggests.

Dennis
20110917.diff (text/plain, 4.1 KB)
diff -urp tin-2.0.0/src/attrib.c tin-2.0.0_r1/src/attrib.c
--- tin-2.0.0/src/attrib.c	2011-05-10 15:45:52.000000000 +0200
+++ tin-2.0.0_r1/src/attrib.c	2011-09-17 11:43:42.000000000 +0200
@@ -55,7 +55,7 @@ int attrib_file_offset;
 /*
  * Local prototypes
  */
-static void set_attrib(int type, const char *scope, void *data);
+static void set_attrib(int type, const char *scope, const char *line, void *data);
 static void set_default_attributes(struct t_attribute *attributes, struct t_attribute *scope, t_bool global);
 static void set_default_state(struct t_attribute_state *state);
 #ifdef DEBUG
@@ -245,25 +245,25 @@ set_default_state(
 #define MATCH_BOOLEAN(pattern, type) \
 	if (match_boolean(line, pattern, &flag)) { \
 		num = (flag != FALSE); \
-		set_attrib(type, scope, &num); \
+		set_attrib(type, scope, line, &num); \
 		found = TRUE; \
 		break; \
 	}
 #define MATCH_INTEGER(pattern, type, maxval) \
 	if (match_integer(line, pattern, &num, maxval)) { \
-		set_attrib(type, scope, &num); \
+		set_attrib(type, scope, line, &num); \
 		found = TRUE; \
 		break; \
 	}
 #define MATCH_STRING(pattern, type) \
 	if (match_string(line, pattern, buf, sizeof(buf) - strlen(pattern))) { \
-		set_attrib(type, scope, buf); \
+		set_attrib(type, scope, line, buf); \
 		found = TRUE; \
 		break; \
 	}
 #define MATCH_LIST(pattern, type, table, tablelen) \
 	if (match_list(line, pattern, table, tablelen, &num)) { \
-		set_attrib(type, scope, &num); \
+		set_attrib(type, scope, line, &num); \
 		found = TRUE; \
 		break; \
 	}
@@ -424,7 +424,7 @@ read_attributes_file(
 					MATCH_STRING("quick_select_scope=", OPT_ATTRIB_QUICK_SELECT_SCOPE);
 					if (match_string(line, "quote_chars=", buf, sizeof(buf))) {
 						quote_dash_to_space(buf);
-						set_attrib(OPT_ATTRIB_QUOTE_CHARS, scope, buf);
+						set_attrib(OPT_ATTRIB_QUOTE_CHARS, scope, line, buf);
 						found = TRUE;
 						break;
 					}
@@ -497,7 +497,7 @@ read_attributes_file(
 								auto_cc_bcc = (auto_bcc ? AUTO_CC_BCC : AUTO_CC);
 							else
 								auto_cc_bcc = (auto_bcc ? AUTO_BCC : 0);
-							set_attrib(OPT_ATTRIB_AUTO_CC_BCC, scope, &auto_cc_bcc);
+							set_attrib(OPT_ATTRIB_AUTO_CC_BCC, scope, line, &auto_cc_bcc);
 							found = TRUE;
 							break;
 						}
@@ -506,7 +506,7 @@ read_attributes_file(
 								auto_cc_bcc = (auto_cc ? AUTO_CC_BCC : AUTO_BCC);
 							else
 								auto_cc_bcc = (auto_cc ? AUTO_CC : 0);
-							set_attrib(OPT_ATTRIB_AUTO_CC_BCC, scope, &auto_cc_bcc);
+							set_attrib(OPT_ATTRIB_AUTO_CC_BCC, scope, line, &auto_cc_bcc);
 							found = TRUE;
 							break;
 						}
@@ -547,21 +547,21 @@ read_attributes_file(
 
 		add_scope("*");
 		snprintf(buf, sizeof(buf), "%s", "~/.tin/headers");
-		set_attrib(OPT_ATTRIB_X_HEADERS, "*", buf);
+		set_attrib(OPT_ATTRIB_X_HEADERS, "*", line, buf);
 
 		add_scope("*sources*");
 		num = POST_PROC_SHAR;
-		set_attrib(OPT_ATTRIB_POST_PROCESS_TYPE, "*sources*", &num);
+		set_attrib(OPT_ATTRIB_POST_PROCESS_TYPE, "*sources*", "", &num);
 
 		add_scope("*binaries*");
 		num = POST_PROC_YES;
-		set_attrib(OPT_ATTRIB_POST_PROCESS_TYPE, "*binaries*", &num);
+		set_attrib(OPT_ATTRIB_POST_PROCESS_TYPE, "*binaries*", "", &num);
 		num = FALSE;
-		set_attrib(OPT_ATTRIB_TEX2ISO_CONV, "*binaries*", &num);
+		set_attrib(OPT_ATTRIB_TEX2ISO_CONV, "*binaries*", "", &num);
 		num = TRUE;
-		set_attrib(OPT_ATTRIB_DELETE_TMP_FILES, "*binaries*", &num);
+		set_attrib(OPT_ATTRIB_DELETE_TMP_FILES, "*binaries*", "", &num);
 		snprintf(buf, sizeof(buf), "%s", "poster");
-		set_attrib(OPT_ATTRIB_FOLLOWUP_TO, "*binaries*", buf);
+		set_attrib(OPT_ATTRIB_FOLLOWUP_TO, "*binaries*", "", buf);
 
 		write_attributes_file(file);
 	}
@@ -589,13 +589,13 @@ static void
 set_attrib(
 	int type,
 	const char *scope,
+	const char *line,
 	void *data)
 {
 	struct t_scope *curr_scope;
 
 	if (scope == NULL || *scope == '\0') {	/* No active scope set yet */
-		/* TODO: include full line in error-message */
-		error_message(2, _("attribute with no scope: %s"), (char *) data); /* TODO: -> lang.c */
+		error_message(2, _("attribute with no scope: %s"), line); /* TODO: -> lang.c */
 		return;
 	}