[BusyBox] [PATCH] add sed -r support.

Rob Landley rob at landley.net
Sun May 16 01:08:12 UTC 2004


I bumped into a couple of things that want to use extended regular expressions 
in sed, and it really isn't that hard to add.  Can't say I've extensively 
tested it, but it's small and isn't going to break anything that doesn't use 
it, so...

Rob

--- /home/landley/pending/cvs/busybox/editors/sed.c	2004-04-25 
00:11:15.000000000 -0500
+++ busybox/editors/sed.c	2004-05-15 20:04:52.824668664 -0500
@@ -112,7 +112,7 @@
 
 /* globals */
 /* options */
-static int be_quiet = 0, in_place=0;
+static int be_quiet = 0, in_place=0, regex_type=0;
 FILE *nonstdout;
 char *outname;
 
@@ -298,7 +298,7 @@
 
 		temp=copy_parsing_slashn(pos,next);
 		*regex = (regex_t *) xmalloc(sizeof(regex_t));
-		xregcomp(*regex, temp, REG_NEWLINE);
+		xregcomp(*regex, temp, regex_type|REG_NEWLINE);
 		free(temp);
 		/* Move position to next character after last delimiter */
 		pos+=(next+1);
@@ -326,7 +326,7 @@
 
 static int parse_subst_cmd(sed_cmd_t * const sed_cmd, char *substr)
 {
-	int cflags = 0;
+	int cflags = regex_type;
 	char *match;
 	int idx = 0;
 
@@ -1113,12 +1113,15 @@
 #endif
 
 	/* do normal option parsing */
-	while ((opt = getopt(argc, argv, "ine:f:")) > 0) {
+	while ((opt = getopt(argc, argv, "irne:f:")) > 0) {
 		switch (opt) {
 		case 'i':
 			in_place++;
 			atexit(cleanup_outname);
 			break;
+		case 'r':
+			regex_type|=REG_EXTENDED;
+			break;
 		case 'n':
 			be_quiet++;
 			break;





More information about the busybox mailing list