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
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 */
55 #define MAGICOFF "noticed" /* no notice if found in pragma */
56 #define MAGICTOP 64 /* must be in these top lines */
57 #define NOTICED "Copyright" /* no notice if found in magic */
58 #define PUBLICDOMAIN "Public Domain" /* no notice if found in magic */
60 struct proto
/* proto buffer state */
62 int brace
; /* {..} level */
63 int call
; /* call level */
64 int fd
; /* input file descriptor */
65 char* file
; /* input file name */
66 long flags
; /* coupled flags */
67 long options
; /* uncoupled flags */
68 char* package
; /* header package */
69 int line
; /* input line count */
70 int test
; /* testing */
72 char* tp
; /* input token base */
74 int iz
; /* input buffer size */
75 char* ib
; /* input buffer base */
76 char* ip
; /* input buffer pointer */
78 int oz
; /* output buffer size */
79 char* ob
; /* output buffer base */
80 char* op
; /* output buffer pointer */
81 char* ox
; /* output buffer externalize */
83 char cc
[3]; /* beg mid end comment char */
84 char pushback
[4]; /* pushback area for caller */
86 char variadic
[256]; /* variadic args buffer */
94 * proto is separate from pp so these undef's are ok
98 #define CLASSIC (1L<<0)
100 #define DECLARE (1L<<1)
102 #define DEFINE (1L<<2)
104 #define DIRECTIVE (1L<<3)
106 #define ERROR (1L<<4)
108 #define EXTERN (1L<<5)
110 #define EXTERNALIZE (1L<<6)
114 #define INDIRECT (1L<<8)
118 #define INIT_DEFINE (1L<<10)
120 #define INIT_INCLUDE (1L<<11)
122 #define JUNK (1L<<12)
124 #define LINESYNC (1L<<13)
126 #define MANGLE (1L<<14)
128 #define MATCH (1L<<15)
130 #define MORE (1L<<16)
132 #define OTHER (1L<<17)
134 #define PASS (1L<<18)
136 #define PLUSONLY (1L<<19)
138 #define PLUSPLUS (1L<<20)
140 #define RECURSIVE (1L<<21)
142 #define SHARP (1L<<22)
144 #define SKIP (1L<<23)
146 #define SLIDE (1L<<24)
148 #define TOKENS (1L<<25)
150 #define TYPEDEF (1L<<26)
152 #define VARIADIC (1L<<27)
154 #define VARIADIC2 (1L<<28)
156 #define YACC (1L<<29)
158 #define YACCSPLIT (1L<<30)
160 #define YACC2 (1L<<31)
163 #define GLOBAL (MORE)
166 #define REGULAR (1L<<0)
171 #define BLOCK (8*CHUNK)
173 #define T_VA_START (N_TOKEN+1)
175 #define RESERVED(b,e,n) ((((long)(b))<<16)|(((long)(e))<<8)|((long)(n)))
179 * pointer to end returned
183 number(register char* p
, register long n
)
187 for (d
= 1000000; d
> 1; d
/= 10)
188 if (n
>= d
) *p
++ = '0' + (n
/ d
) % 10;
200 * namespace pollution forces us to claim parts of libc
204 #define memcpy(t,f,n) memcopy(t,f,n)
206 #define strcpy(t,f) strcopy(t,f)
208 #define strlen(s) sstrlen(s)
210 #define strncmp(s,t,n) sstrncmp(s,t,n)
213 * environmentally safe strlen()
217 sstrlen(register const char* s
)
219 register const char* b
;
221 for (b
= s
; *s
; s
++);
226 * environmentally safe strncmp()
230 sstrncmp(register const char* s
, register char* t
, register int n
)
232 register const char* e
= s
+ n
;
245 * strcpy() except pointer to end returned
249 strcopy(register char* s
, register const char* t
)
258 proto_error(char* iob
, int level
, char* msg
, char* arg
)
263 p
= strcopy(buf
, "proto: ");
266 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
273 p
= strcopy(p
, proto
->file
);
278 p
= strcopy(p
, "line ");
279 p
= number(p
, proto
->line
);
281 else if (proto
->file
)
282 p
= strcopy(p
, proto
->file
);
296 p
= strcopy(p
, "warning: ");
304 write(2, buf
, p
- buf
);
312 * memcpy() but pointer to end returned
316 memcopy(register char* s
, register char* t
, int n
)
318 register char* e
= t
+ n
;
320 while (t
< e
) *s
++ = *t
++;
324 #include "../libast/port/astlicense.c"
328 #define memcopy(s,t,n) (((char*)memcpy(s,t,n))+(n))
334 * pointer to end returned
338 linesync(register struct proto
* proto
, register char* p
, register long n
)
341 if (proto
->flags
& LINESYNC
)
345 p
= strcopy(p
, "\n#line ");
347 p
= strcopy(p
, "\n# ");
357 * pointer to end returned
361 init(struct proto
* proto
, char* op
, int flags
)
365 if (flags
& INIT_DEFINE
)
369 #if !defined(__PROTO__)\n\
370 # if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)\n\
371 # if defined(__cplusplus)\n\
372 # define __LINKAGE__ \"C\"\n\
374 # define __LINKAGE__\n\
376 # define __STDARG__\n\
377 # define __PROTO__(x) x\n\
378 # define __OTORP__(x)\n\
379 # define __PARAM__(n,o) n\n\
380 # if !defined(__STDC__) && !defined(__cplusplus)\n\
381 # if !defined(c_plusplus)\n\
387 # define __V_ char\n\
389 # define __V_ void\n\
392 # define __PROTO__(x) ()\n\
393 # define __OTORP__(x) x\n\
394 # define __PARAM__(n,o) o\n\
395 # define __LINKAGE__\n\
396 # define __V_ char\n\
402 # define __MANGLE__ __LINKAGE__\n\
403 # if defined(__cplusplus) || defined(c_plusplus)\n\
404 # define __VARARG__ ...\n\
406 # define __VARARG__\n\
408 # if defined(__STDARG__)\n\
409 # define __VA_START__(p,a) va_start(p,a)\n\
411 # define __VA_START__(p,a) va_start(p)\n\
413 # if !defined(__INLINE__)\n\
414 # if defined(__cplusplus)\n\
415 # define __INLINE__ extern __MANGLE__ inline\n\
417 # if defined(_WIN32) && !defined(__GNUC__)\n\
418 # define __INLINE__ __inline\n\
423 #if !defined(__LINKAGE__)\n\
424 #define __LINKAGE__ /* 2004-08-11 transition */\n\
431 #if !defined(__PROTO__)\n\
432 #include <prototyped.h>\n\
434 #if !defined(__LINKAGE__)\n\
435 #define __LINKAGE__ /* 2004-08-11 transition */\n\
441 #ifndef __MANGLE_%_DATA__\n\
443 # ifdef __EXPORT__\n\
444 # define __MANGLE_%_DATA__ __MANGLE__ __EXPORT__\n\
446 # define __MANGLE_%_DATA__ __MANGLE__\n\
448 # define __MANGLE_%_FUNC__ __MANGLE__\n\
450 # ifdef __IMPORT__\n\
451 # define __MANGLE_%_DATA__ __MANGLE__ __IMPORT__\n\
453 # define __MANGLE_%_DATA__ __MANGLE__\n\
455 # define __MANGLE_%_FUNC__ __MANGLE__\n\
461 switch (*op
++ = *s
++)
467 op
= strcopy(op
- 1, proto
->package
);
478 #define BACKOUT() (op=ko)
479 #define CACHE() do{CACHEIN();CACHEOUT();call=proto->call;}while(0)
480 #define CACHEIN() (ip=proto->ip)
481 #define CACHEOUT() (op=proto->op)
482 #define GETCHR() (*(unsigned char*)ip++)
483 #define KEEPOUT() (ko=op)
484 #define LASTOUT() (*(op-1))
485 #define PUTCHR(c) (*op++=(c))
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)
489 #define UNGETCHR() (ip--)
490 #define UNPUTCHR() (op--)
493 * advance to the next non-space character
497 nns(register char* s
)
499 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
510 * update directive mask
514 directive(register char* s
, int dir
)
516 switch (*(s
= nns(s
)))
540 * top level calls loop until EOB
541 * recursive calls just return the next token
545 lex(register struct proto
* proto
, register long flags
)
586 if (flags
& EXTERN
) KEEPOUT();
596 while (!(state
= rp
[c
= GETCHR()]));
600 if ((n
= ip
- bp
- 1) > 0)
611 if (op
> proto
->ob
&& *(op
- 1) == '=' && (op
== proto
->ob
+ 1 || *(op
- 2) != '=')) switch (c
)
632 if (INCOMMENTXX(rp
)) goto fsm_newline
;
639 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
) BACKOUT();
653 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
) BACKOUT();
657 rp
= fsm
[INCOMMENTXX(rp
) ? COM5
: COM3
];
666 if (state
= fsm
[TERMINAL
][INDEX(rp
)+1])
673 if ((flags
& (DECLARE
|GLOBAL
|RECURSIVE
)) == GLOBAL
&& (proto
->flags
& MORE
))
676 if (!(flags
& EXTERN
)) /* XXX */
680 if (!(flags
& MATCH
))
685 if (ip
- n
< proto
->ib
)
686 proto
->flags
|= ERROR
;
687 memcopy(proto
->ib
- n
, ip
- n
, n
);
700 if ((n
= read(proto
->fd
, ip
, proto
->iz
)) > 0)
702 if ((proto
->options
& REGULAR
) && n
< proto
->iz
)
704 proto
->flags
&= ~MORE
;
714 proto
->flags
&= ~MORE
;
719 /* NOTE: RECURSIVE lex() should really SLIDE too */
720 if (!(flags
& RECURSIVE
) && (state
= rp
[c
= EOF
]))
733 for (n
= 0, t
= qe
+ 1; t
< op
&& (*t
== ' ' || *t
== '\t' || *t
== '\n' && ++n
|| *t
>= 'A' && *t
<= 'Z' || *t
== '_'); t
++);
753 if (!(flags
& DIRECTIVE
))
754 qe
= (c
== '"') ? op
: (char*)0;
765 else if (c
!= '\n' && c
!= EOF
)
787 if (flags
& CLASSIC
) PUTCHR(c
);
803 lex(proto
, (flags
& GLOBAL
) | RECURSIVE
);
804 for (n
= x
= 0; (c
= GETCHR()), x
< 3; x
++) switch (c
)
806 case '0': case '1': case '2': case '3':
807 case '4': case '5': case '6': case '7':
809 n
= (n
<< 4) + c
- '0';
811 case 'a': case 'b': case 'c': case 'd':
813 n
= (n
<< 4) + c
- 'a' + 10;
815 case 'A': case 'B': case 'C': case 'D':
817 n
= (n
<< 4) + c
- 'A' + 10;
825 PUTCHR(((n
>> 6) & 07) + '0');
826 PUTCHR(((n
>> 3) & 07) + '0');
827 PUTCHR((n
& 07) + '0');
840 if ((flags
& EXTERN
) && *proto
->tp
== 's' && !strncmp(proto
->tp
, "static", 6))
846 if (*proto
->tp
== '_' && !strncmp(proto
->tp
, "__STDPP__directive", 6)) c
= '#';
857 if (op
!= proto
->ob
&& LASTOUT() != ' ' && LASTOUT() != '\n')
863 if (flags
& DIRECTIVE
)
868 if (flags
& EXTERN
) BACKOUT();
872 op
= strcopy(om
, "/* ");
873 op
= strcopy(op
, im
);
874 op
= strcopy(op
, " */\n");
876 flags
&= ~(DEFINE
|DIRECTIVE
|IDID
|INDIRECT
|JUNK
|MATCH
|SHARP
|TYPEDEF
);
881 if ((flags
& (DEFINE
|SHARP
)) == (DEFINE
|SHARP
))
884 op
= strcopy(om
, "#if defined(__STDC__) || defined(__STDPP__)\n");
885 op
= strcopy(op
, im
);
886 op
= strcopy(op
, "\n#else\n");
891 if (*op
++ == '#' && *ip
!= '(')
894 while (*--op
== ' ' || *op
== '\t');
897 op
= strcopy(op
+ 1, "/**/");
898 while (*++ip
== ' ' || *ip
== '\t');
902 if (*op
!= '"') *++op
= '"';
904 while (*ip
== ' ' || *ip
== '\t') ip
++;
905 while ((c
= *ip
) >= 'A' && c
<= 'Z' || c
>= 'a' && c
<= 'z' || c
>= '0' && c
<= '9' || c
== '_') *op
++ = *ip
++;
906 while (*ip
== ' ' || *ip
== '\t') ip
++;
907 if (*ip
== '"') ip
++;
912 op
= strcopy(op
, "\n#endif\n");
913 op
= linesync(proto
, op
, proto
->line
);
915 flags
&= ~(DEFINE
|DIRECTIVE
|IDID
|INDIRECT
|MATCH
|OTHER
|SHARP
|SKIP
|TOKENS
|TYPEDEF
);
922 if (paren
== 0 && (flags
& (MATCH
|RECURSIVE
|SKIP
|SLIDE
)) == SLIDE
)
925 if (flags
& EXTERN
) BACKOUT();
934 rp
= fsm
[NEXT(state
)];
951 if (!(flags
& DECLARE
)) switch (RESERVED(*proto
->tp
, *(ip
- 1), ip
- proto
->tp
))
953 case RESERVED('N', 'N', 3):
954 if (proto
->tp
[1] == 'o')
957 case RESERVED('d', 'o', 2):
960 case RESERVED('e', 'e', 4):
961 if (!(flags
& RECURSIVE
) && (flags
& (DIRECTIVE
|TOKENS
)) != DIRECTIVE
&& !strncmp(proto
->tp
, "else", 4))
967 case RESERVED('e', 'n', 6):
968 if (!strncmp(proto
->tp
, "extern", 6))
971 case RESERVED('f', 'r', 3):
972 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "for", 3))
978 case RESERVED('i', 'f', 2):
981 case RESERVED('i', 'e', 6):
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))
987 op
= strcopy(op
- 6, "__INLINE__");
991 case RESERVED('r', 'n', 6):
992 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "return", 6))
998 case RESERVED('s', 'c', 6):
999 if ((proto
->options
& EXTERNALIZE
) && !strncmp(proto
->tp
, "static", 6))
1002 flags
|= EXTERNALIZE
;
1005 case RESERVED('t', 'f', 7):
1006 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "typedef", 7))
1012 case RESERVED('v', 't', 8):
1013 if (*ip
== '(' && !strncmp(proto
->tp
, "va_start", 8)) c
= T_VA_START
;
1015 case RESERVED('v', 'd', 4):
1016 if (!strncmp(proto
->tp
, "void", 4))
1018 if (flags
& (CLASSIC
|PLUSONLY
|INIT_DEFINE
|INIT_INCLUDE
)) c
= T_VOID
;
1023 if (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
) == '*')
1025 memcopy(op
- 4, "__V_", 4);
1026 memcopy(ip
- 4, "__V_", 4);
1035 case RESERVED('w', 'e', 5):
1036 if (!(flags
& RECURSIVE
) && !strncmp(proto
->tp
, "while", 5))
1044 if ((flags
& CLASSIC
) && c
!= T_EXTERN
)
1055 if ((flags
& (EXTERN
|MATCH
)) == EXTERN
)
1057 while (op
> proto
->ob
&& (*(op
- 1) == ' ' || *(op
- 1) == '\t'))
1059 if (op
> proto
->ob
&& *(op
- 1) != '\n') *op
++ = ' ';
1069 if (!(n
= GETCHR()))
1087 if (state
>= TERMINAL
)
1095 if (!(flags
& (INIT_DEFINE
|INIT_INCLUDE
|RECURSIVE
)))
1097 if (!(flags
& DIRECTIVE
)) switch (c
)
1101 if (!(flags
& CLASSIC
) || proto
->brace
== 0)
1107 if (!(flags
& CLASSIC
) || group
<= 1)
1113 if (group
++ == 0) group
++;
1114 else if (flags
& INDIRECT
) call
++;
1121 else if (paren
== 2 && !aim
)
1129 else if (flags
& INDIRECT
)
1134 else if ((flags
& (MATCH
|TOKENS
)) == MATCH
)
1136 for (m
= ip
- 2; m
> im
&& (*m
== ' ' || *m
== '\t'); m
--);
1137 if (m
!= im
&& sub
== 1)
1139 m
= im
+ (*nns(ip
) == '*');
1147 else if ((flags
& MATCH
) && sub
== 1 && *nns(ip
) != '*')
1158 if (!(flags
& CLASSIC
) || proto
->brace
== 0)
1163 if (flags
& CLASSIC
)
1175 else if (paren
== 1 && (flags
& INDIRECT
) && !aie
)
1179 if (last
== '(' && group
== 2)
1190 dir
= directive(ip
, dir
);
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
))
1193 else if (!(flags
& (DECLARE
|DIRECTIVE
)))
1196 if (!(flags
& PLUSONLY
))
1199 while (*ip
== ' ' || *ip
== '\t') ip
++;
1200 if (*ip
== 'l' && *++ip
== 'i' && *++ip
== 'n' && *++ip
== 'e')
1202 if (*++ip
== ' ' || *ip
== '\t')
1205 while (*++ip
>= '0' && *ip
<= '9')
1206 proto
->line
= proto
->line
* 10 + *ip
- '0';
1211 else if ((flags
& (CLASSIC
|EXTERN
)) == CLASSIC
)
1215 while (ip
< t
&& *ip
>= 'a' && *ip
<= 'z')
1216 n
= HASHKEYPART(n
, *ip
++);
1219 case HASHKEY4('e','l','s','e'):
1220 case HASHKEY5('e','n','d','i','f'):
1221 while (*ip
== ' ' || *ip
== '\t') ip
++;
1222 if (*ip
!= '\n' && *ip
!= '/' && *(ip
+ 1) != '*')
1224 flags
|= JUNK
|MATCH
;
1226 om
= op
+ (ip
- bp
);
1229 case HASHKEY4('e','l','i','f'):
1230 case HASHKEY5('e','r','r','o','r'):
1231 case HASHKEY2('i','f'):
1232 case HASHKEY5('i','f','d','e','f'):
1233 case HASHKEY6('i','f','n','d','e','f'):
1234 case HASHKEY5('u','n','d','e','f'):
1236 case HASHKEY6('i','n','c','l','u','d'):
1237 if (*ip
== 'e') ip
++;
1239 case HASHKEY6('d','e','f','i','n','e'):
1240 case HASHKEY6('p','r','a','g','m','a'):
1241 if (*ip
< 'a' || *ip
> 'z') break;
1244 flags
|= JUNK
|MATCH
;
1253 if (*ip
== 'i' && *++ip
== 'n' && *++ip
== 'c' && *++ip
== 'l' && *++ip
== 'u' && *++ip
== 'd' && *++ip
== 'e')
1255 while (*++ip
== ' ' || *ip
== '\t');
1256 if (*ip
++ == '<' && *ip
++ == 's' && *ip
++ == 't' && *ip
++ == 'd' && *ip
++ == 'a' && *ip
++ == 'r' && *ip
++ == 'g' && *ip
++ == '.' && *ip
++ == 'h' && *ip
++ == '>')
1259 if !defined(va_start)\n\
1260 #if defined(__STDARG__)\n\
1261 #include <stdarg.h>\n\
1263 #include <varargs.h>\n\
1267 op
= linesync(proto
, op
, proto
->line
);
1271 else if (*ip
== 'd' && *++ip
== 'e' && *++ ip
== 'f' && *++ip
== 'i' && *++ip
== 'n' && *++ip
== 'e' && (*++ip
== ' ' || *ip
== '\t'))
1273 while (*++ip
== ' ' || *ip
== '\t');
1274 if (*ip
== 'e' && *++ip
== 'x' && *++ ip
== 't' && *++ip
== 'e' && *++ip
== 'r' && *++ip
== 'n' && (*++ip
== ' ' || *ip
== '\t'))
1277 while (*++t
== ' ' || *t
== '\t');
1278 if (*t
== 'e' && *++t
== 'x' && *++ t
== 't' && *++t
== 'e' && *++t
== 'r' && *++t
== 'n' && (*++t
== ' ' || *t
== '\t' || *t
== '\n' || *t
== '\r'))
1281 while (*++t
== ' ' || *t
== '\t');
1282 if (*t
== '_' && *(t
+ 1) == '_')
1284 op
= strcopy(op
, "undef __MANGLE__\n");
1285 op
= linesync(proto
, op
, proto
->line
);
1286 op
= strcopy(op
, "#define __MANGLE__ __LINKAGE__");
1290 flags
|= DEFINE
|MATCH
;
1294 else if (*ip
== 'u' && *++ip
== 'n' && *++ ip
== 'd' && *++ip
== 'e' && *++ip
== 'f' && (*++ip
== ' ' || *ip
== '\t'))
1296 while (*++ip
== ' ' || *ip
== '\t');
1297 if (*ip
== 'e' && *++ip
== 'x' && *++ ip
== 't' && *++ip
== 'e' && *++ip
== 'r' && *++ip
== 'n' && (*++ip
== ' ' || *ip
== '\t' || *ip
== '\n' || *ip
== '\r'))
1299 op
= strcopy(op
, "undef __MANGLE__\n");
1300 op
= linesync(proto
, op
, proto
->line
);
1301 op
= strcopy(op
, "#define __MANGLE__ __LINKAGE__");
1304 flags
|= DEFINE
|MATCH
;
1317 if (proto
->brace
++ == 0 && paren
== 0)
1319 if (last
== '=') flags
|= INIT
;
1321 else if (flags
& CLASSIC
)
1323 if ((flags
& (MATCH
|OTHER
|SKIP
)) == MATCH
)
1327 v
= number(op
, args
< 0 ? -args
: args
);
1328 v
= strcopy(v
, " argument actual/formal mismatch");
1330 v
= memcopy(v
, im
, ie
- im
);
1332 proto_error((char*)proto
+ sizeof(struct proto
), 2, op
, NiL
);
1338 if (*ie
++ == '/' && *ie
== '*')
1345 while (ie
< ip
&& *ie
== '*') ie
++;
1346 if (ie
< ip
&& *ie
== '/')
1348 while (++ie
< ip
&& (*ie
== ' ' || *ie
== '\t'));
1349 while (e
> v
&& (*(e
- 1) == ' ' || *(e
- 1) == '\t')) e
--;
1350 if (e
> v
&& *e
!= '\n') *e
++ = ' ';
1366 while (v
> ko
&& *--v
!= ' ');
1369 om
= (v
= (op
+= 4)) + 1;
1375 memcopy(ko
, "int ", 4);
1379 while (*(v
+ 1) == '*')
1384 om
= (e
= ++op
) + 1;
1392 om
= (v
= (op
+= 7)) + 1;
1398 memcopy(ko
, "extern ", 7);
1406 if ((c
= *ie
) == ' ' || c
== '\t' || c
== '\n')
1408 while ((c
= *++ie
) == ' ' || c
== '\t' || c
== '\n');
1409 if (ie
>= ip
) break;
1410 if (c
!= '*' && op
> om
) PUTCHR(' ');
1412 if ((n
= ((c
= *ie
) == ',')) || c
== ';')
1417 while (op
> om
&& ((c
= *(op
- 1)) == '(' || c
== ')' || c
== '[' || c
== ']'))
1420 while (op
> om
&& (c
= *(op
- 1)) != ' ' && c
!= '*')
1422 while (*(op
- 1) == ' ')
1427 while (e
> om
&& *(e
- 1) == '*')
1430 #if _s5r4_386_compiler_bug_fixed_
1431 if (op
<= om
|| *(op
- 1) == ',' && (*op
++ = ' '))
1432 op
= strcopy(op
, "int");
1435 op
= strcopy(op
, "int");
1436 else if (*(op
- 1) == ',')
1437 op
= strcopy(op
, " int");
1445 if (x
= !e
) e
= op
- 1;
1453 while (*--e
!= ' ');
1454 while (*(e
- 1) == '*') e
--;
1458 while ((c
= *++ie
) == ' ' || c
== '\t' || c
== '\n');
1459 if (ie
>= ip
) UNPUTCHR();
1467 else if (*ie
== '*')
1469 if (op
> om
&& (c
= *(op
- 1)) == ' ') op
--;
1470 while (*ie
== '*') PUTCHR(*ie
++);
1471 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1472 if (c
!= '(') PUTCHR(' ');
1474 else if (*ie
== '(')
1476 if (op
> om
&& *(op
- 1) == ' ') op
--;
1478 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1480 else if (*ie
== ')')
1482 if (op
> om
&& *(op
- 1) == '(')
1483 proto_error((char*)proto
+ sizeof(struct proto
), 1, "function pointer argument prototype omitted", NiL
);
1485 while (*ie
== ' ' || *ie
== '\t' || *ie
== '\n') ie
++;
1487 else if ((flags
& EXTERN
) && (op
== om
|| *(op
- 1) == ' ') && *ie
== 'r' && !strncmp(ie
, "register", 8) && (*(ie
+ 8) == ' ' || *(ie
+ 8) == '\t' || *(ie
+ 8) == '\n'))
1490 if (op
> om
) UNPUTCHR();
1495 if (op
<= om
) op
= strcopy(op
, "void");
1510 flags
&= ~(MATCH
|SKIP
);
1514 else if ((flags
& (MATCH
|PLUSONLY
|SKIP
|TOKENS
)) == (MATCH
|TOKENS
))
1517 op
= strcopy(om
, " __PARAM__(");
1518 op
= memcopy(op
, im
, ie
- im
);
1522 flags
&= ~(MATCH
|SKIP
);
1523 if (flags
& VARIADIC
)
1525 if ((vc
= ie
- im
+ 1) > sizeof(proto
->variadic
)) vc
= sizeof(proto
->variadic
);
1526 memcopy(proto
->variadic
, im
, vc
);
1527 op
= strcopy(op
, "va_alist)) __OTORP__(va_dcl)\n{");
1538 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1547 if (paren
++) group
++;
1555 flags
&= ~(MATCH
|SKIP
);
1556 op
= memcopy(op
, m
, e
- m
);
1567 flags
&= ~(MATCH
|SKIP
);
1568 op
= memcopy(op
, m
, e
- m
);
1576 if (group
<= 1 && !brack
)
1591 if (!(flags
& SKIP
))
1594 proto
->op
= strcopy(op
, " __OTORP__(");
1600 lex(proto
, (flags
& GLOBAL
) | DECLARE
);
1607 if (flags
& EXTERNALIZE
) memcpy(proto
->ox
, "extern", 6);
1608 op
= linesync(proto
, op
, proto
->line
= line
);
1609 if (flags
& DIRECTIVE
)
1615 else if (!(flags
& VARIADIC
)) PUTCHR('{');
1618 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
);
1623 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
|TOKENS
);
1624 if (--proto
->brace
== 0)
1626 flags
&= ~(INIT
|VARIADIC
|VARIADIC2
);
1628 if (flags
& EXTERN
) BACKOUT();
1636 if (last
== '?') flags
|= DIRECTIVE
;
1637 else if (paren
== 0 && (flags
& (INIT
|MATCH
|SKIP
)) == MATCH
)
1639 if (last
== ')' && proto
->brace
&& (group
!= 2 || call
!= 2)) flags
|= SKIP
;
1640 else goto fsm_statement
;
1645 if (flags
& CLASSIC
)
1647 if (paren
== 1) args
++;
1656 if (paren
== 0 && (flags
& DECLARE
)) *(op
- 1) = c
= ';';
1660 if (flags
& INIT
) /* ignore */;
1662 else if (flags
& CLASSIC
)
1666 if ((flags
& MATCH
) && last
== ')')
1668 if (!(flags
& MATCH
))
1673 if (flags
& EXTERN
) BACKOUT();
1683 if ((flags
& (EXTERN
|SKIP
)) == (EXTERN
|SKIP
))
1689 else if (paren
== 0)
1691 if ((flags
& (MATCH
|OTHER
|SKIP
)) == MATCH
&& call
> 1)
1693 if ((flags
& MANGLE
) && func
)
1701 if ((flags
& (DECLARE
|INDIRECT
)) == INDIRECT
&& aim
&& aie
< im
)
1703 while (aie
< ip
&& (*aie
== ' ' || *aie
== '\t' || *aie
== '\n')) aie
++;
1706 if (*v
++ == ')') break;
1707 while (v
< aie
&& (*v
== ' ' || *v
== '\t' || *v
== '\n')) v
++;
1708 if (v
== aie
|| !(flags
& PLUSPLUS
))
1710 if (flags
& PLUSPLUS
) n
= 3;
1711 else if (v
== aie
&& *v
== '(') n
= 10;
1721 if (flags
& PLUSPLUS
) memcopy(aom
, "(...))", 6);
1722 else if (n
== 10) memcopy(aom
, "(__VARARG__))", 13);
1725 ko
= strcopy(aom
, " __PROTO__(");
1726 ko
= memcopy(ko
, aim
, aie
- aim
);
1736 else if (flags
& TYPEDEF
)
1739 while (*--op
== ' ' || *op
== '\t' || *op
== '\n');
1744 while ((x
= *(op
- 14)) >= 'A' && x
<= 'Z' || x
>= 'a' && x
<= 'z' || x
>= '0' && x
<= '9' || x
== '_')
1746 memcopy(op
- 13, "(__OTORP__(*)", 13);
1751 else if (flags
& PLUSPLUS
)
1754 if (!(flags
& TOKENS
)) op
= strcopy(op
, "(...)");
1755 else op
= memcopy(op
, im
, ie
- im
);
1760 if (flags
& DECLARE
) op
= strcopy(om
, "()");
1761 else if (!(flags
& TOKENS
)) op
= strcopy(om
, "(__VARARG__)");
1764 op
= strcopy(om
, " __PROTO__(");
1765 op
= memcopy(op
, im
, ie
- im
);
1768 if (flags
& EXTERNALIZE
) memcpy(proto
->ox
, "extern", 6);
1771 flags
&= ~(MATCH
|VARIADIC
|VARIADIC2
);
1772 if (c
== ',' && !(flags
& INDIRECT
))
1779 else if (flags
& (OTHER
|SKIP
)) call
= 0;
1782 flags
&= ~(EXTERNALIZE
|MANGLE
|TOKENS
|TYPEDEF
);
1790 else call
= call
> 1 && c
== ',';
1792 flags
&= ~(IDID
|INDIRECT
|MATCH
|OTHER
|SKIP
);
1794 else if (paren
== 1 && group
== 1 && !(flags
& (IDID
|MANGLE
))) flags
|= TOKENS
|OTHER
;
1798 flags
|= TOKENS
|SKIP
;
1802 if (flags
& CLASSIC
)
1804 if (proto
->brace
== 0)
1809 if (paren
== 0 && !(flags
& TYPEDEF
))
1812 if (!(flags
& PLUSONLY
) || proto
->package
)
1814 op
= strcopy(op
, " __MANGLE__");
1817 op
= strcopy(op
- 1, proto
->package
);
1819 op
= strcopy(op
, "_DATA__");
1827 if (paren
== 0 && (flags
& (DECLARE
|VARIADIC
)) == DECLARE
)
1833 if (paren
== 1 && !(flags
& SKIP
))
1840 if ((flags
& (PLUSONLY
|VARIADIC
)) == VARIADIC
)
1844 op
= strcopy(op
- 8, "__VA_START__");
1848 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1854 if (!(flags
& MATCH
))
1877 op
= strcopy(op
, " __OTORP__(");
1878 proto
->ip
= proto
->variadic
;
1883 if (*bp
== 'r' && !strncmp(bp
, "register", 8) && (*(bp
+ 8) == ' ' || *(bp
+ 8) == '\t')) bp
+= 9;
1886 switch (lex(proto
, (flags
& GLOBAL
) | RECURSIVE
))
1889 if (paren
++) group
++;
1897 if (!(flags
& VARIADIC2
))
1899 op
= memcopy(op
, m
, e
- m
);
1900 op
= strcopy(op
, " = ");
1902 op
= strcopy(op
, "va_arg(");
1903 op
= memcopy(op
, v
, n
);
1906 if (m
> bp
) op
= memcopy(op
, bp
, m
- bp
);
1907 else op
= strcopy(op
, "int ");
1908 if (group
> 1) op
= strcopy(op
, ")()");
1909 else op
= memcopy(op
, e
, proto
->ip
- e
- 1);
1923 if (!(flags
& VARIADIC2
))
1925 op
= memcopy(op
, m
, e
- m
);
1926 op
= strcopy(op
, " = ");
1928 op
= strcopy(op
, "va_arg(");
1929 op
= memcopy(op
, v
, n
);
1932 if (m
> bp
) op
= memcopy(op
, bp
, m
- bp
);
1933 else op
= strcopy(op
, "int ");
1934 if (group
> 1) op
= strcopy(op
, ")()");
1935 else op
= memcopy(op
, e
, proto
->ip
- e
- 1);
1939 if (*bp
== 'r' && !strncmp(bp
, "register", 8) && (*(bp
+ 8) == ' ' || *(bp
+ 8) == '\t')) bp
+= 9;
1958 op
= strcopy(op
, ")");
1968 if (flags
& CLASSIC
)
1970 if (!args
&& paren
== 1) args
++;
1978 if (proto
->brace
== 0 && !(flags
& DECLARE
)) flags
|= SKIP
;
1981 else if ((flags
& SKIP
) || c
== T_ID
|| c
== T_VOID
) call
++;
1983 if (last
== T_ID
) flags
|= IDID
;
1989 if (*proto
->tp
>= '0' && *proto
->tp
<= '9')
1999 while ((c
= *--t
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z');
2010 while ((c
= *--t
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z');
2032 while ((c
= *--m
) >= '0' && c
<= '9' || c
>= 'a' && c
<= 'z' || c
>= 'A' && c
<= 'Z')
2035 strcopy(m
+ 1, "(unsigned)");
2043 if ((flags
& CLASSIC
) && paren
== 0 && group
<= 2) flags
|= SKIP
;
2049 if (flags
& CLASSIC
) break;
2052 if (paren
== 0) flags
|= OTHER
;
2055 else if (c
== '#' && *ip
!= '(') flags
|= SHARP
;
2058 if ((flags
& (EXTERN
|MATCH
)) == (EXTERN
|MATCH
) && ((flags
& (DIRECTIVE
|SKIP
)) || proto
->brace
|| c
!= '(' && c
!= ')' && c
!= '*' && c
!= T_ID
))
2065 else if (flags
& (INIT_DEFINE
|INIT_INCLUDE
))
2068 if ((flags
& YACC
) && c
== '%' && *ip
== '{') t
= 0;
2072 if (c
== '#') for (t
= ip
; *t
== ' ' || *t
== '\t'; t
++);
2074 if (*t
++ == 'i' && *t
++ == 'f' && *t
++ == 'n' && *t
++ == 'd' && *t
++ == 'e' && *t
++ == 'f')
2077 while (*t
== ' ' || *t
== '\t') t
++;
2088 else while (*ip
!= '\n') *op
++ = *ip
++;
2089 op
= init(proto
, op
, flags
);
2090 op
= linesync(proto
, op
, proto
->line
);
2091 flags
&= ~(INIT_DEFINE
|INIT_INCLUDE
);
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
2114 * read buffer pointer returned
2115 * 0 returned on error or if no magic
2117 * file !=0 file path to open, otherwise use fd
2118 * fd open file fd if file==0
2119 * notice !=0 copyright notice info commented at the top
2120 * options !=0 additional notice name=value pairs, space or ; separated
2121 * package !=0 generate header for this package
2125 pppopen(char* file
, int fd
, char* notice
, char* options
, char* package
, char* comment
, int flags
)
2127 register struct proto
* proto
;
2146 if (flags
& PROTO_CLASSIC
) flags
&= ~PROTO_INCLUDE
;
2148 if (flags
& PROTO_RETAIN
) flags
&= ~retain
;
2149 else retain
&= PROTO_INITIALIZED
;
2150 if (file
&& (fd
= open(file
, O_RDONLY
)) < 0) return 0;
2152 if ((n
= lseek(fd
, 0L, 2)) > 0)
2154 if (lseek(fd
, 0L, 0)) return 0;
2155 if (n
< CHUNK
) n
= CHUNK
;
2156 else if (n
> 2 * BLOCK
) n
= 0;
2162 * file read in one chunk
2165 if (!(proto
= newof(0, struct proto
, 1, 4 * n
+ 2)))
2175 * file read in BLOCK chunks
2179 if (!(proto
= newof(0, struct proto
, 1, 5 * n
+ 2)))
2183 proto
->flags
|= MORE
;
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]))
2194 notice
= options
= 0;
2195 else if (comment
[1])
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];
2204 * read the first chunk
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
2219 * pragma blanked out if found
2222 * 0 #pragma noprototyped
2223 * 1 #pragma prototyped
2225 * NOTE: matches may occur inside comments and quotes
2229 if (!notice
&& !options
|| (comlen
= astlicense(com
, sizeof(com
), NiL
, "type=check", proto
->cc
[0], proto
->cc
[1], proto
->cc
[2])) <= 0)
2235 while (m
-- > 0 && *s
)
2237 while (*s
== ' ' || *s
== '\t') s
++;
2241 while (*s
== ' ' || *s
== '\t') s
++;
2242 if (!strncmp(s
, MAGICDIR
, sizeof(MAGICDIR
) - 1) && (*(s
+= sizeof(MAGICDIR
) - 1) == ' ' || *s
== '\t'))
2244 while (*s
== ' ' || *s
== '\t') s
++;
2245 if (*s
== 'n' && *(s
+ 1) == 'o')
2250 if (!strncmp(s
, MAGICARG
, sizeof(MAGICARG
) - 1) && (*(s
+= sizeof(MAGICARG
) - 1) == ' ' || *s
== '\t' || *s
== '\n' || *s
== '\r'))
2253 if ((*(s
- 1) == ' ' || *(s
- 1) == '\t') && *s
== *MAGICOFF
&& !strncmp(s
, MAGICOFF
, sizeof(MAGICOFF
) - 1))
2254 notice
= options
= 0;
2259 if (!(flags
& PROTO_DISABLE
) || (flags
& PROTO_NOPRAGMA
))
2261 for (s
--; b
< s
; *b
++ = ' ');
2268 else if (*s
== '/' && !strncmp(s
, MAGICGEN
, sizeof(MAGICGEN
) - 1))
2274 else if (*s
== '%' && *(s
+ 1) == '{')
2275 proto
->flags
|= YACC
;
2276 if (notice
|| options
)
2278 if (*s
== *com
&& !strncmp(s
, com
, comlen
))
2279 notice
= options
= 0;
2283 if (*s
== *NOTICED
&& !strncmp(s
, NOTICED
, sizeof(NOTICED
) - 1))
2285 s
+= sizeof(NOTICED
) - 1;
2286 while (*s
== ' ' || *s
== '\t')
2288 if (*s
== '(' && (*(s
+ 1) == 'c' || *(s
+ 1) == 'C') && *(s
+ 2) == ')' || *s
>= '0' && *s
<= '9' && *(s
+ 1) >= '0' && *(s
+ 1) <= '9')
2290 notice
= options
= 0;
2294 if (*s
== *PUBLICDOMAIN
&& !strncmp(s
, PUBLICDOMAIN
, sizeof(PUBLICDOMAIN
) - 1))
2296 notice
= options
= 0;
2299 else if (*s
++ == '\n')
2307 while (*s
&& *s
++ != '\n');
2310 if (flags
& PROTO_PLUSPLUS
) proto
->flags
|= PLUSPLUS
;
2311 if (flags
& PROTO_TEST
) proto
->test
= 1;
2312 if (flags
& PROTO_EXTERNALIZE
) proto
->options
|= EXTERNALIZE
;
2314 if (flags
& PROTO_CLASSIC
) pragma
= -pragma
;
2315 if (flags
& PROTO_DISABLE
) pragma
= 0;
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
;
2322 if (flags
& PROTO_PLUSPLUS
)
2324 flags
&= ~(PROTO_HEADER
|PROTO_INCLUDE
);
2325 proto
->flags
|= PLUSONLY
;
2327 else if (!(flags
& (PROTO_FORCE
|PROTO_PASS
)))
2332 else if ((flags
& (PROTO_FORCE
|PROTO_PASS
)) == PROTO_PASS
|| !pragma
)
2334 proto
->flags
|= PASS
;
2335 if (proto
->flags
& MORE
)
2336 proto
->oz
+= proto
->iz
;
2338 if (notice
|| options
)
2340 if (proto
->cc
[0] == '#' && proto
->ip
[0] == '#' && proto
->ip
[1] == '!')
2343 while (*s
&& *s
++ != '\n');
2345 proto
->op
= memcopy(proto
->op
, proto
->ip
, m
);
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
);
2367 if (!(retain
& PROTO_INITIALIZED
))
2369 retain
|= PROTO_INITIALIZED
;
2370 ppfsm(FSM_INIT
, NiL
);
2375 if (notice
|| options
|| (flags
& (PROTO_HEADER
|PROTO_INCLUDE
)))
2378 if (notice
|| options
)
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
;
2386 if (flags
& PROTO_INCLUDE
)
2388 proto
->flags
|= INIT_INCLUDE
;
2389 if (flags
& PROTO_RETAIN
)
2390 retain
|= PROTO_INCLUDE
;
2392 else if (flags
& PROTO_HEADER
)
2394 if (flags
& PROTO_RETAIN
) retain
|= PROTO_HEADER
;
2396 if (flags
& PROTO_CLASSIC
)
2399 proto
->op
= strcopy(proto
->op
, MAGICDIR
);
2401 proto
->op
= strcopy(proto
->op
, MAGICARG
);
2402 *proto
->op
++ = '\n';
2406 proto
->flags
|= INIT_DEFINE
;
2409 if (!(flags
& PROTO_CLASSIC
))
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");
2419 if (n
|| notice
|| options
)
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
);
2433 if (flags
& PROTO_CLASSIC
)
2435 proto
->flags
|= CLASSIC
;
2436 if (!(flags
& PROTO_HEADER
)) proto
->flags
|= EXTERN
;
2443 * read next proto'd chunk into iob
2444 * the chunk is 0 terminated and its size is returned
2450 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
2453 if (proto
->flags
& PASS
)
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
;
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
;
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
)
2502 while (op
< ep
&& (n
= *op
++ = *ip
))
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
);
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
;
2541 * drop control of iob after first pppread()
2542 * return value is input fd
2543 * if fd<0 then all data in iob
2549 register struct proto
* proto
= (struct proto
*)(iob
- sizeof(struct proto
));
2551 if (proto
->flags
& MORE
)
2553 proto
->flags
&= ~MORE
;