Hi!

----

Attached (as "astopen20120612_sgrep_patch001.diff") is a patch which
adds "sgrep" (shell pattern grep) and "kgrep" (kornshell pattern grep)
to "grep.c" per Olga&&Lionel's request.

Notes:
- I've moved the original "--strict" from -S to -W... but AFAIK it
should be "+O" (e.g. reverse of -O... which is the default) ... but to
be honestly I couldn't remember at 5.00h AM how to test for +<letter>
options from C code... ;-(

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
--- grep.c.original	Sun Jun 17 05:29:04 2012
+++ grep.c	Sun Jun 17 06:22:03 2012
@@ -21,7 +21,7 @@
 #pragma prototyped
 
 static const char usage[] =
-"[-?\n@(#)$Id: grep (AT&T Research) 2012-05-11 $\n]"
+"[-?\n@(#)$Id: grep (AT&T Research) 2012-06-16 $\n]"
 USAGE_LICENSE
 "[--plugin?ksh]"
 "[+NAME?grep - search lines in files for matching patterns]"
@@ -53,6 +53,8 @@
 "[F:fixed-string?\bfgrep\b mode: fixed string \apatterns\a.]"
 "[A:approximate-regexp?\bagrep\b mode: approximate regular expression "
     "\apatterns\a (not implemented.)]"
+"[S:shell-regex?\bsgrep\b mode: POSIX shell pattern expressions \apatterns\a.]"
+"[K:korn-shell-regex?\bkgrep\b mode: korn shell 93 pattern expressions \apatterns\a.]"
 "[C:context?Set the matched line context \abefore\a and \aafter\a count. "
     "If ,\aafter\a is omitted then it is set to \abefore\a. By default only "
     "matched lines are printed.]:?[before[,after]]:=2,2]"
@@ -85,7 +87,7 @@
 "[r|R:recursive?Recursively process all files in each named directory. "
     "Use \btw -e\b \aexpression\a \bgrep ...\b to control the directory "
     "traversal.]"
-"[S:strict?Enable strict \apattern\a interpretation with diagnostics.]"
+"[W:strict?Enable strict \apattern\a interpretation with diagnostics.]"
 "[s:suppress|no-messages?Suppress error and warning messages.]"
 "[t:total?Only print a single matching line count for all files.]"
 "[T:test?Enable implementation specific tests.]: [test]"
@@ -731,6 +733,9 @@
 		case 'H':
 			state.prefix = opt_info.num;
 			break;
+		case 'K':
+			state.options |= REG_SHELL|REG_AUGMENTED;
+			break;
 		case 'L':
 			state.list = -opt_info.num;
 			break;
@@ -744,7 +749,7 @@
 			state.options |= REG_EXTENDED|REG_LENIENT;
 			break;
 		case 'S':
-			state.options &= ~REG_LENIENT;
+			state.options |= REG_SHELL;
 			break;
 		case 'T':
 			s = opt_info.arg;
@@ -785,6 +790,9 @@
 				break;
 			}
 			break;
+		case 'W':
+			state.options &= ~REG_LENIENT;
+			break;
 		case 'X':
 			state.options |= REG_AUGMENTED;
 			break;
@@ -859,9 +867,12 @@
 			goto done;
 		}
 	argv += opt_info.index;
-	if ((state.options & REG_LITERAL) && (state.options & (REG_AUGMENTED|REG_EXTENDED)))
+	if ((((state.options & REG_LITERAL) != 0) +
+		((state.options & (REG_AUGMENTED|REG_EXTENDED)) !=0) +
+		((state.options & REG_SHELL) !=0) > 1) &&
+		((state.options & (REG_SHELL|REG_AUGMENTED))!=(REG_SHELL|REG_AUGMENTED)))
 	{
-		error(2, "-F and -A or -P or -X are incompatible");
+		error(2, "-F and -A or -P or -X or -K and -S are incompatible");
 		goto done;
 	}
 	if ((state.options & REG_LITERAL) && state.words)
@@ -992,11 +1003,21 @@
 		s = "fgrep";
 		options = REG_LITERAL;
 		break;
+	case 'k':
+	case 'K':
+		s = "kgrep";
+		options = REG_SHELL|REG_AUGMENTED;
+		break;
 	case 'p':
 	case 'P':
 		s = "pgrep";
 		options = REG_EXTENDED|REG_LENIENT;
 		break;
+	case 's':
+	case 'S':
+		s = "sgrep";
+		options = REG_SHELL;
+		break;
 	case 'x':
 	case 'X':
 		s = "xgrep";
@@ -1024,6 +1045,13 @@
 }
 
 int
+b_kgrep(int argc, char** argv, Shbltin_t* context)
+{
+	NoP(argc);
+	return grep("kgrep", REG_SHELL|REG_AUGMENTED, argc, argv, context);
+}
+
+int
 b_pgrep(int argc, char** argv, Shbltin_t* context)
 {
 	NoP(argc);
@@ -1030,6 +1058,13 @@
 	return grep("pgrep", REG_EXTENDED|REG_LENIENT, argc, argv, context);
 }
 
+int
+b_sgrep(int argc, char** argv, Shbltin_t* context)
+{
+	NoP(argc);
+	return grep("sgrep", REG_SHELL, argc, argv, context);
+}
+
 int
 b_xgrep(int argc, char** argv, Shbltin_t* context)
 {
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to