2 * Mini sed implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 static const char sed_usage[] =
35 "sed [-n] [-e script] [file...]\n"
36 "Allowed scripts come in two forms:\n"
38 "\tattempt to match regexp against the pattern space\n"
39 "'s/regexp/replacement/[gp]'\n"
40 "\tattempt to match regexp against the pattern space\n"
41 "\tand if successful replaces the matched portion with replacement."
43 "-e\tadd the script to the commands to be executed\n"
44 "-n\tsuppress automatic printing of pattern space\n\n"
46 "This version of sed matches full regexps.\n";
48 "This version of sed matches strings (not full regexps).\n";
52 static int replaceFlag = FALSE;
53 static int noprintFlag = FALSE;
56 extern int sed_main (int argc, char **argv)
66 char haystack[BUF_SIZE];
87 if (*(*argv)+1 != '\'' && **argv != '\"') {
91 if (*(*argv)+1 != '\'' && **argv != '\"') {
94 /* Find the specified modes */
96 if ( parse_mode(*(++argv), &mode) == FALSE ) {
97 fprintf(stderr, "Unknown mode: %s\n", *argv);
113 fp = fopen (name, "r");
121 while (fgets (haystack, sizeof (haystack), fp)) {
123 cp = &haystack[strlen (haystack) - 1];
126 fprintf (stderr, "%s: Line too long\n", name);
128 if (find_match(haystack, needle, ignoreCase) == TRUE) {
130 printf ("%s: ", name);
133 printf ("%ld: ", line);
135 fputs (haystack, stdout);