|
|
1.1 root 1: /*
2: * sed/sed1.c
3: * A stream editor.
4: * Main.
5: */
6:
7: #include <stdio.h>
8: #include <ctype.h>
9: #include <stdlib.h>
10: #include "sed.h"
11:
12: main(argc, argv)
13: char *argv[];
14: {
15: ECL **eclpp;
16: int scrflag;
17: register ECL *ep;
18: register int i;
19: register char *cp;
20:
21: scrflag = 0;
22: initialise();
23: eclpp = &eclp;
24: for (i=1; i<argc; i++) {
25: cp = &argv[i][0];
26: if (*cp++ != '-') {
27: *eclpp = ep = (ECL *)salloc(sizeof (ECL));
28: eclpp = &ep->e_next;
29: ep->e_argp = argv[i];
30: continue;
31: }
32: while (*cp) {
33: switch (*cp++) {
34: case 'e':
35: if (++i >= argc)
36: usage();
37: compstr(argv[i]);
38: scrflag++;
39: continue;
40: case 'f':
41: if (++i >= argc)
42: usage();
43: compfil(argv[i]);
44: scrflag++;
45: continue;
46: case 'n':
47: nflag++;
48: continue;
49: case 's':
50: sflag++;
51: continue;
52: default:
53: usage();
54: }
55: }
56: }
57: *eclpp = NULL;
58: if (scrflag==0 && eclp!=NULL) {
59: ep = eclp;
60: eclp = eclp->e_next;
61: compstr(ep->e_argp);
62: free(ep);
63: }
64: compstr(":");
65: load();
66: if (nerr != 0)
67: exit(1);
68: ifp = eclp==NULL ? stdin : NULL;
69: process();
70: }
71:
72: /*
73: * Print out a usage message.
74: */
75: usage()
76: {
77: fprintf(stderr, "Usage: sed [-n] [-e script] [-f sfile] [file]\n");
78: exit(1);
79: }
80:
81: /*
82: * Initialisation.
83: */
84: initialise()
85: {
86: compp = ∁
87: filp = NULL;
88: labp = NULL;
89: qcbp = NULL;
90: pattlen = 0;
91: holdlen = 0;
92: nflag = 0;
93: sflag = 0;
94: nerr = 0;
95: lno = 0;
96: }
97:
98: /*
99: * Leave.
100: */
101: leave()
102: {
103: exit(0);
104: }
105:
106: /*
107: * Allocate `n' bytes of memory.
108: */
109: char *
110: salloc(n)
111: {
112: register char *cp;
113:
114: if ((cp = malloc(n)) == NULL) {
115: fprintf(stderr, "Out of space\n");
116: exit(1);
117: }
118: return cp;
119: }
120:
121: /* end of sed/sed1.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.