1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1986-2009 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
25 * convert C prototypes to ANSI, K&R and C++ styles or K&R to ANSI
26 * slips into the pp block read
28 * define PROTOMAIN for standalone proto
29 * PROTOMAIN is coded for minimal library support
49 #define MAGICGEN "/* : : generated by proto : : */\n"
51 #define MAGICDIR "pragma" /* proto magic directive */
52 #define MAGICARG "prototyped" /* proto magic directive arg */
53 #define MAGICOFF "noticed" /* no notice if found in pragma */
54 #define MAGICTOP 64 /* must be in these top lines */
55 #define NOTICED "Copyright" /* no notice if found in magic */
56 #define PUBLICDOMAIN "Public Domain" /* no notice if found in magic */
58 struct proto
/* proto buffer state */
60 int brace
; /* {..} level */
61 int call
; /* call level */
62 int fd
; /* input file descriptor */
63 char* file
; /* input file name */
64 long flags
; /* coupled flags */
65 long options
; /* uncoupled flags */
66 char* package
; /* header package */
67 int line
; /* input line count */
68 int test
; /* testing */
70 char* tp
; /* input token base */
72 int iz
; /* input buffer size */
73 char* ib
; /* input buffer base */
74 char* ip
; /* input buffer pointer */
76 int oz
; /* output buffer size */
77 char* ob
; /* output buffer base */
78 char* op
; /* output buffer pointer */
79 char* ox
; /* output buffer externalize */
81 char cc
[3]; /* beg mid end comment char */
82 char pushback
[4]; /* pushback area for caller */
84 char variadic
[256]; /* variadic args buffer */
92 * proto is separate from pp so these undef's are ok
96 #define CLASSIC (1L<<0)
98 #define DECLARE (1L<<1)
100 #define DEFINE (1L<<2)
102 #define DIRECTIVE (1L<<3)
104 #define ERROR (1L<<4)
106 #define EXTERN (1L<<5)
108 #define EXTERNALIZE (1L<<6)
112 #define INDIRECT (1L<<8)
116 #define INIT_DEFINE (1L<<10)
118 #define INIT_INCLUDE (1L<<11)
120 #define JUNK (1L<<12)
122 #define LINESYNC (1L<<13)
124 #define MANGLE (1L<<14)
126 #define MATCH (1L<<15)
128 #define MORE (1L<<16)
130 #define OTHER (1L<<17)
132 #define PASS (1L<<18)
134 #define PLUSONLY (1L<<19)
136 #define PLUSPLUS (1L<<20)
138 #define RECURSIVE (1L<<21)
140 #define SHARP (1L<<22)
142 #define SKIP (1L<<23)
144 #define SLIDE (1L<<24)
146 #define TOKENS (1L<<25)
148 #define TYPEDEF (1L<<26)
150 #define VARIADIC (1L<<27)
152 #define VARIADIC2 (1L<<28)
154 #define YACC (1L<<29)
156 #define YACCSPLIT (1L<<30)
158 #define YACC2 (1L<<31)
161 #define GLOBAL (MORE)
164 #define REGULAR (1L<<0)
169 #define BLOCK (8*CHUNK)
171 #define T_VA_START (N_TOKEN+1)
173 #define RESERVED(b,e,n) ((((long)(b))<<16)|(((long)(e))<<8)|((long)(n)))
177 * pointer to end returned
181 number(register char* p
, register long n
)
185 for (d
= 1000000; d
> 1; d
/= 10)
186 if (n
>= d
) *p
++ = '0' + (n
/ d
) % 10;
198 * namespace pollution forces us to claim parts of libc
202 #define memcpy(t,f,n) memcopy(t,f,n)
204 #define strcpy(t,f) strcopy(t,f)
206 #define strlen(s) sstrlen(s)
208 #define strncmp(s,t,n) sstrncmp(s,t,n)
211 * environmentally safe strlen()
215 sstrlen(register const char* s
)
217 register const char* b
;
219 for (b
= s
; *s
; s
++);
224 * environmentally safe strncmp()
228 sstrncmp(register const char* s
, register char* t
, register int n
)
230 register const char* e
= s
+ n
;
243 * strcpy() except pointer to end returned
247 strcopy(register char* s
, register const char* t
)
256 proto_error(char* iob
, int level
, char* msg
, char* arg
)
261 p
= strcopy(buf
, "proto: ");
264 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
271 p
= strcopy(p
, proto
->file
);
276 p
= strcopy(p
, "line ");
277 p
= number(p
, proto
->line
);
279 else if (proto
->file
)
280 p
= strcopy(p
, proto
->file
);
294 p
= strcopy(p
, "warning: ");
302 write(2, buf
, p
- buf
);
310 * memcpy() but pointer to end returned
314 memcopy(register char* s
, register char* t
, int n
)
316 register char* e
= t
+ n
;
318 while (t
< e
) *s
++ = *t
++;
322 #include "../libast/port/astlicense.c"
326 #define memcopy(s,t,n) (((char*)memcpy(s,t,n))+(n))
332 * pointer to end returned
336 linesync(register struct proto
* proto
, register char* p
, register long n
)
339 if (proto
->flags
& LINESYNC
)
343 p
= strcopy(p
, "\n#line ");
345 p
= strcopy(p
, "\n# ");
355 * pointer to end returned
359 init(struct proto
* proto
, char* op
, int flags
)
363 if (flags
& INIT_DEFINE
)
367 #if !defined(__PROTO__)\n\
368 # if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)\n\
369 # if defined(__cplusplus)\n\
370 # define __LINKAGE__ \"C\"\n\
372 # define __LINKAGE__\n\
374 # define __STDARG__\n\
375 # define __PROTO__(x) x\n\
376 # define __OTORP__(x)\n\
377 # define __PARAM__(n,o) n\n\
378 # if !defined(__STDC__) && !defined(__cplusplus)\n\
379 # if !defined(c_plusplus)\n\
385 # define __V_ char\n\
387 # define __V_ void\n\
390 # define __PROTO__(x) ()\n\
391 # define __OTORP__(x) x\n\
392 # define __PARAM__(n,o) o\n\
393 # define __LINKAGE__\n\
394 # define __V_ char\n\
400 # define __MANGLE__ __LINKAGE__\n\
401 # if defined(__cplusplus) || defined(c_plusplus)\n\
402 # define __VARARG__ ...\n\
404 # define __VARARG__\n\
406 # if defined(__STDARG__)\n\
407 # define __VA_START__(p,a) va_start(p,a)\n\
409 # define __VA_START__(p,a) va_start(p)\n\
411 # if !defined(__INLINE__)\n\
412 # if defined(__cplusplus)\n\
413 # define __INLINE__ extern __MANGLE__ inline\n\
415 # if defined(_WIN32) && !defined(__GNUC__)\n\
416 # define __INLINE__ __inline\n\
421 #if !defined(__LINKAGE__)\n\
422 #define __LINKAGE__ /* 2004-08-11 transition */\n\
429 #if !defined(__PROTO__)\n\
430 #include <prototyped.h>\n\
432 #if !defined(__LINKAGE__)\n\
433 #define __LINKAGE__ /* 2004-08-11 transition */\n\
439 #ifndef __MANGLE_%_DATA__\n\
441 # ifdef __EXPORT__\n\
442 # define __MANGLE_%_DATA__ __MANGLE__ __EXPORT__\n\
444 # define __MANGLE_%_DATA__ __MANGLE__\n\
446 # define __MANGLE_%_FUNC__ __MANGLE__\n\
448 # ifdef __IMPORT__\n\
449 # define __MANGLE_%_DATA__ __MANGLE__ __IMPORT__\n\
451 # define __MANGLE_%_DATA__ __MANGLE__\n\
453 # define __MANGLE_%_FUNC__ __MANGLE__\n\
459 switch (*op
++ = *s
++)
465 op
= strcopy(op
- 1, proto
->package
);
476 #define BACKOUT() (op=ko)
477 #define CACHE() do{CACHEIN();CACHEOUT();call=proto->call;}while(0)
478 #define CACHEIN() (ip=proto->ip)
479 #define CACHEOUT() (op=proto->op)
480 #define GETCHR() (*(unsigned char*)ip++)
481 #define KEEPOUT() (ko=op)
482 #define LASTOUT() (*(op-1))
483 #define PUTCHR(c) (*op++=(c))
484 #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)
485 #define SYNCIN() (proto->ip=ip)
486 #define SYNCOUT() (proto->op=op)
487 #define UNGETCHR() (ip--)
488 #define UNPUTCHR() (op--)
491 * advance to the next non-space character
495 nns(register char* s
)
497 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
508 * update directive mask
512 directive(register char* s
, int dir
)
514 switch (*(s
= nns(s
)))
538 * top level calls loop until EOB
539 * recursive calls just return the next token
543 lex(register struct proto
* proto
, register long flags
)
584 if (flags
& EXTERN
) KEEPOUT();
594 while (!(state
= rp
[c
= GETCHR()]));
598 if ((n
= ip
- bp
- 1) > 0)
609 if (op
> proto
->ob
&& *(op
- 1) == '=' && (op
== proto
->ob
+ 1 || *(op
- 2) != '=')) switch (c
)
630 if (INCOMMENTXX(rp
)) goto fsm_newline
;
637 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
) BACKOUT();
651 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
) BACKOUT();
655 rp
= fsm
[INCOMMENTXX(rp
) ? COM5
: COM3
];
664 if (state
= fsm
[TERMINAL
][INDEX(rp
)+1])
671 if ((flags
& (DECLARE
|GLOBAL
|RECURSIVE
)) == GLOBAL
&& (proto
->flags
& MORE
))
674 if (!(flags
& EXTERN
)) /* XXX */
678 if (!(flags
& MATCH
))
683 if (ip
- n
< proto
->ib
)
684 proto
->flags
|= ERROR
;
685 memcopy(proto
->ib
- n
, ip
- n
, n
);
698 if ((n
= read(proto
->fd
, ip
, proto
->iz
)) > 0)
700 if ((proto
->options
& REGULAR
) && n
< proto
->iz
)
702 proto
->flags
&= ~MORE
;
712 proto
->flags
&= ~MORE
;
717 /* NOTE: RECURSIVE lex() should really SLIDE too */
718 if (!(flags
& RECURSIVE
) && (state
= rp
[c
= EOF
]))
731 for (n
= 0, t
= qe
+ 1; t
< op
&& (*t
== ' ' || *t
== '\t' || *t
== '\n' && ++n
|| *t
>= 'A' && *t
<= 'Z' || *t
== '_'); t
++);
751 if (!(flags
& DIRECTIVE
))
752 qe
= (c
== '"') ? op
: (char*)0;
763 else if (c
!= '\n' && c
!= EOF
)
785 if (flags
& CLASSIC
) PUTCHR(c
);
801 lex(proto
, (flags
& GLOBAL
) | RECURSIVE
);
802 for (n
= x
= 0; (c
= GETCHR()), x
< 3; x
++) switch (c
)
804 case '0': case '1': case '2': case '3':
805 case '4': case '5': case '6': case '7':
807 n
= (n
<< 4) + c
- '0';
809 case 'a': case 'b': case 'c': case 'd':
811 n
= (n
<< 4) + c
- 'a' + 10;
813 case 'A': case 'B': case 'C': case 'D':
815 n
= (n
<< 4) + c
- 'A' + 10;
823 PUTCHR(((n
>> 6) & 07) + '0');
824 PUTCHR(((n
>> 3) & 07) + '0');
825 PUTCHR((n
& 07) + '0');
838 if ((flags
& EXTERN
) && *proto
->tp
== 's' && !strncmp(proto
->tp
, "static", 6))
844 if (*proto
->tp
== '_' && !strncmp(proto
->tp
, "__STDPP__directive", 6)) c
= '#';
855 if (op
!= proto
->ob
&& LASTOUT() != ' ' && LASTOUT() != '\n')
861 if (flags
& DIRECTIVE
)
866 if (flags
& EXTERN
) BACKOUT();
870 op
= strcopy(om
, "/* ");
871 op
= strcopy(op
, im
);
872 op
= strcopy(op
, " */\n");
874 flags
&= ~(DEFINE
|DIRECTIVE
|IDID
|INDIRECT
|JUNK
|MATCH
|SHARP
|TYPEDEF
);
879 if ((flags
& (DEFINE
|SHARP
)) == (DEFINE
|SHARP
))
882 op
= strcopy(om
, "#if defined(__STDC__) || defined(__STDPP__)\n");
883 op
= strcopy(op
, im
);
884 op
= strcopy(op
, "\n#else\n");
889 if (*op
++ == '#' && *ip
!= '(')
892 while (*--op
== ' ' || *op
== '\t');
895 op
= strcopy(op
+ 1, "/**/");
896 while (*++ip
== ' ' || *ip
== '\t');
900 if (*op
!= '"') *++op
= '"';
902 while (*ip
== ' ' || *ip
== '\t') ip
++;
903 while ((c
= *ip
) >= 'A' && c
<= 'Z' || c
>= 'a' && c
<= 'z' || c
>= '0' && c
<= '9' || c
== '_') *op
++ = *ip
++;
904 while (*ip
== ' ' || *ip
== '\t') ip
++;
905 if (*ip
== '"') ip
++;
910 op
= strcopy(op
, "\n#endif\n");
911 op
= linesync(proto
, op
, proto
->line
);
913 flags
&= ~(DEFINE
|DIRECTIVE
|IDID
|INDIRECT
|MATCH
|OTHER
|SHARP
|SKIP
|TOKENS
|TYPEDEF
);
920 if (paren
== 0 && (flags
& (MATCH
|RECURSIVE
|SKIP
|SLIDE
)) == SLIDE
)
923 if (flags
& EXTERN
) BACKOUT();
932 rp
= fsm
[NEXT(state
)];
949 if (!(flags
& DECLARE
)) switch (RESERVED(*proto
->tp
, *(ip
- 1), ip
- proto
->tp
))
951 case RESERVED('N', 'N', 3):
952 if (proto
->tp
[1] == 'o')
955 case RESERVED('d', 'o', 2):
958 case RESERVED('e', 'e', 4):
959 if (!(flags
& RECURSIVE
) && (flags
& (DIRECTIVE
|TOKENS
)) != DIRECTIVE
&& !strncmp(proto
->tp
, "else", 4))
965 case RESERVED('e', 'n', 6):
966 if (!strncmp(proto
->tp
, "extern", 6))
969 case RESERVED('f', 'r', 3):
970 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "for", 3))
976 case RESERVED('i', 'f', 2):
979 case RESERVED('i', 'e', 6):
980 if (!strncmp(proto
->tp
, "inline", 6) && !(flags
& (MATCH
|SKIP
|TOKENS
|TYPEDEF
)) && proto
->brace
== 0 && paren
== 0 && group
== 0 && (last
== ';' || last
== '}' || last
== '\n' || last
== 0))
985 op
= strcopy(op
- 6, "__INLINE__");
989 case RESERVED('r', 'n', 6):
990 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "return", 6))
996 case RESERVED('s', 'c', 6):
997 if ((proto
->options
& EXTERNALIZE
) && !strncmp(proto
->tp
, "static", 6))
1000 flags
|= EXTERNALIZE
;
1003 case RESERVED('t', 'f', 7):
1004 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "typedef", 7))
1010 case RESERVED('v', 't', 8):
1011 if (*ip
== '(' && !strncmp(proto
->tp
, "va_start", 8)) c
= T_VA_START
;
1013 case RESERVED('v', 'd', 4):
1014 if (!strncmp(proto
->tp
, "void", 4))
1016 if (flags
& (CLASSIC
|PLUSONLY
|INIT_DEFINE
|INIT_INCLUDE
)) c
= T_VOID
;
1021 if (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
) == '*')
1023 memcopy(op
- 4, "__V_", 4);
1024 memcopy(ip
- 4, "__V_", 4);
1033 case RESERVED('w', 'e', 5):
1034 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "while", 5))
1042 if ((flags
& CLASSIC
) && c
!= T_EXTERN
)
1053 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
)
1055 while (op
> proto
->ob
&& (*(op
- 1) == ' ' || *(op
- 1) == '\t'))
1057 if (op
> proto
->ob
&& *(op
- 1) != '\n') *op
++ = ' ';
1067 if (!(n
= GETCHR()))
1085 if (state
>= TERMINAL
)
1093 if (!(flags
& (INIT_DEFINE
|INIT_INCLUDE
|RECURSIVE
)))
1095 if (!(flags
& DIRECTIVE
)) switch (c
)
1099 if (!(flags
& CLASSIC
) || proto
->brace
== 0)
1105 if (!(flags
& CLASSIC
) || group
<= 1)
1111 if (group
++ == 0) group
++;
1112 else if (flags
& INDIRECT
) call
++;
1119 else if (paren
== 2 && !aim
)
1127 else if (flags
& INDIRECT
)
1132 else if ((flags
& (MATCH
|TOKENS
)) == MATCH
)
1134 for (m
= ip
- 2; m
> im
&& (*m
== ' ' || *m
== '\t'); m
--);
1135 if (m
!= im
&& sub
== 1)
1137 m
= im
+ (*nns(ip
) == '*');
1145 else if ((flags
& MATCH
) && sub
== 1 && *nns(ip
) != '*')
1156 if (!(flags
& CLASSIC
) || proto
->brace
== 0)
1161 if (flags
& CLASSIC
)
1173 else if (paren
== 1 && (flags
& INDIRECT
) && !aie
)
1177 if (last
== '(' && group
== 2)
1188 dir
= directive(ip
, dir
);
1189 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
))
1191 else if (!(flags
& (DECLARE
|DIRECTIVE
)))
1194 if (!(flags
& PLUSONLY
))
1197 while (*ip
== ' ' || *ip
== '\t') ip
++;
1198 if (*ip
== 'l' && *++ip
== 'i' && *++ip
== 'n' && *++ip
== 'e')
1200 if (*++ip
== ' ' || *ip
== '\t')
1203 while (*++ip
>= '0' && *ip
<= '9')
1204 proto
->line
= proto
->line
* 10 + *ip
- '0';
1209 else if ((flags
& (CLASSIC
|EXTERN
)) == CLASSIC
)
1213 while (ip
< t
&& *ip
>= 'a' && *ip
<= 'z')
1214 n
= HASHKEYPART(n
, *ip
++);
1217 case HASHKEY4('e','l','s','e'):
1218 case HASHKEY5('e','n','d','i','f'):
1219 while (*ip
== ' ' || *ip
== '\t') ip
++;
1220 if (*ip
!= '\n' && *ip
!= '/' && *(ip
+ 1) != '*')
1222 flags
|= JUNK
|MATCH
;
1224 om
= op
+ (ip
- bp
);
1227 case HASHKEY4('e','l','i','f'):
1228 case HASHKEY5('e','r','r','o','r'):
1229 case HASHKEY2('i','f'):
1230 case HASHKEY5('i','f','d','e','f'):
1231 case HASHKEY6('i','f','n','d','e','f'):
1232 case HASHKEY5('u','n','d','e','f'):
1234 case HASHKEY6('i','n','c','l','u','d'):
1235 if (*ip
== 'e') ip
++;
1237 case HASHKEY6('d','e','f','i','n','e'):
1238 case HASHKEY6('p','r','a','g','m','a'):
1239 if (*ip
< 'a' || *ip
> 'z') break;
1242 flags
|= JUNK
|MATCH
;
1251 if (*ip
== 'i' && *++ip
== 'n' && *++ip
== 'c' && *++ip
== 'l' && *++ip
== 'u' && *++ip
== 'd' && *++ip
== 'e')
1253 while (*++ip
== ' ' || *ip
== '\t');
1254 if (*ip
++ == '<' && *ip
++ == 's' && *ip
++ == 't' && *ip
++ == 'd' && *ip
++ == 'a' && *ip
++ == 'r' && *ip
++ == 'g' && *ip
++ == '.' && *ip
++ == 'h' && *ip
++ == '>')
1257 if !defined(va_start)\n\
1258 #if defined(__STDARG__)\n\
1259 #include <stdarg.h>\n\
1261 #include <varargs.h>\n\
1265 op
= linesync(proto
, op
, proto
->line
);
1269 else if (*ip
== 'd' && *++ip
== 'e' && *++ ip
== 'f' && *++ip
== 'i' && *++ip
== 'n' && *++ip
== 'e' && (*++ip
== ' ' || *ip
== '\t'))
1271 while (*++ip
== ' ' || *ip
== '\t');
1272 if (*ip
== 'e' && *++ip
== 'x' && *++ ip
== 't' && *++ip
== 'e' && *++ip
== 'r' && *++ip
== 'n' && (*++ip
== ' ' || *ip
== '\t'))
1275 while (*++t
== ' ' || *t
== '\t');
1276 if (*t
== 'e' && *++t
== 'x' && *++ t
== 't' && *++t
== 'e' && *++t
== 'r' && *++t
== 'n' && (*++t
== ' ' || *t
== '\t' || *t
== '\n' || *t
== '\r'))
1279 while (*++t
== ' ' || *t
== '\t');
1280 if (*t
== '_' && *(t
+ 1) == '_')
1282 op
= strcopy(op
, "undef __MANGLE__\n");
1283 op
= linesync(proto
, op
, proto
->line
);
1284 op
= strcopy(op
, "#define __MANGLE__ __LINKAGE__");
1288 flags
|= DEFINE
|MATCH
;
1292 else if (*ip
== 'u' && *++ip
== 'n' && *++ ip
== 'd' && *++ip
== 'e' && *++ip
== 'f' && (*++ip
== ' ' || *ip
== '\t'))
1294 while (*++ip
== ' ' || *ip
== '\t');
1295 if (*ip
== 'e' && *++ip
== 'x' && *++ ip
== 't' && *++ip
== 'e' && *++ip
== 'r' && *++ip
== 'n' && (*++ip
== ' ' || *ip
== '\t' || *ip
== '\n' || *ip
== '\r'))
1297 op
= strcopy(op
, "undef __MANGLE__\n");
1298 op
= linesync(proto
, op
, proto
->line
);
1299 op
= strcopy(op
, "#define __MANGLE__ __LINKAGE__");
1302 flags
|= DEFINE
|MATCH
;
1315 if (proto
->brace
++ == 0 && paren
== 0)
1317 if (last
== '=') flags
|= INIT
;
1319 else if (flags
& CLASSIC
)
1321 if ((flags
& (MATCH
|OTHER
|SKIP
)) == MATCH
)
1325 v
= number(op
, args
< 0 ? -args
: args
);
1326 v
= strcopy(v
, " argument actual/formal mismatch");
1328 v
= memcopy(v
, im
, ie
- im
);
1330 proto_error((char*)proto
+ sizeof(struct proto
), 2, op
, NiL
);
1336 if (*ie
++ == '/' && *ie
== '*')
1343 while (ie
< ip
&& *ie
== '*') ie
++;
1344 if (ie
< ip
&& *ie
== '/')
1346 while (++ie
< ip
&& (*ie
== ' ' || *ie
== '\t'));
1347 while (e
> v
&& (*(e
- 1) == ' ' || *(e
- 1) == '\t')) e
--;
1348 if (e
> v
&& *e
!= '\n') *e
++ = ' ';
1364 while (v
> ko
&& *--v
!= ' ');
1367 om
= (v
= (op
+= 4)) + 1;
1373 memcopy(ko
, "int ", 4);
1377 while (*(v
+ 1) == '*')
1382 om
= (e
= ++op
) + 1;
1390 om
= (v
= (op
+= 7)) + 1;
1396 memcopy(ko
, "extern ", 7);
1404 if ((c
= *ie
) == ' ' || c
== '\t' || c
== '\n')
1406 while ((c
= *++ie
) == ' ' || c
== '\t' || c
== '\n');
1407 if (ie
>= ip
) break;
1408 if (c
!= '*' && op
> om
) PUTCHR(' ');
1410 if ((n
= ((c
= *ie
) == ',')) || c
== ';')
1415 while (op
> om
&& ((c
= *(op
- 1)) == '(' || c
== ')' || c
== '[' || c
== ']'))
1418 while (op
> om
&& (c
= *(op
- 1)) != ' ' && c
!= '*')
1420 while (*(op
- 1) == ' ')
1425 while (e
> om
&& *(e
- 1) == '*')
1428 #if _s5r4_386_compiler_bug_fixed_
1429 if (op
<= om
|| *(op
- 1) == ',' && (*op
++ = ' '))
1430 op
= strcopy(op
, "int");
1433 op
= strcopy(op
, "int");
1434 else if (*(op
- 1) == ',')
1435 op
= strcopy(op
, " int");
1443 if (x
= !e
) e
= op
- 1;
1451 while (*--e
!= ' ');
1452 while (*(e
- 1) == '*') e
--;
1456 while ((c
= *++ie
) == ' ' || c
== '\t' || c
== '\n');
1457 if (ie
>= ip
) UNPUTCHR();
1465 else if (*ie
== '*')
1467 if (op
> om
&& (c
= *(op
- 1)) == ' ') op
--;
1468 while (*ie
== '*') PUTCHR(*ie
++);
1469 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1470 if (c
!= '(') PUTCHR(' ');
1472 else if (*ie
== '(')
1474 if (op
> om
&& *(op
- 1) == ' ') op
--;
1476 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1478 else if (*ie
== ')')
1480 if (op
> om
&& *(op
- 1) == '(')
1481 proto_error((char*)proto
+ sizeof(struct proto
), 1, "function pointer argument prototype omitted", NiL
);
1483 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1485 else if ((flags
& EXTERN
) && (op
== om
|| *(op
- 1) == ' ') && *ie
== 'r' && !strncmp(ie
, "register", 8) && (*(ie
+ 8) == ' ' || *(ie
+ 8) == '\t' || *(ie
+ 8) == '\n'))
1488 if (op
> om
) UNPUTCHR();
1493 if (op
<= om
) op
= strcopy(op
, "void");
1508 flags
&= ~(MATCH
|SKIP
);
1512 else if ((flags
& (MATCH
|PLUSONLY
|SKIP
|TOKENS
)) == (MATCH
|TOKENS
))
1515 op
= strcopy(om
, " __PARAM__(");
1516 op
= memcopy(op
, im
, ie
- im
);
1520 flags
&= ~(MATCH
|SKIP
);
1521 if (flags
& VARIADIC
)
1523 if ((vc
= ie
- im
+ 1) > sizeof(proto
->variadic
)) vc
= sizeof(proto
->variadic
);
1524 memcopy(proto
->variadic
, im
, vc
);
1525 op
= strcopy(op
, "va_alist)) __OTORP__(va_dcl)\n{");
1536 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1545 if (paren
++) group
++;
1553 flags
&= ~(MATCH
|SKIP
);
1554 op
= memcopy(op
, m
, e
- m
);
1565 flags
&= ~(MATCH
|SKIP
);
1566 op
= memcopy(op
, m
, e
- m
);
1574 if (group
<= 1 && !brack
)
1589 if (!(flags
& SKIP
))
1592 proto
->op
= strcopy(op
, " __OTORP__(");
1598 lex(proto
, (flags
& GLOBAL
) | DECLARE
);
1605 if (flags
& EXTERNALIZE
) memcpy(proto
->ox
, "extern", 6);
1606 op
= linesync(proto
, op
, proto
->line
= line
);
1607 if (flags
& DIRECTIVE
)
1613 else if (!(flags
& VARIADIC
)) PUTCHR('{');
1616 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
);
1621 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
|TOKENS
);
1622 if (--proto
->brace
== 0)
1624 flags
&= ~(INIT
|VARIADIC
|VARIADIC2
);
1626 if (flags
& EXTERN
) BACKOUT();
1634 if (last
== '?') flags
|= DIRECTIVE
;
1635 else if (paren
== 0 && (flags
& (INIT
|MATCH
|SKIP
)) == MATCH
)
1637 if (last
== ')' && proto
->brace
&& (group
!= 2 || call
!= 2)) flags
|= SKIP
;
1638 else goto fsm_statement
;
1643 if (flags
& CLASSIC
)
1645 if (paren
== 1) args
++;
1654 if (paren
== 0 && (flags
& DECLARE
)) *(op
- 1) = c
= ';';
1658 if (flags
& INIT
) /* ignore */;
1660 else if (flags
& CLASSIC
)
1664 if ((flags
& MATCH
) && last
== ')')
1666 if (!(flags
& MATCH
))
1671 if (flags
& EXTERN
) BACKOUT();
1681 if ((flags
& (EXTERN
|SKIP
)) == (EXTERN
|SKIP
))
1687 else if (paren
== 0)
1689 if ((flags
& (MATCH
|OTHER
|SKIP
)) == MATCH
&& call
> 1)
1691 if ((flags
& MANGLE
) && func
)
1699 if ((flags
& (DECLARE
|INDIRECT
)) == INDIRECT
&& aim
&& aie
< im
)
1701 while (aie
< ip
&& (*aie
== ' ' || *aie
== '\t' || *aie
== '\n')) aie
++;
1704 if (*v
++ == ')') break;
1705 while (v
< aie
&& (*v
== ' ' || *v
== '\t' || *v
== '\n')) v
++;
1706 if (v
== aie
|| !(flags
& PLUSPLUS
))
1708 if (flags
& PLUSPLUS
) n
= 3;
1709 else if (v
== aie
&& *v
== '(') n
= 10;
1719 if (flags
& PLUSPLUS
) memcopy(aom
, "(...))", 6);
1720 else if (n
== 10) memcopy(aom
, "(__VARARG__))", 13);
1723 ko
= strcopy(aom
, " __PROTO__(");
1724 ko
= memcopy(ko
, aim
, aie
- aim
);
1734 else if (flags
& TYPEDEF
)
1737 while (*--op
== ' ' || *op
== '\t' || *op
== '\n');
1742 while ((x
= *(op
- 14)) >= 'A' && x
<= 'Z' || x
>= 'a' && x
<= 'z' || x
>= '0' && x
<= '9' || x
== '_')
1744 memcopy(op
- 13, "(__OTORP__(*)", 13);
1749 else if (flags
& PLUSPLUS
)
1752 if (!(flags
& TOKENS
)) op
= strcopy(op
, "(...)");
1753 else op
= memcopy(op
, im
, ie
- im
);
1758 if (flags
& DECLARE
) op
= strcopy(om
, "()");
1759 else if (!(flags
& TOKENS
)) op
= strcopy(om
, "(__VARARG__)");
1762 op
= strcopy(om
, " __PROTO__(");
1763 op
= memcopy(op
, im
, ie
- im
);
1766 if (flags
& EXTERNALIZE
) memcpy(proto
->ox
, "extern", 6);
1769 flags
&= ~(MATCH
|VARIADIC
|VARIADIC2
);
1770 if (c
== ',' && !(flags
& INDIRECT
))
1777 else if (flags
& (OTHER
|SKIP
)) call
= 0;
1780 flags
&= ~(EXTERNALIZE
|MANGLE
|TOKENS
|TYPEDEF
);
1788 else call
= call
> 1 && c
== ',';
1790 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
);
1792 else if (paren
== 1 && group
== 1 && !(flags
& (IDID
|MANGLE
))) flags
|= TOKENS
|OTHER
;
1796 flags
|= TOKENS
|SKIP
;
1800 if (flags
& CLASSIC
)
1802 if (proto
->brace
== 0)
1807 if (paren
== 0 && !(flags
& TYPEDEF
))
1810 if (!(flags
& PLUSONLY
) || proto
->package
)
1812 op
= strcopy(op
, " __MANGLE__");
1815 op
= strcopy(op
- 1, proto
->package
);
1817 op
= strcopy(op
, "_DATA__");
1825 if (paren
== 0 && (flags
& (DECLARE
|VARIADIC
)) == DECLARE
)
1831 if (paren
== 1 && !(flags
& SKIP
))
1838 if ((flags
& (PLUSONLY
|VARIADIC
)) == VARIADIC
)
1842 op
= strcopy(op
- 8, "__VA_START__");
1846 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1852 if (!(flags
& MATCH
))
1875 op
= strcopy(op
, " __OTORP__(");
1876 proto
->ip
= proto
->variadic
;
1881 if (*bp
== 'r' && !strncmp(bp
, "register", 8) && (*(bp
+ 8) == ' ' || *(bp
+ 8) == '\t')) bp
+= 9;
1884 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1887 if (paren
++) group
++;
1895 if (!(flags
& VARIADIC2
))
1897 op
= memcopy(op
, m
, e
- m
);
1898 op
= strcopy(op
, " = ");
1900 op
= strcopy(op
, "va_arg(");
1901 op
= memcopy(op
, v
, n
);
1904 if (m
> bp
) op
= memcopy(op
, bp
, m
- bp
);
1905 else op
= strcopy(op
, "int ");
1906 if (group
> 1) op
= strcopy(op
, ")()");
1907 else op
= memcopy(op
, e
, proto
->ip
- e
- 1);
1921 if (!(flags
& VARIADIC2
))
1923 op
= memcopy(op
, m
, e
- m
);
1924 op
= strcopy(op
, " = ");
1926 op
= strcopy(op
, "va_arg(");
1927 op
= memcopy(op
, v
, n
);
1930 if (m
> bp
) op
= memcopy(op
, bp
, m
- bp
);
1931 else op
= strcopy(op
, "int ");
1932 if (group
> 1) op
= strcopy(op
, ")()");
1933 else op
= memcopy(op
, e
, proto
->ip
- e
- 1);
1937 if (*bp
== 'r' && !strncmp(bp
, "register", 8) && (*(bp
+ 8) == ' ' || *(bp
+ 8) == '\t')) bp
+= 9;
1956 op
= strcopy(op
, ")");
1966 if (flags
& CLASSIC
)
1968 if (!args
&& paren
== 1) args
++;
1976 if (proto
->brace
== 0 && !(flags
& DECLARE
)) flags
|= SKIP
;
1979 else if ((flags
& SKIP
) || c
== T_ID
|| c
== T_VOID
) call
++;
1981 if (last
== T_ID
) flags
|= IDID
;
1987 if (*proto
->tp
>= '0' && *proto
->tp
<= '9')
1997 while ((c
= *--t
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z');
2008 while ((c
= *--t
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z');
2030 while ((c
= *--m
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z')
2033 strcopy(m
+ 1, "(unsigned)");
2041 if ((flags
& CLASSIC
) && paren
== 0 && group
<= 2) flags
|= SKIP
;
2047 if (flags
& CLASSIC
) break;
2050 if (paren
== 0) flags
|= OTHER
;
2053 else if (c
== '#' && *ip
!= '(') flags
|= SHARP
;
2056 if ((flags
& (EXTERN
|MATCH
)) == (EXTERN
|MATCH
) && ((flags
& (DIRECTIVE
|SKIP
)) || proto
->brace
|| c
!= '(' && c
!= ')' && c
!= '*' && c
!= T_ID
))
2063 else if (flags
& (INIT_DEFINE
|INIT_INCLUDE
))
2066 if ((flags
& YACC
) && c
== '%' && *ip
== '{') t
= 0;
2070 if (c
== '#') for (t
= ip
; *t
== ' ' || *t
== '\t'; t
++);
2072 if (*t
++ == 'i' && *t
++ == 'f' && *t
++ == 'n' && *t
++ == 'd' && *t
++ == 'e' && *t
++ == 'f')
2075 while (*t
== ' ' || *t
== '\t') t
++;
2086 else while (*ip
!= '\n') *op
++ = *ip
++;
2087 op
= init(proto
, op
, flags
);
2088 op
= linesync(proto
, op
, proto
->line
);
2089 flags
&= ~(INIT_DEFINE
|INIT_INCLUDE
);
2090 proto
->flags
&= ~(INIT_DEFINE
|INIT_INCLUDE
);
2098 * close a proto buffer stream
2104 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
2106 if (proto
->flags
& MORE
) close(proto
->fd
);
2107 free((char*)proto
); /* some ANSI cc's botch the free() prototype */
2111 * open a new proto buffer stream
2112 * read buffer pointer returned
2113 * 0 returned on error or if no magic
2115 * file !=0 file path to open, otherwise use fd
2116 * fd open file fd if file==0
2117 * notice !=0 copyright notice info commented at the top
2118 * options !=0 additional notice name=value pairs, space or ; separated
2119 * package !=0 generate header for this package
2123 pppopen(char* file
, int fd
, char* notice
, char* options
, char* package
, char* comment
, int flags
)
2125 register struct proto
* proto
;
2144 if (flags
& PROTO_CLASSIC
) flags
&= ~PROTO_INCLUDE
;
2146 if (flags
& PROTO_RETAIN
) flags
&= ~retain
;
2147 else retain
&= PROTO_INITIALIZED
;
2148 if (file
&& (fd
= open(file
, O_RDONLY
)) < 0) return 0;
2150 if ((n
= lseek(fd
, 0L, 2)) > 0)
2152 if (lseek(fd
, 0L, 0)) return 0;
2153 if (n
< CHUNK
) n
= CHUNK
;
2154 else if (n
> 2 * BLOCK
) n
= 0;
2160 * file read in one chunk
2163 if (!(proto
= newof(0, struct proto
, 1, 4 * n
+ 2)))
2173 * file read in BLOCK chunks
2177 if (!(proto
= newof(0, struct proto
, 1, 5 * n
+ 2)))
2181 proto
->flags
|= MORE
;
2184 proto
->package
= package
;
2185 iob
= (char*)proto
+ sizeof(struct proto
);
2186 proto
->op
= proto
->ob
= iob
;
2187 proto
->ip
= proto
->ib
= iob
+ proto
->oz
+ n
;
2188 if (m
) proto
->options
|= REGULAR
;
2191 if (!(proto
->cc
[0] = comment
[0]))
2192 notice
= options
= 0;
2193 else if (comment
[1])
2195 proto
->cc
[1] = comment
[1];
2196 proto
->cc
[2] = comment
[2] ? comment
[2] : comment
[0];
2199 proto
->cc
[1] = proto
->cc
[2] = comment
[0];
2202 * read the first chunk
2205 n
= read(fd
, proto
->ip
, proto
->iz
);
2206 if (!(proto
->flags
& MORE
))
2213 *(proto
->ip
+ n
) = 0;
2216 * check for proto pragma in first block of lines
2217 * pragma blanked out if found
2220 * 0 #pragma noprototyped
2221 * 1 #pragma prototyped
2223 * NOTE: matches may occur inside comments and quotes
2227 if (!notice
&& !options
|| (comlen
= astlicense(com
, sizeof(com
), NiL
, "type=check", proto
->cc
[0], proto
->cc
[1], proto
->cc
[2])) <= 0)
2233 while (m
-- > 0 && *s
)
2235 while (*s
== ' ' || *s
== '\t') s
++;
2239 while (*s
== ' ' || *s
== '\t') s
++;
2240 if (!strncmp(s
, MAGICDIR
, sizeof(MAGICDIR
) - 1) && (*(s
+= sizeof(MAGICDIR
) - 1) == ' ' || *s
== '\t'))
2242 while (*s
== ' ' || *s
== '\t') s
++;
2243 if (*s
== 'n' && *(s
+ 1) == 'o')
2248 if (!strncmp(s
, MAGICARG
, sizeof(MAGICARG
) - 1) && (*(s
+= sizeof(MAGICARG
) - 1) == ' ' || *s
== '\t' || *s
== '\n' || *s
== '\r'))
2251 if ((*(s
- 1) == ' ' || *(s
- 1) == '\t') && *s
== *MAGICOFF
&& !strncmp(s
, MAGICOFF
, sizeof(MAGICOFF
) - 1))
2252 notice
= options
= 0;
2257 if (!(flags
& PROTO_DISABLE
) || (flags
& PROTO_NOPRAGMA
))
2259 for (s
--; b
< s
; *b
++ = ' ');
2266 else if (*s
== '/' && !strncmp(s
, MAGICGEN
, sizeof(MAGICGEN
) - 1))
2272 else if (*s
== '%' && *(s
+ 1) == '{')
2273 proto
->flags
|= YACC
;
2274 if (notice
|| options
)
2276 if (*s
== *com
&& !strncmp(s
, com
, comlen
))
2277 notice
= options
= 0;
2281 if (*s
== *NOTICED
&& !strncmp(s
, NOTICED
, sizeof(NOTICED
) - 1))
2283 s
+= sizeof(NOTICED
) - 1;
2284 while (*s
== ' ' || *s
== '\t')
2286 if (*s
== '(' && (*(s
+ 1) == 'c' || *(s
+ 1) == 'C') && *(s
+ 2) == ')' || *s
>= '0' && *s
<= '9' && *(s
+ 1) >= '0' && *(s
+ 1) <= '9')
2288 notice
= options
= 0;
2292 if (*s
== *PUBLICDOMAIN
&& !strncmp(s
, PUBLICDOMAIN
, sizeof(PUBLICDOMAIN
) - 1))
2294 notice
= options
= 0;
2297 else if (*s
++ == '\n')
2305 while (*s
&& *s
++ != '\n');
2308 if (flags
& PROTO_PLUSPLUS
) proto
->flags
|= PLUSPLUS
;
2309 if (flags
& PROTO_TEST
) proto
->test
= 1;
2310 if (flags
& PROTO_EXTERNALIZE
) proto
->options
|= EXTERNALIZE
;
2312 if (flags
& PROTO_CLASSIC
) pragma
= -pragma
;
2313 if (flags
& PROTO_DISABLE
) pragma
= 0;
2314 if (flags
& PROTO_LINESYNC
) proto
->flags
|= LINESYNC
;
2315 if (!(proto
->flags
& YACC
) && file
&& (m
= strlen(file
)) > 2 && file
[--m
] == 'y' && file
[--m
] == '.')
2316 proto
->flags
|= YACC
;
2320 if (flags
& PROTO_PLUSPLUS
)
2322 flags
&= ~(PROTO_HEADER
|PROTO_INCLUDE
);
2323 proto
->flags
|= PLUSONLY
;
2325 else if (!(flags
& (PROTO_FORCE
|PROTO_PASS
)))
2330 else if ((flags
& (PROTO_FORCE
|PROTO_PASS
)) == PROTO_PASS
|| !pragma
)
2332 proto
->flags
|= PASS
;
2333 if (proto
->flags
& MORE
)
2334 proto
->oz
+= proto
->iz
;
2336 if (notice
|| options
)
2338 if (proto
->cc
[0] == '#' && proto
->ip
[0] == '#' && proto
->ip
[1] == '!')
2341 while (*s
&& *s
++ != '\n');
2343 proto
->op
= memcopy(proto
->op
, proto
->ip
, m
);
2350 if ((comlen
= astlicense(proto
->op
, proto
->oz
, notice
, options
, proto
->cc
[0], proto
->cc
[1], proto
->cc
[2])) < 0)
2351 proto_error((char*)proto
+ sizeof(struct proto
), 1, proto
->op
, NiL
);
2353 proto
->op
+= comlen
;
2355 if (!(flags
& PROTO_CLASSIC
) && !(proto
->flags
& YACC
))
2357 proto
->op
= linesync(proto
, proto
->op
, 1);
2358 proto
->iz
+= proto
->op
- proto
->ob
;
2360 memcopy(proto
->op
, proto
->ip
, n
);
2365 if (!(retain
& PROTO_INITIALIZED
))
2367 retain
|= PROTO_INITIALIZED
;
2368 ppfsm(FSM_INIT
, NiL
);
2373 if (notice
|| options
|| (flags
& (PROTO_HEADER
|PROTO_INCLUDE
)))
2376 if (notice
|| options
)
2378 if ((comlen
= astlicense(proto
->op
, proto
->oz
, notice
, options
, proto
->cc
[0], proto
->cc
[1], proto
->cc
[2])) < 0)
2379 proto_error((char*)proto
+ sizeof(struct proto
), 1, proto
->op
, NiL
);
2381 proto
->op
+= comlen
;
2384 if (flags
& PROTO_INCLUDE
)
2386 proto
->flags
|= INIT_INCLUDE
;
2387 if (flags
& PROTO_RETAIN
)
2388 retain
|= PROTO_INCLUDE
;
2390 else if (flags
& PROTO_HEADER
)
2392 if (flags
& PROTO_RETAIN
) retain
|= PROTO_HEADER
;
2394 if (flags
& PROTO_CLASSIC
)
2397 proto
->op
= strcopy(proto
->op
, MAGICDIR
);
2399 proto
->op
= strcopy(proto
->op
, MAGICARG
);
2400 *proto
->op
++ = '\n';
2404 proto
->flags
|= INIT_DEFINE
;
2407 if (!(flags
& PROTO_CLASSIC
))
2409 if (proto
->flags
& YACC
)
2411 proto
->op
= strcopy(proto
->op
, "\n%{\n" + !notice
);
2412 proto
->op
= strcopy(proto
->op
, MAGICGEN
);
2413 proto
->op
= strcopy(proto
->op
, "%}\n");
2417 if (n
|| notice
|| options
)
2418 *proto
->op
++ = '\n';
2419 proto
->op
= strcopy(proto
->op
, MAGICGEN
);
2421 proto
->op
= linesync(proto
, proto
->op
, proto
->line
);
2422 else if (proto
->flags
& (INIT_DEFINE
|INIT_INCLUDE
))
2423 proto
->op
= init(proto
, proto
->op
, proto
->flags
);
2431 if (flags
& PROTO_CLASSIC
)
2433 proto
->flags
|= CLASSIC
;
2434 if (!(flags
& PROTO_HEADER
)) proto
->flags
|= EXTERN
;
2441 * read next proto'd chunk into iob
2442 * the chunk is 0 terminated and its size is returned
2448 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
2451 if (proto
->flags
& PASS
)
2458 else if (!(proto
->flags
& MORE
)) n
= 0;
2459 else if ((n
= read(proto
->fd
, proto
->ob
, proto
->oz
)) <= 0 || (proto
->options
& REGULAR
) && n
< proto
->oz
)
2461 proto
->flags
&= ~MORE
;
2467 if (proto
->op
== proto
->ob
)
2469 if (proto
->flags
& ERROR
) return -1;
2471 if (proto
->flags
& YACC
)
2473 register char* ip
= proto
->ip
;
2474 register char* op
= proto
->ob
;
2475 register char* ep
= proto
->ob
+ proto
->oz
- 2;
2479 ip
= proto
->ip
= proto
->ib
;
2480 if (!(proto
->flags
& MORE
)) n
= 0;
2481 else if ((n
= read(proto
->fd
, ip
, proto
->iz
)) <= 0 || (proto
->options
& REGULAR
) && n
< proto
->iz
)
2484 proto
->flags
&= ~MORE
;
2489 if (proto
->flags
& YACCSPLIT
)
2491 proto
->flags
&= ~YACCSPLIT
;
2495 if (proto
->flags
& YACC2
) proto
->flags
&= ~YACC
;
2496 else proto
->flags
|= YACC2
;
2499 if (proto
->flags
& YACC
)
2500 while (op
< ep
&& (n
= *op
++ = *ip
))
2505 if (*ip
== '%' && (ip
== proto
->ip
+ 1 || *(ip
- 2) == '\n'))
2508 if (proto
->flags
& YACC2
) proto
->flags
&= ~YACC
;
2509 else proto
->flags
|= YACC2
;
2515 proto
->flags
|= YACCSPLIT
;
2519 else if (n
== '\n') proto
->line
++;
2521 proto
->op
= memcopy(proto
->ob
, proto
->ip
, ip
- proto
->ip
);
2526 lex(proto
, proto
->flags
);
2527 if ((proto
->flags
& (ERROR
|MORE
)) == ERROR
)
2528 proto
->op
= strcopy(proto
->op
, "/* NOTE: some constructs may not have been converted */\n");
2530 n
= proto
->op
- proto
->ob
;
2531 proto
->op
= proto
->ob
;
2539 * drop control of iob after first pppread()
2540 * return value is input fd
2541 * if fd<0 then all data in iob
2547 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
2549 if (proto
->flags
& MORE
)
2551 proto
->flags
&= ~MORE
;