[elinks-dev] Smart config - patch

Witold Filipczyk witekfl at poczta.gazeta.pl
Thu Oct 30 23:37:06 PST 2003


Once again patch for smart config. No need for '\n' in descriptions.
Descriptions are automatically wrapped around 80th column.
-- 
Witold Filipczyk tohu-bohu
<witekfl at poczta.gazeta.pl>
-------------- next part --------------
--- elinks/src/config/conf.c	Sat Oct 25 06:36:24 2003
+++ elinks.2/src/config/conf.c	Sat Oct 25 05:33:04 2003
@@ -479,7 +481,6 @@
 		       int action, int i18n)
 {
 	unsigned char *desc_i18n;
-	int i, l;
 
 	/* When we're OPT_TREE, we won't get called with action 2 anyway and
 	 * we want to pop out a comment. */
@@ -515,22 +516,44 @@
 				break;
 
 			desc_i18n = conf_i18n(option->desc, i18n);
-			l = strlen(desc_i18n);
 
 			if (depth)
 				add_xchar_to_string(string, ' ', depth * indentation);
 			add_to_string(string, "# ");
+			{
+				unsigned char *i = desc_i18n;
+				unsigned char *j = i;
+				unsigned char *last_space = NULL;
+				int config_width = 80;
+				int n = depth * indentation + 2;
+				
+				for (; *i; i++, n++) {
+					if (*i == '\n') {
+						add_bytes_to_string(string, j, i - j + 1);
+						if (depth)
+							add_xchar_to_string(string, ' ', depth * indentation);
+						add_to_string(string, "# ");
+						j = i + 1;
+						n = depth * indentation + 1;
+						last_space = NULL;
+						continue;
+					}
 
-			for (i = 0; i < l; i++) {
-				add_char_to_string(string, desc_i18n[i]);
-				if (desc_i18n[i] == '\n') {
-					if (depth)
-						add_xchar_to_string(string, ' ',
-								    depth * indentation);
-					add_to_string(string, "# ");
+					if (*i == ' ') last_space = i;
+
+					if (n >= config_width && last_space) {
+						add_bytes_to_string(string, j, last_space - j);
+						add_char_to_string(string, '\n');
+						if (depth)
+							add_xchar_to_string(string, ' ', depth * indentation);
+						add_to_string(string, "# ");
+						j = last_space + 1;
+						n = depth * indentation + 1 + i - last_space;
+						last_space = NULL;
+					}
 				}
+				add_to_string(string, j);
 			}
-
 			add_char_to_string(string, '\n');
 			break;
 


More information about the elinks-dev mailing list