summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-28 16:06:25 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-28 16:06:25 +0000
commit6b6b3f6ef2f44898a8bddfaae93cc4ef3aa79661 (patch)
treeac9548482088082aece2d2df1406c72339c77b6f
parentc7c41d306b8e172a2fba432d3c4b9f97b9963816 (diff)
downloadbusybox-w32-6b6b3f6ef2f44898a8bddfaae93cc4ef3aa79661.tar.gz
busybox-w32-6b6b3f6ef2f44898a8bddfaae93cc4ef3aa79661.tar.bz2
busybox-w32-6b6b3f6ef2f44898a8bddfaae93cc4ef3aa79661.zip
Stuf
-rw-r--r--console-tools/deallocvt.c1
-rw-r--r--deallocvt.c1
-rw-r--r--editors/sed.c150
-rw-r--r--find.c25
-rw-r--r--findutils/find.c25
-rw-r--r--findutils/grep.c6
-rw-r--r--grep.c6
-rw-r--r--sed.c150
8 files changed, 310 insertions, 54 deletions
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c
index a8feeb53c..ae4dbb5a8 100644
--- a/console-tools/deallocvt.c
+++ b/console-tools/deallocvt.c
@@ -2,6 +2,7 @@
2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s) 2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3 * Renamed deallocvt. 3 * Renamed deallocvt.
4 */ 4 */
5#include "internal.h"
5#include <stdlib.h> 6#include <stdlib.h>
6#include <fcntl.h> 7#include <fcntl.h>
7#include <sys/types.h> 8#include <sys/types.h>
diff --git a/deallocvt.c b/deallocvt.c
index a8feeb53c..ae4dbb5a8 100644
--- a/deallocvt.c
+++ b/deallocvt.c
@@ -2,6 +2,7 @@
2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s) 2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3 * Renamed deallocvt. 3 * Renamed deallocvt.
4 */ 4 */
5#include "internal.h"
5#include <stdlib.h> 6#include <stdlib.h>
6#include <fcntl.h> 7#include <fcntl.h>
7#include <sys/types.h> 8#include <sys/types.h>
diff --git a/editors/sed.c b/editors/sed.c
new file mode 100644
index 000000000..4dd552a2d
--- /dev/null
+++ b/editors/sed.c
@@ -0,0 +1,150 @@
1/*
2 * Mini sed implementation for busybox
3 *
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include "internal.h"
25#include "regexp.h"
26#include <stdio.h>
27#include <dirent.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <signal.h>
31#include <time.h>
32#include <ctype.h>
33
34static const char sed_usage[] =
35"sed [-n] [-e script] [file...]\n"
36"Allowed scripts come in two forms:\n"
37"'/regexp/[gp]'\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."
42"Options:\n"
43"-e\tadd the script to the commands to be executed\n"
44"-n\tsuppress automatic printing of pattern space\n\n"
45#if defined BB_REGEXP
46"This version of sed matches full regexps.\n";
47#else
48"This version of sed matches strings (not full regexps).\n";
49#endif
50
51
52static int replaceFlag = FALSE;
53static int noprintFlag = FALSE;
54
55
56extern int sed_main (int argc, char **argv)
57{
58 FILE *fp;
59 const char *needle;
60 const char *name;
61 const char *cp;
62 int tellName=TRUE;
63 int ignoreCase=FALSE;
64 int tellLine=FALSE;
65 long line;
66 char haystack[BUF_SIZE];
67
68 ignoreCase = FALSE;
69 tellLine = FALSE;
70
71 argc--;
72 argv++;
73 if (argc < 1) {
74 usage(grep_usage);
75 }
76
77 if (**argv == '-') {
78 argc--;
79 cp = *argv++;
80
81 while (*++cp)
82 switch (*cp) {
83 case 'n':
84 noprintFlag = TRUE;
85 break;
86 case 'e':
87 if (*(*argv)+1 != '\'' && **argv != '\"') {
88 if (--argc == 0)
89 usage( mkdir_usage);
90 ++argv;
91 if (*(*argv)+1 != '\'' && **argv != '\"') {
92 usage( mkdir_usage);
93 }
94 /* Find the specified modes */
95 mode = 0;
96 if ( parse_mode(*(++argv), &mode) == FALSE ) {
97 fprintf(stderr, "Unknown mode: %s\n", *argv);
98 exit( FALSE);
99 }
100 break;
101
102 default:
103 usage(grep_usage);
104 }
105 }
106
107 needle = *argv++;
108 argc--;
109
110 while (argc-- > 0) {
111 name = *argv++;
112
113 fp = fopen (name, "r");
114 if (fp == NULL) {
115 perror (name);
116 continue;
117 }
118
119 line = 0;
120
121 while (fgets (haystack, sizeof (haystack), fp)) {
122 line++;
123 cp = &haystack[strlen (haystack) - 1];
124
125 if (*cp != '\n')
126 fprintf (stderr, "%s: Line too long\n", name);
127
128 if (find_match(haystack, needle, ignoreCase) == TRUE) {
129 if (tellName==TRUE)
130 printf ("%s: ", name);
131
132 if (tellLine==TRUE)
133 printf ("%ld: ", line);
134
135 fputs (haystack, stdout);
136 }
137 }
138
139 if (ferror (fp))
140 perror (name);
141
142 fclose (fp);
143 }
144 exit( TRUE);
145}
146
147
148/* END CODE */
149
150
diff --git a/find.c b/find.c
index c154cf4e7..ab9ebf434 100644
--- a/find.c
+++ b/find.c
@@ -42,34 +42,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
42{ 42{
43 if (pattern==NULL) 43 if (pattern==NULL)
44 fprintf(stdout, "%s\n", fileName); 44 fprintf(stdout, "%s\n", fileName);
45 else if (find_match(fileName, pattern, TRUE) == TRUE) 45 else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
46 fprintf(stdout, "%s\n", fileName); 46 fprintf(stdout, "%s\n", fileName);
47 return( TRUE); 47 return( TRUE);
48} 48}
49 49
50static int dirAction(const char *fileName, struct stat* statbuf)
51{
52 DIR *dir;
53 struct dirent *entry;
54
55 if (pattern==NULL)
56 fprintf(stdout, "%s\n", fileName);
57 else if (find_match(fileName, pattern, TRUE) == TRUE)
58 fprintf(stdout, "%s\n", fileName);
59
60 dir = opendir( fileName);
61 if (!dir) {
62 perror("Can't open directory");
63 exit(FALSE);
64 }
65 while ((entry = readdir(dir)) != NULL) {
66 char dirName[NAME_MAX];
67 sprintf(dirName, "%s/%s", fileName, entry->d_name);
68 recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
69 }
70 return( TRUE);
71}
72
73int find_main(int argc, char **argv) 50int find_main(int argc, char **argv)
74{ 51{
75 /* peel off the "find" */ 52 /* peel off the "find" */
diff --git a/findutils/find.c b/findutils/find.c
index c154cf4e7..ab9ebf434 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -42,34 +42,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
42{ 42{
43 if (pattern==NULL) 43 if (pattern==NULL)
44 fprintf(stdout, "%s\n", fileName); 44 fprintf(stdout, "%s\n", fileName);
45 else if (find_match(fileName, pattern, TRUE) == TRUE) 45 else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
46 fprintf(stdout, "%s\n", fileName); 46 fprintf(stdout, "%s\n", fileName);
47 return( TRUE); 47 return( TRUE);
48} 48}
49 49
50static int dirAction(const char *fileName, struct stat* statbuf)
51{
52 DIR *dir;
53 struct dirent *entry;
54
55 if (pattern==NULL)
56 fprintf(stdout, "%s\n", fileName);
57 else if (find_match(fileName, pattern, TRUE) == TRUE)
58 fprintf(stdout, "%s\n", fileName);
59
60 dir = opendir( fileName);
61 if (!dir) {
62 perror("Can't open directory");
63 exit(FALSE);
64 }
65 while ((entry = readdir(dir)) != NULL) {
66 char dirName[NAME_MAX];
67 sprintf(dirName, "%s/%s", fileName, entry->d_name);
68 recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
69 }
70 return( TRUE);
71}
72
73int find_main(int argc, char **argv) 50int find_main(int argc, char **argv)
74{ 51{
75 /* peel off the "find" */ 52 /* peel off the "find" */
diff --git a/findutils/grep.c b/findutils/grep.c
index 44ca02834..9495bf858 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -47,9 +47,9 @@ static const char grep_usage[] =
47extern int grep_main (int argc, char **argv) 47extern int grep_main (int argc, char **argv)
48{ 48{
49 FILE *fp; 49 FILE *fp;
50 const char *needle; 50 char *needle;
51 const char *name; 51 char *name;
52 const char *cp; 52 char *cp;
53 int tellName=TRUE; 53 int tellName=TRUE;
54 int ignoreCase=FALSE; 54 int ignoreCase=FALSE;
55 int tellLine=FALSE; 55 int tellLine=FALSE;
diff --git a/grep.c b/grep.c
index 44ca02834..9495bf858 100644
--- a/grep.c
+++ b/grep.c
@@ -47,9 +47,9 @@ static const char grep_usage[] =
47extern int grep_main (int argc, char **argv) 47extern int grep_main (int argc, char **argv)
48{ 48{
49 FILE *fp; 49 FILE *fp;
50 const char *needle; 50 char *needle;
51 const char *name; 51 char *name;
52 const char *cp; 52 char *cp;
53 int tellName=TRUE; 53 int tellName=TRUE;
54 int ignoreCase=FALSE; 54 int ignoreCase=FALSE;
55 int tellLine=FALSE; 55 int tellLine=FALSE;
diff --git a/sed.c b/sed.c
new file mode 100644
index 000000000..4dd552a2d
--- /dev/null
+++ b/sed.c
@@ -0,0 +1,150 @@
1/*
2 * Mini sed implementation for busybox
3 *
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include "internal.h"
25#include "regexp.h"
26#include <stdio.h>
27#include <dirent.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <signal.h>
31#include <time.h>
32#include <ctype.h>
33
34static const char sed_usage[] =
35"sed [-n] [-e script] [file...]\n"
36"Allowed scripts come in two forms:\n"
37"'/regexp/[gp]'\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."
42"Options:\n"
43"-e\tadd the script to the commands to be executed\n"
44"-n\tsuppress automatic printing of pattern space\n\n"
45#if defined BB_REGEXP
46"This version of sed matches full regexps.\n";
47#else
48"This version of sed matches strings (not full regexps).\n";
49#endif
50
51
52static int replaceFlag = FALSE;
53static int noprintFlag = FALSE;
54
55
56extern int sed_main (int argc, char **argv)
57{
58 FILE *fp;
59 const char *needle;
60 const char *name;
61 const char *cp;
62 int tellName=TRUE;
63 int ignoreCase=FALSE;
64 int tellLine=FALSE;
65 long line;
66 char haystack[BUF_SIZE];
67
68 ignoreCase = FALSE;
69 tellLine = FALSE;
70
71 argc--;
72 argv++;
73 if (argc < 1) {
74 usage(grep_usage);
75 }
76
77 if (**argv == '-') {
78 argc--;
79 cp = *argv++;
80
81 while (*++cp)
82 switch (*cp) {
83 case 'n':
84 noprintFlag = TRUE;
85 break;
86 case 'e':
87 if (*(*argv)+1 != '\'' && **argv != '\"') {
88 if (--argc == 0)
89 usage( mkdir_usage);
90 ++argv;
91 if (*(*argv)+1 != '\'' && **argv != '\"') {
92 usage( mkdir_usage);
93 }
94 /* Find the specified modes */
95 mode = 0;
96 if ( parse_mode(*(++argv), &mode) == FALSE ) {
97 fprintf(stderr, "Unknown mode: %s\n", *argv);
98 exit( FALSE);
99 }
100 break;
101
102 default:
103 usage(grep_usage);
104 }
105 }
106
107 needle = *argv++;
108 argc--;
109
110 while (argc-- > 0) {
111 name = *argv++;
112
113 fp = fopen (name, "r");
114 if (fp == NULL) {
115 perror (name);
116 continue;
117 }
118
119 line = 0;
120
121 while (fgets (haystack, sizeof (haystack), fp)) {
122 line++;
123 cp = &haystack[strlen (haystack) - 1];
124
125 if (*cp != '\n')
126 fprintf (stderr, "%s: Line too long\n", name);
127
128 if (find_match(haystack, needle, ignoreCase) == TRUE) {
129 if (tellName==TRUE)
130 printf ("%s: ", name);
131
132 if (tellLine==TRUE)
133 printf ("%ld: ", line);
134
135 fputs (haystack, stdout);
136 }
137 }
138
139 if (ferror (fp))
140 perror (name);
141
142 fclose (fp);
143 }
144 exit( TRUE);
145}
146
147
148/* END CODE */
149
150