aboutsummaryrefslogtreecommitdiff
path: root/sed.c
diff options
context:
space:
mode:
Diffstat (limited to 'sed.c')
-rw-r--r--sed.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/sed.c b/sed.c
index 0df53a7f8..f0a6a3b48 100644
--- a/sed.c
+++ b/sed.c
@@ -57,7 +57,8 @@ extern int sed_main (int argc, char **argv)
57 char *cp; 57 char *cp;
58 int ignoreCase=FALSE; 58 int ignoreCase=FALSE;
59 int foundOne=FALSE; 59 int foundOne=FALSE;
60 int noprintFlag=FALSE; 60 int printFlag=FALSE;
61 int quietFlag=FALSE;
61 int stopNow; 62 int stopNow;
62 char *haystack; 63 char *haystack;
63 64
@@ -75,7 +76,7 @@ extern int sed_main (int argc, char **argv)
75 while (*++cp && stopNow==FALSE) 76 while (*++cp && stopNow==FALSE)
76 switch (*cp) { 77 switch (*cp) {
77 case 'n': 78 case 'n':
78 noprintFlag = TRUE; 79 quietFlag = TRUE;
79 break; 80 break;
80 case 'e': 81 case 'e':
81 if (*(cp+1)==0 && --argc < 0) { 82 if (*(cp+1)==0 && --argc < 0) {
@@ -113,6 +114,23 @@ extern int sed_main (int argc, char **argv)
113 break; 114 break;
114 } 115 }
115 *pos=0; 116 *pos=0;
117 if (pos+2 != 0) {
118 while (*++pos) {
119 fprintf(stderr, "pos='%s'\n", pos);
120 switch (*pos) {
121 case 'i':
122 ignoreCase=TRUE;
123 break;
124 case 'p':
125 printFlag=TRUE;
126 break;
127 case 'g':
128 break;
129 default:
130 usage( sed_usage);
131 }
132 }
133 }
116 } 134 }
117 cp++; 135 cp++;
118 } 136 }
@@ -135,13 +153,13 @@ extern int sed_main (int argc, char **argv)
135 continue; 153 continue;
136 } 154 }
137 155
138 haystack = (char*)malloc( BUF_SIZE); 156 haystack = (char*)malloc( 1024);
139 while (fgets (haystack, BUF_SIZE-1, fp)) { 157 while (fgets (haystack, 1023, fp)) {
140 158
141 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase); 159 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
142 if (noprintFlag==TRUE && foundOne==TRUE) 160 if (foundOne==TRUE && printFlag==TRUE)
143 fputs (haystack, stdout); 161 fputs (haystack, stdout);
144 else 162 if (quietFlag==FALSE)
145 fputs (haystack, stdout); 163 fputs (haystack, stdout);
146 /* Avoid any mem leaks */ 164 /* Avoid any mem leaks */
147 free(haystack); 165 free(haystack);