This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: xconq/8: Rule called "replace".


> Here is a patch that fixes the problem.

Sorry, that was the wrong file. Next try.

Index: keyword.def
===================================================================
RCS file: /cvs/xconq/xconq/kernel/keyword.def,v
retrieving revision 1.20
diff -u -3 -p -r1.20 keyword.def
--- keyword.def	6 Aug 2003 00:18:20 -0000	1.20
+++ keyword.def	6 Aug 2003 13:13:21 -0000
@@ -218,6 +218,7 @@ DEF_KWD("rearm-percent", K_REARM_PERCENT
 DEF_KWD("reject", K_REJECT)
 DEF_KWD("remove", K_REMOVE)
 DEF_KWD("repair-percent", K_REPAIR_PERCENT)
+DEF_KWD("replace", K_REPLACE)
 DEF_KWD("reserve", K_RESERVE)
 DEF_KWD("reset", K_RESET)
 DEF_KWD("restrict", K_RESTRICT)
Index: mknames.c
===================================================================
RCS file: /cvs/xconq/xconq/kernel/mknames.c,v
retrieving revision 1.11
diff -u -3 -p -r1.11 mknames.c
--- mknames.c	6 Aug 2003 00:18:20 -0000	1.11
+++ mknames.c	6 Aug 2003 13:13:21 -0000
@@ -423,6 +423,57 @@ gen_from_rule(Obj *rule, Obj *rules, int
 		if (islower(rslt[oldlen]))
 		  rslt[oldlen] = uppercase(rslt[oldlen]);
 		break;
+	      case K_REPLACE:
+		gen_from_rule(cadr(rule), rules, depth + 1, rslt);
+		found = TRUE;
+		while (found) {
+		  for_all_list(cddr(rule), rejrest) {
+		    Obj * replpair = car(rejrest);
+		    if (consp(replpair)) {
+		      Obj * old = car(replpair);
+		      if (symbolp(old) || stringp(old)) {
+			Obj * new = cadr(replpair);
+			if (symbolp(new) || stringp(new)) {
+			  const char * const old_str = c_string(old);
+			  const char * const new_str = c_string(new);
+			  const size_t old_str_len = strlen(old_str);
+			  const size_t new_str_len = strlen(new_str);
+			  char * begin, * after;
+			  if (strcmp(old_str, new_str)) {
+			    if (begin = strstr(rslt, old_str)) {
+			      run_warning
+				("found replacement: %s : %s (old_str_len = %d, "
+				 "new_str_len = %d)",
+				 rslt, old_str, old_str_len, new_str_len);
+			      after = begin + old_str_len;
+			      memmove
+				(begin + new_str_len, after,
+				 strlen(after) + 1);
+			      memcpy(begin, new_str, new_str_len);
+			      goto end_outerloop;
+			    }
+			  }
+			  else {
+			    run_warning
+			      ("replace: old and new are equal (%s)", old_str);
+			  }
+			}
+			else {
+			  run_warning("new of replpair is not symbol or string");
+			}
+		      }
+		      else {
+			run_warning("old of replpair is not symbol or string");
+		      }
+		    }
+		    else {
+		      run_warning("non-consp in replace-list");
+		    }
+		  }
+		  found = FALSE;
+		end_outerloop:;
+		}
+		break;
 	      case K_REJECT:
 		/* Run the rule, then retry if the result includes any
 		   substrings that we want to exclude. */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]