annotate 3rdparty/packages/ed/ed.c @ 1942:b41df77588b0

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