APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
--- /dev/null 2005-04-24 01:00:01.350003056 -0400
-+++ editors/ed.c 2005-04-24 01:15:09.000000000 -0400
-@@ -0,0 +1,1447 @@
++++ ed.c 2005-04-24 01:38:51.000000000 -0400
+@@ -0,0 +1,1425 @@
+/*
+ * Copyright (c) 2002 by David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+#include <ctype.h>
+#include <sys/param.h>
+#include <malloc.h>
-+//#include "sash.h"
++#include "busybox.h"
+
+#define USERSIZE 1024 /* max line length typed in by user */
+#define INITBUF_SIZE 1024 /* initial buffer size */
+
+typedef int BOOL;
-+
-+#define FALSE ((BOOL) 0)
-+#define TRUE ((BOOL) 1)
-+
-+#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
-+#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
-+
-+#define STDOUT 1
-+
+typedef int NUM;
+typedef int LEN;
+
-+typedef struct LINE LINE;
-+
-+struct LINE
-+{
-+ LINE * next;
-+ LINE * prev;
++typedef struct LINE LINE;
++struct LINE {
++ LINE *next;
++ LINE *prev;
+ LEN len;
-+ char data[1];
++ char data[1];
+};
+
++static LINE lines;
++static LINE *curLine;
++static NUM curNum;
++static NUM lastNum;
++static NUM marks[26];
++static BOOL dirty;
++static char *fileName;
++static char searchString[USERSIZE];
+
-+static LINE lines;
-+static LINE * curLine;
-+static NUM curNum;
-+static NUM lastNum;
-+static NUM marks[26];
-+static BOOL dirty;
-+static char * fileName;
-+static char searchString[USERSIZE];
-+
-+static char * bufBase;
-+static char * bufPtr;
-+static LEN bufUsed;
-+static LEN bufSize;
-+
++static char *bufBase;
++static char *bufPtr;
++static LEN bufUsed;
++static LEN bufSize;
+
+static void doCommands(void);
+static void subCommand(const char * cmd, NUM num1, NUM num2);
+static NUM searchLines(const char * str, NUM num1, NUM num2);
+static LINE * findLine(NUM num);
+
-+static LEN findString
-+ (const LINE * lp, const char * str, LEN len, LEN offset);
++static LEN findString(const LINE * lp, const char * str, LEN len, LEN offset);
+
-+
-+void
-+ed_main(int argc, const char ** argv)
++int ed_main(int argc, char **argv)
+{
+ if (!initEdit())
-+ return;
++ return EXIT_FAILURE;
+
-+ if (argc > 1)
-+ {
++ if (argc > 1) {
+ fileName = strdup(argv[1]);
+
-+ if (fileName == NULL)
-+ {
-+ fprintf(stderr, "No memory\n");
++ if (fileName == NULL) {
++ bb_error_msg("No memory");
+ termEdit();
-+
-+ return;
++ return EXIT_SUCCESS;
+ }
+
-+ if (!readLines(fileName, 1))
-+ {
++ if (!readLines(fileName, 1)) {
+ termEdit();
-+
-+ return;
++ return EXIT_SUCCESS;
+ }
+
+ if (lastNum)
+ doCommands();
+
+ termEdit();
++ return EXIT_SUCCESS;
+}
+
-+
+/*
+ * Read commands until we are told to stop.
+ */
-+static void
-+doCommands(void)
++static void doCommands(void)
+{
+ const char * cp;
+ char * endbuf;
+
+ if (*endbuf != '\n')
+ {
-+ fprintf(stderr, "Command line too long\n");
++ bb_error_msg("Command line too long");
+
+ do
+ {
+ continue;
+ }
+
-+ while ((endbuf > buf) && isBlank(endbuf[-1]))
++ while ((endbuf > buf) && isblank(endbuf[-1]))
+ endbuf--;
+
+ *endbuf = '\0';
+
+ cp = buf;
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ have1 = FALSE;
+ if (!getNum(&cp, &have1, &num1))
+ continue;
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if (*cp == ',')
+ break;
+
+ case 'f':
-+ if (*cp && !isBlank(*cp))
++ if (*cp && !isblank(*cp))
+ {
-+ fprintf(stderr, "Bad file command\n");
++ bb_error_msg("Bad file command");
+ break;
+ }
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if (*cp == '\0')
+
+ if (newname == NULL)
+ {
-+ fprintf(stderr, "No memory for file name\n");
++ bb_error_msg("No memory for file name");
+ break;
+ }
+
+ break;
+
+ case 'k':
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if ((*cp < 'a') || (*cp > 'a') || cp[1])
+ {
-+ fprintf(stderr, "Bad mark name\n");
++ bb_error_msg("Bad mark name");
+ break;
+ }
+
+ break;
+
+ case 'q':
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if (have1 || *cp)
+ {
-+ fprintf(stderr, "Bad quit command\n");
++ bb_error_msg("Bad quit command");
+ break;
+ }
+
+ fgets(buf, sizeof(buf), stdin);
+ cp = buf;
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if ((*cp == 'y') || (*cp == 'Y'))
+ break;
+
+ case 'r':
-+ if (*cp && !isBlank(*cp))
++ if (*cp && !isblank(*cp))
+ {
-+ fprintf(stderr, "Bad read command\n");
++ bb_error_msg("Bad read command");
+ break;
+ }
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if (*cp == '\0')
+ {
-+ fprintf(stderr, "No file name\n");
++ bb_error_msg("No file name");
+ break;
+ }
+
+ break;
+
+ case 'w':
-+ if (*cp && !isBlank(*cp))
++ if (*cp && !isblank(*cp))
+ {
-+ fprintf(stderr, "Bad write command\n");
++ bb_error_msg("Bad write command");
+ break;
+ }
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ if (!have1) {
+
+ if (cp == NULL)
+ {
-+ fprintf(stderr, "No file name specified\n");
++ bb_error_msg("No file name specified");
+ break;
+ }
+
+ case '.':
+ if (have1)
+ {
-+ fprintf(stderr, "No arguments allowed\n");
++ bb_error_msg("No arguments allowed");
+ break;
+ }
+
+ break;
+
+ default:
-+ fprintf(stderr, "Unimplemented command\n");
++ bb_error_msg("Unimplemented command");
+ break;
+ }
+ }
+
+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
+ {
-+ fprintf(stderr, "Bad line range for substitute\n");
++ bb_error_msg("Bad line range for substitute");
+
+ return;
+ }
+ strcpy(buf, cmd);
+ cp = buf;
+
-+ if (isBlank(*cp) || (*cp == '\0'))
++ if (isblank(*cp) || (*cp == '\0'))
+ {
-+ fprintf(stderr, "Bad delimiter for substitute\n");
++ bb_error_msg("Bad delimiter for substitute");
+
+ return;
+ }
+
+ if (cp == NULL)
+ {
-+ fprintf(stderr, "Missing 2nd delimiter for substitute\n");
++ bb_error_msg("Missing 2nd delimiter for substitute");
+
+ return;
+ }
+ break;
+
+ default:
-+ fprintf(stderr, "Unknown option for substitute\n");
++ bb_error_msg("Unknown option for substitute");
+
+ return;
+ }
+ {
+ if (searchString[0] == '\0')
+ {
-+ fprintf(stderr, "No previous search string\n");
++ bb_error_msg("No previous search string");
+
+ return;
+ }
+
+ if (nlp == NULL)
+ {
-+ fprintf(stderr, "Cannot get memory for line\n");
++ bb_error_msg("Cannot get memory for line");
+
+ return;
+ }
+ }
+
+ if (!didSub)
-+ fprintf(stderr, "No substitutions found for \"%s\"\n", oldStr);
++ bb_error_msg("No substitutions found for \"%s\"", oldStr);
+}
+
+
+
+ if (buf[len - 1] != '\n')
+ {
-+ fprintf(stderr, "Line too long\n");
++ bb_error_msg("Line too long");
+
+ do
+ {
+
+ while (TRUE)
+ {
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ switch (*cp)
+
+ if ((*cp < 'a') || (*cp > 'z'))
+ {
-+ fprintf(stderr, "Bad mark name\n");
++ bb_error_msg("Bad mark name");
+
+ return FALSE;
+ }
+ break;
+
+ default:
-+ if (!isDecimal(*cp))
++ if (!isdigit(*cp))
+ {
+ *retcp = cp;
+ *retHaveNum = haveNum;
+
+ num = 0;
+
-+ while (isDecimal(*cp))
++ while (isdigit(*cp))
+ num = num * 10 + *cp++ - '0';
+
+ haveNum = TRUE;
+
+ value += num * sign;
+
-+ while (isBlank(*cp))
++ while (isblank(*cp))
+ cp++;
+
+ switch (*cp)
+
+ if (bufBase == NULL)
+ {
-+ fprintf(stderr, "No memory for buffer\n");
++ bb_error_msg("No memory for buffer");
+
+ return FALSE;
+ }
+
+ if ((num < 1) || (num > lastNum + 1))
+ {
-+ fprintf(stderr, "Bad line for read\n");
++ bb_error_msg("Bad line for read");
+
+ return FALSE;
+ }
+
+ if (cp == NULL)
+ {
-+ fprintf(stderr, "No memory for buffer\n");
++ bb_error_msg("No memory for buffer");
+ close(fd);
+
+ return FALSE;
+
+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
+ {
-+ fprintf(stderr, "Bad line range for write\n");
++ bb_error_msg("Bad line range for write");
+
+ return FALSE;
+ }
+
+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
+ {
-+ fprintf(stderr, "Bad line range for print\n");
++ bb_error_msg("Bad line range for print");
+
+ return FALSE;
+ }
+ {
+ if (!expandFlag)
+ {
-+ write(STDOUT, lp->data, lp->len);
++ write(1, lp->data, lp->len);
+ setCurNum(num1++);
+ lp = lp->next;
+
+
+ if ((num < 1) || (num > lastNum + 1))
+ {
-+ fprintf(stderr, "Inserting at bad line number\n");
++ bb_error_msg("Inserting at bad line number");
+
+ return FALSE;
+ }
+
+ if (newLp == NULL)
+ {
-+ fprintf(stderr, "Failed to allocate memory for line\n");
++ bb_error_msg("Failed to allocate memory for line");
+
+ return FALSE;
+ }
+
+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
+ {
-+ fprintf(stderr, "Bad line numbers for delete\n");
++ bb_error_msg("Bad line numbers for delete");
+
+ return FALSE;
+ }
+
+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
+ {
-+ fprintf(stderr, "Bad line numbers for search\n");
++ bb_error_msg("Bad line numbers for search");
+
+ return 0;
+ }
+ {
+ if (searchString[0] == '\0')
+ {
-+ fprintf(stderr, "No previous search string\n");
++ bb_error_msg("No previous search string");
+
+ return 0;
+ }
+ lp = lp->next;
+ }
+
-+ fprintf(stderr, "Cannot find string \"%s\"\n", str);
++ bb_error_msg("Cannot find string \"%s\"", str);
+
+ return 0;
+}
+
+ if ((num < 1) || (num > lastNum))
+ {
-+ fprintf(stderr, "Line number %d does not exist\n", num);
++ bb_error_msg("Line number %d does not exist", num);
+
+ return NULL;
+ }