|
|
1.1 root 1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
2:
3: * ******************************************************
4: * ******************************************************
5: * *** SUBSTITUTE COMMAND SIMILAR TO UNIX EDITORS 's' ***
6: * ************ R. B. Drake WH 8C-005 X4163 *************
7: * ************** Sun Aug 26 11:51:03 1979 **************
8: * ******************************************************
9: * ******************************************************
10:
11: */
12: /* "@(#) sub.c: V 1.1 12/21/80" */
13:
14: /* routine to do character substitution for the editor */
15: #include "bas.h"
16: #define ertst if(ifnul(work)) return(-1)
17: char temp[80];
18: extern char _string[];
19: int line;
20: sub()
21: {
22: char *strptr,c,*op;
23: char *lp,*work,*from,*to,*isthere(),what[80],with[80],delim;
24: lp=what;
25: work= expr;
26: while(num(*work))
27: *lp++ = *work++; /* get the line number to work on */
28: ertst;
29: *lp='\0';
30: line = atoi(what);
31: ertst;
32: while((c= *work) == ' ' || c == '\t')
33: {
34: ertst;
35: work++;
36: }
37: delim= *work++; /* get the delimeter */
38: from=what;
39: to=with;
40: while(*work != delim)
41: {
42: ertst;
43: *from++ = *work++;
44: }
45: *from='\0';
46: work++; /* bump past delimeter */
47: while (*work != delim && *work != '\0')
48: *to++ = *work++;
49: *to++ = '\0';
50: fetch(line,&lbdptr); /* get the line to be edited */
51: if(inst.thing.linno != line) /* if no such line , complain and exit */
52: {
53: error(line,0);
54: return(-1);
55: }
56: expand(); /* expand the expression part of program line */
57: op = decode(inst.thing.opcode.lobyte);
58: if(op[0] == '\010')
59: sprintf(temp,"%d %s\n",inst.thing.linno,linbuf);
60: else
61: sprintf(temp,"%d %s %s\n",inst.thing.linno,op,linbuf);
62: if((lp=isthere(what,temp,0)) == 0)
63: {
64: error(0,1);
65: return(-1); /* no such expression in that line */
66: }
67: strptr= _string;
68: from=temp;
69: to=with;
70: while( *from != '\n')
71: {
72: if( from == lp)
73: {
74: from += strlen(what);
75: while(*to)
76: *strptr++ = *to++;
77: }
78: else
79: *strptr++ = *from++;
80: }
81: *strptr++= '\n';
82: *strptr = '\0';
83: bed((FILE *)0);
84: fetch(line,&lbdptr);
85: prin();
86: return(0);
87: }
88: ifnul(work)
89: char *work;
90: {
91: if(*work == '\0')
92: {
93: error(0,20);
94: return(1);
95: }
96: return(0);
97: }
98: /* undo the last substitute or single line delete */
99: undo()
100: {
101: char *strptr,*from;
102: strptr=_string;
103: from=temp;
104: while(*from != '\0')
105: *strptr++ = *from++;
106: *strptr='\0';
107: bed((FILE *)0);
108: fetch(line,&lbdptr);
109: prin();
110: return(0);
111: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.