Lines Matching refs:proto

28  * define PROTOMAIN for standalone proto
32 static const char id[] = "\n@(#)$Id: proto (AT&T Research) 2012-04-14 $\0\n";
51 #define GENERATED "/* : : generated by proto : : */\n"
68 typedef struct Proto_s /* proto buffer state */
102 * proto is separate from pp so these undef's are ok
293 p = strcopy(buf, "proto: ");
296 register Proto_t* proto = (Proto_t*)(iob - sizeof(Proto_t));
298 if (proto->line)
300 if (proto->file)
303 p = strcopy(p, proto->file);
309 p = number(p, proto->line);
311 else if (proto->file)
312 p = strcopy(p, proto->file);
368 linesync(register Proto_t* proto, register char* p, register long n)
371 if (proto->flags & LINESYNC)
391 init(Proto_t* proto, char* op, int flags)
468 if (proto->package)
497 op = strcopy(op - 1, proto->package);
509 #define CACHE() do{CACHEIN();CACHEOUT();call=proto->call;}while(0)
510 #define CACHEIN() (ip=proto->ip)
511 #define CACHEOUT() (op=proto->op)
516 #define SYNC() do{SYNCIN();SYNCOUT();proto->flags&=~(EXTERN|INIT|OTHER|VARIADIC|VARIADIC2);proto->flags|=flags&(EXTERN|INIT|OTHER|VARIADIC|VARIADIC2);proto->call=call;}while(0)
517 #define SYNCIN() (proto->ip=ip)
518 #define SYNCOUT() (proto->op=op)
575 lex(register Proto_t* proto, register long flags)
619 proto->tp = ip;
641 if (op > proto->ob && *(op - 1) == '=' && (op == proto->ob + 1 || *(op - 2) != '=')) switch (c)
664 proto->line++;
703 if ((flags & (DECLARE|GLOBAL|RECURSIVE)) == GLOBAL && (proto->flags & MORE))
709 c = ip - proto->ib;
711 im = proto->tp;
712 if (ip > proto->ib)
715 if (ip - n < proto->ib)
716 proto->flags |= ERROR;
717 memcopy(proto->ib - n, ip - n, n);
718 ip = proto->ib;
720 proto->tp -= c;
730 if ((n = read(proto->fd, ip, proto->iz)) > 0)
732 if ((proto->options & REGULAR) && n < proto->iz)
734 proto->flags &= ~MORE;
735 close(proto->fd);
744 proto->flags &= ~MORE;
745 close(proto->fd);
833 lex(proto, (flags & GLOBAL) | RECURSIVE);
870 if ((flags & EXTERN) && *proto->tp == 's' && !strncmp(proto->tp, "static", 6))
876 if (*proto->tp == '_' && !strncmp(proto->tp, "__STDPP__directive", 6)) c = '#';
883 proto->line++;
887 if (op != proto->ob && LASTOUT() != ' ' && LASTOUT() != '\n')
943 op = linesync(proto, op, proto->line);
981 if (!(flags & DECLARE)) switch (RESERVED(*proto->tp, *(ip - 1), ip - proto->tp))
984 if (proto->tp[1] == 'o')
991 if (!(flags & RECURSIVE) && (flags & (DIRECTIVE|TOKENS)) != DIRECTIVE && !strncmp(proto->tp, "else", 4))
998 if (!strncmp(proto->tp, "extern", 6))
1002 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "for", 3))
1012 if (!strncmp(proto->tp, "inline", 6) && !(flags & (MATCH|SKIP|TOKENS|TYPEDEF)) && proto->brace == 0 && paren == 0 && group == 0 && (last == ';' || last == '}' || last == '\n' || last == 0))
1016 line = proto->line;
1022 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "return", 6))
1029 if ((proto->options & EXTERNALIZE) && !strncmp(proto->tp, "static", 6))
1031 proto->ox = op - 6;
1036 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "typedef", 7))
1043 if (*ip == '(' && !strncmp(proto->tp, "va_start", 8)) c = T_VA_START;
1046 if (!strncmp(proto->tp, "void", 4))
1052 line = proto->line;
1053 if (lex(proto, (flags & GLOBAL) | RECURSIVE) == '*')
1059 proto->line = line;
1066 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "while", 5))
1087 while (op > proto->ob && (*(op - 1) == ' ' || *(op - 1) == '\t'))
1089 if (op > proto->ob && *(op - 1) != '\n') *op++ = ' ';
1108 proto->line++;
1131 if (!(flags & CLASSIC) || proto->brace == 0)
1188 if (!(flags & CLASSIC) || proto->brace == 0)
1221 if (proto->brace == 0 && paren == 0 && last != '=' && (flags & (CLASSIC|DECLARE|DIRECTIVE|MATCH|PLUSONLY|SKIP|TOKENS)) == (MATCH|TOKENS) && ((dir & DIR) != DIR_en || ((dir>>2) & DIR) != DIR_if))
1234 proto->line = 0;
1236 proto->line = proto->line * 10 + *ip - '0';
1237 proto->line--;
1297 op = linesync(proto, op, proto->line);
1315 op = linesync(proto, op, proto->line);
1330 op = linesync(proto, op, proto->line);
1347 if (proto->brace++ == 0 && paren == 0)
1362 proto_error((char*)proto + sizeof(Proto_t), 2, op, NiL);
1513 proto_error((char*)proto + sizeof(Proto_t), 1, "function pointer argument prototype omitted", NiL);
1546 line = proto->line;
1555 if ((vc = ie - im + 1) > sizeof(proto->variadic)) vc = sizeof(proto->variadic);
1556 memcopy(proto->variadic, im, vc);
1562 proto->ip = im;
1563 proto->op = op;
1568 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1602 proto->op = op;
1609 m = proto->tp;
1610 e = proto->ip;
1624 proto->op = strcopy(op, " __OTORP__(");
1625 proto->ip = im + 1;
1630 lex(proto, (flags & GLOBAL) | DECLARE);
1633 proto->ip = ie;
1634 op = proto->op;
1637 if (flags & EXTERNALIZE) memcpy(proto->ox, "extern", 6);
1638 op = linesync(proto, op, proto->line = line);
1641 proto->brace = 0;
1654 if (--proto->brace == 0)
1669 if (last == ')' && proto->brace && (group != 2 || call != 2)) flags |= SKIP;
1798 if (flags & EXTERNALIZE) memcpy(proto->ox, "extern", 6);
1834 if (proto->brace == 0)
1842 if (!(flags & PLUSONLY) || proto->package)
1845 if (proto->package)
1847 op = strcopy(op - 1, proto->package);
1873 line = proto->line;
1878 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1887 m = proto->tp;
1888 e = proto->ip;
1908 proto->ip = proto->variadic;
1909 proto->op = op;
1912 bp = proto->ip + 1;
1916 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1939 else op = memcopy(op, e, proto->ip - e - 1);
1965 else op = memcopy(op, e, proto->ip - e - 1);
1968 bp = proto->ip + 1;
1972 proto->op = op;
1979 m = proto->tp;
1980 e = proto->ip;
1990 proto->line = line;
2008 if (proto->brace == 0 && !(flags & DECLARE)) flags |= SKIP;
2019 if (*proto->tp >= '0' && *proto->tp <= '9')
2088 if ((flags & (EXTERN|MATCH)) == (EXTERN|MATCH) && ((flags & (DIRECTIVE|SKIP)) || proto->brace || c != '(' && c != ')' && c != '*' && c != T_ID))
2121 n = ip - proto->tp;
2126 op = proto->op;
2132 op = init(proto, op, flags);
2133 op = linesync(proto, op, proto->line);
2135 proto->flags &= ~(INIT_DEFINE|INIT_INCLUDE);
2143 * close a proto buffer stream
2149 register Proto_t* proto = (Proto_t*)(iob - sizeof(Proto_t));
2151 if (proto->flags & MORE) close(proto->fd);
2152 free((char*)proto); /* some ANSI cc's botch the free() prototype */
2156 * open a new proto buffer stream
2170 register Proto_t* proto;
2190 * initialize proto
2213 if (!(proto = newof(0, Proto_t, 1, 4 * n + 2)))
2215 proto->iz = n;
2216 proto->oz = 3 * n;
2227 if (!(proto = newof(0, Proto_t, 1, 5 * n + 2)))
2229 proto->iz = n;
2230 proto->oz = 3 * n;
2231 proto->flags |= MORE;
2233 proto->fd = fd;
2234 proto->package = package;
2235 iob = (char*)proto + sizeof(Proto_t);
2236 proto->op = proto->ob = iob;
2237 proto->ip = proto->ib = iob + proto->oz + n;
2238 if (m) proto->options |= REGULAR;
2241 if (!(proto->cc[0] = comment[0]))
2245 proto->cc[1] = comment[1];
2246 proto->cc[2] = comment[2] ? comment[2] : comment[0];
2249 proto->cc[1] = proto->cc[2] = comment[0];
2255 n = read(fd, proto->ip, proto->iz);
2256 if (!(proto->flags & MORE))
2263 *(proto->ip + n) = 0;
2266 * check for proto pragma in first block of lines
2277 if (!notice && !options || (comlen = astlicense(com, sizeof(com), NiL, "type=check", proto->cc[0], proto->cc[1], proto->cc[2])) <= 0)
2282 s = proto->ip;
2333 proto->flags |= YACC;
2368 if (flags & PROTO_PLUSPLUS) proto->flags |= PLUSPLUS;
2369 if (flags & PROTO_TEST) proto->test = 1;
2370 if (flags & PROTO_EXTERNALIZE) proto->options |= EXTERNALIZE;
2374 if (flags & PROTO_LINESYNC) proto->flags |= LINESYNC;
2375 if (!(proto->flags & YACC) && file && (m = strlen(file)) > 2 && file[--m] == 'y' && file[--m] == '.')
2376 proto->flags |= YACC;
2383 proto->flags |= PLUSONLY;
2392 proto->flags |= PASS;
2393 if (proto->flags & MORE)
2394 proto->oz += proto->iz;
2395 proto->iz = n;
2398 if (proto->cc[0] == '#' && proto->ip[0] == '#' && proto->ip[1] == '!')
2400 s = proto->ip;
2402 m = s - proto->ip;
2403 proto->op = memcopy(proto->op, proto->ip, m);
2404 proto->ip = s;
2405 proto->iz = n -= m;
2408 if (proto->cc[0])
2410 if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
2411 proto_error((char*)proto + sizeof(Proto_t), 1, proto->op, NiL);
2413 proto->op += comlen;
2415 if (!(flags & PROTO_CLASSIC) && !(proto->flags & YACC))
2417 proto->op = linesync(proto, proto->op, 1);
2418 proto->iz += proto->op - proto->ob;
2420 memcopy(proto->op, proto->ip, n);
2431 proto->line = 1;
2438 if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
2439 proto_error((char*)proto + sizeof(Proto_t), 1, proto->op, NiL);
2441 proto->op += comlen;
2446 proto->flags |= INIT_INCLUDE;
2456 *proto->op++ = '#';
2457 proto->op = strcopy(proto->op, PRAGMADIR);
2458 *proto->op++ = ' ';
2459 proto->op = strcopy(proto->op, pragmas[0].name);
2460 *proto->op++ = '\n';
2464 proto->flags |= INIT_DEFINE;
2469 if (proto->flags & YACC)
2471 proto->op = strcopy(proto->op, "\n%{\n" + !notice);
2472 proto->op = strcopy(proto->op, GENERATED);
2473 proto->op = strcopy(proto->op, "%}\n");
2478 *proto->op++ = '\n';
2479 proto->op = strcopy(proto->op, GENERATED);
2481 proto->op = linesync(proto, proto->op, proto->line);
2482 else if (proto->flags & (INIT_DEFINE|INIT_INCLUDE))
2483 proto->op = init(proto, proto->op, proto->flags);
2490 proto->file = file;
2493 proto->flags |= CLASSIC;
2494 if (!(flags & PROTO_HEADER)) proto->flags |= EXTERN;
2501 * read next proto'd chunk into iob
2508 register Proto_t* proto = (Proto_t*)(iob - sizeof(Proto_t));
2511 if (proto->flags & PASS)
2513 if (proto->iz)
2515 n = proto->iz;
2516 proto->iz = 0;
2518 else if (!(proto->flags & MORE)) n = 0;
2519 else if ((n = read(proto->fd, proto->ob, proto->oz)) <= 0 || (proto->options & REGULAR) && n < proto->oz)
2521 proto->flags &= ~MORE;
2522 close(proto->fd);
2527 if (proto->op == proto->ob)
2529 if (proto->flags & ERROR) return -1;
2531 if (proto->flags & YACC)
2533 register char* ip = proto->ip;
2534 register char* op = proto->ob;
2535 register char* ep = proto->ob + proto->oz - 2;
2539 ip = proto->ip = proto->ib;
2540 if (!(proto->flags & MORE)) n = 0;
2541 else if ((n = read(proto->fd, ip, proto->iz)) <= 0 || (proto->options & REGULAR) && n < proto->iz)
2544 proto->flags &= ~MORE;
2545 close(proto->fd);
2549 if (proto->flags & YACCSPLIT)
2551 proto->flags &= ~YACCSPLIT;
2555 if (proto->flags & YACC2) proto->flags &= ~YACC;
2556 else proto->flags |= YACC2;
2559 if (proto->flags & YACC)
2565 if (*ip == '%' && (ip == proto->ip + 1 || *(ip - 2) == '\n'))
2568 if (proto->flags & YACC2) proto->flags &= ~YACC;
2569 else proto->flags |= YACC2;
2575 proto->flags |= YACCSPLIT;
2579 else if (n == '\n') proto->line++;
2581 proto->op = memcopy(proto->ob, proto->ip, ip - proto->ip);
2582 proto->ip = ip;
2586 lex(proto, proto->flags);
2587 if ((proto->flags & (ERROR|MORE)) == ERROR)
2588 proto->op = strcopy(proto->op, "/* NOTE: some constructs may not have been converted */\n");
2590 n = proto->op - proto->ob;
2591 proto->op = proto->ob;
2607 register Proto_t* proto = (Proto_t*)(iob - sizeof(Proto_t));
2609 if (proto->flags & MORE)
2611 proto->flags &= ~MORE;
2612 return proto->fd;