aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-04-24 05:39:52 +0000
committervapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-04-24 05:39:52 +0000
commit87e8ae5bd3aab742e7c5d8b09f021ab960ce3021 (patch)
tree5b6df589596fdfab50c871142ec0f4348c93da2a
parent63fbff9539b190103eff8c8c17a2df04ef68e36f (diff)
downloadbusybox-w32-87e8ae5bd3aab742e7c5d8b09f021ab960ce3021.tar.gz
busybox-w32-87e8ae5bd3aab742e7c5d8b09f021ab960ce3021.tar.bz2
busybox-w32-87e8ae5bd3aab742e7c5d8b09f021ab960ce3021.zip
use busybox funcs to make smaller
git-svn-id: svn://busybox.net/trunk/busybox@10175 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--patches/ed.patch184
1 files changed, 81 insertions, 103 deletions
diff --git a/patches/ed.patch b/patches/ed.patch
index cc3d13853..6d51830a5 100644
--- a/patches/ed.patch
+++ b/patches/ed.patch
@@ -60,8 +60,8 @@ Index: include/applets.h
60 APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER) 60 APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
61 #endif 61 #endif
62--- /dev/null 2005-04-24 01:00:01.350003056 -0400 62--- /dev/null 2005-04-24 01:00:01.350003056 -0400
63+++ editors/ed.c 2005-04-24 01:15:09.000000000 -0400 63+++ ed.c 2005-04-24 01:38:51.000000000 -0400
64@@ -0,0 +1,1447 @@ 64@@ -0,0 +1,1425 @@
65+/* 65+/*
66+ * Copyright (c) 2002 by David I. Bell 66+ * Copyright (c) 2002 by David I. Bell
67+ * Permission is granted to use, distribute, or modify this source, 67+ * Permission is granted to use, distribute, or modify this source,
@@ -80,49 +80,36 @@ Index: include/applets.h
80+#include <ctype.h> 80+#include <ctype.h>
81+#include <sys/param.h> 81+#include <sys/param.h>
82+#include <malloc.h> 82+#include <malloc.h>
83+//#include "sash.h" 83+#include "busybox.h"
84+ 84+
85+#define USERSIZE 1024 /* max line length typed in by user */ 85+#define USERSIZE 1024 /* max line length typed in by user */
86+#define INITBUF_SIZE 1024 /* initial buffer size */ 86+#define INITBUF_SIZE 1024 /* initial buffer size */
87+ 87+
88+typedef int BOOL; 88+typedef int BOOL;
89+
90+#define FALSE ((BOOL) 0)
91+#define TRUE ((BOOL) 1)
92+
93+#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
94+#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
95+
96+#define STDOUT 1
97+
98+typedef int NUM; 89+typedef int NUM;
99+typedef int LEN; 90+typedef int LEN;
100+ 91+
101+typedef struct LINE LINE; 92+typedef struct LINE LINE;
102+ 93+struct LINE {
103+struct LINE 94+ LINE *next;
104+{ 95+ LINE *prev;
105+ LINE * next;
106+ LINE * prev;
107+ LEN len; 96+ LEN len;
108+ char data[1]; 97+ char data[1];
109+}; 98+};
110+ 99+
100+static LINE lines;
101+static LINE *curLine;
102+static NUM curNum;
103+static NUM lastNum;
104+static NUM marks[26];
105+static BOOL dirty;
106+static char *fileName;
107+static char searchString[USERSIZE];
111+ 108+
112+static LINE lines; 109+static char *bufBase;
113+static LINE * curLine; 110+static char *bufPtr;
114+static NUM curNum; 111+static LEN bufUsed;
115+static NUM lastNum; 112+static LEN bufSize;
116+static NUM marks[26];
117+static BOOL dirty;
118+static char * fileName;
119+static char searchString[USERSIZE];
120+
121+static char * bufBase;
122+static char * bufPtr;
123+static LEN bufUsed;
124+static LEN bufSize;
125+
126+ 113+
127+static void doCommands(void); 114+static void doCommands(void);
128+static void subCommand(const char * cmd, NUM num1, NUM num2); 115+static void subCommand(const char * cmd, NUM num1, NUM num2);
@@ -139,33 +126,25 @@ Index: include/applets.h
139+static NUM searchLines(const char * str, NUM num1, NUM num2); 126+static NUM searchLines(const char * str, NUM num1, NUM num2);
140+static LINE * findLine(NUM num); 127+static LINE * findLine(NUM num);
141+ 128+
142+static LEN findString 129+static LEN findString(const LINE * lp, const char * str, LEN len, LEN offset);
143+ (const LINE * lp, const char * str, LEN len, LEN offset);
144+ 130+
145+ 131+int ed_main(int argc, char **argv)
146+void
147+ed_main(int argc, const char ** argv)
148+{ 132+{
149+ if (!initEdit()) 133+ if (!initEdit())
150+ return; 134+ return EXIT_FAILURE;
151+ 135+
152+ if (argc > 1) 136+ if (argc > 1) {
153+ {
154+ fileName = strdup(argv[1]); 137+ fileName = strdup(argv[1]);
155+ 138+
156+ if (fileName == NULL) 139+ if (fileName == NULL) {
157+ { 140+ bb_error_msg("No memory");
158+ fprintf(stderr, "No memory\n");
159+ termEdit(); 141+ termEdit();
160+ 142+ return EXIT_SUCCESS;
161+ return;
162+ } 143+ }
163+ 144+
164+ if (!readLines(fileName, 1)) 145+ if (!readLines(fileName, 1)) {
165+ {
166+ termEdit(); 146+ termEdit();
167+ 147+ return EXIT_SUCCESS;
168+ return;
169+ } 148+ }
170+ 149+
171+ if (lastNum) 150+ if (lastNum)
@@ -177,14 +156,13 @@ Index: include/applets.h
177+ doCommands(); 156+ doCommands();
178+ 157+
179+ termEdit(); 158+ termEdit();
159+ return EXIT_SUCCESS;
180+} 160+}
181+ 161+
182+
183+/* 162+/*
184+ * Read commands until we are told to stop. 163+ * Read commands until we are told to stop.
185+ */ 164+ */
186+static void 165+static void doCommands(void)
187+doCommands(void)
188+{ 166+{
189+ const char * cp; 167+ const char * cp;
190+ char * endbuf; 168+ char * endbuf;
@@ -213,7 +191,7 @@ Index: include/applets.h
213+ 191+
214+ if (*endbuf != '\n') 192+ if (*endbuf != '\n')
215+ { 193+ {
216+ fprintf(stderr, "Command line too long\n"); 194+ bb_error_msg("Command line too long");
217+ 195+
218+ do 196+ do
219+ { 197+ {
@@ -224,14 +202,14 @@ Index: include/applets.h
224+ continue; 202+ continue;
225+ } 203+ }
226+ 204+
227+ while ((endbuf > buf) && isBlank(endbuf[-1])) 205+ while ((endbuf > buf) && isblank(endbuf[-1]))
228+ endbuf--; 206+ endbuf--;
229+ 207+
230+ *endbuf = '\0'; 208+ *endbuf = '\0';
231+ 209+
232+ cp = buf; 210+ cp = buf;
233+ 211+
234+ while (isBlank(*cp)) 212+ while (isblank(*cp))
235+ cp++; 213+ cp++;
236+ 214+
237+ have1 = FALSE; 215+ have1 = FALSE;
@@ -246,7 +224,7 @@ Index: include/applets.h
246+ if (!getNum(&cp, &have1, &num1)) 224+ if (!getNum(&cp, &have1, &num1))
247+ continue; 225+ continue;
248+ 226+
249+ while (isBlank(*cp)) 227+ while (isblank(*cp))
250+ cp++; 228+ cp++;
251+ 229+
252+ if (*cp == ',') 230+ if (*cp == ',')
@@ -288,13 +266,13 @@ Index: include/applets.h
288+ break; 266+ break;
289+ 267+
290+ case 'f': 268+ case 'f':
291+ if (*cp && !isBlank(*cp)) 269+ if (*cp && !isblank(*cp))
292+ { 270+ {
293+ fprintf(stderr, "Bad file command\n"); 271+ bb_error_msg("Bad file command");
294+ break; 272+ break;
295+ } 273+ }
296+ 274+
297+ while (isBlank(*cp)) 275+ while (isblank(*cp))
298+ cp++; 276+ cp++;
299+ 277+
300+ if (*cp == '\0') 278+ if (*cp == '\0')
@@ -311,7 +289,7 @@ Index: include/applets.h
311+ 289+
312+ if (newname == NULL) 290+ if (newname == NULL)
313+ { 291+ {
314+ fprintf(stderr, "No memory for file name\n"); 292+ bb_error_msg("No memory for file name");
315+ break; 293+ break;
316+ } 294+ }
317+ 295+
@@ -326,12 +304,12 @@ Index: include/applets.h
326+ break; 304+ break;
327+ 305+
328+ case 'k': 306+ case 'k':
329+ while (isBlank(*cp)) 307+ while (isblank(*cp))
330+ cp++; 308+ cp++;
331+ 309+
332+ if ((*cp < 'a') || (*cp > 'a') || cp[1]) 310+ if ((*cp < 'a') || (*cp > 'a') || cp[1])
333+ { 311+ {
334+ fprintf(stderr, "Bad mark name\n"); 312+ bb_error_msg("Bad mark name");
335+ break; 313+ break;
336+ } 314+ }
337+ 315+
@@ -347,12 +325,12 @@ Index: include/applets.h
347+ break; 325+ break;
348+ 326+
349+ case 'q': 327+ case 'q':
350+ while (isBlank(*cp)) 328+ while (isblank(*cp))
351+ cp++; 329+ cp++;
352+ 330+
353+ if (have1 || *cp) 331+ if (have1 || *cp)
354+ { 332+ {
355+ fprintf(stderr, "Bad quit command\n"); 333+ bb_error_msg("Bad quit command");
356+ break; 334+ break;
357+ } 335+ }
358+ 336+
@@ -366,7 +344,7 @@ Index: include/applets.h
366+ fgets(buf, sizeof(buf), stdin); 344+ fgets(buf, sizeof(buf), stdin);
367+ cp = buf; 345+ cp = buf;
368+ 346+
369+ while (isBlank(*cp)) 347+ while (isblank(*cp))
370+ cp++; 348+ cp++;
371+ 349+
372+ if ((*cp == 'y') || (*cp == 'Y')) 350+ if ((*cp == 'y') || (*cp == 'Y'))
@@ -375,18 +353,18 @@ Index: include/applets.h
375+ break; 353+ break;
376+ 354+
377+ case 'r': 355+ case 'r':
378+ if (*cp && !isBlank(*cp)) 356+ if (*cp && !isblank(*cp))
379+ { 357+ {
380+ fprintf(stderr, "Bad read command\n"); 358+ bb_error_msg("Bad read command");
381+ break; 359+ break;
382+ } 360+ }
383+ 361+
384+ while (isBlank(*cp)) 362+ while (isblank(*cp))
385+ cp++; 363+ cp++;
386+ 364+
387+ if (*cp == '\0') 365+ if (*cp == '\0')
388+ { 366+ {
389+ fprintf(stderr, "No file name\n"); 367+ bb_error_msg("No file name");
390+ break; 368+ break;
391+ } 369+ }
392+ 370+
@@ -406,13 +384,13 @@ Index: include/applets.h
406+ break; 384+ break;
407+ 385+
408+ case 'w': 386+ case 'w':
409+ if (*cp && !isBlank(*cp)) 387+ if (*cp && !isblank(*cp))
410+ { 388+ {
411+ fprintf(stderr, "Bad write command\n"); 389+ bb_error_msg("Bad write command");
412+ break; 390+ break;
413+ } 391+ }
414+ 392+
415+ while (isBlank(*cp)) 393+ while (isblank(*cp))
416+ cp++; 394+ cp++;
417+ 395+
418+ if (!have1) { 396+ if (!have1) {
@@ -425,7 +403,7 @@ Index: include/applets.h
425+ 403+
426+ if (cp == NULL) 404+ if (cp == NULL)
427+ { 405+ {
428+ fprintf(stderr, "No file name specified\n"); 406+ bb_error_msg("No file name specified");
429+ break; 407+ break;
430+ } 408+ }
431+ 409+
@@ -450,7 +428,7 @@ Index: include/applets.h
450+ case '.': 428+ case '.':
451+ if (have1) 429+ if (have1)
452+ { 430+ {
453+ fprintf(stderr, "No arguments allowed\n"); 431+ bb_error_msg("No arguments allowed");
454+ break; 432+ break;
455+ } 433+ }
456+ 434+
@@ -480,7 +458,7 @@ Index: include/applets.h
480+ break; 458+ break;
481+ 459+
482+ default: 460+ default:
483+ fprintf(stderr, "Unimplemented command\n"); 461+ bb_error_msg("Unimplemented command");
484+ break; 462+ break;
485+ } 463+ }
486+ } 464+ }
@@ -512,7 +490,7 @@ Index: include/applets.h
512+ 490+
513+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) 491+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
514+ { 492+ {
515+ fprintf(stderr, "Bad line range for substitute\n"); 493+ bb_error_msg("Bad line range for substitute");
516+ 494+
517+ return; 495+ return;
518+ } 496+ }
@@ -528,9 +506,9 @@ Index: include/applets.h
528+ strcpy(buf, cmd); 506+ strcpy(buf, cmd);
529+ cp = buf; 507+ cp = buf;
530+ 508+
531+ if (isBlank(*cp) || (*cp == '\0')) 509+ if (isblank(*cp) || (*cp == '\0'))
532+ { 510+ {
533+ fprintf(stderr, "Bad delimiter for substitute\n"); 511+ bb_error_msg("Bad delimiter for substitute");
534+ 512+
535+ return; 513+ return;
536+ } 514+ }
@@ -542,7 +520,7 @@ Index: include/applets.h
542+ 520+
543+ if (cp == NULL) 521+ if (cp == NULL)
544+ { 522+ {
545+ fprintf(stderr, "Missing 2nd delimiter for substitute\n"); 523+ bb_error_msg("Missing 2nd delimiter for substitute");
546+ 524+
547+ return; 525+ return;
548+ } 526+ }
@@ -568,7 +546,7 @@ Index: include/applets.h
568+ break; 546+ break;
569+ 547+
570+ default: 548+ default:
571+ fprintf(stderr, "Unknown option for substitute\n"); 549+ bb_error_msg("Unknown option for substitute");
572+ 550+
573+ return; 551+ return;
574+ } 552+ }
@@ -577,7 +555,7 @@ Index: include/applets.h
577+ { 555+ {
578+ if (searchString[0] == '\0') 556+ if (searchString[0] == '\0')
579+ { 557+ {
580+ fprintf(stderr, "No previous search string\n"); 558+ bb_error_msg("No previous search string");
581+ 559+
582+ return; 560+ return;
583+ } 561+ }
@@ -665,7 +643,7 @@ Index: include/applets.h
665+ 643+
666+ if (nlp == NULL) 644+ if (nlp == NULL)
667+ { 645+ {
668+ fprintf(stderr, "Cannot get memory for line\n"); 646+ bb_error_msg("Cannot get memory for line");
669+ 647+
670+ return; 648+ return;
671+ } 649+ }
@@ -707,7 +685,7 @@ Index: include/applets.h
707+ } 685+ }
708+ 686+
709+ if (!didSub) 687+ if (!didSub)
710+ fprintf(stderr, "No substitutions found for \"%s\"\n", oldStr); 688+ bb_error_msg("No substitutions found for \"%s\"", oldStr);
711+} 689+}
712+ 690+
713+ 691+
@@ -774,7 +752,7 @@ Index: include/applets.h
774+ 752+
775+ if (buf[len - 1] != '\n') 753+ if (buf[len - 1] != '\n')
776+ { 754+ {
777+ fprintf(stderr, "Line too long\n"); 755+ bb_error_msg("Line too long");
778+ 756+
779+ do 757+ do
780+ { 758+ {
@@ -817,7 +795,7 @@ Index: include/applets.h
817+ 795+
818+ while (TRUE) 796+ while (TRUE)
819+ { 797+ {
820+ while (isBlank(*cp)) 798+ while (isblank(*cp))
821+ cp++; 799+ cp++;
822+ 800+
823+ switch (*cp) 801+ switch (*cp)
@@ -839,7 +817,7 @@ Index: include/applets.h
839+ 817+
840+ if ((*cp < 'a') || (*cp > 'z')) 818+ if ((*cp < 'a') || (*cp > 'z'))
841+ { 819+ {
842+ fprintf(stderr, "Bad mark name\n"); 820+ bb_error_msg("Bad mark name");
843+ 821+
844+ return FALSE; 822+ return FALSE;
845+ } 823+ }
@@ -869,7 +847,7 @@ Index: include/applets.h
869+ break; 847+ break;
870+ 848+
871+ default: 849+ default:
872+ if (!isDecimal(*cp)) 850+ if (!isdigit(*cp))
873+ { 851+ {
874+ *retcp = cp; 852+ *retcp = cp;
875+ *retHaveNum = haveNum; 853+ *retHaveNum = haveNum;
@@ -880,7 +858,7 @@ Index: include/applets.h
880+ 858+
881+ num = 0; 859+ num = 0;
882+ 860+
883+ while (isDecimal(*cp)) 861+ while (isdigit(*cp))
884+ num = num * 10 + *cp++ - '0'; 862+ num = num * 10 + *cp++ - '0';
885+ 863+
886+ haveNum = TRUE; 864+ haveNum = TRUE;
@@ -889,7 +867,7 @@ Index: include/applets.h
889+ 867+
890+ value += num * sign; 868+ value += num * sign;
891+ 869+
892+ while (isBlank(*cp)) 870+ while (isblank(*cp))
893+ cp++; 871+ cp++;
894+ 872+
895+ switch (*cp) 873+ switch (*cp)
@@ -928,7 +906,7 @@ Index: include/applets.h
928+ 906+
929+ if (bufBase == NULL) 907+ if (bufBase == NULL)
930+ { 908+ {
931+ fprintf(stderr, "No memory for buffer\n"); 909+ bb_error_msg("No memory for buffer");
932+ 910+
933+ return FALSE; 911+ return FALSE;
934+ } 912+ }
@@ -999,7 +977,7 @@ Index: include/applets.h
999+ 977+
1000+ if ((num < 1) || (num > lastNum + 1)) 978+ if ((num < 1) || (num > lastNum + 1))
1001+ { 979+ {
1002+ fprintf(stderr, "Bad line for read\n"); 980+ bb_error_msg("Bad line for read");
1003+ 981+
1004+ return FALSE; 982+ return FALSE;
1005+ } 983+ }
@@ -1059,7 +1037,7 @@ Index: include/applets.h
1059+ 1037+
1060+ if (cp == NULL) 1038+ if (cp == NULL)
1061+ { 1039+ {
1062+ fprintf(stderr, "No memory for buffer\n"); 1040+ bb_error_msg("No memory for buffer");
1063+ close(fd); 1041+ close(fd);
1064+ 1042+
1065+ return FALSE; 1043+ return FALSE;
@@ -1121,7 +1099,7 @@ Index: include/applets.h
1121+ 1099+
1122+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) 1100+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
1123+ { 1101+ {
1124+ fprintf(stderr, "Bad line range for write\n"); 1102+ bb_error_msg("Bad line range for write");
1125+ 1103+
1126+ return FALSE; 1104+ return FALSE;
1127+ } 1105+ }
@@ -1193,7 +1171,7 @@ Index: include/applets.h
1193+ 1171+
1194+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) 1172+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
1195+ { 1173+ {
1196+ fprintf(stderr, "Bad line range for print\n"); 1174+ bb_error_msg("Bad line range for print");
1197+ 1175+
1198+ return FALSE; 1176+ return FALSE;
1199+ } 1177+ }
@@ -1207,7 +1185,7 @@ Index: include/applets.h
1207+ { 1185+ {
1208+ if (!expandFlag) 1186+ if (!expandFlag)
1209+ { 1187+ {
1210+ write(STDOUT, lp->data, lp->len); 1188+ write(1, lp->data, lp->len);
1211+ setCurNum(num1++); 1189+ setCurNum(num1++);
1212+ lp = lp->next; 1190+ lp = lp->next;
1213+ 1191+
@@ -1274,7 +1252,7 @@ Index: include/applets.h
1274+ 1252+
1275+ if ((num < 1) || (num > lastNum + 1)) 1253+ if ((num < 1) || (num > lastNum + 1))
1276+ { 1254+ {
1277+ fprintf(stderr, "Inserting at bad line number\n"); 1255+ bb_error_msg("Inserting at bad line number");
1278+ 1256+
1279+ return FALSE; 1257+ return FALSE;
1280+ } 1258+ }
@@ -1283,7 +1261,7 @@ Index: include/applets.h
1283+ 1261+
1284+ if (newLp == NULL) 1262+ if (newLp == NULL)
1285+ { 1263+ {
1286+ fprintf(stderr, "Failed to allocate memory for line\n"); 1264+ bb_error_msg("Failed to allocate memory for line");
1287+ 1265+
1288+ return FALSE; 1266+ return FALSE;
1289+ } 1267+ }
@@ -1330,7 +1308,7 @@ Index: include/applets.h
1330+ 1308+
1331+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) 1309+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
1332+ { 1310+ {
1333+ fprintf(stderr, "Bad line numbers for delete\n"); 1311+ bb_error_msg("Bad line numbers for delete");
1334+ 1312+
1335+ return FALSE; 1313+ return FALSE;
1336+ } 1314+ }
@@ -1391,7 +1369,7 @@ Index: include/applets.h
1391+ 1369+
1392+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) 1370+ if ((num1 < 1) || (num2 > lastNum) || (num1 > num2))
1393+ { 1371+ {
1394+ fprintf(stderr, "Bad line numbers for search\n"); 1372+ bb_error_msg("Bad line numbers for search");
1395+ 1373+
1396+ return 0; 1374+ return 0;
1397+ } 1375+ }
@@ -1400,7 +1378,7 @@ Index: include/applets.h
1400+ { 1378+ {
1401+ if (searchString[0] == '\0') 1379+ if (searchString[0] == '\0')
1402+ { 1380+ {
1403+ fprintf(stderr, "No previous search string\n"); 1381+ bb_error_msg("No previous search string");
1404+ 1382+
1405+ return 0; 1383+ return 0;
1406+ } 1384+ }
@@ -1427,7 +1405,7 @@ Index: include/applets.h
1427+ lp = lp->next; 1405+ lp = lp->next;
1428+ } 1406+ }
1429+ 1407+
1430+ fprintf(stderr, "Cannot find string \"%s\"\n", str); 1408+ bb_error_msg("Cannot find string \"%s\"", str);
1431+ 1409+
1432+ return 0; 1410+ return 0;
1433+} 1411+}
@@ -1444,7 +1422,7 @@ Index: include/applets.h
1444+ 1422+
1445+ if ((num < 1) || (num > lastNum)) 1423+ if ((num < 1) || (num > lastNum))
1446+ { 1424+ {
1447+ fprintf(stderr, "Line number %d does not exist\n", num); 1425+ bb_error_msg("Line number %d does not exist", num);
1448+ 1426+
1449+ return NULL; 1427+ return NULL;
1450+ } 1428+ }