Lines Matching defs:proto

28  * define PROTOMAIN for standalone proto
32 static const char id[] = "\n@(#)$Id: proto (AT&T Research) 2008-05-11 $\0\n";
51 #define MAGICGEN "/* : : generated by proto : : */\n"
53 #define MAGICDIR "pragma" /* proto magic directive */
54 #define MAGICARG "prototyped" /* proto magic directive arg */
60 struct proto /* proto buffer state */
94 * proto is separate from pp so these undef's are ok
263 p = strcopy(buf, "proto: ");
266 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
268 if (proto->line)
270 if (proto->file)
273 p = strcopy(p, proto->file);
279 p = number(p, proto->line);
281 else if (proto->file)
282 p = strcopy(p, proto->file);
338 linesync(register struct proto* proto, register char* p, register long n)
341 if (proto->flags & LINESYNC)
361 init(struct proto* proto, char* op, int flags)
438 if (proto->package)
467 op = strcopy(op - 1, proto->package);
479 #define CACHE() do{CACHEIN();CACHEOUT();call=proto->call;}while(0)
480 #define CACHEIN() (ip=proto->ip)
481 #define CACHEOUT() (op=proto->op)
486 #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)
487 #define SYNCIN() (proto->ip=ip)
488 #define SYNCOUT() (proto->op=op)
545 lex(register struct proto* proto, register long flags)
589 proto->tp = ip;
611 if (op > proto->ob && *(op - 1) == '=' && (op == proto->ob + 1 || *(op - 2) != '=')) switch (c)
634 proto->line++;
673 if ((flags & (DECLARE|GLOBAL|RECURSIVE)) == GLOBAL && (proto->flags & MORE))
679 c = ip - proto->ib;
681 im = proto->tp;
682 if (ip > proto->ib)
685 if (ip - n < proto->ib)
686 proto->flags |= ERROR;
687 memcopy(proto->ib - n, ip - n, n);
688 ip = proto->ib;
690 proto->tp -= c;
700 if ((n = read(proto->fd, ip, proto->iz)) > 0)
702 if ((proto->options & REGULAR) && n < proto->iz)
704 proto->flags &= ~MORE;
705 close(proto->fd);
714 proto->flags &= ~MORE;
715 close(proto->fd);
803 lex(proto, (flags & GLOBAL) | RECURSIVE);
840 if ((flags & EXTERN) && *proto->tp == 's' && !strncmp(proto->tp, "static", 6))
846 if (*proto->tp == '_' && !strncmp(proto->tp, "__STDPP__directive", 6)) c = '#';
853 proto->line++;
857 if (op != proto->ob && LASTOUT() != ' ' && LASTOUT() != '\n')
913 op = linesync(proto, op, proto->line);
951 if (!(flags & DECLARE)) switch (RESERVED(*proto->tp, *(ip - 1), ip - proto->tp))
954 if (proto->tp[1] == 'o')
961 if (!(flags & RECURSIVE) && (flags & (DIRECTIVE|TOKENS)) != DIRECTIVE && !strncmp(proto->tp, "else", 4))
968 if (!strncmp(proto->tp, "extern", 6))
972 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "for", 3))
982 if (!strncmp(proto->tp, "inline", 6) && !(flags & (MATCH|SKIP|TOKENS|TYPEDEF)) && proto->brace == 0 && paren == 0 && group == 0 && (last == ';' || last == '}' || last == '\n' || last == 0))
986 line = proto->line;
992 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "return", 6))
999 if ((proto->options & EXTERNALIZE) && !strncmp(proto->tp, "static", 6))
1001 proto->ox = op - 6;
1006 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "typedef", 7))
1013 if (*ip == '(' && !strncmp(proto->tp, "va_start", 8)) c = T_VA_START;
1016 if (!strncmp(proto->tp, "void", 4))
1022 line = proto->line;
1023 if (lex(proto, (flags & GLOBAL) | RECURSIVE) == '*')
1029 proto->line = line;
1036 if (!(flags & RECURSIVE) && !strncmp(proto->tp, "while", 5))
1057 while (op > proto->ob && (*(op - 1) == ' ' || *(op - 1) == '\t'))
1059 if (op > proto->ob && *(op - 1) != '\n') *op++ = ' ';
1078 proto->line++;
1101 if (!(flags & CLASSIC) || proto->brace == 0)
1158 if (!(flags & CLASSIC) || proto->brace == 0)
1191 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))
1204 proto->line = 0;
1206 proto->line = proto->line * 10 + *ip - '0';
1207 proto->line--;
1267 op = linesync(proto, op, proto->line);
1285 op = linesync(proto, op, proto->line);
1300 op = linesync(proto, op, proto->line);
1317 if (proto->brace++ == 0 && paren == 0)
1332 proto_error((char*)proto + sizeof(struct proto), 2, op, NiL);
1483 proto_error((char*)proto + sizeof(struct proto), 1, "function pointer argument prototype omitted", NiL);
1516 line = proto->line;
1525 if ((vc = ie - im + 1) > sizeof(proto->variadic)) vc = sizeof(proto->variadic);
1526 memcopy(proto->variadic, im, vc);
1532 proto->ip = im;
1533 proto->op = op;
1538 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1572 proto->op = op;
1579 m = proto->tp;
1580 e = proto->ip;
1594 proto->op = strcopy(op, " __OTORP__(");
1595 proto->ip = im + 1;
1600 lex(proto, (flags & GLOBAL) | DECLARE);
1603 proto->ip = ie;
1604 op = proto->op;
1607 if (flags & EXTERNALIZE) memcpy(proto->ox, "extern", 6);
1608 op = linesync(proto, op, proto->line = line);
1611 proto->brace = 0;
1624 if (--proto->brace == 0)
1639 if (last == ')' && proto->brace && (group != 2 || call != 2)) flags |= SKIP;
1768 if (flags & EXTERNALIZE) memcpy(proto->ox, "extern", 6);
1804 if (proto->brace == 0)
1812 if (!(flags & PLUSONLY) || proto->package)
1815 if (proto->package)
1817 op = strcopy(op - 1, proto->package);
1843 line = proto->line;
1848 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1857 m = proto->tp;
1858 e = proto->ip;
1878 proto->ip = proto->variadic;
1879 proto->op = op;
1882 bp = proto->ip + 1;
1886 switch (lex(proto, (flags & GLOBAL) | RECURSIVE))
1909 else op = memcopy(op, e, proto->ip - e - 1);
1935 else op = memcopy(op, e, proto->ip - e - 1);
1938 bp = proto->ip + 1;
1942 proto->op = op;
1949 m = proto->tp;
1950 e = proto->ip;
1960 proto->line = line;
1978 if (proto->brace == 0 && !(flags & DECLARE)) flags |= SKIP;
1989 if (*proto->tp >= '0' && *proto->tp <= '9')
2058 if ((flags & (EXTERN|MATCH)) == (EXTERN|MATCH) && ((flags & (DIRECTIVE|SKIP)) || proto->brace || c != '(' && c != ')' && c != '*' && c != T_ID))
2086 op = proto->op;
2089 op = init(proto, op, flags);
2090 op = linesync(proto, op, proto->line);
2092 proto->flags &= ~(INIT_DEFINE|INIT_INCLUDE);
2100 * close a proto buffer stream
2106 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
2108 if (proto->flags & MORE) close(proto->fd);
2109 free((char*)proto); /* some ANSI cc's botch the free() prototype */
2113 * open a new proto buffer stream
2127 register struct proto* proto;
2142 * initialize proto
2165 if (!(proto = newof(0, struct proto, 1, 4 * n + 2)))
2167 proto->iz = n;
2168 proto->oz = 3 * n;
2179 if (!(proto = newof(0, struct proto, 1, 5 * n + 2)))
2181 proto->iz = n;
2182 proto->oz = 3 * n;
2183 proto->flags |= MORE;
2185 proto->fd = fd;
2186 proto->package = package;
2187 iob = (char*)proto + sizeof(struct proto);
2188 proto->op = proto->ob = iob;
2189 proto->ip = proto->ib = iob + proto->oz + n;
2190 if (m) proto->options |= REGULAR;
2193 if (!(proto->cc[0] = comment[0]))
2197 proto->cc[1] = comment[1];
2198 proto->cc[2] = comment[2] ? comment[2] : comment[0];
2201 proto->cc[1] = proto->cc[2] = comment[0];
2207 n = read(fd, proto->ip, proto->iz);
2208 if (!(proto->flags & MORE))
2215 *(proto->ip + n) = 0;
2218 * check for proto pragma in first block of lines
2229 if (!notice && !options || (comlen = astlicense(com, sizeof(com), NiL, "type=check", proto->cc[0], proto->cc[1], proto->cc[2])) <= 0)
2233 s = proto->ip;
2275 proto->flags |= YACC;
2310 if (flags & PROTO_PLUSPLUS) proto->flags |= PLUSPLUS;
2311 if (flags & PROTO_TEST) proto->test = 1;
2312 if (flags & PROTO_EXTERNALIZE) proto->options |= EXTERNALIZE;
2316 if (flags & PROTO_LINESYNC) proto->flags |= LINESYNC;
2317 if (!(proto->flags & YACC) && file && (m = strlen(file)) > 2 && file[--m] == 'y' && file[--m] == '.')
2318 proto->flags |= YACC;
2325 proto->flags |= PLUSONLY;
2334 proto->flags |= PASS;
2335 if (proto->flags & MORE)
2336 proto->oz += proto->iz;
2337 proto->iz = n;
2340 if (proto->cc[0] == '#' && proto->ip[0] == '#' && proto->ip[1] == '!')
2342 s = proto->ip;
2344 m = s - proto->ip;
2345 proto->op = memcopy(proto->op, proto->ip, m);
2346 proto->ip = s;
2347 proto->iz = n -= m;
2350 if (proto->cc[0])
2352 if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
2353 proto_error((char*)proto + sizeof(struct proto), 1, proto->op, NiL);
2355 proto->op += comlen;
2357 if (!(flags & PROTO_CLASSIC) && !(proto->flags & YACC))
2359 proto->op = linesync(proto, proto->op, 1);
2360 proto->iz += proto->op - proto->ob;
2362 memcopy(proto->op, proto->ip, n);
2373 proto->line = 1;
2380 if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
2381 proto_error((char*)proto + sizeof(struct proto), 1, proto->op, NiL);
2383 proto->op += comlen;
2388 proto->flags |= INIT_INCLUDE;
2398 *proto->op++ = '#';
2399 proto->op = strcopy(proto->op, MAGICDIR);
2400 *proto->op++ = ' ';
2401 proto->op = strcopy(proto->op, MAGICARG);
2402 *proto->op++ = '\n';
2406 proto->flags |= INIT_DEFINE;
2411 if (proto->flags & YACC)
2413 proto->op = strcopy(proto->op, "\n%{\n" + !notice);
2414 proto->op = strcopy(proto->op, MAGICGEN);
2415 proto->op = strcopy(proto->op, "%}\n");
2420 *proto->op++ = '\n';
2421 proto->op = strcopy(proto->op, MAGICGEN);
2423 proto->op = linesync(proto, proto->op, proto->line);
2424 else if (proto->flags & (INIT_DEFINE|INIT_INCLUDE))
2425 proto->op = init(proto, proto->op, proto->flags);
2432 proto->file = file;
2435 proto->flags |= CLASSIC;
2436 if (!(flags & PROTO_HEADER)) proto->flags |= EXTERN;
2443 * read next proto'd chunk into iob
2450 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
2453 if (proto->flags & PASS)
2455 if (proto->iz)
2457 n = proto->iz;
2458 proto->iz = 0;
2460 else if (!(proto->flags & MORE)) n = 0;
2461 else if ((n = read(proto->fd, proto->ob, proto->oz)) <= 0 || (proto->options & REGULAR) && n < proto->oz)
2463 proto->flags &= ~MORE;
2464 close(proto->fd);
2469 if (proto->op == proto->ob)
2471 if (proto->flags & ERROR) return -1;
2473 if (proto->flags & YACC)
2475 register char* ip = proto->ip;
2476 register char* op = proto->ob;
2477 register char* ep = proto->ob + proto->oz - 2;
2481 ip = proto->ip = proto->ib;
2482 if (!(proto->flags & MORE)) n = 0;
2483 else if ((n = read(proto->fd, ip, proto->iz)) <= 0 || (proto->options & REGULAR) && n < proto->iz)
2486 proto->flags &= ~MORE;
2487 close(proto->fd);
2491 if (proto->flags & YACCSPLIT)
2493 proto->flags &= ~YACCSPLIT;
2497 if (proto->flags & YACC2) proto->flags &= ~YACC;
2498 else proto->flags |= YACC2;
2501 if (proto->flags & YACC)
2507 if (*ip == '%' && (ip == proto->ip + 1 || *(ip - 2) == '\n'))
2510 if (proto->flags & YACC2) proto->flags &= ~YACC;
2511 else proto->flags |= YACC2;
2517 proto->flags |= YACCSPLIT;
2521 else if (n == '\n') proto->line++;
2523 proto->op = memcopy(proto->ob, proto->ip, ip - proto->ip);
2524 proto->ip = ip;
2528 lex(proto, proto->flags);
2529 if ((proto->flags & (ERROR|MORE)) == ERROR)
2530 proto->op = strcopy(proto->op, "/* NOTE: some constructs may not have been converted */\n");
2532 n = proto->op - proto->ob;
2533 proto->op = proto->ob;
2549 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
2551 if (proto->flags & MORE)
2553 proto->flags &= ~MORE;
2554 return proto->fd;