Lines Matching refs:cp

92 	struct s_command *cp;
102 cp = prog;
104 while (cp != NULL) {
105 if (!applies(cp)) {
106 cp = cp->next;
109 switch (cp->code) {
111 cp = cp->u.c;
120 appends[appendx].s = cp->t;
121 appends[appendx].len = strlen(cp->t);
125 cp = cp->u.c;
130 if (cp->a2 == NULL || lastaddr || lastline())
131 (void) fprintf(outfile, "%s", cp->t);
164 (void) fprintf(outfile, "%s", cp->t);
212 appends[appendx].s = cp->t;
213 appends[appendx].len = strlen(cp->t);
217 sdone |= substitute(cp);
222 cp = cp->u.c;
229 if (cp->u.fd == -1 && (cp->u.fd = open(cp->t,
232 err(1, "%s", cp->t);
233 if (write(cp->u.fd, ps, psl) != (ssize_t)psl ||
234 write(cp->u.fd, "\n", 1) != 1)
235 err(1, "%s", cp->t);
253 do_tr(cp->u.y);
261 cp = cp->next;
262 } /* for all cp */
283 applies(struct s_command *cp)
288 if (cp->a1 == NULL && cp->a2 == NULL)
290 else if (cp->a2)
291 if (cp->startline > 0) {
292 if (MATCH(cp->a2)) {
293 cp->startline = 0;
296 } else if (linenum - cp->startline <= cp->a2->u.l)
298 else if ((cp->a2->type == AT_LINE &&
299 linenum > cp->a2->u.l) ||
300 (cp->a2->type == AT_RELLINE &&
301 linenum - cp->startline > cp->a2->u.l)) {
306 cp->startline = 0;
310 } else if (MATCH(cp->a1)) {
318 if ((cp->a2->type == AT_LINE &&
319 linenum >= cp->a2->u.l) ||
320 (cp->a2->type == AT_RELLINE && cp->a2->u.l == 0))
323 cp->startline = linenum;
329 r = MATCH(cp->a1);
330 return (cp->nonsel ? ! r : r);
339 struct s_command *cp;
344 for (cp = prog; cp; cp = cp->code == '{' ? cp->u.c : cp->next)
345 if (cp->a2)
346 cp->startline = 0;
361 substitute(struct s_command *cp)
370 re = cp->u.s->re;
372 if (defpreg != NULL && cp->u.s->maxbref > defpreg->re_nsub) {
373 linenum = cp->u.s->linenum;
375 cp->u.s->maxbref);
383 n = cp->u.s->n;
395 regsub(&SS, s, cp->u.s->new);
434 regsub(&SS, s, cp->u.s->new);
452 if (cp->u.s->p)
456 if (cp->u.s->wfile && !pd) {
457 if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile,
459 err(1, "%s", cp->u.s->wfile);
460 if (write(cp->u.s->wfd, ps, psl) != (ssize_t)psl ||
461 write(cp->u.s->wfd, "\n", 1) != 1)
462 err(1, "%s", cp->u.s->wfile);
748 cfclose(struct s_command *cp, struct s_command *end)
751 for (; cp != end; cp = cp->next)
752 switch (cp->code) {
754 if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
755 err(1, "%s", cp->u.s->wfile);
756 cp->u.s->wfd = -1;
759 if (cp->u.fd != -1 && close(cp->u.fd))
760 err(1, "%s", cp->t);
761 cp->u.fd = -1;
764 cfclose(cp->u.c, cp->next);