* gres -- substitute in lines matching (or not) a pattern
bufend
= &linebuf
[LBSIZE
];
reend
= &respace
[RESIZE
];
while (--argc
> 0 && (++argv
)[0][0]=='-')
printf2("Unknown flag: %c\n", argv
[0][1]);
else while(--argc
>= 0) {
if((fin
= open(*++argv
, 0)) < 0) {
printf2("Cannot open pattern file: %s\n",
while(*++cp
= getchar()) {
printf2("RE too long, line %d\n", lnum
);
p
= compile(linebuf
, rep
->re1
, &rep
->gcirc
);
printf2("RE error, line %d\n", lnum
);
if(p
== 1 && rep
->gcirc
== 0) {
rep
->gcirc
= rep
[-1].scirc
;
printf2("RE error, line %d\n",
if((rep
->re2
= rep
->re1
+ p
) > reend
)
printf2("RE space exhausted; line %d\n", lnum
);
while(*++cp
= getchar()) {
printf("RE too long, line %d\n", lnum
);
p
= compile(linebuf
, rep
->re2
, &rep
->scirc
);
printf2("RE error, line %d\n", lnum
);
if(p
== 1 && rep
->scirc
== 0) {
if((rep
->rhs
= rep
->re2
+ p
) > reend
)
printf2("RE space exhausted, line %d\n", lnum
);
while(*++cp
= getchar()) {
printf2("RE too long, line %d\n", lnum
);
if((p
= compsub(linebuf
, rep
->rhs
)) < 1)
printf2("RHS error, line %d\n", lnum
);
printf2("Too many lines in pattern file, %d\n",
if ((rep
->re1
= rep
[-1].rhs
+ p
) > reend
)
printf2("RE space exhausted, line %d\n", lnum
);
p
= compile(*++argv
, rep
->re1
, &rep
->gcirc
);
printf2("RE error, re%d\n", 1);
if(p
== 1 && rep
->gcirc
== 0) {
rep
->gcirc
= rep
[-1].scirc
;
printf2("RE error: re1\n");
if((p
= compile(*++argv
, rep
->re2
, &rep
->scirc
)) < 1)
printf2("RE error, re%d\n", 2);
if(p
== 1 && rep
->scirc
== 0) {
if((p
= compsub(*++argv
, rep
->rhs
)) < 1)
printf2("Too many patterns\n");
if((rep
->re1
= rep
[-1].rhs
+ p
) > reend
)
printf2("RE space exhausted\n");
compile(astr
, expbuf
, circf
)
char bracket
[NBRA
], *bracketp
;
if (ep
>= &expbuf
[ESIZE
])
if(c
== '\n') return(-1);
if(ep
>= expbuf
[ESIZE
] - 1) return(-1);
if (*sp
!= '\0' && *sp
!= '\n')
if ((c
= *sp
++) == '^') {
if (c
=='\0' || ep
>= &expbuf
[ESIZE
])
} while ((c
= *sp
++) != ']');
if ((f
= open(file
, 0)) < 0) {
printf2("Can't open %s\n", file
);
if ((count
= c
= read(f
, ibuf
, 512)) <= 0) {
if (p1
< &linebuf
[LBSIZE
-1])
for(rep
= ptrspace
; rep
->re1
; rep
++) {
/* fast check for first character */
if (count
!= 512) flush();
register char *lp
, *ep
, *curlp
;
for (;;) switch (*ep
++) {
if (cclass(ep
, *lp
++, 1)) {
if (cclass(ep
, *lp
++, 0)) {
while (cclass(ep
, *lp
++, ep
[-1]==(CCL
|STAR
)));
if(sexec(0) == 0) return;
register char *p1
, *p2
, c
;
if(rep
->scirc
) return(0);
/* fast check for first character */
rhsend
= &rhsbuf
[LBSIZE
];
register char *lp
, *sp
, *rp
;
sp
= place(sp
, loc1
, loc2
);
} else if (c
<0 && (c
=& 0177) >='1' && c
< NBRA
+'1') {
sp
= place(sp
, braslist
[c
-'1'], braelist
[c
-'1']);
if (sp
>= &genbuf
[LBSIZE
])
printf2("output line too long.\n");
loc2
= sp
+ linebuf
- genbuf
;
if (sp
>= &genbuf
[LBSIZE
]) {
printf2("Output line too long.\n");
register char *sp
, *l1
, *l2
;
if (sp
>= &genbuf
[LBSIZE
])
printf2("Output line too long.\n");