[Initng-svn] r4009 - initng/trunk/plugins/iparser

svn at initng.thinktux.net svn at initng.thinktux.net
Thu May 4 12:02:18 CEST 2006


Author: jimmy
Date: Thu May  4 12:02:17 2006
New Revision: 4009

Modified:
   initng/trunk/plugins/iparser/initng_i_parser.c

Log:
I parser ability to add \; to not break on a ; char.
This patch will alomoast garranty new bugs, im so sure, but deac promised to fix them all :-)


Modified: initng/trunk/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/trunk/plugins/iparser/initng_i_parser.c	(original)
+++ initng/trunk/plugins/iparser/initng_i_parser.c	Thu May  4 12:02:17 2006
@@ -40,8 +40,10 @@
 #include <initng_error.h>
 #include <initng_handler.h>
 #include <initng-paths.h>
-
-#define ENDED(x) (!(x)[0] || (x)[0]=='\n')
+/* a check with escape chars check */
+#define CH_(STRING, CHAR) (((*STRING)[0] == CHAR) && ((*STRING)[-1] != '\\'))
+#define CHL_(STRING, LEN, CHAR) (((*STRING)[LEN] == CHAR) && ((*STRING)[LEN-1] != '\\'))
+#define ENDED(x) (!(x)[0] || ((x)[0]=='\n' && (x)[-1]!='\\'))
 const char *g_filename = NULL;
 const char *g_pointer = NULL;	/* a pointer to the first char we can back step to when printing line copies */
 
@@ -338,7 +340,8 @@
 			   exact_match ? exact_match->name : NULL);
 
 			/* ok, jump the ending '}' stack */
-			if (file[0] == '}')
+			/* NOTE: file == file_conenct, we cant check file[-1] */
+			if (file[0] == '}' && (file != file_content && file[-1] != '\\'))
 				file++;
 		}
 
@@ -419,7 +422,7 @@
 
 	/* service test : class { */
 	/*              |         */
