sus.c (2748B)
1 /* 2 * grep - search a file for a pattern 3 * 4 * Gunnar Ritter, Freiburg i. Br., Germany, April 2001. 5 */ 6 /* 7 * Copyright (c) 2003 Gunnar Ritter 8 * 9 * This software is provided 'as-is', without any express or implied 10 * warranty. In no event will the authors be held liable for any damages 11 * arising from the use of this software. 12 * 13 * Permission is granted to anyone to use this software for any purpose, 14 * including commercial applications, and to alter it and redistribute 15 * it freely, subject to the following restrictions: 16 * 17 * 1. The origin of this software must not be misrepresented; you must not 18 * claim that you wrote the original software. If you use this software 19 * in a product, an acknowledgment in the product documentation would be 20 * appreciated but is not required. 21 * 22 * 2. Altered source versions must be plainly marked as such, and must not be 23 * misrepresented as being the original software. 24 * 25 * 3. This notice may not be removed or altered from any source distribution. 26 */ 27 28 /* Sccsid @(#)sus.c 1.24 (gritter) 5/29/05> */ 29 30 /* 31 * Code for POSIX.2 command version only. 32 */ 33 34 #include <sys/types.h> 35 #include <stdio.h> 36 #include <stdlib.h> 37 #include <string.h> 38 #include "alloc.h" 39 #include "grep.h" 40 41 #if defined (SU3) 42 int sus = 3; 43 #if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4 44 #define USED __attribute__ ((used)) 45 #elif defined __GNUC__ 46 #define USED __attribute__ ((unused)) 47 #else 48 #define USED 49 #endif 50 static const char su3id[] USED = "@(#)grep_su3.sl 1.24 (gritter) 5/29/05"; 51 #else 52 int sus = 1; 53 #endif 54 char *stdinmsg = "(standard input)"; 55 56 /* 57 * Usage message. 58 */ 59 void 60 usage(void) 61 { 62 char *sEF, *sq, *ss; 63 64 if (*progname == 'f') { 65 sq = ""; 66 ss = ""; 67 } else { 68 sq = "|-q"; 69 ss = "s"; 70 } 71 if (*progname == 'f' || *progname == 'e') 72 sEF = ""; 73 else 74 sEF = "[-E|-F] "; 75 fprintf(stderr, "%s: Usage:\n\ 76 %s[-c|-l%s] [-bhin%svx] pattern [file ...]\n\ 77 %s[-c|-l%s] [-bhin%svx] -e pattern ... [-f file ...] [file ...]\n\ 78 %s[-c|-l%s] [-bhin%svx] -f file ... [-e pattern ...] [file ...]\n", 79 progname, 80 sEF, sq, ss, 81 sEF, sq, ss, 82 sEF, sq, ss); 83 exit(2); 84 } 85 86 void 87 misop(void) 88 { 89 usage(); 90 } 91 92 void 93 rc_error(struct expr *e, int rerror) 94 { 95 char *regerrs; 96 size_t resz; 97 98 resz = regerror(rerror, e->e_exp, NULL, 0) + 1; 99 regerrs = smalloc(resz); 100 regerror(rerror, e->e_exp, regerrs, resz); 101 fprintf(stderr, "%s: RE error: %s\n", progname, regerrs); 102 exit(2); 103 } 104 105 void 106 init(void) 107 { 108 switch (*progname) { 109 case 'e': 110 Eflag = 2; 111 rc_select(); 112 options = "EFbce:f:hilnqrRsvxyz"; 113 break; 114 case 'f': 115 Fflag = 2; 116 ac_select(); 117 options = "Fbce:f:hilnqrRsvxyz"; 118 break; 119 default: 120 rc_select(); 121 options = "EFbce:f:hilnqrRsvwxyz"; 122 } 123 } 124 125 void 126 eg_select(void) 127 { 128 } 129 130 void 131 st_select(void) 132 { 133 }