994
|
1 /* ed.c */
|
|
2 /* Copyright 1987 Brian Beattie Rights Reserved.
|
|
3 *
|
|
4 * Permission to copy and/or distribute granted under the
|
|
5 * following conditions:
|
|
6 *
|
|
7 * 1). No charge may be made other than resonable charges
|
|
8 * for reproduction.
|
|
9 *
|
|
10 * 2). This notice must remain intact.
|
|
11 *
|
|
12 * 3). No further restrictions may be added.
|
|
13 *
|
|
14 */
|
|
15 #include <stdio.h>
|
|
16 #include <signal.h>
|
|
17 #include "tools.h"
|
|
18 #include "ed.h"
|
|
19 #include <setjmp.h>
|
|
20 jmp_buf env;
|
|
21
|
|
22 #define isatty(fd) 1
|
|
23
|
|
24 LINE line0;
|
|
25 int curln = 0;
|
|
26 int lastln = 0;
|
|
27 char *inptr;
|
|
28 static char inlin[MAXLINE];
|
|
29 int nflg, lflg;
|
|
30 int line1, line2, nlines;
|
|
31 extern char fname[];
|
|
32 int version = 1;
|
|
33 int diag = 1;
|
|
34
|
|
35 intr(sig)
|
|
36 int sig;
|
|
37 {
|
|
38 printf("?\n");
|
|
39 longjmp(env, 1);
|
|
40 }
|
|
41
|
|
42 int main(argc, argv)
|
|
43 int argc;
|
|
44 char **argv;
|
|
45 {
|
|
46 int stat, i, doflush;
|
|
47
|
|
48 pflinit();
|
|
49 set_buf();
|
|
50 doflush = isatty(1);
|
|
51
|
|
52 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 0) {
|
|
53 diag = 0;
|
|
54 argc--;
|
|
55 argv++;
|
|
56 }
|
|
57 if (argc > 1) {
|
|
58 for (i = 1; i < argc; i++) {
|
|
59 if (doread(0, argv[i]) == 0) {
|
|
60 curln = 1;
|
|
61 strcpy(fname, argv[i]);
|
|
62 break;
|
|
63 }
|
|
64 }
|
|
65 }
|
|
66 while (1) {
|
|
67 setjmp(env);
|
|
68 if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, intr);
|
|
69
|
|
70 if (doflush) fflush(stdout);
|
|
71
|
|
72 if (fgets(inlin, sizeof(inlin), stdin) == NULL) {
|
|
73 break;
|
|
74 }
|
|
75 inptr = inlin;
|
|
76 if (getlst() >= 0)
|
|
77 if ((stat = ckglob()) != 0) {
|
|
78 if (stat >= 0 && (stat = doglob()) >= 0) {
|
|
79 curln = stat;
|
|
80 continue;
|
|
81 }
|
|
82 } else {
|
|
83 if ((stat = docmd(0)) >= 0) {
|
|
84 if (stat == 1) doprnt(curln, curln);
|
|
85 continue;
|
|
86 }
|
|
87 }
|
|
88 if (stat == EOF) {
|
|
89 exit(0);
|
|
90 }
|
|
91 if (stat == FATAL) {
|
|
92 fputs("FATAL ERROR\n", stderr);
|
|
93 exit(1);
|
|
94 }
|
|
95 printf("?\n");
|
|
96 }
|
|
97 return(0);
|
|
98 }
|
|
99
|