Lines Matching refs:cp

98 	struct s_command *cp;
109 cp = prog;
111 while (cp != NULL) {
112 if (!applies(cp)) {
113 cp = cp->next;
116 switch (cp->code) {
118 cp = cp->u.c;
127 appends[appendx].s = cp->t;
128 appends[appendx].len = strlen(cp->t);
132 cp = cp->u.c;
137 if (cp->a2 == NULL || lastaddr || lastline())
138 (void)fprintf(outfile, "%s", cp->t);
170 (void)fprintf(outfile, "%s", cp->t);
225 appends[appendx].s = cp->t;
226 appends[appendx].len = strlen(cp->t);
230 sdone |= substitute(cp);
235 cp = cp->u.c;
242 if (cp->u.fd == -1 && (cp->u.fd = open(cp->t,
245 err(1, "%s", cp->t);
246 if (write(cp->u.fd, ps, psl) != (ssize_t)psl ||
247 write(cp->u.fd, "\n", 1) != 1)
248 err(1, "%s", cp->t);
267 do_tr(cp->u.y);
275 cp = cp->next;
276 } /* for all cp */
297 applies(struct s_command *cp)
302 if (cp->a1 == NULL && cp->a2 == NULL)
304 else if (cp->a2)
305 if (cp->startline > 0) {
306 switch (cp->a2->type) {
308 if (linenum - cp->startline <= cp->a2->u.l)
311 cp->startline = 0;
316 if (MATCH(cp->a2)) {
317 cp->startline = 0;
320 } else if (cp->a2->type == AT_LINE &&
321 linenum > cp->a2->u.l) {
327 cp->startline = 0;
332 } else if (cp->a1 && MATCH(cp->a1)) {
340 if ((cp->a2->type == AT_LINE &&
341 linenum >= cp->a2->u.l) ||
342 (cp->a2->type == AT_RELLINE && cp->a2->u.l == 0))
345 cp->startline = linenum;
351 r = MATCH(cp->a1);
352 return (cp->nonsel ? ! r : r);
361 struct s_command *cp;
366 for (cp = prog; cp; cp = cp->code == '{' ? cp->u.c : cp->next)
367 if (cp->a2)
368 cp->startline = 0;
383 substitute(struct s_command *cp)
393 re = cp->u.s->re;
395 if (defpreg != NULL && cp->u.s->maxbref > defpreg->re_nsub) {
396 linenum = cp->u.s->linenum;
398 linenum, fname, cp->u.s->maxbref);
406 n = cp->u.s->n;
419 regsub(&SS, ps, cp->u.s->new);
475 if (cp->u.s->p)
479 if (cp->u.s->wfile && !pd) {
480 if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile,
482 err(1, "%s", cp->u.s->wfile);
483 if (write(cp->u.s->wfd, ps, psl) != (ssize_t)psl ||
484 write(cp->u.s->wfd, "\n", 1) != 1)
485 err(1, "%s", cp->u.s->wfile);
769 cfclose(struct s_command *cp, struct s_command *end)
772 for (; cp != end; cp = cp->next)
773 switch(cp->code) {
775 if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
776 err(1, "%s", cp->u.s->wfile);
777 cp->u.s->wfd = -1;
780 if (cp->u.fd != -1 && close(cp->u.fd))
781 err(1, "%s", cp->t);
782 cp->u.fd = -1;
785 cfclose(cp->u.c, cp->next);