2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: shipproto.c /main/5 1995/11/01 16:03:47 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
31 * Copyright (c) 1995 AT&T Corp. *
32 * All Rights Reserved *
34 * This software is licensed by AT&T Corp. *
35 * under the terms and conditions of the license in *
36 * http://www.research.att.com/orgs/ssr/book/reuse *
38 * This software was created by the *
39 * Software Engineering Research Department *
40 * AT&T Bell Laboratories *
42 * For further information contact *
43 * gsf@research.att.com *
45 ***************************************************************/
47 /* : : generated by proto : : */
49 #if !defined(__PROTO__)
50 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
51 #if defined(__cplusplus)
52 #define __MANGLE__ "C"
57 #define __PROTO__(x) x
59 #define __PARAM__(n,o) n
60 #if !defined(__STDC__) && !defined(__cplusplus)
61 #if !defined(c_plusplus)
72 #define __PROTO__(x) ()
73 #define __OTORP__(x) x
74 #define __PARAM__(n,o) o
82 #if defined(__cplusplus) || defined(c_plusplus)
83 #define __VARARG__ ...
87 #if defined(__STDARG__)
88 #define __VA_START__(p,a) va_start(p,a)
90 #define __VA_START__(p,a) va_start(p)
93 #line 1 "/home/gsf/src/cmd/proto/proto.c"
103 # define ctime _huh_ctime
105 # include <sys/types.h>
106 # include <sys/stat.h>
112 # define remove(x) unlink(x)
113 # define rename(x,y) ((link(x,y)||remove(x))?-1:0)
124 replace __PARAM__((const char* newfile, const char* oldfile, int preserve), (newfile, oldfile, preserve)) __OTORP__(const char* newfile; const char* oldfile; int preserve;){
128 if (preserve && stat(oldfile, &st) || remove(oldfile) || rename(newfile, oldfile))
134 preserve = utime(oldfile, ut);
139 #line 1 "../../lib/libpp/ppproto.c"
152 static const char id[] = "\n@(#)proto (AT&T Bell Laboratories) 05/09/95\000\n";
156 #line 1 "../../lib/libpp/ppfsm.c"
166 #line 1 "../../lib/libpp/pplib.h"
268 typedef char* (*PPBUILTIN) __PROTO__((char*, const char*, const char*));
269 typedef void (*PPCOMMENT) __PROTO__((const char*, const char*, const char*, int));
270 typedef void (*PPINCREF) __PROTO__((const char*, const char*, int, int));
271 typedef void (*PPLINESYNC) __PROTO__((int, const char*));
272 typedef void (*PPMACREF) __PROTO__((struct ppsymbol*, const char*, int, int, unsigned long));
273 typedef int (*PPOPTARG) __PROTO__((int, int, const char*));
274 typedef void (*PPPRAGMA) __PROTO__((const char*, const char*, const char*, const char*, int));
279 struct ppinstk* next;
280 struct ppinstk* prev;
285 struct ppsymbol* symbol;
287 struct ppindex* index;
320 struct ppmacro* macro;
327 struct ppmacstk* next;
328 struct ppmacstk* prev;
335 struct ppdirs* archive;
336 unsigned long offset;
378 #line 1 "../../lib/libpp/pp.h"
697 unsigned char c; unsigned char hosted; unsigned char index; unsigned char type; union { char* buffer; char* sp; struct ppdirs* subdir; } info;
714 int size; char* formals;
723 struct ppmacro* macro;
727 struct pphide* hidden;
747 struct ppsymbol* symbol;
753 unsigned long offset;
756 struct ppdirs* lcldirs; struct ppdirs* stddirs; int flags; char* symtab;
760 struct ppcontext* context; long state; long mode; long option; long test; char* filedeps; struct ppdirs* firstdir; struct ppdirs* lastdir; int hide; int column; int pending; char* firstfile; char* lastfile; char* ignore; char* probe; char* filtab; char* prdtab; char* date; char* time; char* maps; long ro_state; long ro_mode; long ro_option; char* cdir; char* hostdir; char* ppdefault; struct ppindex* firstindex; struct ppindex* lastindex; struct oplist* firstop; struct oplist* lastop; struct oplist* firsttx; struct oplist* lasttx; unsigned char arg_file; unsigned char arg_mode; unsigned char arg_style; unsigned char c; unsigned char hosted; unsigned char ignoresrc; unsigned char initialized; unsigned char standalone; unsigned char spare_1;
764 char* checkpoint; int constack; struct ppinstk* in; char* addp; char* args; char* addbuf; char* catbuf; char* path; char* tmpbuf; char* valbuf; char* include; char* prefix; struct ppmember* member; int hidden; int hiding; int level; struct { int input; int output; } pool; int truncate; struct ppmacstk* macp; char* maxmac; char* mactop; char* toknxt; long* control; long* maxcon; struct oplist* chop; struct ppfile* insert; struct ppfile* original; char* dirtab; char* strtab; PPBUILTIN builtin; PPCOMMENT comment; PPINCREF incref; PPLINESYNC linesync; PPLINESYNC olinesync; PPMACREF macref; PPOPTARG optarg; PPPRAGMA pragma; struct counter counter;
775 extern __MANGLE__ struct ppglobals pp;
776 extern __MANGLE__ char _pp_ctype[];
778 extern __MANGLE__ int ppargs __PROTO__((char**, int));
779 extern __MANGLE__ void ppcpp __PROTO__((void));
780 extern __MANGLE__ void ppcomment __PROTO__((char*, char*, char*, int));
781 extern __MANGLE__ __V_* ppcontext __PROTO__((__V_*, int));
782 extern __MANGLE__ void pperror __PROTO__((int, ...));
783 extern __MANGLE__ void ppincref __PROTO__((char*, char*, int, int));
784 extern __MANGLE__ void ppinput __PROTO__((char*, char*, int));
785 extern __MANGLE__ int pplex __PROTO__((void));
786 extern __MANGLE__ void ppline __PROTO__((int, char*));
787 extern __MANGLE__ void ppmacref __PROTO__((struct ppsymbol*, char*, int, int));
788 extern __MANGLE__ void ppop __PROTO__((int, ...));
789 extern __MANGLE__ void pppragma __PROTO__((char*, char*, char*, char*, int));
790 extern __MANGLE__ int ppprintf __PROTO__((char*, ...));
793 #line 313 "../../lib/libpp/pplib.h"
795 #line 1 "../../lib/libpp/ppdef.h"
963 #line 314 "../../lib/libpp/pplib.h"
965 #line 1 "../../lib/libpp/ppkey.h"
1084 extern __MANGLE__ struct ppkeyword ppkey[];
1087 #line 315 "../../lib/libpp/pplib.h"
1290 struct ppdirs* lcldirs; struct ppdirs* stddirs; int flags; char* symtab;
1291 struct ppcontext* context; long state; long mode; long option; long test; char* filedeps; struct ppdirs* firstdir; struct ppdirs* lastdir; int hide; int column; int pending; char* firstfile; char* lastfile; char* ignore; char* probe; char* filtab; char* prdtab; char* date; char* time; char* maps; long ro_state; long ro_mode; long ro_option; char* cdir; char* hostdir; char* ppdefault; struct ppindex* firstindex; struct ppindex* lastindex; struct oplist* firstop; struct oplist* lastop; struct oplist* firsttx; struct oplist* lasttx; unsigned char arg_file; unsigned char arg_mode; unsigned char arg_style; unsigned char c; unsigned char hosted; unsigned char ignoresrc; unsigned char initialized; unsigned char standalone; unsigned char spare_1;
1297 struct ppsymbol* guard;
1298 struct ppfile* bound[3];
1306 struct ppindex* next;
1307 struct ppfile* file;
1308 unsigned long begin;
1316 struct ppsymbol sym;
1334 extern __MANGLE__ int access __PROTO__((const char*, int));
1335 extern __MANGLE__ __V_* calloc __PROTO__((size_t, size_t));
1336 extern __MANGLE__ int close __PROTO__((int));
1337 extern __MANGLE__ int creat __PROTO__((const char*, int));
1338 extern __MANGLE__ char* ctime __PROTO__((time_t*));
1339 extern __MANGLE__ void exit __PROTO__((int));
1340 extern __MANGLE__ void free __PROTO__((__V_*));
1341 extern __MANGLE__ int link __PROTO__((const char*, const char*));
1342 extern __MANGLE__ int open __PROTO__((const char*, int, ...));
1343 extern __MANGLE__ int read __PROTO__((int, __V_*, int));
1344 extern __MANGLE__ int strncmp __PROTO__((const char*, const char*, size_t));
1345 extern __MANGLE__ time_t time __PROTO__((time_t*));
1346 extern __MANGLE__ int unlink __PROTO__((const char*));
1347 extern __MANGLE__ int write __PROTO__((int, const __V_*, int));
1358 extern __MANGLE__ void ppassert __PROTO__((int, char*, char*));
1359 extern __MANGLE__ void ppbuiltin __PROTO__((void));
1360 extern __MANGLE__ int ppcall __PROTO__((struct ppsymbol*, int));
1361 extern __MANGLE__ int ppcontrol __PROTO__((void));
1362 extern __MANGLE__ void ppdump __PROTO__((void));
1363 extern __MANGLE__ char* ppexpand __PROTO__((char*));
1364 extern __MANGLE__ long ppexpr __PROTO__((int*));
1365 extern __MANGLE__ void ppfsm __PROTO__((int, char*));
1366 extern __MANGLE__ char* ppinstr __PROTO__((struct ppinstk*));
1367 extern __MANGLE__ char* ppkeyname __PROTO__((int, int));
1368 extern __MANGLE__ char* pplexstr __PROTO__((int));
1369 extern __MANGLE__ void ppload __PROTO__((char*));
1370 extern __MANGLE__ char* ppmodestr __PROTO__((long));
1371 extern __MANGLE__ int ppmultiple __PROTO__((struct ppfile*, struct ppsymbol*));
1372 extern __MANGLE__ void ppnest __PROTO__((void));
1373 extern __MANGLE__ int ppoption __PROTO__((char*));
1374 extern __MANGLE__ char* ppoptionstr __PROTO__((long));
1375 extern __MANGLE__ void pppclose __PROTO__((char*));
1376 extern __MANGLE__ int pppdrop __PROTO__((char*));
1377 extern __MANGLE__ char* pppopen __PROTO__((char*, int, char*, int));
1378 extern __MANGLE__ int pppread __PROTO__((char*));
1379 extern __MANGLE__ int pppredargs __PROTO__((void));
1380 extern __MANGLE__ void pppush __PROTO__((int, char*, char*, int));
1381 extern __MANGLE__ struct ppsymbol* pprefmac __PROTO__((char*, int));
1382 extern __MANGLE__ int ppsearch __PROTO__((char*, int, int));
1383 extern __MANGLE__ char* ppstatestr __PROTO__((long));
1384 extern __MANGLE__ char* pptokstr __PROTO__((char*, int));
1385 extern __MANGLE__ void pptrace __PROTO__((int));
1388 #line 11 "../../lib/libpp/ppfsm.c"
1390 #line 1 "../../lib/libpp/ppfsm.h"
1569 extern __MANGLE__ short _pp_fsmtab[(0+26)+1][255+1];
1575 extern __MANGLE__ char _pp_trigraph[255+1];
1577 extern __MANGLE__ void _pp_refill __PROTO__((int));
1580 #line 12 "../../lib/libpp/ppfsm.c"
1601 unsigned char ch[4];
1605 static struct fsminit fsminit[] =
1608 { 0, { 6 }, ((0+26)+11), },
1610 { 0, { 2 }, (0+21), },
1611 { 0, { '.' }, (0+23), },
1612 { 0, { 1 }, (0+17), },
1613 { 0, { 'L' }, (0+18), },
1614 { 0, { 'd', 'e', 'f', 'i' }, (0+1), },
1615 { 0, { 'r', 't', 'v', 'w' }, (0+1), },
1616 { 0, { '"', '\'' }, ((0+26)+3), },
1617 { 0, { '/' }, (0+10), },
1618 { 0, { '\n' }, ((0+26)+7), },
1619 { 0, { ' ','\t','\f','\013' }, (0+25), },
1622 { (0+1), { 6 }, ((0+26)+6), },
1623 { (0+1), { 1, 2 }, (0+17), },
1624 { (0+1), { 'a' }, (0+2), },
1625 { (0+1), { 'e' }, (0+3), },
1626 { (0+1), { 'f' }, (0+4), },
1627 { (0+1), { 'h' }, (0+5), },
1628 { (0+1), { 'l' }, (0+6), },
1629 { (0+1), { 'o' }, (0+7), },
1630 { (0+1), { 'x' }, (0+8), },
1631 { (0+1), { 'y' }, (0+9), },
1634 { (0+2), { 6 }, (((0+26)+12)), },
1635 { (0+2), { 1, 2 }, (0+17), },
1636 { (0+2), { '_','s','t','a' }, (0+2), },
1637 { (0+2), { 'r' }, (0+2), },
1640 { (0+3), { 6 }, (((0+26)+12)), },
1641 { (0+3), { 1, 2 }, (0+17), },
1642 { (0+3), { 't','u','r','n' }, (0+3), },
1645 { (0+4), { 6 }, (((0+26)+12)), },
1646 { (0+4), { 1, 2 }, (0+17), },
1649 { (0+5), { 6 }, (((0+26)+12)), },
1650 { (0+5), { 1, 2 }, (0+17), },
1651 { (0+5), { 'i','l','e' }, (0+5), },
1654 { (0+6), { 6 }, (((0+26)+12)), },
1655 { (0+6), { 1, 2 }, (0+17), },
1656 { (0+6), { 's','e' }, (0+6), },
1659 { (0+7), { 6 }, (((0+26)+12)), },
1660 { (0+7), { 1, 2 }, (0+17), },
1661 { (0+7), { 'r', 'i','d' }, (0+7), },
1664 { (0+8), { 6 }, (((0+26)+12)), },
1665 { (0+8), { 1, 2 }, (0+17), },
1666 { (0+8), { 't','e','r','n' }, (0+8), },
1669 { (0+9), { 6 }, (((0+26)+12)), },
1670 { (0+9), { 1, 2 }, (0+17), },
1671 { (0+9), { 'p','e','d','f' }, (0+9), },
1674 { (0+10), { 6 }, ((0+26)+0), },
1675 { (0+10), { '*' }, (0+11), },
1677 { (0+10), { '/' }, (0+14), },
1681 { (0+11), { 6 }, (0+11), },
1682 { (0+11), { '\n', 5 }, ((0+26)+1), },
1683 { (0+11), { '/' }, (0+13), },
1684 { (0+11), { '*' }, (0+12), },
1685 { (0+11), { '#', ';', ')' }, ((( (0+11))<<(7+1))|(((0+26)+8))), },
1688 { (0+12), { 6 }, (0+11), },
1689 { (0+12), { '\n', 5 }, ((0+26)+1), },
1690 { (0+12), { '#', ';', ')' }, ((( (0+11))<<(7+1))|(((0+26)+8))), },
1691 { (0+12), { '*' }, (0+12), },
1692 { (0+12), { '/' }, ((0+26)+1), },
1695 { (0+13), { 6 }, (0+11), },
1696 { (0+13), { '*', '\n', 5 }, ((0+26)+1), },
1697 { (0+13), { '/' }, (0+13), },
1700 { (0+14), { 6 }, (0+14), },
1701 { (0+14), { '\n', 5 }, ((0+26)+1), },
1702 { (0+14), { '/' }, (0+15), },
1703 { (0+14), { '*' }, (0+16), },
1706 { (0+15), { 6 }, (0+14), },
1707 { (0+15), { '*', '\n', 5 }, ((0+26)+1), },
1708 { (0+15), { '/' }, (0+15), },
1711 { (0+16), { 6 }, (0+14), },
1712 { (0+16), { '\n', 5 }, ((0+26)+1), },
1713 { (0+16), { '*' }, (0+16), },
1714 { (0+16), { '/' }, ((0+26)+1), },
1717 { (0+17), { 6 }, ((0+26)+6), },
1718 { (0+17), { 1, 2 }, (0+17), },
1721 { (0+23), { 6 }, ((0+26)+0), },
1722 { (0+23), { '.' }, (0+24), },
1723 { (0+23), { 2 }, (0+21), },
1726 { (0+24), { 6 }, (((( (0401+1))-0401)<<(7+1))|( ((0+26)+14))), },
1727 { (0+24), { '.' }, (((( (0401+29))-0401)<<(7+1))|( ((0+26)+13))), },
1730 { (0+18), { 6 }, ((0+26)+6), },
1731 { (0+18), { 1, 2 }, (0+17), },
1732 { (0+18), { '"', '\'' }, ((( (0+19))<<(7+1))|(((0+26)+8))), },
1735 { (0+19), { 6 }, (0+19), },
1736 { (0+19), { '"', '\'' }, ((0+26)+4), },
1737 { (0+19), { '\n', 5 }, ((0+26)+4), },
1738 { (0+19), { '\\' }, (0+20), },
1741 { (0+20), { 6 }, ((0+26)+5), },
1742 { (0+20), { '\n', 5 }, ((0+26)+4), },
1745 { (0+21), { 6 }, (((( (0401+1))-0401)<<(7+1))|( ((0+26)+14))), },
1746 { (0+21), { 1, 2, '.' }, (0+21), },
1747 { (0+21), { 'e', 'E' }, (0+22), },
1750 { (0+22), { 6 }, (((( (0401+1))-0401)<<(7+1))|( ((0+26)+14))), },
1751 { (0+22), { 1, 2, '.' }, (0+21), },
1752 { (0+22), { '+', '-' }, (0+21), },
1755 { (0+25), { 6 }, ((0+26)+15), },
1756 { (0+25), { ' ', '\t' }, (0+25), },
1757 { (0+25), { '\f', '\013' }, ((0+26)+10), },
2018 short _pp_fsmtab[(0+26)+1][255+1];
2020 char _pp_trigraph[255+1];
2023 static char spl[] = { '\\', '\r', 0 };
2024 static char aln[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$@";
2029 static char* let = &aln[10];
2030 static char hex[] = "fedcbaFEDCBA9876543210";
2031 static char* dec = &hex[12];
2032 static char* oct = &hex[14];
2040 ppfsm __PARAM__((int op, register char* s), (op, s)) __OTORP__(int op; register char* s;){
2045 register struct fsminit* fp;
2082 for (fp = fsminit;; fp++)
2084 if ((n = fp->nextstate) >= (0+26)) n = ~n;
2085 if (fp->state == (-1))
2102 rp = _pp_fsmtab[fp->state];
2103 for (i = 0; i < sizeof(fp->ch) && (c = fp->ch[i]); i++)
2108 for (c = 0; c <= 255; c++)
2113 _pp_fsmtab[(0+26)][fp->state+1] = n < 0 ? ~n : n;
2146 for (i = 0; i < (0+26); i++)
2151 if (c != '@' || !(( rp)>=_pp_fsmtab[(0+11)]&&( rp)<=_pp_fsmtab[(0+13)]||(( rp)>=_pp_fsmtab[(0+14)]&&( rp)<=_pp_fsmtab[(0+16)])))
2153 if (rp[c] >= 0) rp[c] = ~rp[c];
2156 rp[0] = ~((0+26)+2);
2157 for (c = 0; c <= 255; c++)
2161 _pp_fsmtab[(0+26)][0] = ~((0+26)+2);
2409 #line 18 "../../lib/libpp/ppproto.c"
2559 sstrlen __PARAM__((register char* s), (s)) __OTORP__(register char* s;){
2562 for (b = s; *s; s++);
2571 sstrncmp __PARAM__((register char* s, register char* t, register int n), (s, t, n)) __OTORP__(register char* s; register char* t; register int n;){
2572 register char* e = s + n;
2576 if (*s != *t || !*s) return(*s - *t);
2588 memcopy __PARAM__((register char* s, register char* t, int n), (s, t, n)) __OTORP__(register char* s; register char* t; int n;){
2589 register char* e = t + n;
2591 while (t < e) *s++ = *t++;
2600 strcopy __PARAM__((register char* s, register char* t), (s, t)) __OTORP__(register char* s; register char* t;){
2601 while (*s++ = *t++);
2615 comment __PARAM__((register char* p, register char* s, register int n, int u), (p, s, n, u)) __OTORP__(register char* p; register char* s; register int n; int u;){
2623 *p++ = (n > 0) ? '/' : '*';
2625 while (p < e) *p++ = '*';
2626 *p++ = (n > 0) ? '*' : '/';
2634 e = p + (62 - n) / 2;
2636 while (p < e) *p++ = ' ';
2641 if (u && n >= 'a' && n <= 'z') n = n - 'a' + 'A';
2645 while (p < e) *p++ = ' ';
2678 copyright __PARAM__((register char* p, register char* s), (p, s)) __OTORP__(register char* p; register char* s;){
2690 for (i = 0; i < 5; i++)
2691 notice.item[i].data = 0;
2695 while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
2700 while (c && c != '=' && c != ' ' && c != '\t' && c != '\n' && c != '\r')
2703 h = (h << 5) + c - 'a';
2708 n = (*++s == '"' || *s == '\'') ? *s++ : 0;
2710 while ((c = *s) && (n && c != n || !n && c != ' ' && c != '\t' && c != '\n' && c != '\r'))
2714 case ((('c'-'a')<<25)|(('o'-'a')<<20)|(('m'-'a')<<15)|(('p'-'a')<<10)|(('a'-'a')<<5)|('n'-'a')):
2717 case ((('c'-'a')<<25)|(('o'-'a')<<20)|(('n'-'a')<<15)|(('t'-'a')<<10)|(('a'-'a')<<5)|('c'-'a')):
2720 case ((('c'-'a')<<25)|(('o'-'a')<<20)|(('r'-'a')<<15)|(('p'-'a')<<10)|(('o'-'a')<<5)|('r'-'a')):
2723 case ((('l'-'a')<<25)|(('i'-'a')<<20)|(('c'-'a')<<15)|(('e'-'a')<<10)|(('n'-'a')<<5)|('s'-'a')):
2726 case ((('o'-'a')<<25)|(('r'-'a')<<20)|(('g'-'a')<<15)|(('a'-'a')<<10)|(('n'-'a')<<5)|('i'-'a')):
2729 case ((('t'-'a')<<15)|(('y'-'a')<<10)|(('p'-'a')<<5)|('e'-'a')):
2730 if (!sstrncmp( v, "proprietary", 11))
2732 else if (!sstrncmp( v, "nonexclusive", 11))
2739 if (c >= 0 && (notice.item[c].size = s - v))
2740 notice.item[c].data = v;
2744 while (c && c != '\n')
2746 if (notice.item[i].size = s - x)
2748 notice.item[i].data = x;
2751 notice.item[3].data = v = x;
2752 while ((c = *x) && c != '\n' && c != ' ' && (c < 'a' || c > 'z'))
2754 if ((c = (x - v)) >= 3)
2756 notice.item[3].size = c++;
2757 notice.item[0].data += c;
2758 notice.item[0].size -= c;
2760 else notice.item[3].data = 0;
2768 p = comment(p, ((char*)0), 1, 0);
2769 p = comment(p, ((char*)0), 0, 0);
2771 if (notice.type == 2)
2773 if ((x = notice.item[i = 3].data) || (x = notice.item[i = 0].data))
2775 s = memcopy(s, x, notice.item[i].size);
2780 s = strcopy(s, "Proprietary");
2781 p = comment(p, buf, s - buf, 1);
2782 p = comment(p, ((char*)0), 0, 0);
2783 if (notice.item[4].data)
2785 s = strcopy(buf, "This is proprietary source code");
2786 if (notice.item[3].data || notice.item[0].data)
2787 s = strcopy(s, " licensed by");
2788 p = comment(p, buf, s - buf, 1);
2789 if (x = notice.item[3].data)
2791 s = memcopy(buf, x, notice.item[3].size);
2792 s = strcopy(s, " Corp.");
2793 p = comment(p, buf, s - buf, 1);
2795 else if (x = notice.item[0].data)
2796 p = comment(p, x, notice.item[0].size, 1);
2800 s = strcopy(buf, "This is unpublished proprietary source code");
2801 if (x) s = strcopy(s, " of");
2802 p = comment(p, buf, s - buf, 1);
2804 if (x = notice.item[3].data)
2805 s = memcopy(s, x, notice.item[3].size);
2806 if (x = notice.item[0].data)
2810 s = memcopy(s, x, notice.item[0].size);
2813 p = comment(p, buf, s - buf, 1);
2814 p = comment( p, "and is not to be disclosed or used except in",sizeof( "and is not to be disclosed or used except in")-1, 1);
2815 p = comment( p, "accordance with applicable agreements",sizeof( "accordance with applicable agreements")-1, 1);
2817 p = comment(p, ((char*)0), 0, 0);
2819 else if (notice.type == 1)
2821 p = comment( p, "For nonexclusive individual use",sizeof( "For nonexclusive individual use")-1, 1);
2822 p = comment(p, ((char*)0), 0, 0);
2824 s = strcopy(buf, "Copyright (c) ");
2826 s = memcopy(s, ctime(&clock) + 20, 4);
2827 if (x = notice.item[3].data)
2830 s = memcopy(s, x, notice.item[3].size);
2832 s = strcopy(s, "Corp.");
2834 else if (x = notice.item[0].data)
2837 s = memcopy(s, x, notice.item[0].size);
2839 p = comment(p, buf, s - buf, 0);
2840 if (notice.type == 2)
2842 if (!notice.item[4].data)
2843 p = comment( p, "Unpublished & Not for Publication",sizeof( "Unpublished & Not for Publication")-1, 0);
2844 p = comment( p, "All Rights Reserved",sizeof( "All Rights Reserved")-1, 0);
2846 p = comment(p, ((char*)0), 0, 0);
2847 if (notice.item[4].data)
2849 s = strcopy(buf, "This software is licensed");
2850 if (x = notice.item[3].data)
2852 s = strcopy(s, " by ");
2853 s = memcopy(s, x, notice.item[3].size);
2855 s = strcopy(s, "Corp.");
2857 else if (x = notice.item[0].data)
2859 s = strcopy(s, " by ");
2860 s = memcopy(s, x, notice.item[0].size);
2862 p = comment(p, buf, s - buf, 0);
2863 p = comment( p, "under the terms and conditions of the license in",sizeof( "under the terms and conditions of the license in")-1, 0);
2864 p = comment(p, notice.item[4].data, notice.item[4].size, 0);
2865 p = comment(p, ((char*)0), 0, 0);
2867 else if (notice.type == 2)
2869 p = comment( p, "The copyright notice above does not evidence any",sizeof( "The copyright notice above does not evidence any")-1, 0);
2870 p = comment( p, "actual or intended publication of such source code",sizeof( "actual or intended publication of such source code")-1, 0);
2871 p = comment(p, ((char*)0), 0, 0);
2873 if (x = notice.item[1].data)
2875 p = comment( p, "This software was created by the",sizeof( "This software was created by the")-1, 0);
2876 p = comment(p, x, notice.item[1].size, 0);
2878 if (x = notice.item[3].data)
2879 s = memcopy(s, x, notice.item[3].size);
2880 if (x = notice.item[0].data)
2884 s = memcopy(s, x, notice.item[0].size);
2887 p = comment(p, buf, s - buf, 0);
2888 p = comment(p, ((char*)0), 0, 0);
2890 if (x = notice.item[2].data)
2892 p = comment( p, "For further information contact",sizeof( "For further information contact")-1, 0);
2893 p = comment(p, x, notice.item[2].size, 0);
2894 p = comment(p, ((char*)0), 0, 0);
2896 p = comment(p, ((char*)0), -1, 0);
2912 number __PARAM__((register char* p, register long n), (p, n)) __OTORP__(register char* p; register long n;){
2915 for (d = 1000000; d > 1; d /= 10)
2916 if (n >= d) *p++ = '0' + (n / d) % 10;
2917 *p++ = '0' + n % 10;
2927 proto_error __PARAM__((char* iob, int level, char* msg, char* arg), (iob, level, msg, arg)) __OTORP__(char* iob; int level; char* msg; char* arg;){
2931 p = strcopy(buf, "proto: ");
2934 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
2941 p = strcopy(p, proto->file);
2946 p = strcopy(p, "line ");
2947 p = number(p, proto->line);
2949 else if (proto->file) p = strcopy(p, proto->file);
2953 p = strcopy(p, msg);
2959 if (level == 1) p = strcopy(p, "warning: ");
2960 p = strcopy(p, msg);
2964 p = strcopy(p, arg);
2967 write(2, buf, p - buf);
2968 if (level >= 3) exit(level - 2);
2969 if (level >= 2) errors++;
2980 linesync __PARAM__((register struct proto* proto, register char* p, register long n), (proto, p, n)) __OTORP__(register struct proto* proto; register char* p; register long n;){
2982 if (proto->flags & (1L<<12))
2985 p = strcopy(p, "\n#line ");
3002 init __PARAM__((char* op, int flags), (op, flags)) __OTORP__(char* op; int flags;){
3003 if (flags & (1L<<9)) op = strcopy(op, "\
3005 #if !defined(__PROTO__)\n\
3006 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)\n\
3007 #if defined(__cplusplus)\n\
3008 #define __MANGLE__ \"C\"\n\
3010 #define __MANGLE__\n\
3012 #define __STDARG__\n\
3013 #define __PROTO__(x) x\n\
3014 #define __OTORP__(x)\n\
3015 #define __PARAM__(n,o) n\n\
3016 #if !defined(__STDC__) && !defined(__cplusplus)\n\
3017 #if !defined(c_plusplus)\n\
3023 #define __V_ char\n\
3025 #define __V_ void\n\
3028 #define __PROTO__(x) ()\n\
3029 #define __OTORP__(x) x\n\
3030 #define __PARAM__(n,o) o\n\
3031 #define __MANGLE__\n\
3032 #define __V_ char\n\
3038 #if defined(__cplusplus) || defined(c_plusplus)\n\
3039 #define __VARARG__ ...\n\
3041 #define __VARARG__\n\
3043 #if defined(__STDARG__)\n\
3044 #define __VA_START__(p,a) va_start(p,a)\n\
3046 #define __VA_START__(p,a) va_start(p)\n\
3050 else op = strcopy(op, "\
3052 #if !defined(__PROTO__)\n\
3053 #include <prototyped.h>\n\
3080 lex __PARAM__((register struct proto* proto, register long flags), (proto, flags)) __OTORP__(register struct proto* proto; register long flags;){
3114 ((ip=proto->ip),(op=proto->op));
3116 if (flags & (1L<<5)) (ko=op);
3124 rp = _pp_fsmtab[state];
3126 while (!(state = rp[c = (*(unsigned char*)ip++)]));
3129 } while (state > 0);
3130 if ((n = ip - bp - 1) > 0)
3133 do switch( n) { default : memcpy( op, ip, n); op += n; ip += n; break; case 7 : * op++ = * ip++; case 6 : * op++ = * ip++; case 5 : * op++ = * ip++; case 4 : * op++ = * ip++; case 3 : * op++ = * ip++; case 2 : * op++ = * ip++; case 1 : * op++ = * ip++; case 0 : break; } while (0);
3138 switch ((( state)&((1<<(7+1))-1)))
3141 if (op > proto->ob && *(op - 1) == '=' && (op == proto->ob + 1 || *(op - 2) != '=')) switch (c)
3162 if ((( rp)>=_pp_fsmtab[(0+14)]&&( rp)<=_pp_fsmtab[(0+16)])) goto fsm_newline;
3165 rp = _pp_fsmtab[(0+11)];
3169 if ((flags & ((1L<<5)|(1L<<14))) == (1L<<5)) (op=ko);
3173 if ((( rp)>=_pp_fsmtab[(0+14)]&&( rp)<=_pp_fsmtab[(0+16)]))
3175 rp = _pp_fsmtab[(0+14)];
3183 if ((flags & ((1L<<5)|(1L<<14))) == (1L<<5)) (op=ko);
3187 rp = _pp_fsmtab[(( rp)>=_pp_fsmtab[(0+14)]&&( rp)<=_pp_fsmtab[(0+16)]) ? (0+14) : (0+12)];
3196 if (state = _pp_fsmtab[(0+26)][((( rp)-_pp_fsmtab[0])/(255+1))+1])
3198 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3203 if ((flags & ((1L<<1)|((1L<<15))|(1L<<20))) == ((1L<<15)) && (proto->flags & (1L<<15)))
3206 if (!(flags & (1L<<5)))
3210 if (!(flags & (1L<<14))) im = proto->tp;
3212 if (ip - n < proto->ib)
3213 proto->flags |= (1L<<4);
3214 memcopy(proto->ib - n, ip - n, n);
3217 if (flags & (1L<<14))
3224 if ((n = read(proto->fd, ip, proto->iz)) > 0)
3226 if ((proto->flags & (1L<<21)) && n < proto->iz)
3228 proto->flags &= ~(1L<<15);
3232 if (state & (1<<7)) goto fsm_splice;
3237 proto->flags &= ~(1L<<15);
3240 if (state & (1<<7)) goto fsm_splice;
3242 if (!(flags & (1L<<20)) && (state = rp[c = (255+1)]))
3247 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3255 for (n = 0, t = qe + 1; t < op && (*t == ' ' || *t == '\t' || *t == '\n' && ++n); t++);
3267 rp = _pp_fsmtab[(0+19)];
3275 if (!(flags & (1L<<3)))
3276 qe = (c == '"') ? op : (char*)0;
3287 else if (c != '\n' && c != (255+1))
3309 if (flags & (1L<<0)) (*op++=( c));
3325 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3326 lex(proto, (flags & ((1L<<15))) | (1L<<20));
3327 for (n = x = 0; (c = (*(unsigned char*)ip++)), x < 3; x++) switch (c)
3329 case '0': case '1': case '2': case '3':
3330 case '4': case '5': case '6': case '7':
3332 n = (n << 4) + c - '0';
3334 case 'a': case 'b': case 'c': case 'd':
3336 n = (n << 4) + c - 'a' + 10;
3338 case 'A': case 'B': case 'C': case 'D':
3340 n = (n << 4) + c - 'A' + 10;
3347 (*op++=( ((n >> 6) & 07) + '0'));
3348 (*op++=( ((n >> 3) & 07) + '0'));
3349 (*op++=( (n & 07) + '0'));
3355 rp = _pp_fsmtab[(0+19)];
3362 if ((flags & (1L<<5)) && *proto->tp == 's' && !sstrncmp( proto->tp, "static", 6))
3368 if (*proto->tp == '_' && !sstrncmp( proto->tp, "__STDPP__directive", 6)) c = '#';
3377 if (flags & (1L<<5))
3379 if (op != proto->ob && (*(op-1)) != ' ' && (*(op-1)) != '\n')
3385 if (flags & (1L<<3))
3388 if (flags & (1L<<0))
3390 if (flags & (1L<<5)) (op=ko);
3391 if (flags & (1L<<11))
3394 op = strcopy(om, "/* ");
3395 op = strcopy(op, im);
3396 op = strcopy(op, " */\n");
3398 flags &= ~((1L<<2)|(1L<<3)|(1L<<6)|(1L<<7)|(1L<<11)|(1L<<14)|(1L<<22)|(1L<<26));
3403 if ((flags & ((1L<<2)|(1L<<22))) == ((1L<<2)|(1L<<22)))
3406 op = strcopy(om, "#if defined(__STDC__) || defined(__STDPP__)\n");
3407 op = strcopy(op, im);
3408 op = strcopy(op, "\n#else\n");
3413 if (*op++ == '#' && *ip != '(')
3416 while (*--op == ' ' || *op == '\t');
3419 op = strcopy(op + 1, "/**/");
3420 while (*++ip == ' ' || *ip == '\t');
3424 if (*op != '"') *++op = '"';
3426 while (*ip == ' ' || *ip == '\t') ip++;
3427 while ((c = *ip) >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '_') *op++ = *ip++;
3428 while (*ip == ' ' || *ip == '\t') ip++;
3429 if (*ip == '"') ip++;
3434 op = strcopy(op, "\n#endif\n");
3435 op = linesync(proto, op, proto->line);
3437 flags &= ~((1L<<2)|(1L<<3)|(1L<<6)|(1L<<7)|(1L<<14)|(1L<<16)|(1L<<22)|(1L<<23)|(1L<<26));
3444 if (paren == 0 && (flags & ((1L<<14)|(1L<<20)|(1L<<23)|(1L<<24))) == (1L<<24))
3447 if (flags & (1L<<5)) (op=ko);
3449 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3456 rp = _pp_fsmtab[((( state)>>(7+1))&((1<<7)-1))];
3462 c = (((( state)>>(7+1))&((1<<7)-1))+0401);
3467 c = (((( state)>>(7+1))&((1<<7)-1))+0401);
3473 if (!(flags & (1L<<1))) switch (((((long)( *proto->tp))<<16)|(((long)( *(ip - 1)))<<8)|((long)( ip - proto->tp))))
3475 case ((((long)( 'd'))<<16)|(((long)( 'o'))<<8)|((long)( 2))):
3478 case ((((long)( 'e'))<<16)|(((long)( 'e'))<<8)|((long)( 4))):
3479 if (!(flags & (1L<<20)) && !sstrncmp( proto->tp, "else", 4))
3485 case ((((long)( 'e'))<<16)|(((long)( 'n'))<<8)|((long)( 6))):
3486 if (!sstrncmp( proto->tp, "extern", 6))
3489 case ((((long)( 'f'))<<16)|(((long)( 'r'))<<8)|((long)( 3))):
3490 if (!(flags & (1L<<20)) && !sstrncmp( proto->tp, "for", 3))
3496 case ((((long)( 'i'))<<16)|(((long)( 'f'))<<8)|((long)( 2))):
3499 case ((((long)( 'r'))<<16)|(((long)( 'n'))<<8)|((long)( 6))):
3500 if (!(flags & (1L<<20)) && !sstrncmp( proto->tp, "return", 6))
3506 case ((((long)( 't'))<<16)|(((long)( 'f'))<<8)|((long)( 7))):
3507 if (!(flags & (1L<<20)) && !sstrncmp( proto->tp, "typedef", 7))
3513 case ((((long)( 'v'))<<16)|(((long)( 't'))<<8)|((long)( 8))):
3514 if (*ip == '(' && !sstrncmp( proto->tp, "va_start", 8)) c = (0500+1);
3516 case ((((long)( 'v'))<<16)|(((long)( 'd'))<<8)|((long)( 4))):
3517 if (!sstrncmp( proto->tp, "void", 4))
3519 if (flags & ((1L<<0)|(1L<<18)|(1L<<9)|(1L<<10))) c = ((0500+4)+30);
3522 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3524 if (lex(proto, (flags & ((1L<<15))) | (1L<<20)) == '*')
3526 memcopy(op - 4, "__V_", 4);
3527 memcopy(ip - 4, "__V_", 4);
3529 else c = ((0500+4)+30);
3531 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
3536 case ((((long)( 'w'))<<16)|(((long)( 'e'))<<8)|((long)( 5))):
3537 if (!(flags & (1L<<20)) && !sstrncmp( proto->tp, "while", 5))
3545 if ((flags & (1L<<0)) && c != ((0500+4)+9))
3556 if ((flags & ((1L<<5)|(1L<<14))) == (1L<<5))
3558 while (op > proto->ob && (*(op - 1) == ' ' || *(op - 1) == '\t'))
3560 if (op > proto->ob && *(op - 1) != '\n') *op++ = ' ';
3566 if (c == '\\' && (state & (1<<7)))
3568 if (!(n = (*(unsigned char*)ip++)))
3573 n = (*(unsigned char*)ip++);
3585 if (state >= (0+26)) goto fsm_terminal;
3586 rp = _pp_fsmtab[state];
3592 if (!(flags & ((1L<<9)|(1L<<10)|(1L<<20))))
3594 if (!(flags & (1L<<3))) switch (c)
3598 if (!(flags & (1L<<0)) || proto->brace == 0)
3604 if (!(flags & (1L<<0)) || group <= 1)
3610 if (group++ == 0) group++;
3611 else if (flags & (1L<<7)) call++;
3617 else if (paren == 2 && !aim)
3619 if (flags & (1L<<7))
3624 else if ((flags & ((1L<<14)|(1L<<25))) == (1L<<14))
3626 for (m = ip - 2; m > im && (*m == ' ' || *m == '\t'); m--);
3639 if (!(flags & (1L<<0)) || proto->brace == 0)
3644 if (flags & (1L<<0))
3656 else if (paren == 1 && (flags & (1L<<7)) && !aie)
3660 if (last == '(' && group == 2)
3672 if (!(flags & ((1L<<1)|(1L<<3))))
3675 if (!(flags & (1L<<18)))
3678 while (*ip == ' ' || *ip == '\t') ip++;
3679 if (*ip == 'l' && *++ip == 'i' && *++ip == 'n' && *++ip == 'e')
3681 if (*++ip == ' ' || *ip == '\t')
3684 while (*++ip >= '0' && *ip <= '9')
3685 proto->line = proto->line * 10 + *ip - '0';
3690 else if ((flags & ((1L<<0)|(1L<<5))) == (1L<<0))
3694 while (ip < t && *ip >= 'a' && *ip <= 'z') n = (n << 5) | (*ip++ - 'a');
3697 case ((('e'-'a')<<15)|(('l'-'a')<<10)|(('s'-'a')<<5)|('e'-'a')):
3698 case ((('e'-'a')<<20)|(('n'-'a')<<15)|(('d'-'a')<<10)|(('i'-'a')<<5)|('f'-'a')):
3699 while (*ip == ' ' || *ip == '\t') ip++;
3700 if (*ip != '\n' && *ip != '/' && *(ip + 1) != '*')
3702 flags |= (1L<<11)|(1L<<14);
3704 om = op + (ip - bp);
3707 case ((('e'-'a')<<15)|(('l'-'a')<<10)|(('i'-'a')<<5)|('f'-'a')):
3708 case ((('e'-'a')<<20)|(('r'-'a')<<15)|(('r'-'a')<<10)|(('o'-'a')<<5)|('r'-'a')):
3709 case ((('i'-'a')<<5)|('f'-'a')):
3710 case ((('i'-'a')<<20)|(('f'-'a')<<15)|(('d'-'a')<<10)|(('e'-'a')<<5)|('f'-'a')):
3711 case ((('i'-'a')<<25)|(('f'-'a')<<20)|(('n'-'a')<<15)|(('d'-'a')<<10)|(('e'-'a')<<5)|('f'-'a')):
3712 case ((('u'-'a')<<20)|(('n'-'a')<<15)|(('d'-'a')<<10)|(('e'-'a')<<5)|('f'-'a')):
3714 case ((('i'-'a')<<25)|(('n'-'a')<<20)|(('c'-'a')<<15)|(('l'-'a')<<10)|(('u'-'a')<<5)|('d'-'a')):
3715 if (*ip == 'e') ip++;
3717 case ((('d'-'a')<<25)|(('e'-'a')<<20)|(('f'-'a')<<15)|(('i'-'a')<<10)|(('n'-'a')<<5)|('e'-'a')):
3718 case ((('p'-'a')<<25)|(('r'-'a')<<20)|(('a'-'a')<<15)|(('g'-'a')<<10)|(('m'-'a')<<5)|('a'-'a')):
3719 if (*ip < 'a' || *ip > 'z') break;
3722 flags |= (1L<<11)|(1L<<14);
3731 if (*ip == 'i' && *++ip == 'n' && *++ip == 'c' && *++ip == 'l' && *++ip == 'u' && *++ip == 'd' && *++ip == 'e')
3733 while (*++ip == ' ' || *ip == '\t');
3734 if (*ip++ == '<' && *ip++ == 's' && *ip++ == 't' && *ip++ == 'd' && *ip++ == 'a' && *ip++ == 'r' && *ip++ == 'g' && *ip++ == '.' && *ip++ == 'h' && *ip++ == '>')
3737 if !defined(va_start)\n\
3738 #if defined(__STDARG__)\n\
3739 #include <stdarg.h>\n\
3741 #include <varargs.h>\n\
3745 op = linesync(proto, op, proto->line);
3749 else if (*ip == 'd' && *++ip == 'e' && *++ ip == 'f' && *++ip == 'i' && *++ip == 'n' && *++ip == 'e' && (*++ip == ' ' || *ip == '\t'))
3751 flags |= (1L<<2)|(1L<<14);
3761 if (proto->brace++ == 0 && paren == 0)
3763 if (last == '=') flags |= (1L<<8);
3765 else if (flags & (1L<<0))
3767 if ((flags & ((1L<<14)|(1L<<16)|(1L<<23))) == (1L<<14))
3771 v = number(op, args < 0 ? -args : args);
3772 v = strcopy(v, " argument actual/formal mismatch");
3774 v = memcopy(v, im, ie - im);
3776 proto_error((char*)proto + sizeof(struct proto), 2, op, ((char*)0));
3782 if (*ie++ == '/' && *ie == '*')
3789 while (ie < ip && *ie == '*') ie++;
3790 if (ie < ip && *ie == '/')
3792 while (++ie < ip && (*ie == ' ' || *ie == '\t'));
3793 while (e > v && (*(e - 1) == ' ' || *(e - 1) == '\t')) e--;
3794 if (e > v && *e != '\n') *e++ = ' ';
3807 if (flags & (1L<<5))
3810 while (v > ko && *--v != ' ');
3813 om = (v = (op += 4)) + 1;
3819 memcopy(ko, "int ", 4);
3823 while (*(v + 1) == '*')
3828 om = (e = ++op) + 1;
3836 om = (v = (op += 7)) + 1;
3842 memcopy(ko, "extern ", 7);
3850 if ((c = *ie) == ' ' || c == '\t' || c == '\n')
3852 while ((c = *++ie) == ' ' || c == '\t' || c == '\n');
3853 if (ie >= ip) break;
3854 if (c != '*' && op > om) (*op++=( ' '));
3856 if ((n = ((c = *ie) == ',')) || c == ';')
3858 if (flags & (1L<<5))
3861 while (op > om && ((c = *(op - 1)) == '(' || c == ')' || c == '[' || c == ']'))
3864 while (op > om && (c = *(op - 1)) != ' ' && c != '*')
3866 while (*(op - 1) == ' ')
3871 while (e > om && *(e - 1) == '*')
3879 op = strcopy(op, "int");
3880 else if (*(op - 1) == ',')
3881 op = strcopy(op, " int");
3889 if (x = !e) e = op - 1;
3897 while (*--e != ' ');
3898 while (*(e - 1) == '*') e--;
3902 while ((c = *++ie) == ' ' || c == '\t' || c == '\n');
3903 if (ie >= ip) (op--);
3904 else (*op++=( ' '));
3911 else if (*ie == '*')
3913 if (op > om && (c = *(op - 1)) == ' ') op--;
3914 while (*ie == '*') (*op++=( *ie++));
3915 while (*ie == ' ' || *ie == '\t' || *ie == '\n') ie++;
3916 if (c != '(') (*op++=( ' '));
3918 else if (*ie == '(')
3920 if (op > om && *(op - 1) == ' ') op--;
3922 while (*ie == ' ' || *ie == '\t' || *ie == '\n') ie++;
3924 else if (*ie == ')')
3926 if (op > om && *(op - 1) == '(')
3927 proto_error((char*)proto + sizeof(struct proto), 1, "function pointer argument prototype omitted", ((char*)0));
3929 while (*ie == ' ' || *ie == '\t' || *ie == '\n') ie++;
3931 else if ((flags & (1L<<5)) && (op == om || *(op - 1) == ' ') && *ie == 'r' && !sstrncmp( ie, "register", 8) && (*(ie + 8) == ' ' || *(ie + 8) == '\t' || *(ie + 8) == '\n'))
3934 if (op > om) (op--);
3936 else (*op++=( *ie++));
3939 if (op <= om) op = strcopy(op, "void");
3941 if (flags & (1L<<5))
3954 flags &= ~((1L<<14)|(1L<<23));
3958 else if ((flags & ((1L<<14)|(1L<<18)|(1L<<23)|(1L<<25))) == ((1L<<14)|(1L<<25)))
3961 op = strcopy(om, " __PARAM__(");
3962 op = memcopy(op, im, ie - im);
3966 flags &= ~((1L<<14)|(1L<<23));
3967 if (flags & (1L<<27))
3969 if ((vc = ie - im + 1) > sizeof(proto->variadic)) vc = sizeof(proto->variadic);
3970 memcopy(proto->variadic, im, vc);
3971 op = strcopy(op, "va_alist)) __OTORP__(va_dcl)\n{");
3981 switch (lex(proto, (flags & ((1L<<15))) | (1L<<20)))
3984 if (paren++) group++;
3990 if (flags & (1L<<14))
3992 flags &= ~((1L<<14)|(1L<<23));
3993 op = memcopy(op, m, e - m);
4002 if (flags & (1L<<14))
4004 flags &= ~((1L<<14)|(1L<<23));
4005 op = memcopy(op, m, e - m);
4028 if (!(flags & (1L<<23)))
4031 proto->op = strcopy(op, " __OTORP__(");
4037 lex(proto, (flags & ((1L<<15))) | (1L<<1));
4044 op = linesync(proto, op, proto->line = line);
4045 if (!(flags & (1L<<27))) (*op++=( '{'));
4048 flags &= ~((1L<<6)|(1L<<7)|(1L<<14)|(1L<<16)|(1L<<23));
4053 flags &= ~((1L<<6)|(1L<<7)|(1L<<14)|(1L<<16)|(1L<<23)|(1L<<25));
4054 if (--proto->brace == 0)
4056 flags &= ~((1L<<8)|(1L<<27)|(1L<<28));
4058 if (flags & (1L<<5)) (op=ko);
4066 if (last == '?') flags |= (1L<<3);
4067 else if (paren == 0 && (flags & ((1L<<8)|(1L<<14)|(1L<<23))) == (1L<<14)) goto fsm_statement;
4071 if (flags & (1L<<0))
4073 if (paren == 1) args++;
4082 if (paren == 0 && (flags & (1L<<1))) *(op - 1) = c = ';';
4086 if (flags & (1L<<8)) ;
4088 else if (flags & (1L<<0))
4092 if ((flags & (1L<<14)) && last == ')')
4094 if (!(flags & (1L<<14)))
4099 if (flags & (1L<<5)) (op=ko);
4100 if (flags & (1L<<24))
4102 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
4109 if ((flags & ((1L<<5)|(1L<<23))) == ((1L<<5)|(1L<<23)))
4115 else if (paren == 0)
4117 if ((flags & ((1L<<14)|(1L<<16)|(1L<<23))) == (1L<<14) && call > 1)
4119 if ((flags & ((1L<<1)|(1L<<7))) == (1L<<7) && aim && aie < im)
4121 while (aie < ip && (*aie == ' ' || *aie == '\t' || *aie == '\n')) aie++;
4124 if (*v++ == ')') break;
4125 while (v < aie && (*v == ' ' || *v == '\t' || *v == '\n')) v++;
4126 if (v == aie || !(flags & (1L<<19)))
4128 if (flags & (1L<<19)) n = 3;
4129 else if (v == aie && *v == '(') n = 10;
4139 if (flags & (1L<<19)) memcopy(aom, "(...))", 6);
4140 else if (n == 10) memcopy(aom, "(__VARARG__))", 13);
4143 ko = strcopy(aom, " __PROTO__(");
4144 ko = memcopy(ko, aim, aie - aim);
4154 else if (flags & (1L<<26))
4157 while (*--op == ' ' || *op == '\t' || *op == '\n');
4162 while ((x = *(op - 14)) >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z' || x >= '0' && x <= '9' || x == '_')
4164 memcopy(op - 13, "(__OTORP__(*)", 13);
4167 if (flags & (1L<<19))
4169 if (!(flags & (1L<<25)))
4171 op = strcopy(om, "(...)");
4177 if (flags & (1L<<1)) op = strcopy(om, "()");
4178 else if (!(flags & (1L<<25))) op = strcopy(om, "(__VARARG__)");
4181 op = strcopy(om, " __PROTO__(");
4182 op = memcopy(op, im, ie - im);
4187 flags &= ~((1L<<14)|(1L<<27)|(1L<<28));
4188 if (c == ',' && !(flags & (1L<<7)))
4195 else if (flags & ((1L<<16)|(1L<<23))) call = 0;
4198 flags &= ~((1L<<13)|(1L<<26));
4199 if (flags & (1L<<24))
4201 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
4206 else call = call > 1 && c == ',';
4208 flags &= ~((1L<<6)|(1L<<7)|(1L<<14)|(1L<<16)|(1L<<23));
4210 else if (paren == 1 && group == 1 && !(flags & ((1L<<6)|(1L<<13)))) flags |= (1L<<25)|(1L<<16);
4214 flags |= (1L<<25)|(1L<<23);
4218 if (flags & (1L<<0))
4220 if (proto->brace == 0)
4225 if (paren == 0 && !(flags & (1L<<26)))
4228 if (!(flags & (1L<<18)))
4229 op = strcopy(op, " __MANGLE__");
4233 if (paren == 0 && (flags & ((1L<<1)|(1L<<27))) == (1L<<1))
4236 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
4239 if (paren == 1 && !(flags & (1L<<23)))
4246 if ((flags & ((1L<<18)|(1L<<27))) == (1L<<27))
4250 op = strcopy(op - 8, "__VA_START__");
4251 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
4254 switch (lex(proto, (flags & ((1L<<15))) | (1L<<20)))
4260 if (!(flags & (1L<<14)))
4272 ((ip=proto->ip),(op=proto->op));
4273 if (flags & (1L<<14))
4283 op = strcopy(op, " __OTORP__(");
4284 proto->ip = proto->variadic;
4289 if (*bp == 'r' && !sstrncmp( bp, "register", 8) && (*(bp + 8) == ' ' || *(bp + 8) == '\t')) bp += 9;
4292 switch (lex(proto, (flags & ((1L<<15))) | (1L<<20)))
4295 if (paren++) group++;
4300 if (flags & (1L<<14))
4303 if (!(flags & (1L<<28)))
4305 op = memcopy(op, m, e - m);
4306 op = strcopy(op, " = ");
4308 op = strcopy(op, "va_arg(");
4309 op = memcopy(op, v, n);
4312 if (m > bp) op = memcopy(op, bp, m - bp);
4313 else op = strcopy(op, "int ");
4314 if (group > 1) op = strcopy(op, ")()");
4315 else op = memcopy(op, e, proto->ip - e - 1);
4326 if (flags & (1L<<14))
4329 if (!(flags & (1L<<28)))
4331 op = memcopy(op, m, e - m);
4332 op = strcopy(op, " = ");
4334 op = strcopy(op, "va_arg(");
4335 op = memcopy(op, v, n);
4338 if (m > bp) op = memcopy(op, bp, m - bp);
4339 else op = strcopy(op, "int ");
4340 if (group > 1) op = strcopy(op, ")()");
4341 else op = memcopy(op, e, proto->ip - e - 1);
4345 if (*bp == 'r' && !sstrncmp( bp, "register", 8) && (*(bp + 8) == ' ' || *(bp + 8) == '\t')) bp += 9;
4364 op = strcopy(op, ")");
4374 if (flags & (1L<<0))
4376 if (!args && paren == 1) args++;
4384 if (proto->brace == 0 && !(flags & (1L<<1))) flags |= (1L<<23);
4387 else if ((flags & (1L<<23)) || c == (0401+0) || c == ((0500+4)+30)) call++;
4388 else flags |= (1L<<23);
4389 if (last == (0401+0)) flags |= (1L<<6);
4395 if (*proto->tp >= '0' && *proto->tp <= '9')
4406 *(op - 2) = *(op - 1);
4419 if ((flags & (1L<<0)) && paren == 0 && group <= 2) flags |= (1L<<23);
4425 if (flags & (1L<<0)) break;
4428 if (paren == 0) flags |= (1L<<16);
4431 else if (c == '#' && *ip != '(') flags |= (1L<<22);
4434 if ((flags & ((1L<<5)|(1L<<14))) == ((1L<<5)|(1L<<14)) && ((flags & ((1L<<3)|(1L<<23))) || proto->brace || c != '(' && c != ')' && c != '*' && c != (0401+0)))
4441 else if (flags & ((1L<<9)|(1L<<10)))
4444 if ((flags & (1L<<29)) && c == '%' && *ip == '{') t = 0;
4448 if (c == '#') for (t = ip; *t == ' ' || *t == '\t'; t++);
4450 if (*t++ == 'i' && *t++ == 'f' && *t++ == 'n' && *t++ == 'd' && *t++ == 'e' && *t++ == 'f')
4464 else while (*ip != '\n') *op++ = *ip++;
4465 op = init(op, flags);
4466 op = linesync(proto, op, proto->line);
4467 flags &= ~((1L<<9)|(1L<<10));
4468 proto->flags &= ~((1L<<9)|(1L<<10));
4471 do{(proto->ip=ip);(proto->op=op);proto->flags&=~((1L<<8)|(1L<<27)|(1L<<28));proto->flags|=flags&((1L<<8)|(1L<<27)|(1L<<28));}while(0);
4480 pppclose __PARAM__((char* iob), (iob)) __OTORP__(char* iob;){
4481 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
4483 if (proto->flags & (1L<<15)) close(proto->fd);
4498 pppopen __PARAM__((char* file, int fd, char* notice, int flags), (file, fd, notice, flags)) __OTORP__(char* file; int fd; char* notice; int flags;){
4499 register struct proto* proto;
4518 if (flags & (1<<0)) flags &= ~(1<<4);
4520 if (flags & (1<<10)) flags &= ~retain;
4521 else retain &= (1<<5);
4522 if (file && (fd = open(file, 0)) < 0) return(0);
4551 if (!(proto = (( 0)?( struct proto*)realloc((char*)( 0),sizeof( struct proto)*( 1)+( 5 * n + 2)):( struct proto*)calloc(1,sizeof( struct proto)*( 1)+( 5 * n + 2)))))
4555 proto->flags |= (1L<<15);
4558 iob = (char*)proto + sizeof(struct proto);
4559 proto->op = proto->ob = iob;
4560 proto->ip = proto->ib = iob + proto->oz + n;
4561 if (m) proto->flags |= (1L<<21);
4567 n = read(fd, proto->ip, proto->iz);
4568 if (!(proto->flags & (1L<<15)))
4575 *(proto->ip + n) = 0;
4591 s = comment(com, ((char*)0), 0, 0);
4599 while (m-- > 0 && *s)
4601 while (*s == ' ' || *s == '\t') s++;
4605 while (*s == ' ' || *s == '\t') s++;
4606 if (!sstrncmp( s, "pragma", sizeof("pragma") - 1) && (*(s += sizeof("pragma") - 1) == ' ' || *s == '\t'))
4608 while (*s == ' ' || *s == '\t') s++;
4609 if (*s == 'n' && *(s + 1) == 'o')
4614 if (!sstrncmp( s, "prototyped", sizeof("prototyped") - 1) && (*(s += sizeof("prototyped") - 1) == ' ' || *s == '\t' || *s == '\n' || *s == '\r'))
4621 if (!(flags & (1<<1)) || (flags & (1<<7)))
4623 for (s--; b < s; *b++ = ' ');
4630 else if (*s == '/' && !sstrncmp( s, "/* : : generated by proto : : */\n", sizeof("/* : : generated by proto : : */\n") - 1))
4636 else if (*s == '%' && *(s + 1) == '{') proto->flags |= (1L<<29);
4639 if (*s == *com && !sstrncmp( s, com, comlen)) notice = 0;
4644 if (*s == *"Copyright"&& !sstrncmp( s, "Copyright", sizeof("Copyright") - 1))
4646 s += sizeof("Copyright") - 1;
4647 while (*s == ' ' || *s == '\t') s++;
4648 if (*s == '(' && (*(s + 1) == 'c' || *(s + 1) == 'C') && *(s + 2) == ')')
4651 else if (*s++ == '\n') break;
4657 while (*s && *s++ != '\n');
4660 if (flags & (1<<9)) proto->flags |= (1L<<19);
4661 if (flags & (1<<11)) proto->test = 1;
4663 if (flags & (1<<0)) pragma = -pragma;
4664 if (flags & (1<<1)) pragma = 0;
4665 if (flags & (1<<6)) proto->flags |= (1L<<12);
4666 if (!(proto->flags & (1L<<29)) && file && (m = sstrlen( file)) > 2 && file[--m] == 'y' && file[--m] == '.')
4667 proto->flags |= (1L<<29);
4673 flags &= ~((1<<3)|(1<<4));
4674 proto->flags |= (1L<<18);
4676 else if (!(flags & ((1<<2)|(1<<8))))
4681 else if ((flags & (1<<8)) || !pragma)
4683 proto->flags |= (1L<<17);
4684 if (proto->flags & (1L<<15)) proto->oz += proto->iz;
4689 proto->op = copyright(proto->op, notice);
4690 if (!(flags & (1<<0)) && !(proto->flags & (1L<<29)))
4692 proto->op = linesync(proto, proto->op, 1);
4693 proto->iz += proto->op - proto->ob;
4695 memcopy(proto->op, proto->ip, n);
4700 if (!(retain & (1<<5)))
4703 ppfsm(4, ((char*)0));
4708 if (notice || (flags & ((1<<3)|(1<<4))))
4711 if (notice) proto->op = copyright(proto->op, notice);
4715 proto->flags |= (1L<<10);
4716 if (flags & (1<<10))
4719 else if (flags & (1<<3))
4721 if (flags & (1<<10)) retain |= (1<<3);
4726 proto->op = strcopy(proto->op, "pragma");
4728 proto->op = strcopy(proto->op, "prototyped");
4729 *proto->op++ = '\n';
4733 proto->flags |= (1L<<9);
4736 if (!(flags & (1<<0)))
4738 if (proto->flags & (1L<<29))
4740 proto->op = strcopy(proto->op, "\n%{\n"+ !notice);
4741 proto->op = strcopy(proto->op, "/* : : generated by proto : : */\n");
4742 proto->op = strcopy(proto->op, "%}\n");
4746 if (n || notice) *proto->op++ = '\n';
4747 proto->op = strcopy(proto->op, "/* : : generated by proto : : */\n");
4748 if (n) proto->op = linesync(proto, proto->op, proto->line);
4749 else if (proto->flags & ((1L<<9)|(1L<<10)))
4750 proto->op = init(proto->op, proto->flags);
4760 proto->flags |= (1L<<0);
4761 if (!(flags & (1<<3))) proto->flags |= (1L<<5);
4773 pppread __PARAM__((char* iob), (iob)) __OTORP__(char* iob;){
4774 register struct proto* proto = (struct proto*)(iob - sizeof(struct proto));
4777 if (proto->flags & (1L<<17))
4784 else if (!(proto->flags & (1L<<15))) n = 0;
4785 else if ((n = read(proto->fd, proto->ob, proto->oz)) <= 0 || (proto->flags & (1L<<21)) && n < proto->oz)
4787 proto->flags &= ~(1L<<15);
4793 if (proto->op == proto->ob)
4795 if (proto->flags & (1L<<4)) return(-1);
4797 if (proto->flags & (1L<<29))
4799 register char* ip = proto->ip;
4800 register char* op = proto->ob;
4801 register char* ep = proto->ob + proto->oz - 2;
4805 ip = proto->ip = proto->ib;
4806 if (!(proto->flags & (1L<<15))) n = 0;
4807 else if ((n = read(proto->fd, ip, proto->iz)) <= 0 || (proto->flags & (1L<<21)) && n < proto->iz)
4810 proto->flags &= ~(1L<<15);
4815 if (proto->flags & (1L<<30))
4817 proto->flags &= ~(1L<<30);
4821 if (proto->flags & (1L<<31)) proto->flags &= ~(1L<<29);
4822 else proto->flags |= (1L<<31);
4825 if (proto->flags & (1L<<29))
4826 while (op < ep && (n = *op++ = *ip))
4831 if (*ip == '%' && (ip == proto->ip + 1 || *(ip - 2) == '\n'))
4834 if (proto->flags & (1L<<31)) proto->flags &= ~(1L<<29);
4835 else proto->flags |= (1L<<31);
4841 proto->flags |= (1L<<30);
4845 else if (n == '\n') proto->line++;
4847 proto->op = memcopy(proto->ob, proto->ip, ip - proto->ip);
4852 lex(proto, proto->flags);
4853 if ((proto->flags & ((1L<<4)|(1L<<15))) == (1L<<4))
4854 proto->op = strcopy(proto->op, "/* NOTE: some constructs may not have been converted */\n");
4856 n = proto->op - proto->ob;
4857 proto->op = proto->ob;
4884 #line 69 "/home/gsf/src/cmd/proto/proto.c"
4890 proto __PARAM__((char* file, char* notice, int flags), (file, notice, flags)) __OTORP__(char* file; char* notice; int flags;){
4897 if (file && access(file, 4)) proto_error(((char*)0), 2, file, "not found");
4898 else if (b = pppopen(file, 0, notice, flags))
4902 e = file + sstrlen( file) - 1;
4905 if ((fd = (flags & ((1<<13)<<1)) ? creat(file, 0666) : 1) < 0)
4907 proto_error(b, 2, "cannot create temporary file", ((char*)0));
4913 while ((n = pppread(b)) > 0)
4914 if (write(fd, b, n) != n)
4916 proto_error(b, 2, "write error", ((char*)0));
4917 flags |= ((1<<13)<<0);
4920 if (file && (flags & ((1<<13)<<1)))
4926 if (replace(b, file, !(flags & (1<<0))))
4927 proto_error(b, 2, "cannot rename to", file);
4935 main __PARAM__((int argc, char** argv), (argc, argv)) __OTORP__(int argc; char** argv;){
4945 while ((file = *++argv) && *file == '-' && *(file + 1))
4954 if (!*(notice = ++file) && !(notice = *++argv))
4973 if (!*(list = ++file) && !(list = *++argv))
4986 flags |= ((1<<13)<<1);
4995 flags |= (1<<1)|(1<<7);
5001 proto_error(((char*)0), 2, file, "unknown option");
5004 b = "Usage: proto [-dfhinprst+] [-c \"name='value' ...\"] [-l list] file ...\n";
5005 write(2, b, sstrlen( b));
5013 if (*list == '-' && !*(list + 1)) fd = 0;
5014 else if ((fd = open(list, 0)) < 0) proto_error(((char*)0), 3, list, "not found");
5018 while (read(0, b, 1) == 1 && *b != '\n' && b < &buf[sizeof(buf) - 1]) b++;
5019 if (b == buf) break;
5021 flags = proto(buf, notice, flags);
5024 if (file) do flags = proto(file, notice, flags); while (file = *++argv);
5025 else if (!list) flags = proto(file, notice, flags);
5026 exit(errors ? 1 : (flags & ((1<<13)<<0)) ? 2 : 0);