-	if ((*to_parse)[0] == ':')
+	if (CH_(to_parse, ':'))
 	{
 		(*to_parse)++;
 		/* service test : class { */
@@ -470,7 +473,7 @@
 	DL_(*to_parse, "Parse opt, should stand directly over { char");
 	/* service test : class { */
 	/*                      | */
-	if ((*to_parse)[0] != '{')
+	if (!CH_(to_parse, '{'))
 	{
 		/* something is wrong */
 		FL_(*to_parse, "error parsing, expected something else.");
@@ -530,14 +533,15 @@
 		JUMP_NSPACES(*to_parse);
 
 		/* end of row */
-		if ((*to_parse)[0] == ';')
+		/* TODO, make sure (*to_parse)[-1] is not before the string */
+		if (CH_(to_parse, ';'))
 		{
 			(*to_parse)++;
 			continue;
 		}
 
 		/* end of file or stack */
-		if (!(*to_parse)[0] || (*to_parse)[0] == '}')
+		if (!(*to_parse) || CH_(to_parse, '}'))
 		{
 			DL_(*to_parse,
 				"When escaping from parse_service_line while loop");
@@ -545,7 +549,7 @@
 		}
 
 		/* skip lines starting with '#' */
-		if ((*to_parse)[0] == '#')
+		if (CH_(to_parse, '#'))
 		{
 			REALLY_JUMP_TO_NEXT_ROW(*to_parse);
 			continue;
@@ -557,7 +561,7 @@
 		/* parse line - search for keywords in g.option_table */
 		if (parse_opt(to_parse, type, new_service))
 		{
-			if ((*to_parse)[0] != ';')
+			if (!CH_(to_parse, ';'))
 			{
 				FL_(*to_parse, "Must be a ';' char here");
 				break;
@@ -647,7 +651,7 @@
 	 */
 
 	/* skip empty services */
-	if ((*where)[0] == '}')
+	if (CH_(where, '}'))
 	{
 		FL_(*where, "found a } char here!");
 		return (FALSE);
@@ -696,7 +700,7 @@
 	 */
 	DL_(*where, "parse opt, before fetching opt name:");
 
-	if ((*where)[0] != '=' && (*where)[0] != ';')
+	if (!CH_(where, '=') && !CH_(where, ';'))
 	{
 		/* count number of chars this option name have */
 		if (!(var_len = strcspn((*where), "\n; \t=\"'")))
@@ -837,7 +841,7 @@
 	 * "         |"
 	 */
 
-	if ((*value)[0] == ';')
+	if (CH_(value, ';'))
 	{
 		D_("set_parser(%s,s,%s);\n", type->opt_name, from_service->name);
 		set_var(type, va, from_service);
@@ -849,7 +853,7 @@
 	 * "   enable = yes"
 	 * "          |    "
 	 */
-	if ((*value)[0] != '=')
+	if (!CH_(value, '='))
 	{
 		FL_(*value, "There should be an ';' or '=' here!");
 		return (FALSE);
@@ -912,7 +916,7 @@
 	 */
 
 	DL_(*value, "string_parser()");
-	if ((*value)[0] != '=')
+	if (!CH_(value, '='))
 	{
 		FL_(*value, "There should be an = here.");
 		return (FALSE);
@@ -946,7 +950,7 @@
 	to = dup_string_and_walk(value, FALSE);
 
 	/* go to the end and stay there */
-	while ((*value)[0] && (*value)[0] != ';')
+	while ((*value)[0] && !CH_(value, ';'))
 		(*value)++;
 
 	DL_(*value, "skip to the ';' char");
@@ -964,7 +968,7 @@
 		return (FALSE);
 	}
 
-	if ((*value)[0] != ';')
+	if (!CH_(value, ';'))
 	{
 		FL_(*value, "There should be an ; here.");
 		if ((*value)[0] == '\n')
@@ -997,7 +1001,8 @@
 	 * "         |     "
 	 */
 
-	if ((*value)[0] != '=')
+	if (!CH_(value, '='))
+	
 	{
 		FL_(*value, "Missing an '=' here.");
 		return (FALSE);
@@ -1031,7 +1036,7 @@
 
 	len = strcspn(*value, "\n;");
 	/* make sure the end is a ';' */
-	if ((*value)[len] != ';')
+	if (!CHL_(value, len, ';'))
 	{
 		FL_(*value, "Missing an ';' char.");
 		return (FALSE);
@@ -1078,7 +1083,7 @@
 	DL_(*value, "strings_parser()");
 
 
-	if ((*value)[0] != '=')
+	if (!CH_(value, '='))
 	{
 		FL_(*value, "Missing an '=' here.");
 		return (FALSE);
@@ -1122,13 +1127,13 @@
 			set_another_string_var(type, NULL, from_service, to);
 		}
 		/* check if this is end */
-		if ((*value)[0] == ';')
+		if (CH_(value, ';'))
 			break;
 
 		JUMP_NSPACES(*value);
 
 		/* check if this is end */
-		if ((*value)[0] == ';')
+		if (CH_(value, ';'))
 			break;
 		if (ENDED(*value))
 			break;
@@ -1148,7 +1153,7 @@
 	 */
 
 	DL_(*value, "all added");
-	if ((*value)[0] != ';')
+	if (!CH_(value, ';'))
 	{
 		FL_(*value, "End char is not an ';'.");
 		return (FALSE);
@@ -1206,7 +1211,7 @@
 
 
 	/* If this value we should copy is stacked in braces */
-	if ((*value)[0] == '{')
+	if (CH_(value, '{'))
 	{
 		int stack = 1;
 
@@ -1218,14 +1223,13 @@
 		/* count length to the '}' char */
 		while ((*value)[len])
 		{
-			if ((*value)[len] == '{')
+			if (CHL_(value, len, '{'))
 				stack++;
-			else if ((*value)[len] == '}')
+			else if (CHL_(value, len, '}'))
 				stack--;
 
 			/* if stack is zero or below, we are standing on a '}' with no escape char before */
-			if (stack <= 0 && (*value)[len] == '}'
-				&& (*value)[len - 1] != '\\')
+			if (stack <= 0 && CHL_(value, len, '}'))
 			{
 				(*value)[len] = ';';
 				break;
@@ -1234,8 +1238,8 @@
 		}
 
 #ifndef NOTRIM
-		while ((*value)[len - 1] == ' ' || (*value)[len - 1] == '\t'
-			   || (*value)[len - 1] == '\n')
+		while (((*value)[len - 1] == ' ' || (*value)[len - 1] == '\t'
+			   || (*value)[len - 1] == '\n') && (*value)[len-2] != '\\')
 			len--;
 #endif
 		/* ok, copy the code */
@@ -1251,7 +1255,7 @@
 #ifndef NOTRIM
 		JUMP_NSPACES(*value);
 #endif
-		if ((*value)[0] == '}')
+		if (CH_(value, '}'))
 			(*value)++;
 
 		DL_(*value, "after += len");
@@ -1262,7 +1266,7 @@
 
 
 	/* if it is embraced in with '"' */
-	if ((*value)[0] == '"')
+	if (CH_(value, '"'))
 	{
 		/* skip the '"' char */
 		(*value)++;
@@ -1271,7 +1275,7 @@
 		while ((*value)[len])
 		{
 			/* if this is the ending '"' with no escape char before */
-			if ((*value)[len] == '"' && (*value)[len - 1] != '\\')
+			if (CH_(value, '"'))
 			{
 				break;
 			}
@@ -1287,7 +1291,7 @@
 
 		/* walk forward again */
 		(*value) += len;
-		if ((*value)[0] == '"')
+		if (CH_(value, '"'))
 			(*value)++;
 
 		DL_(*value, "after += len");
@@ -1301,24 +1305,17 @@
 	/* Count length */
 	while ((*value)[len])
 	{
-		/* this char is escaped by the char before */
-		if ((*value)[len - 1] == '\\')
-		{
-			len++;
-			continue;
-		}
-
 		/* If we should break copying on a space, check this */
 		if (space_is_new_word == TRUE)
 		{
 			DL_(*value, "Space is new word");
-			if ((*value)[len] == ' ' || (*value)[len] == '\t'
-				|| (*value)[len] == '\n')
+			if (((*value)[len] == ' ' || (*value)[len] == '\t'
+				|| (*value)[len] == '\n') && (*value)[len-1] != '\\')
 				break;
 		}
 
 		/* always break on a ; */
-		if ((*value)[len] == ';')
+		if (CHL_(value, len, ';'))
 			break;
 
 		len++;


More information about the Initng-svn mailing list