/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1986-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* convert C prototypes to ANSI, K&R and C++ styles or K&R to ANSI
* slips into the pp block read
*
* define PROTOMAIN for standalone proto
* PROTOMAIN is coded for minimal library support
*/
#if PROTOMAIN
#include "ppfsm.c"
#include <hashkey.h>
#if PROTO_STANDALONE
#endif
#else
#include "pplib.h"
#include "ppfsm.h"
#endif
#ifndef elementsof
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
#endif
typedef struct Key_s
{
const char* name;
int hit;
int val;
} Key_t;
{
/* output buffer */
/* slide buffer */
/* input buffer */
} Proto_t;
/*
* proto is separate from pp so these undef's are ok
*/
#ifndef CHUNK
#endif
{
};
{
};
/*
* generate integer
* pointer to end returned
*/
static char*
number(register char* p, register long n)
{
register long d;
for (d = 1000000; d > 1; d /= 10)
if (n >= d) *p++ = '0' + (n / d) % 10;
*p++ = '0' + n % 10;
return p;
}
#if PROTOMAIN
static int errors;
#if PROTO_STANDALONE
/*
* namespace pollution forces us to claim parts of libc
*/
/*
* environmentally safe strlen()
*/
static int
sstrlen(register const char* s)
{
register const char* b;
for (b = s; *s; s++);
return s - b;
}
/*
* environmentally safe strncmp()
*/
static int
sstrncmp(register const char* s, register const char* t, register int n)
{
register const char* e = s + n;
while (s < e)
{
if (*s != *t || !*s)
return *s - *t;
s++;
t++;
}
return 0;
}
/*
* strcpy() except pointer to end returned
*/
static char*
strcopy(register char* s, register const char* t)
{
while (*s++ = *t++);
return s - 1;
}
#endif
static void
{
register char* p;
if (iob)
{
{
{
*p++ = '"';
*p++ = '"';
*p++ = ',';
*p++ = ' ';
}
p = strcopy(p, "line ");
}
}
else
{
arg = 0;
}
if (*(p - 1) != ' ')
{
*p++ = ':';
*p++ = ' ';
}
if (level == 1)
p = strcopy(p, "warning: ");
if (arg)
{
*p++ = ' ';
}
*p++ = '\n';
if (level >= 3)
if (level >= 2)
errors++;
}
/*
* memcpy() but pointer to end returned
*/
static char*
memcopy(register char* s, register char* t, int n)
{
register char* e = t + n;
while (t < e) *s++ = *t++;
return s;
}
#include "../libast/port/astlicense.c"
#else
#endif
/*
* generate line sync
* pointer to end returned
*/
static char*
{
#if PROTOMAIN
#endif
{
#if PROTOMAIN
p = strcopy(p, "\n#line ");
#else
p = strcopy(p, "\n# ");
#endif
p = number(p, n);
*p++ = '\n';
}
return p;
}
/*
* output init header
* pointer to end returned
*/
static char*
{
register char* s;
if (flags & INIT_DEFINE)
{
\n\
#if !defined(__PROTO__)\n\
# if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)\n\
# if defined(__cplusplus)\n\
# define __LINKAGE__ \"C\"\n\
# else\n\
# define __LINKAGE__\n\
# endif\n\
# define __STDARG__\n\
# define __PROTO__(x) x\n\
# define __OTORP__(x)\n\
# define __PARAM__(n,o) n\n\
# if !defined(__STDC__) && !defined(__cplusplus)\n\
# if !defined(c_plusplus)\n\
# define const\n\
# endif\n\
# define signed\n\
# define void int\n\
# define volatile\n\
# define __V_ char\n\
# else\n\
# define __V_ void\n\
# endif\n\
# else\n\
# define __PROTO__(x) ()\n\
# define __OTORP__(x) x\n\
# define __PARAM__(n,o) o\n\
# define __LINKAGE__\n\
# define __V_ char\n\
# define const\n\
# define signed\n\
# define void int\n\
# define volatile\n\
# endif\n\
# define __MANGLE__ __LINKAGE__\n\
# if defined(__cplusplus) || defined(c_plusplus)\n\
# define __VARARG__ ...\n\
# else\n\
# define __VARARG__\n\
# endif\n\
# if defined(__STDARG__)\n\
# define __VA_START__(p,a) va_start(p,a)\n\
# else\n\
# define __VA_START__(p,a) va_start(p)\n\
# endif\n\
# if !defined(__INLINE__)\n\
# if defined(__cplusplus)\n\
# define __INLINE__ extern __MANGLE__ inline\n\
# else\n\
# if defined(_WIN32) && !defined(__GNUC__)\n\
# define __INLINE__ __inline\n\
# endif\n\
# endif\n\
# endif\n\
#endif\n\
#if !defined(__LINKAGE__)\n\
#define __LINKAGE__ /* 2004-08-11 transition */\n\
#endif\n\
");
}
else
\n\
#if !defined(__PROTO__)\n\
#include <prototyped.h>\n\
#endif\n\
#if !defined(__LINKAGE__)\n\
#define __LINKAGE__ /* 2004-08-11 transition */\n\
#endif\n\
");
{
s = "\
#ifndef __MANGLE_%_DATA__\n\
# ifdef _BLD_%\n\
# ifdef __EXPORT__\n\
# define __MANGLE_%_DATA__ __MANGLE__ __EXPORT__\n\
# else\n\
# define __MANGLE_%_DATA__ __MANGLE__\n\
# endif\n\
# define __MANGLE_%_FUNC__ __MANGLE__\n\
# else\n\
# ifdef __IMPORT__\n\
# define __MANGLE_%_DATA__ __MANGLE__ __IMPORT__\n\
# else\n\
# define __MANGLE_%_DATA__ __MANGLE__\n\
# endif\n\
# define __MANGLE_%_FUNC__ __MANGLE__\n\
# endif\n\
#endif\n\
";
for (;;)
{
switch (*op++ = *s++)
{
case 0:
op--;
break;
case '%':
continue;
default:
continue;
}
break;
}
}
return op;
}
#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)
/*
* advance to the next non-space character
*/
static char*
nns(register char* s)
{
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
return s;
}
/*
* update directive mask
*/
static int
{
switch (*(s = nns(s)))
{
case 'e':
case 'i':
dir <<= 2;
switch (*++s)
{
case 'f':
break;
case 'l':
break;
case 'n':
break;
}
break;
}
return dir;
}
/*
* the tokenizer
* top level calls loop until EOB
* recursive calls just return the next token
*/
static int
{
register char* ip;
register char* op;
register int c;
register int state;
register short* rp;
char* m;
char* e;
char* t;
char* bp;
char* v;
char* im;
char* ko;
char* aom;
int n;
int line;
int quot;
int brack;
int sub;
int x;
int vc;
char* ie = 0;
char* om = 0;
char* aim = 0;
char* aie = 0;
char* func = 0;
int call = 0;
int dir = 0;
int group = 0;
int last = 0;
int paren = 0;
#if PROTOMAIN
char* qe = 0;
int qn = 0;
int args = 0;
#endif
CACHE();
#if PROTOMAIN
#endif
do
{
;
} while (state > 0);
{
ip++;
}
{
case S_CHR:
{
case '+':
case '-':
case '*':
case '&':
PUTCHR(' ');
break;
}
PUTCHR(c);
break;
case S_CHRB:
UNGETCHR();
c = LASTOUT();
break;
case S_COMMENT:
switch (c)
{
case '\n':
PUTCHR(c);
break;
case '/':
#if PROTOMAIN
else
#endif
PUTCHR(c);
if (INCOMMENTXX(rp))
{
break;
}
goto fsm_start;
case EOF:
break;
default:
#if PROTOMAIN
else
#endif
PUTCHR(c);
break;
}
goto fsm_get;
case S_EOB:
if (c)
{
goto fsm_terminal;
SYNC();
return 0;
}
UNGETCHR();
{
#if PROTOMAIN
#endif
{
}
{
im -= c;
ie -= c;
}
if (aim)
aim -= c;
if (aie)
aie -= c;
{
{
}
*(ip + n) = 0;
goto fsm_splice;
goto fsm_get;
}
*ip = 0;
}
goto fsm_splice;
/* NOTE: RECURSIVE lex() should really SLIDE too */
{
goto fsm_next;
}
SYNC();
return 0;
case S_LITBEG:
quot = c;
#if PROTOMAIN
if (c == '"' && qe)
{
for (n = 0, t = qe + 1; t < op && (*t == ' ' || *t == '\t' || *t == '\n' && ++n || *t >= 'A' && *t <= 'Z' || *t == '_'); t++);
if (t == op)
{
qe = 0;
qn = n;
}
else PUTCHR(c);
}
else
#endif
PUTCHR(c);
goto fsm_get;
case S_LITEND:
if (c == quot)
{
#if PROTOMAIN
#endif
PUTCHR(c);
#if PROTOMAIN
while (qn > 0)
{
qn--;
PUTCHR('\n');
}
#endif
}
else if (c != '\n' && c != EOF)
{
PUTCHR(c);
goto fsm_get;
}
else
{
#if PROTOMAIN
while (qn > 0)
{
qn--;
PUTCHR('\n');
}
#endif
UNGETCHR();
}
c = T_INVALID;
break;
case S_LITESC:
#if PROTOMAIN
else
#endif
switch (c)
{
case 'a':
n = CC_bel;
goto fsm_oct;
case 'E':
n = CC_esc;
goto fsm_oct;
case 'v':
n = CC_vt;
goto fsm_oct;
case 'x':
SYNC();
for (n = x = 0; (c = GETCHR()), x < 3; x++) switch (c)
{
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9':
n = (n << 4) + c - '0';
break;
case 'a': case 'b': case 'c': case 'd':
case 'e': case 'f':
n = (n << 4) + c - 'a' + 10;
break;
case 'A': case 'B': case 'C': case 'D':
case 'E': case 'F':
n = (n << 4) + c - 'A' + 10;
break;
default:
goto fsm_hex;
}
UNGETCHR();
break;
default:
PUTCHR(c);
break;
}
goto fsm_get;
case S_MACRO:
UNGETCHR();
#if PROTOMAIN
{
c = T_EXTERN;
break;
}
#endif
else c = T_ID;
break;
case S_NL:
#if PROTOMAIN
{
PUTCHR(' ');
}
else
#endif
PUTCHR(c);
{
#if PROTOMAIN
{
{
*(ip - 1) = 0;
}
}
else
#endif
{
{
*(ip - 1) = 0;
{
op--;
if (*ip == '#')
{
}
else
{
op++;
while ((c = *ip) >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '_') *op++ = *ip++;
else *op++ = '"';
}
}
}
}
call = 0;
group = 0;
paren = 0;
last = '\n';
}
{
#if PROTOMAIN
#endif
SYNC();
return 0;
}
goto fsm_start;
case S_QUAL:
PUTCHR(c);
goto fsm_get;
case S_TOK:
PUTCHR(c);
break;
case S_TOKB:
UNGETCHR();
break;
case S_RESERVED:
UNGETCHR();
c = T_ID;
{
c = T_DO;
break;
c = T_DO;
break;
if (!(flags & RECURSIVE) && (flags & (DIRECTIVE|TOKENS)) != DIRECTIVE && !strncmp(proto->tp, "else", 4))
{
c = T_ELSE;
goto fsm_id;
}
break;
c = T_EXTERN;
break;
{
c = T_FOR;
goto fsm_id;
}
break;
c = T_IF;
break;
if (!strncmp(proto->tp, "inline", 6) && !(flags & (MATCH|SKIP|TOKENS|TYPEDEF)) && proto->brace == 0 && paren == 0 && group == 0 && (last == ';' || last == '}' || last == '\n' || last == 0))
{
SYNC();
SYNC();
}
break;
{
c = T_RETURN;
goto fsm_id;
}
break;
{
flags |= EXTERNALIZE;
}
break;
{
c = T_EXTERN;
}
break;
break;
{
else
{
SYNC();
{
}
else c = T_VOID;
SYNC();
}
}
break;
{
c = T_WHILE;
goto fsm_id;
}
break;
}
#if PROTOMAIN
c = T_ID;
#endif
break;
case S_VS:
goto fsm_start;
case S_WS:
UNGETCHR();
#if PROTOMAIN
{
op--;
}
#endif
goto fsm_start;
default:
{
if (c == '\\')
{
if (!(n = GETCHR()))
{
goto fsm_eob;
c = '\\';
n = GETCHR();
}
if (n == '\n')
{
PUTCHR('\\');
PUTCHR('\n');
goto fsm_get;
}
UNGETCHR();
}
goto fsm_terminal;
}
PUTCHR(c);
goto fsm_get;
}
{
{
case '(':
#if PROTOMAIN
#endif
{
if (paren++ == 0)
{
#if PROTOMAIN
#endif
{
#if PROTOMAIN
args = 0;
#endif
}
sub = 0;
}
{
sub++;
if (last == '(')
{
om = 0;
}
{
}
{
{
}
if (m == im)
{
om = 0;
}
}
{
om = 0;
}
}
}
break;
case ')':
#if PROTOMAIN
#endif
if (--paren == 0)
{
#if PROTOMAIN
{
if (group != 2)
{
c = T_ID;
break;
}
group++;
}
#endif
}
break;
case '*':
{
group--;
if (paren == 1)
{
}
}
break;
case '#':
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))
{
{
{
{
}
}
#if PROTOMAIN
{
n = 0;
t = ip + 6;
n = HASHKEYPART(n, *ip++);
switch (n)
{
{
}
break;
break;
/*FALLTHROUGH*/
/*FALLTHROUGH*/
default:
break;
}
}
else
#endif
{
if (*ip == 'i' && *++ip == 'n' && *++ip == 'c' && *++ip == 'l' && *++ip == 'u' && *++ip == 'd' && *++ip == 'e')
{
if (*ip++ == '<' && *ip++ == 's' && *ip++ == 't' && *ip++ == 'd' && *ip++ == 'a' && *ip++ == 'r' && *ip++ == 'g' && *ip++ == '.' && *ip++ == 'h' && *ip++ == '>')
{
if !defined(va_start)\n\
#if defined(__STDARG__)\n\
#include <stdarg.h>\n\
#else\n\
#include <varargs.h>\n\
#endif\n\
#endif\n\
");
break;
}
}
else if (*ip == 'd' && *++ip == 'e' && *++ ip == 'f' && *++ip == 'i' && *++ip == 'n' && *++ip == 'e' && (*++ip == ' ' || *ip == '\t'))
{
if (*ip == 'e' && *++ip == 'x' && *++ ip == 't' && *++ip == 'e' && *++ip == 'r' && *++ip == 'n' && (*++ip == ' ' || *ip == '\t'))
{
t = ip;
while (*++t == ' ' || *t == '\t');
if (*t == 'e' && *++t == 'x' && *++ t == 't' && *++t == 'e' && *++t == 'r' && *++t == 'n' && (*++t == ' ' || *t == '\t' || *t == '\n' || *t == '\r'))
ip = t;
t = ip;
while (*++t == ' ' || *t == '\t');
if (*t == '_' && *(t + 1) == '_')
{
break;
}
}
}
else if (*ip == 'u' && *++ip == 'n' && *++ ip == 'd' && *++ip == 'e' && *++ip == 'f' && (*++ip == ' ' || *ip == '\t'))
{
if (*ip == 'e' && *++ip == 'x' && *++ ip == 't' && *++ip == 'e' && *++ip == 'r' && *++ip == 'n' && (*++ip == ' ' || *ip == '\t' || *ip == '\n' || *ip == '\r'))
{
break;
}
}
}
}
break;
}
else
break;
/*FALLTHROUGH*/
case '{':
{
#if PROTOMAIN
{
{
if (args)
{
*v++ = ' ';
*v = 0;
}
ip--;
/*UNDENT...*/
v = ie;
{
e = ie - 1;
{
if (*ie == '*')
{
{
while (e > v && (*(e - 1) == ' ' || *(e - 1) == '\t')) e--;
if (e > v && *e != '\n') *e++ = ' ';
t = ie;
while (--e >= v)
*--t = *e;
v = t;
break;
}
}
}
}
ie = v;
/*...INDENT*/
{
v = op;
while (v > ko && *--v != ' ');
if (*v != ' ')
{
while (v >= ko + 4)
{
*v = *(v - 4);
v--;
}
}
if (*v == ' ')
{
while (*(v + 1) == '*')
*v++ = '*';
*v = '\t';
if ((v - ko) <= 8)
{
while (e > v)
{
*e = *(e - 1);
e--;
}
}
}
while (v >= ko + 7)
{
*v = *(v - 7);
v--;
}
}
PUTCHR('(');
t = op;
e = 0;
/*UNDENT...*/
{
{
}
{
{
m = op;
op--;
v = op;
op--;
op--;
if (!e)
{
e = op;
e--;
}
#else
#endif
while (v < m)
PUTCHR(*v++);
}
PUTCHR(',');
if (n)
{
if (x = !e) e = op - 1;
PUTCHR(' ');
m = t;
while (m < e)
PUTCHR(*m++);
if (x)
{
m = e;
while (*--e != ' ');
while (*(e - 1) == '*') e--;
op -= m - e;
}
}
else PUTCHR(' ');
if (!n)
{
t = op;
e = 0;
}
}
else if (*ie == '*')
{
}
else if (*ie == '(')
{
}
else if (*ie == ')')
{
}
else if ((flags & EXTERN) && (op == om || *(op - 1) == ' ') && *ie == 'r' && !strncmp(ie, "register", 8) && (*(ie + 8) == ' ' || *(ie + 8) == '\t' || *(ie + 8) == '\n'))
{
ie += 8;
}
}
/*...INDENT*/
PUTCHR(')');
{
PUTCHR(';');
PUTCHR('\n');
SYNCOUT();
KEEPOUT();
}
else
{
PUTCHR('\n');
}
ip++;
}
}
#endif
{
PUTCHR(',');
PUTCHR(' ');
PUTCHR('(');
{
}
else
{
group = 0;
brack = 0;
for (;;)
{
{
case '[':
brack++;
continue;
case ']':
brack--;
continue;
case '(':
continue;
case ')':
if (--paren == 0)
{
group = 0;
{
}
break;
}
continue;
case ',':
if (paren == 1)
{
group = 0;
{
}
PUTCHR(',');
PUTCHR(' ');
}
continue;
case T_ID:
{
}
continue;
default:
continue;
}
break;
}
PUTCHR(')');
PUTCHR(')');
}
{
n = *(ie - 1);
c = *ie;
*ie = 0;
*(ie - 1) = n;
*ie = c;
PUTCHR(')');
}
{
PUTCHR('\n');
PUTCHR('#');
}
}
}
call = 0;
group = 0;
break;
case '}':
{
#if PROTOMAIN
#endif
}
call = 0;
group = 0;
paren = 0;
break;
case '=':
{
else goto fsm_statement;
}
goto fsm_other;
case ',':
#if PROTOMAIN
{
else
{
args--;
}
break;
}
#endif
/*FALLTHROUGH*/
case ';':
#if PROTOMAIN
{
if (paren == 0)
{
{
call = 0;
group = 0;
{
SYNC();
return 0;
}
}
else
{
args--;
BACKOUT();
}
}
}
#endif
else if (paren == 0)
{
{
{
func[0] = 'F';
func = 0;
}
{
v = aim;
while (v < aie)
if (*v++ == ')') break;
{
else n = 11;
om += n;
v = op += n;
while (v >= ko + n)
{
*v = *(v - n);
v--;
}
else
{
*ko = ')';
{
*ko++ = ')';
}
}
}
}
{
if (*op != ')')
{
*--op = ')';
while ((x = *(op - 14)) >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z' || x >= '0' && x <= '9' || x == '_')
*--op = x;
}
}
;
{
PUTCHR(c);
}
else
{
else
{
PUTCHR(')');
}
PUTCHR(c);
}
{
call = 1;
group = 0;
break;
}
}
if (c == ';')
{
call = 0;
{
SYNC();
return 0;
}
}
group = 0;
}
break;
case T_DO:
case T_IF:
break;
case T_EXTERN:
#if PROTOMAIN
{
}
else
#endif
{
{
{
}
}
else
func = 0;
}
break;
case T_VARIADIC:
{
op -= 3;
SYNC();
return c;
}
break;
case T_VOID:
goto fsm_id;
case T_VA_START:
{
SYNC();
for (;;)
{
{
case 0:
case ';':
break;
case T_ID:
{
}
continue;
default:
continue;
}
break;
}
CACHE();
{
v = m;
n = e - m;
}
else
{
v = "ap";
n = 2;
}
group = 0;
for (;;)
{
{
case '(':
continue;
case ')':
if (--paren == 0)
{
{
{
}
PUTCHR(',');
PUTCHR(' ');
PUTCHR(')');
PUTCHR(';');
}
group = 0;
break;
}
continue;
case ',':
if (paren == 1)
{
{
{
}
PUTCHR(',');
PUTCHR(' ');
PUTCHR(')');
PUTCHR(';');
}
group = 0;
}
continue;
case T_ID:
if (group <= 1)
{
}
continue;
default:
continue;
}
break;
}
call = 0;
break;
}
/*FALLTHROUGH*/
case T_ID:
#if PROTOMAIN
{
break;
}
#endif
if (paren == 0)
{
if (last == ')')
{
}
}
c = T_ID;
break;
case T_INVALID:
{
n = 0;
for (;; op--)
{
switch (*(op - 1))
{
case 'f':
case 'F':
t = op;
while ((c = *--t) >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z');
if (*t == '.')
op--;
n = 0;
break;
case 'l':
case 'L':
if (!(n & 01))
{
n |= 01;
t = op;
while ((c = *--t) >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z');
if (*t == '.')
{
n = 0;
op--;
break;
}
}
continue;
case 'u':
case 'U':
n |= 02;
continue;
}
break;
}
if (n & 01)
*op++ = 'L';
if (n & 02)
{
m = op;
t = op = m + 10;
while ((c = *--m) >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
*--t = c;
c = *t;
*t = c;
break;
}
}
goto fsm_other;
#if PROTOMAIN
case '[':
/*FALLTHROUGH*/
#endif
default:
#if PROTOMAIN
#endif
break;
}
last = c;
#if PROTOMAIN
if ((flags & (EXTERN|MATCH)) == (EXTERN|MATCH) && ((flags & (DIRECTIVE|SKIP)) || proto->brace || c != '(' && c != ')' && c != '*' && c != T_ID))
CACHEOUT();
else
#endif
SYNCOUT();
goto fsm_start;
}
{
#if PROTOMAIN
t = 0;
else
#endif
{
if (c == '#')
{
if (*t++ == 'i' && *t++ == 'f' && *t++ == 'n' && *t++ == 'd' && *t++ == 'e' && *t++ == 'f')
{
#if !PROTOMAIN
while (*t == ' ' || *t == '\t') t++;
if (*t != '_')
#endif
t = 0;
}
}
else
t = "";
}
if (t)
{
#if PROTOMAIN
ip -= n;
op -= n;
#else
#endif
}
else
while (*ip != '\n')
goto fsm_start;
}
SYNC();
return c;
}
/*
* close a proto buffer stream
*/
void
{
}
/*
* open a new proto buffer stream
* read buffer pointer returned
* 0 returned on error or if no magic
*
* file !=0 file path to open, otherwise use fd
* fd open file fd if file==0
* notice !=0 copyright notice info commented at the top
* options !=0 additional notice name=value pairs, space or ; separated
* package !=0 generate header for this package
*/
char*
{
register char* iob;
register long n;
register char* s;
char* t;
int pragma;
int clr;
int hit;
int i;
int z;
char* b;
#if PROTOMAIN
int comlen;
#endif
int m = 0;
static int retain;
/*
* initialize proto
*/
#if PROTOMAIN
#endif
else retain &= PROTO_INITIALIZED;
#if !PROTOMAIN
{
else if (n > 2 * BLOCK) n = 0;
m = 1;
}
if (n > 0)
{
/*
* file read in one chunk
*/
return 0;
n = 0;
}
else
#endif
{
/*
* file read in BLOCK chunks
*/
n = BLOCK;
return 0;
}
if (!comment)
comment = "/*";
else if (comment[1])
{
}
else
/*
* read the first chunk
*/
if (n < 0)
{
return 0;
}
/*
* check for proto pragma in first block of lines
* pragma blanked out if found
*
* -1 no pragma
* 0 #pragma noprototyped
* 1 #pragma prototyped
*
* NOTE: matches may occur inside comments and quotes
*/
#if PROTOMAIN
if (!notice && !options || (comlen = astlicense(com, sizeof(com), NiL, "type=check", proto->cc[0], proto->cc[1], proto->cc[2])) <= 0)
*com = 0;
#endif
pragma = -1;
m = MAGICTOP;
{
while (*s == ' ' || *s == '\t')
s++;
if (*s == '#')
{
b = s++;
while (*s == ' ' || *s == '\t')
s++;
if (*s == *PRAGMADIR && !strncmp(s, PRAGMADIR, sizeof(PRAGMADIR) - 1) && (*(s += sizeof(PRAGMADIR) - 1) == ' ' || *s == '\t'))
{
clr = 0;
while (*s && *s != '\r' && *s != '\n')
{
for (; *s == ' ' || *s == '\t'; s++);
for (t = s; *s && *s != ' ' && *s != '\t' && *s != '\r' && *s != '\n'; s++);
z = s - t;
for (i = 0; i < elementsof(pragmas); i++)
{
clr = 1;
{
case HIT_noticed:
break;
case HIT_prototyped:
break;
}
}
}
if (clr)
{
#if PROTOMAIN
#endif
for (; b < s; *b++ = ' ');
}
}
}
{
pragma = 0;
break;
}
#if PROTOMAIN
else if (*s == '%' && *(s + 1) == '{')
else if (!(hit & HIT_noticed))
{
{
hit |= HIT_noticed;
}
else
for (i = 0; i < elementsof(notices); i++)
{
{
while (*s == ' ' || *s == '\t')
s++;
if (*s == '(' && (*(s + 1) == 'c' || *(s + 1) == 'C') && *(s + 2) == ')' || *s >= '0' && *s <= '9' && *(s + 1) >= '0' && *(s + 1) <= '9')
{
}
}
else
{
}
break;
}
}
#endif
while (*s && *s++ != '\n');
}
#if PROTOMAIN
if (flags & PROTO_CLASSIC) pragma = -pragma;
if (flags & PROTO_DISABLE) pragma = 0;
if (!(proto->flags & YACC) && file && (m = strlen(file)) > 2 && file[--m] == 'y' && file[--m] == '.')
#endif
if (pragma <= 0)
{
if (flags & PROTO_PLUSPLUS)
{
}
{
return 0;
}
{
{
{
while (*s && *s++ != '\n');
}
#if PROTOMAIN
{
if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
else
}
#endif
}
return iob;
}
}
#if PROTOMAIN
if (!(retain & PROTO_INITIALIZED))
{
}
#endif
#if CHUNK >= 512
{
#if PROTOMAIN
{
if ((comlen = astlicense(proto->op, proto->oz, notice, options, proto->cc[0], proto->cc[1], proto->cc[2])) < 0)
else
}
#endif
if (flags & PROTO_INCLUDE)
{
if (flags & PROTO_RETAIN)
retain |= PROTO_INCLUDE;
}
else if (flags & PROTO_HEADER)
{
#if PROTOMAIN
if (flags & PROTO_CLASSIC)
{
}
else
#endif
}
#if PROTOMAIN
if (!(flags & PROTO_CLASSIC))
{
{
}
else
{
if (n)
}
}
#endif
}
#endif
#if PROTOMAIN
if (flags & PROTO_CLASSIC)
{
}
#endif
return iob;
}
/*
* read next proto'd chunk into iob
* the chunk is 0 terminated and its size is returned
*/
int
{
register int n;
{
{
}
else if ((n = read(proto->fd, proto->ob, proto->oz)) <= 0 || (proto->options & REGULAR) && n < proto->oz)
{
}
}
else
{
{
#if PROTOMAIN
{
if (!*ip)
{
{
if (n < 0) n = 0;
}
ip[n] = 0;
}
{
if (*ip == '%')
{
}
}
{
ip++;
if (n == '%')
{
{
break;
}
if (!*ip)
{
*op++ = '%';
break;
}
}
}
}
else
#endif
}
}
return n;
}
#if !PROTOMAIN
/*
* drop control of iob after first pppread()
* return value is input fd
* if fd<0 then all data in iob
*/
int
{
{
}
return -1;
}
#endif