Lines Matching +defs:p +defs:c

1 /*	$OpenBSD: compile.c,v 1.53 2024/07/17 20:57:15 millert Exp $	*/
4 * Copyright (c) 1992 Diomidis Spinellis.
5 * Copyright (c) 1992, 1993
91 {'c', 2, TEXT},
102 {'p', 2, EMPTY},
136 if (p) \
137 while (isascii((unsigned char)*p) && \
138 isspace((unsigned char)*p)) \
139 p++; \
145 char *p;
154 if ((p = cu_getline(&lbuf, &bufsize)) == NULL) {
161 if (*p == '#' || *p == '\0')
163 if (*p == ';') {
164 p++;
174 #define addrchar(c) (strchr("0123456789/\\$", (c)))
175 if (addrchar(*p)) {
178 p = compile_addr(p, cmd->a1);
180 if (*p == ',') {
181 p++;
185 p = compile_addr(p, cmd->a2);
195 if (!*p)
197 cmd->code = *p;
199 if (fp->code == *p)
202 error("invalid command code %c", *p);
204 error("command %c expects up to %d address(es),"
205 " found %d", *p, fp->naddr, naddr);
208 p++;
213 p++;
217 link = &cmd->u.c;
218 if (*p)
233 case EMPTY: /* d D g G h H l n N p P q x = \0 */
234 p++;
236 if (*p == ';') {
237 p++;
241 if (*p)
242 error("extra characters at the end of %c"
245 case TEXT: /* a c i */
246 p++;
248 if (*p != '\\')
249 error("command %c expects \\ followed by text",
251 p++;
253 if (*p)
255 " end of %c command", cmd->code);
261 p++;
263 if (*p == '\0')
265 cmd->t = duptoeol(p, "w command", NULL);
270 else if ((cmd->u.fd = open(p,
273 err(1, "%s", p);
277 p++;
279 if (*p == '\0')
281 cmd->t = duptoeol(p, "read command", NULL);
284 p++;
286 if (*p == '\0' || *p == ';')
289 cmd->t = duptoeol(p, "branch", &p);
290 if (*p == ';') {
291 p++;
296 p++;
298 cmd->t = duptoeol(p, "label", &p);
302 if (*p == ';') {
303 p++;
308 p++;
309 if (*p == '\0' || *p == '\\')
313 p = compile_re(p, &cmd->u.s->re);
314 if (p == NULL)
316 --p;
317 p = compile_subst(p, cmd->u.s);
318 p = compile_flags(p, cmd->u.s);
320 if (*p == ';') {
321 p++;
327 p++;
328 p = compile_tr(p, (char **)&cmd->u.y);
330 if (*p == ';') {
331 p++;
335 if (*p)
353 compile_delimited(char *p, char *d)
355 char c;
357 c = *p++;
358 if (c == '\0')
360 else if (c == '\\')
362 else if (c == '\n')
365 while (p[0]) {
367 if (p[0] == c) {
369 return p + 1;
371 if (p[0] == '\\') {
373 if (p[1] == c) {
374 p++;
377 if (p[1] == 'n') {
379 p += 2;
382 *d++ = *p++;
383 *d++ = *p++;
388 if (p[0] != '[')
389 *d++ = *p++;
394 else if ((d = compile_ccl(&p, d)) == NULL)
405 int c, d;
416 for (c = *s; (*t = *s) != ']' || c != d; s++, t++)
417 if ((c = *s) == '\0')
441 compile_re(char *p, regex_t **repp)
446 re = xmalloc(strlen(p) + 1); /* strlen(re) <= strlen(p) */
447 p = compile_delimited(p, re);
448 if (p && strlen(re) == 0) {
451 return (p);
454 if (p && (eval = regcomp(*repp, re, Eflag ? REG_EXTENDED : 0)) != 0)
459 return (p);
468 compile_subst(char *p, struct s_subst *s)
473 char c, *text, *op, *sp;
476 c = *p++; /* Terminator character */
477 if (c == '\0')
485 size_t len = ROUNDLEN(strlen(p) + 1);
493 for (; *p; p++) {
494 if (*p == '\\' || sawesc) {
503 p++;
505 if (*p == '\0') {
514 p--;
516 } else if (strchr("123456789", *p) != NULL) {
518 ref = *p - '0';
521 error("\\%c not defined in the"
522 " RE", *p);
525 } else if (*p == '&' || *p == '\\')
527 } else if (*p == c) {
528 p++;
532 return (p);
533 } else if (*p == '\n') {
537 *sp++ = *p;
540 } while ((p = cu_getline(&lbuf, &bufsize)));
548 compile_flags(char *p, struct s_subst *s)
554 s->p = 0;
559 switch (*p) {
570 return (p);
571 case 'p':
572 s->p = 1;
581 l = strtol(p, &p, 10);
588 p++;
590 if (*p == '\0')
592 s->wfile = duptoeol(p, "s command w flag", NULL);
593 *p = '\0';
600 return (p);
602 error("bad flag in substitute command: '%c'", *p);
605 p++;
670 * Compile the text following an a, c, or i command.
676 char *lbuf, *text, *p, *op, *s;
681 while ((p = cu_getline(&lbuf, &bufsize))) {
682 size_t len = ROUNDLEN(strlen(p) + 1);
690 for (esc_nl = 0; *p != '\0'; p++) {
691 if (*p == '\\' && p[1] != '\0' && *++p == '\n')
693 *s++ = *p;
712 compile_addr(char *p, struct s_addr *a)
716 switch (*p) {
718 ++p;
721 p = compile_re(p, &a->u.r);
722 if (p == NULL)
725 return (p);
729 return (p + 1);
734 a->u.l = strtoul(p, &end, 10);
793 cp->u.c = NULL;
796 if ((cp->u.c = findlabel(cp->t)) == NULL)
802 fixuplabel(cp->u.c, cp->next);
814 u_char *p;
815 u_int h, c;
817 for (h = 0, p = (u_char *)cp->t; (c = *p) != 0; p++)
818 h = (h << 5) + h + c;
839 u_char *p;
840 u_int h, c;
842 for (h = 0, p = (u_char *)name; (c = *p) != 0; p++)
843 h = (h << 5) + h + c;