From 7f1acfdb8928de69bf02db6cf217f0f3b4af45ea Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 29 Oct 1999 23:09:13 +0000 Subject: More stuf. sed works. --- editors/sed.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'editors/sed.c') diff --git a/editors/sed.c b/editors/sed.c index 0df53a7f8..f0a6a3b48 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -57,7 +57,8 @@ extern int sed_main (int argc, char **argv) char *cp; int ignoreCase=FALSE; int foundOne=FALSE; - int noprintFlag=FALSE; + int printFlag=FALSE; + int quietFlag=FALSE; int stopNow; char *haystack; @@ -75,7 +76,7 @@ extern int sed_main (int argc, char **argv) while (*++cp && stopNow==FALSE) switch (*cp) { case 'n': - noprintFlag = TRUE; + quietFlag = TRUE; break; case 'e': if (*(cp+1)==0 && --argc < 0) { @@ -113,6 +114,23 @@ extern int sed_main (int argc, char **argv) break; } *pos=0; + if (pos+2 != 0) { + while (*++pos) { + fprintf(stderr, "pos='%s'\n", pos); + switch (*pos) { + case 'i': + ignoreCase=TRUE; + break; + case 'p': + printFlag=TRUE; + break; + case 'g': + break; + default: + usage( sed_usage); + } + } + } } cp++; } @@ -135,13 +153,13 @@ extern int sed_main (int argc, char **argv) continue; } - haystack = (char*)malloc( BUF_SIZE); - while (fgets (haystack, BUF_SIZE-1, fp)) { + haystack = (char*)malloc( 1024); + while (fgets (haystack, 1023, fp)) { foundOne = replace_match(haystack, needle, newNeedle, ignoreCase); - if (noprintFlag==TRUE && foundOne==TRUE) - fputs (haystack, stdout); - else + if (foundOne==TRUE && printFlag==TRUE) + fputs (haystack, stdout); + if (quietFlag==FALSE) fputs (haystack, stdout); /* Avoid any mem leaks */ free(haystack); -- cgit v1.2.3