xref: /onnv-gate/usr/src/lib/libast/common/port/astlicense.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin /*
254887Schin  * Glenn Fowler
264887Schin  * AT&T Research
274887Schin  *
284887Schin  * generate a license comment -- see proto(1)
294887Schin  *
304887Schin  * NOTE: coded for minimal library dependence
314887Schin  *	 not so for the legal department
324887Schin  */
334887Schin 
344887Schin #ifndef	_PPLIB_H
354887Schin #include <ast.h>
364887Schin #include <time.h>
374887Schin #endif
384887Schin 
394887Schin #undef	copy
404887Schin #undef	BSD			/* guess who defines this */
414887Schin #undef	END
424887Schin #undef	INLINE
434887Schin #undef	TEST
444887Schin #undef	VERBOSE
454887Schin 
464887Schin #define NONE			0
474887Schin #define INLINE			1
484887Schin #define TEST			2
494887Schin #define VERBOSE			3
504887Schin #define USAGE			4
514887Schin #define OPEN			5
524887Schin #define CPL			6
53*12068SRoger.Faulkner@Oracle.COM #define EPL			7
54*12068SRoger.Faulkner@Oracle.COM #define BSD			8
55*12068SRoger.Faulkner@Oracle.COM #define ZLIB			9
56*12068SRoger.Faulkner@Oracle.COM #define MIT			10
57*12068SRoger.Faulkner@Oracle.COM #define GPL			11
58*12068SRoger.Faulkner@Oracle.COM #define SPECIAL			12
59*12068SRoger.Faulkner@Oracle.COM #define NONEXCLUSIVE		13
60*12068SRoger.Faulkner@Oracle.COM #define NONCOMMERCIAL		14
61*12068SRoger.Faulkner@Oracle.COM #define PROPRIETARY		15
624887Schin 
634887Schin #define AUTHOR			0
644887Schin #define CLASS			1
654887Schin #define COMPANY			2
664887Schin #define CONTRIBUTOR		3
674887Schin #define CORPORATION		4
684887Schin #define DOMAIN			5
694887Schin #define INCORPORATION		6
704887Schin #define LICENSE			7
714887Schin #define LOCATION		8
724887Schin #define NOTICE			9
734887Schin #define ORGANIZATION		10
744887Schin #define PACKAGE			11
754887Schin #define PARENT			12
764887Schin #define QUERY			13
774887Schin #define SINCE			14
784887Schin #define STYLE			15
794887Schin #define URL			16
804887Schin #define URLMD5			17
814887Schin #define VERSION			18
824887Schin 
834887Schin #define IDS			64
844887Schin 
854887Schin #define COMDATA			70
864887Schin #define COMLINE			(COMDATA+4)
874887Schin #define COMLONG			(COMDATA-32)
884887Schin #define COMMENT(x,b,s,u)	comment(x,b,s,sizeof(s)-1,u)
894887Schin 
904887Schin #define PUT(b,c)		(((b)->nxt<(b)->end)?(*(b)->nxt++=(c)):((c),(-1)))
914887Schin #define BUF(b)			((b)->buf)
924887Schin #define USE(b)			((b)->siz=(b)->nxt-(b)->buf,(b)->nxt=(b)->buf,(b)->siz)
934887Schin #define SIZ(b)			((b)->nxt-(b)->buf)
944887Schin #define END(b)			(*((b)->nxt>=(b)->end?((b)->nxt=(b)->end-1):(b)->nxt)=0,(b)->nxt-(b)->buf)
954887Schin 
964887Schin #ifndef NiL
974887Schin #define NiL			((char*)0)
984887Schin #endif
994887Schin 
1004887Schin typedef struct Buffer_s
1014887Schin {
1024887Schin 	char*		buf;
1034887Schin 	char*		nxt;
1044887Schin 	char*		end;
1054887Schin 	int		siz;
1064887Schin } Buffer_t;
1074887Schin 
1084887Schin typedef struct Item_s
1094887Schin {
1104887Schin 	char*		data;
1114887Schin 	int		size;
1124887Schin 	int		quote;
1134887Schin } Item_t;
1144887Schin 
1154887Schin typedef struct Id_s
1164887Schin {
1174887Schin 	Item_t		name;
1184887Schin 	Item_t		value;
1194887Schin } Id_t;
1204887Schin 
1214887Schin /*
1224887Schin  * NOTE: key[] element order must match the corresponding macro
1234887Schin  */
1244887Schin 
1254887Schin #define KEY(s)			{s,sizeof(s)-1,0}
1264887Schin 
1274887Schin static const Item_t	key[] =
1284887Schin {
1294887Schin 	KEY("author"),
1304887Schin 	KEY("class"),
1314887Schin 	KEY("company"),
1324887Schin 	KEY("contributor"),
1334887Schin 	KEY("corporation"),
1344887Schin 	KEY("domain"),
1354887Schin 	KEY("incorporation"),
1364887Schin 	KEY("license"),
1374887Schin 	KEY("location"),
1384887Schin 	KEY("notice"),
1394887Schin 	KEY("organization"),
1404887Schin 	KEY("package"),
1414887Schin 	KEY("parent"),
1424887Schin 	KEY("query"),
1434887Schin 	KEY("since"),
1444887Schin 	KEY("type"),
1454887Schin 	KEY("url"),
1464887Schin 	KEY("urlmd5"),
1474887Schin 	KEY("version"),
1484887Schin 	{0}
1494887Schin };
1504887Schin 
1514887Schin #define ITEMS			(sizeof(key)/sizeof(key[0])-1)
1524887Schin 
1534887Schin #define LIC(s,c)		{s,sizeof(s)-1,c}
1544887Schin 
1554887Schin static const Item_t	lic[] =
1564887Schin {
1574887Schin 	LIC("none", NONE),
1584887Schin 	LIC("inline", SPECIAL),
1594887Schin 	LIC("test", TEST),
1604887Schin 	LIC("verbose", VERBOSE),
1614887Schin 	LIC("usage", USAGE),
1624887Schin 	LIC("open", OPEN),
1634887Schin 	LIC("cpl", OPEN),
164*12068SRoger.Faulkner@Oracle.COM 	LIC("epl", OPEN),
1654887Schin 	LIC("bsd", OPEN),
1664887Schin 	LIC("zlib", OPEN),
1674887Schin 	LIC("mit", OPEN),
1684887Schin 	LIC("gpl", GPL),
1694887Schin 	LIC("special", SPECIAL),
1704887Schin 	LIC("nonexclusive", SPECIAL),
1714887Schin 	LIC("noncommercial", SPECIAL),
1724887Schin 	LIC("proprietary", PROPRIETARY),
1734887Schin 	{0}
1744887Schin };
1754887Schin 
1764887Schin typedef struct Notice_s
1774887Schin {
1784887Schin 	int		test;
1794887Schin 	int		type;
1804887Schin 	int		verbose;
1814887Schin 	int		ids;
1824887Schin 	Item_t		item[ITEMS];
1834887Schin 	Id_t		id[IDS];
1844887Schin 	char		cc[3];
1854887Schin } Notice_t;
1864887Schin 
1874887Schin /*
1884887Schin  * return index given <name,size>
1894887Schin  */
1904887Schin 
1914887Schin static int
lookup(register const Item_t * item,const char * name,int size)1924887Schin lookup(register const Item_t* item, const char* name, int size)
1934887Schin {
1944887Schin 	register int	c;
1954887Schin 	register int	i;
1964887Schin 
1974887Schin 	c = name[0];
1984887Schin 	for (i = 0; item[i].data; i++)
1994887Schin 		if (c == item[i].data[0] && size == item[i].size && !strncmp(name, item[i].data, size))
2004887Schin 			return i;
2014887Schin 	return -1;
2024887Schin }
2034887Schin 
2044887Schin /*
2054887Schin  * copy s of size n to b
2064887Schin  * n<0 means 0 terminated string
2074887Schin  */
2084887Schin 
2094887Schin static void
copy(register Buffer_t * b,register char * s,int n)2104887Schin copy(register Buffer_t* b, register char* s, int n)
2114887Schin {
2124887Schin 	if (n < 0)
2134887Schin 		n = strlen(s);
2144887Schin 	while (n--)
2154887Schin 		PUT(b, *s++);
2164887Schin }
2174887Schin 
2184887Schin /*
2194887Schin  * center and copy comment line s to p
2204887Schin  * if s==0 then
2214887Schin  *	n>0	first frame line
2224887Schin  *	n=0	blank line
2234887Schin  *	n<0	last frame line
2244887Schin  * if u>0 then s converted to upper case
2254887Schin  * if u<0 then s is left justified
2264887Schin  */
2274887Schin 
2284887Schin static void
comment(Notice_t * notice,register Buffer_t * b,register char * s,register int n,int u)2294887Schin comment(Notice_t* notice, register Buffer_t* b, register char* s, register int n, int u)
2304887Schin {
2314887Schin 	register int	i;
2324887Schin 	register int	m;
2334887Schin 	register int	x;
2344887Schin 	int		cc;
2354887Schin 
2364887Schin 	cc = notice->cc[1];
2374887Schin 	if (!s)
2384887Schin 	{
2394887Schin 		if (n)
2404887Schin 		{
2414887Schin 			PUT(b, notice->cc[n > 0 ? 0 : 1]);
2424887Schin 			for (i = 0; i < COMDATA; i++)
2434887Schin 				PUT(b, cc);
2444887Schin 			PUT(b, notice->cc[n > 0 ? 1 : 2]);
2454887Schin 		}
2464887Schin 		else
2474887Schin 			s = "";
2484887Schin 	}
2494887Schin 	if (s)
2504887Schin 	{
2514887Schin 		if (n > COMDATA)
2524887Schin 			n = COMDATA;
2534887Schin 		PUT(b, cc);
2544887Schin 		m = (u < 0) ? 1 : (COMDATA - n) / 2;
2554887Schin 		if ((x = COMDATA - m - n) < 0)
2564887Schin 			n--;
2574887Schin 		while (m-- > 0)
2584887Schin 			PUT(b, ' ');
2594887Schin 		while (n-- > 0)
2604887Schin 		{
2614887Schin 			i = *s++;
2624887Schin 			if (u > 0 && i >= 'a' && i <= 'z')
2634887Schin 				i = i - 'a' + 'A';
2644887Schin 			PUT(b, i);
2654887Schin 		}
2664887Schin 		while (x-- > 0)
2674887Schin 			PUT(b, ' ');
2684887Schin 		PUT(b, cc);
2694887Schin 	}
2704887Schin 	PUT(b, '\n');
2714887Schin }
2724887Schin 
2734887Schin /*
2744887Schin  * expand simple ${...}
2754887Schin  */
2764887Schin 
2774887Schin static void
expand(Notice_t * notice,register Buffer_t * b,const Item_t * item)2784887Schin expand(Notice_t* notice, register Buffer_t* b, const Item_t* item)
2794887Schin {
2804887Schin 	register char*	t;
2814887Schin 	register char*	e;
2824887Schin 	register int	q;
2834887Schin 	register char*	x;
2844887Schin 	register char*	z;
2854887Schin 	register int	c;
286*12068SRoger.Faulkner@Oracle.COM 	int		m;
2874887Schin 
2884887Schin 	if (t = item->data)
2894887Schin 	{
2904887Schin 		q = item->quote;
2914887Schin 		e = t + item->size;
2924887Schin 		while (t < e)
2934887Schin 		{
2944887Schin 			if (*t == '$' && t < (e + 2) && *(t + 1) == '{')
2954887Schin 			{
296*12068SRoger.Faulkner@Oracle.COM 				m = 0;
2974887Schin 				x = t += 2;
2984887Schin 				while (t < e && (c = *t++) != '}')
2994887Schin 					if (c == '.')
3004887Schin 						x = t;
301*12068SRoger.Faulkner@Oracle.COM 					else if (c == '/')
302*12068SRoger.Faulkner@Oracle.COM 					{
303*12068SRoger.Faulkner@Oracle.COM 						m = 1;
304*12068SRoger.Faulkner@Oracle.COM 						break;
305*12068SRoger.Faulkner@Oracle.COM 					}
3064887Schin 				if ((c = lookup(key, x, t - x - 1)) >= 0 && (x = notice->item[c].data))
3074887Schin 				{
3084887Schin 					z = x + notice->item[c].size;
3094887Schin 					while (x < z)
310*12068SRoger.Faulkner@Oracle.COM 					{
311*12068SRoger.Faulkner@Oracle.COM 						c = *x++;
312*12068SRoger.Faulkner@Oracle.COM 						if (!m || c >= '0' && c <= '9')
313*12068SRoger.Faulkner@Oracle.COM 							PUT(b, c);
314*12068SRoger.Faulkner@Oracle.COM 					}
3154887Schin 				}
316*12068SRoger.Faulkner@Oracle.COM 				if (m)
317*12068SRoger.Faulkner@Oracle.COM 					while (t < e && *t++ != '}');
3184887Schin 			}
3194887Schin 			else if (q > 0 && *t == '\\' && (*(t + 1) == q || *(t + 1) == '\\'))
3204887Schin 				t++;
3214887Schin 			else
3224887Schin 				PUT(b, *t++);
3234887Schin 		}
3244887Schin 	}
3254887Schin }
3264887Schin 
3274887Schin /*
3284887Schin  * generate a copright notice
3294887Schin  */
3304887Schin 
3314887Schin static void
copyright(Notice_t * notice,register Buffer_t * b)3324887Schin copyright(Notice_t* notice, register Buffer_t* b)
3334887Schin {
3344887Schin 	register char*	x;
3354887Schin 	register char*	t;
3364887Schin 	time_t		clock;
3374887Schin 
3384887Schin 	copy(b, "Copyright (c) ", -1);
3394887Schin 	if (notice->test)
3404887Schin 		clock = (time_t)1000212300;
3414887Schin 	else
3424887Schin 		time(&clock);
3434887Schin 	t = ctime(&clock) + 20;
3444887Schin 	if ((x = notice->item[SINCE].data) && strncmp(x, t, 4))
3454887Schin 	{
3464887Schin 		expand(notice, b, &notice->item[SINCE]);
3474887Schin 		PUT(b, '-');
3484887Schin 	}
3494887Schin 	copy(b, t, 4);
3504887Schin 	if (notice->item[PARENT].data)
3514887Schin 	{
3524887Schin 		PUT(b, ' ');
3534887Schin 		expand(notice, b, &notice->item[PARENT]);
3544887Schin 	}
3554887Schin 	if (notice->item[CORPORATION].data)
3564887Schin 	{
3574887Schin 		PUT(b, ' ');
3584887Schin 		expand(notice, b, &notice->item[CORPORATION]);
3594887Schin 		if (notice->item[INCORPORATION].data)
3604887Schin 		{
3614887Schin 			PUT(b, ' ');
3624887Schin 			expand(notice, b, &notice->item[INCORPORATION]);
3634887Schin 		}
3644887Schin 	}
3654887Schin 	else if (notice->item[COMPANY].data)
3664887Schin 	{
3674887Schin 		PUT(b, ' ');
3684887Schin 		expand(notice, b, &notice->item[COMPANY]);
3694887Schin 	}
3704887Schin }
3714887Schin 
3724887Schin /*
3734887Schin  * read the license file and generate a comment in p, length size
3744887Schin  * license length in p returned, -1 on error
3754887Schin  * -1 return places 0 terminated error string in p
3764887Schin  */
3774887Schin 
3784887Schin int
astlicense(char * p,int size,char * file,char * options,int cc1,int cc2,int cc3)3794887Schin astlicense(char* p, int size, char* file, char* options, int cc1, int cc2, int cc3)
3804887Schin {
3814887Schin 	register char*	s;
3824887Schin 	register char*	v;
3834887Schin 	register char*	x;
3844887Schin 	register int	c;
3854887Schin 	int		i;
3864887Schin 	int		h;
3874887Schin 	int		k;
3884887Schin 	int		n;
3894887Schin 	int		q;
3904887Schin 	int		contributor;
3914887Schin 	int		first;
3924887Schin 	int		line;
3934887Schin 	int		quote;
3944887Schin 	char		tmpbuf[COMLINE];
3954887Schin 	char		info[8 * 1024];
3964887Schin 	Notice_t	notice;
3974887Schin 	Item_t		item;
3984887Schin 	Buffer_t	buf;
3994887Schin 	Buffer_t	tmp;
4004887Schin 
4014887Schin 	buf.end = (buf.buf = buf.nxt = p) + size;
4024887Schin 	tmp.end = (tmp.buf = tmp.nxt = tmpbuf) + sizeof(tmpbuf);
4034887Schin 	if (file && *file)
4044887Schin 	{
4054887Schin 		if ((i = open(file, O_RDONLY)) < 0)
4064887Schin 		{
4074887Schin 			copy(&buf, file, -1);
4084887Schin 			copy(&buf, ": cannot open", -1);
4094887Schin 			PUT(&buf, 0);
4104887Schin 			return -1;
4114887Schin 		}
4124887Schin 		n = read(i, info, sizeof(info) - 1);
4134887Schin 		close(i);
4144887Schin 		if (n < 0)
4154887Schin 		{
4164887Schin 			copy(&buf, file, -1);
4174887Schin 			copy(&buf, ": cannot read", -1);
4184887Schin 			PUT(&buf, 0);
4194887Schin 			return -1;
4204887Schin 		}
4214887Schin 		s = info;
4224887Schin 		s[n] = 0;
4234887Schin 	}
4244887Schin 	else if (!options)
4254887Schin 		return 0;
4264887Schin 	else
4274887Schin 	{
4284887Schin 		s = options;
4294887Schin 		options = 0;
4304887Schin 	}
4314887Schin 	notice.test = 0;
4324887Schin 	notice.type = NONE;
4334887Schin 	notice.verbose = 0;
4344887Schin 	notice.ids = 0;
4354887Schin 	notice.cc[0] = cc1;
4364887Schin 	notice.cc[1] = cc2;
4374887Schin 	notice.cc[2] = cc3;
4384887Schin 	for (i = 0; i < ITEMS; i++)
4394887Schin 		notice.item[i].data = 0;
4404887Schin 	notice.item[STYLE] = notice.item[CLASS] = lic[notice.type];
4414887Schin 	notice.item[STYLE].quote = notice.item[CLASS].quote = 0;
4424887Schin 	contributor = i = k = 0;
4434887Schin 	line = 0;
4444887Schin 	for (;;)
4454887Schin 	{
44610898Sroland.mainz@nrubsig.org 		first = 1;
44710898Sroland.mainz@nrubsig.org 		while (c = *s)
4484887Schin 		{
4494887Schin 			while (c == ' ' || c == '\t' || c == '\n' && ++line || c == '\r' || c == ',' || c == ';' || c == ')')
4504887Schin 				c = *++s;
4514887Schin 			if (!c)
4524887Schin 				break;
4534887Schin 			if (c == '#')
4544887Schin 			{
4554887Schin 				while (*++s && *s != '\n');
4564887Schin 				if (*s)
4574887Schin 					s++;
4584887Schin 				line++;
4594887Schin 				continue;
4604887Schin 			}
4614887Schin 			if (c == '\n')
4624887Schin 			{
4634887Schin 				s++;
4644887Schin 				line++;
4654887Schin 				continue;
4664887Schin 			}
4674887Schin 			if (c == '[')
4684887Schin 				c = *++s;
4694887Schin 			x = s;
4704887Schin 			n = 0;
4714887Schin 			while (c && c != '=' && c != ']' && c != ')' && c != ',' && c != ' ' && c != '\t' && c != '\n' && c != '\r')
4724887Schin 				c = *++s;
4734887Schin 			n = s - x;
4744887Schin 			h = lookup(key, x, n);
4754887Schin 			if (c == ']')
4764887Schin 				c = *++s;
477*12068SRoger.Faulkner@Oracle.COM 			quote = 0;
4784887Schin 			if (c == '=' || first)
4794887Schin 			{
4804887Schin 				if (c == '=')
4814887Schin 				{
4824887Schin 					q = ((c = *++s) == '"' || c == '\'') ? *s++ : 0;
4834887Schin 					if (c == '(')
4844887Schin 					{
4854887Schin 						s++;
4864887Schin 						if (h == LICENSE)
4874887Schin 							contributor = 0;
4884887Schin 						else if (h == CONTRIBUTOR)
4894887Schin 							contributor = 1;
4904887Schin 						else
4914887Schin 						{
4924887Schin 							q = 1;
4934887Schin 							i = 0;
4944887Schin 							for (;;)
4954887Schin 							{
4964887Schin 								switch (*s++)
4974887Schin 								{
4984887Schin 								case 0:
4994887Schin 									s--;
5004887Schin 									break;
5014887Schin 								case '(':
5024887Schin 									if (!i)
5034887Schin 										q++;
5044887Schin 									continue;
5054887Schin 								case ')':
5064887Schin 									if (!i && !--q)
5074887Schin 										break;
5084887Schin 									continue;
5094887Schin 								case '"':
5104887Schin 								case '\'':
5114887Schin 									if (!i)
5124887Schin 										i = *(s - 1);
5134887Schin 									else if (i == *(s - 1))
5144887Schin 										i = 0;
5154887Schin 									continue;
5164887Schin 								case '\\':
5174887Schin 									if (*s == i && i == '"')
5184887Schin 										i++;
5194887Schin 									continue;
5204887Schin 								case '\n':
5214887Schin 									line++;
5224887Schin 									continue;
5234887Schin 								default:
5244887Schin 									continue;
5254887Schin 								}
5264887Schin 								break;
5274887Schin 							}
5284887Schin 						}
5294887Schin 						continue;
5304887Schin 					}
5314887Schin 					v = s;
5324887Schin 					while ((c = *s) && (q == '"' && (c == '\\' && (*(s + 1) == '"' || *(s + 1) == '\\') && s++ && (quote = q)) || q && c != q || !q && c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != ',' && c != ';'))
5334887Schin 					{
5344887Schin 						if (c == '\n')
5354887Schin 							line++;
5364887Schin 						s++;
5374887Schin 					}
5384887Schin 				}
5394887Schin 				else
5404887Schin 				{
5414887Schin 					h = STYLE;
5424887Schin 					v = x;
5434887Schin 				}
5444887Schin 				if (c == '\n')
5454887Schin 					line++;
5464887Schin 				if (contributor)
5474887Schin 				{
5484887Schin 					for (i = 0; i < notice.ids; i++)
5494887Schin 						if (n == notice.id[i].name.size && !strncmp(x, notice.id[i].name.data, n))
5504887Schin 							break;
5514887Schin 					if (i < IDS)
5524887Schin 					{
5534887Schin 						notice.id[i].name.data = x;
5544887Schin 						notice.id[i].name.size = n;
5554887Schin 						notice.id[i].name.quote = 0;
5564887Schin 						notice.id[i].value.data = v;
5574887Schin 						notice.id[i].value.size = s - v;
5584887Schin 						notice.id[i].value.quote = quote;
5594887Schin 						if (notice.ids <= i)
5604887Schin 							notice.ids = i + 1;
5614887Schin 					}
5624887Schin 				}
5634887Schin 				else if (h == QUERY)
5644887Schin 				{
5654887Schin 					if ((s - v) == 3 && v[0] == 'a' && v[1] == 'l' && v[2] == 'l')
5664887Schin 					{
5674887Schin 						for (i = 0; i < ITEMS; i++)
5684887Schin 							if (notice.item[i].size)
5694887Schin 							{
5704887Schin 								expand(&notice, &buf, &key[i]);
5714887Schin 								PUT(&buf, '=');
5724887Schin 								for (h = 0;; h++)
5734887Schin 									if (h >= notice.item[i].size)
5744887Schin 									{
5754887Schin 										h = 0;
5764887Schin 										break;
5774887Schin 									}
5784887Schin 									else if (notice.item[i].data[h] == ' ' || notice.item[i].data[h] == '\t')
5794887Schin 										break;
5804887Schin 								if (h)
5814887Schin 									PUT(&buf, '\'');
5824887Schin 								expand(&notice, &buf, &notice.item[i]);
5834887Schin 								if (h)
5844887Schin 									PUT(&buf, '\'');
5854887Schin 								PUT(&buf, '\n');
5864887Schin 							}
5874887Schin 					}
5884887Schin 					else
5894887Schin 					{
5904887Schin 						if ((h = lookup(key, v, s - v)) < 0)
5914887Schin 						{
5924887Schin 							item.data = v;
5934887Schin 							item.size = s - v;
5944887Schin 							item.quote = 0;
5954887Schin 							expand(&notice, &buf, &item);
5964887Schin 						}
5974887Schin 						else
5984887Schin 							expand(&notice, &buf, &notice.item[h]);
5994887Schin 						PUT(&buf, '\n');
6004887Schin 					}
6014887Schin 					return END(&buf);
6024887Schin 				}
6034887Schin 				else
6044887Schin 				{
6054887Schin 					if (h == STYLE)
6064887Schin 						switch (c = lookup(lic, v, s - v))
6074887Schin 						{
6084887Schin 						case NONE:
6094887Schin 							return 0;
6104887Schin 						case TEST:
6114887Schin 							notice.test = 1;
6124887Schin 							h = -1;
6134887Schin 							break;
6144887Schin 						case VERBOSE:
6154887Schin 							notice.verbose = 1;
6164887Schin 							h = -1;
6174887Schin 							break;
6184887Schin 						case USAGE:
6194887Schin 							notice.type = c;
6204887Schin 							h = -1;
6214887Schin 							break;
6224887Schin 						case -1:
6234887Schin 							c = SPECIAL;
6244887Schin 							/*FALLTHROUGH*/
6254887Schin 						default:
6264887Schin 							notice.type = c;
6274887Schin 							notice.item[CLASS].data = lic[lic[c].quote].data;
6284887Schin 							notice.item[CLASS].size = lic[lic[c].quote].size;
6294887Schin 							break;
6304887Schin 						}
6314887Schin 					if (h >= 0)
6324887Schin 					{
6334887Schin 						notice.item[h].data = (notice.item[h].size = s - v) ? v : (char*)0;
6344887Schin 						notice.item[h].quote = quote;
6354887Schin 						k = 1;
6364887Schin 					}
6374887Schin 				}
6384887Schin 			}
6394887Schin 			else
6404887Schin 			{
6414887Schin 				if (file)
6424887Schin 				{
6434887Schin 					copy(&buf, "\"", -1);
6444887Schin 					copy(&buf, file, -1);
6454887Schin 					copy(&buf, "\", line ", -1);
6464887Schin 					x = &tmpbuf[sizeof(tmpbuf)];
6474887Schin 					*--x = 0;
6484887Schin 					line++;
6494887Schin 					do *--x = ("0123456789")[line % 10]; while (line /= 10);
6504887Schin 					copy(&buf, x, -1);
6514887Schin 					copy(&buf, ": ", -1);
6524887Schin 				}
6534887Schin 				copy(&buf, "option error: assignment expected", -1);
6544887Schin 				PUT(&buf, 0);
6554887Schin 				return -1;
6564887Schin 			}
6574887Schin 			if (*s)
6584887Schin 				s++;
65910898Sroland.mainz@nrubsig.org 			first = 0;
6604887Schin 		}
6614887Schin 		if (!options || !*(s = options))
6624887Schin 			break;
6634887Schin 		options = 0;
6644887Schin 	}
6654887Schin 	if (!k)
6664887Schin 		return 0;
6674887Schin 	if (notice.type == INLINE && (!notice.verbose || !notice.item[NOTICE].data))
6684887Schin 		return 0;
6694887Schin 	if (notice.type != USAGE)
6704887Schin 	{
6714887Schin 		if (!notice.type)
6724887Schin 			notice.type = SPECIAL;
6734887Schin 		comment(&notice, &buf, NiL, 1, 0);
6744887Schin 		comment(&notice, &buf, NiL, 0, 0);
6754887Schin 		if (notice.item[PACKAGE].data)
6764887Schin 		{
6774887Schin 			copy(&tmp, "This software is part of the ", -1);
6784887Schin 			expand(&notice, &tmp, &notice.item[PACKAGE]);
6794887Schin 			copy(&tmp, " package", -1);
6804887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6814887Schin 		}
6824887Schin 		if (notice.type >= OPEN)
6834887Schin 		{
6844887Schin 			copyright(&notice, &tmp);
6854887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6864887Schin 			if (notice.type >= SPECIAL)
6874887Schin 				COMMENT(&notice, &buf, "All Rights Reserved", 0);
6884887Schin 		}
689*12068SRoger.Faulkner@Oracle.COM 		if (notice.type == CPL || notice.type == EPL)
6904887Schin 		{
6914887Schin 			copy(&tmp, notice.item[PACKAGE].data ? "and" : "This software", -1);
6924887Schin 			copy(&tmp, " is licensed under the", -1);
6934887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
694*12068SRoger.Faulkner@Oracle.COM 			if (notice.type == EPL)
695*12068SRoger.Faulkner@Oracle.COM 				copy(&tmp, "Eclipse Public License", -1);
696*12068SRoger.Faulkner@Oracle.COM 			else
697*12068SRoger.Faulkner@Oracle.COM 				copy(&tmp, "Common Public License", -1);
6984887Schin 			if (notice.item[VERSION].data)
6994887Schin 			{
7004887Schin 				copy(&tmp, ", Version ", -1);
7014887Schin 				expand(&notice, &tmp, &notice.item[VERSION]);
7024887Schin 			}
7034887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7044887Schin 			if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
7054887Schin 			{
7064887Schin 				copy(&tmp, "by ", -1);
7074887Schin 				if (notice.item[PARENT].data)
7084887Schin 				{
7094887Schin 					expand(&notice, &tmp, &notice.item[PARENT]);
7104887Schin 					copy(&tmp, " ", -1);
7114887Schin 				}
7124887Schin 				if (notice.item[CORPORATION].data)
7134887Schin 				{
7144887Schin 					expand(&notice, &tmp, &notice.item[CORPORATION]);
7154887Schin 					if (notice.item[INCORPORATION].data)
7164887Schin 					{
7174887Schin 						copy(&tmp, " ", -1);
7184887Schin 						expand(&notice, &tmp, &notice.item[INCORPORATION]);
7194887Schin 					}
7204887Schin 				}
7214887Schin 				else if (notice.item[COMPANY].data)
7224887Schin 					expand(&notice, &tmp, &notice.item[COMPANY]);
7234887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7244887Schin 			}
7254887Schin 			comment(&notice, &buf, NiL, 0, 0);
7264887Schin 			COMMENT(&notice, &buf, "A copy of the License is available at", 0);
7274887Schin 			if (notice.item[URL].data)
7284887Schin 			{
7294887Schin 				expand(&notice, &tmp, &notice.item[URL]);
7304887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7314887Schin 				if (notice.item[URLMD5].data)
7324887Schin 				{
7334887Schin 					copy(&tmp, "(with md5 checksum ", -1);
7344887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
7354887Schin 					copy(&tmp, ")", -1);
7364887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7374887Schin 				}
7384887Schin 			}
739*12068SRoger.Faulkner@Oracle.COM 			else if (notice.type == EPL)
740*12068SRoger.Faulkner@Oracle.COM 				COMMENT(&notice, &buf, "http://www.eclipse.org/org/documents/epl-v10.html", 0);
7414887Schin 			else
7424887Schin 				COMMENT(&notice, &buf, "http://www.opensource.org/licenses/cpl", 0);
7434887Schin 			comment(&notice, &buf, NiL, 0, 0);
7444887Schin 		}
7454887Schin 		else if (notice.type == OPEN)
7464887Schin 		{
7474887Schin 			copy(&tmp, notice.item[PACKAGE].data ? "and it" : "This software", -1);
7484887Schin 			copy(&tmp, " may only be used by you under license from", -1);
7494887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7504887Schin 			if (notice.item[i = CORPORATION].data)
7514887Schin 			{
7524887Schin 				if (notice.item[PARENT].data)
7534887Schin 				{
7544887Schin 					expand(&notice, &tmp, &notice.item[i = PARENT]);
7554887Schin 					copy(&tmp, " ", -1);
7564887Schin 				}
7574887Schin 				expand(&notice, &tmp, &notice.item[CORPORATION]);
7584887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7594887Schin 			}
7604887Schin 			else if (notice.item[i = COMPANY].data)
7614887Schin 			{
7624887Schin 				if (notice.item[PARENT].data)
7634887Schin 				{
7644887Schin 					expand(&notice, &tmp, &notice.item[i = PARENT]);
7654887Schin 					copy(&tmp, " ", -1);
7664887Schin 				}
7674887Schin 				expand(&notice, &tmp, &notice.item[COMPANY]);
7684887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7694887Schin 			}
7704887Schin 			else
7714887Schin 				i = -1;
7724887Schin 			if (notice.item[URL].data)
7734887Schin 			{
7744887Schin 				COMMENT(&notice, &buf, "A copy of the Source Code Agreement is available", 0);
7754887Schin 				copy(&tmp, "at the ", -1);
7764887Schin 				if (i >= 0)
7774887Schin 					expand(&notice, &tmp, &notice.item[i]);
7784887Schin 				copy(&tmp, " Internet web site URL", -1);
7794887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7804887Schin 				comment(&notice, &buf, NiL, 0, 0);
7814887Schin 				expand(&notice, &tmp, &notice.item[URL]);
7824887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7834887Schin 				if (notice.item[URLMD5].data)
7844887Schin 				{
7854887Schin 					copy(&tmp, "(with an md5 checksum of ", -1);
7864887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
7874887Schin 					copy(&tmp, ")", -1);
7884887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7894887Schin 				}
7904887Schin 				comment(&notice, &buf, NiL, 0, 0);
7914887Schin 			}
7924887Schin 			COMMENT(&notice, &buf, "If you have copied or used this software without agreeing", 0);
7934887Schin 			COMMENT(&notice, &buf, "to the terms of the license you are infringing on", 0);
7944887Schin 			COMMENT(&notice, &buf, "the license and copyright and are violating", 0);
7954887Schin 			if (i >= 0)
7964887Schin 				expand(&notice, &tmp, &notice.item[i]);
7974887Schin 			copy(&tmp, "'s", -1);
7984887Schin 			if (n >= COMLONG)
7994887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
8004887Schin 			else
8014887Schin 				PUT(&tmp, ' ');
8024887Schin 			copy(&tmp, "intellectual property rights.", -1);
8034887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
8044887Schin 			comment(&notice, &buf, NiL, 0, 0);
8054887Schin 		}
8064887Schin 		else if (notice.type == GPL)
8074887Schin 		{
8084887Schin 			comment(&notice, &buf, NiL, 0, 0);
8094887Schin 			COMMENT(&notice, &buf, "This is free software; you can redistribute it and/or", 0);
8104887Schin 			COMMENT(&notice, &buf, "modify it under the terms of the GNU General Public License", 0);
8114887Schin 			COMMENT(&notice, &buf, "as published by the Free Software Foundation;", 0);
8124887Schin 			COMMENT(&notice, &buf, "either version 2, or (at your option) any later version.", 0);
8134887Schin 			comment(&notice, &buf, NiL, 0, 0);
8144887Schin 			COMMENT(&notice, &buf, "This software is distributed in the hope that it", 0);
8154887Schin 			COMMENT(&notice, &buf, "will be useful, but WITHOUT ANY WARRANTY;", 0);
8164887Schin 			COMMENT(&notice, &buf, "without even the implied warranty of MERCHANTABILITY", 0);
8174887Schin 			COMMENT(&notice, &buf, "or FITNESS FOR A PARTICULAR PURPOSE.", 0);
8184887Schin 			COMMENT(&notice, &buf, "See the GNU General Public License for more details.", 0);
8194887Schin 			comment(&notice, &buf, NiL, 0, 0);
8204887Schin 			COMMENT(&notice, &buf, "You should have received a copy of the", 0);
8214887Schin 			COMMENT(&notice, &buf, "GNU General Public License", 0);
8224887Schin 			COMMENT(&notice, &buf, "along with this software (see the file COPYING.)", 0);
8234887Schin 			COMMENT(&notice, &buf, "If not, a copy is available at", 0);
8244887Schin 			COMMENT(&notice, &buf, "http://www.gnu.org/copyleft/gpl.html", 0);
8254887Schin 			comment(&notice, &buf, NiL, 0, 0);
8264887Schin 		}
8274887Schin 		else if (notice.type == BSD)
8284887Schin 		{
8294887Schin 			comment(&notice, &buf, NiL, 0, 0);
8304887Schin 			COMMENT(&notice, &buf, "Redistribution and use in source and binary forms, with or", -1);
8314887Schin 			COMMENT(&notice, &buf, "without modification, are permitted provided that the following", -1);
8324887Schin 			COMMENT(&notice, &buf, "conditions are met:", -1);
8334887Schin 			comment(&notice, &buf, NiL, 0, 0);
8344887Schin 			COMMENT(&notice, &buf, "   1. Redistributions of source code must retain the above", -1);
8354887Schin 			COMMENT(&notice, &buf, "      copyright notice, this list of conditions and the", -1);
8364887Schin 			COMMENT(&notice, &buf, "      following disclaimer.", -1);
8374887Schin 			comment(&notice, &buf, NiL, 0, 0);
8384887Schin 			COMMENT(&notice, &buf, "   2. Redistributions in binary form must reproduce the above", -1);
8394887Schin 			COMMENT(&notice, &buf, "      copyright notice, this list of conditions and the", -1);
8404887Schin 			COMMENT(&notice, &buf, "      following disclaimer in the documentation and/or other", -1);
8414887Schin 			COMMENT(&notice, &buf, "      materials provided with the distribution.", -1);
8424887Schin 			comment(&notice, &buf, NiL, 0, 0);
8434887Schin 			copy(&tmp, "   3. Neither the name of ", -1);
8444887Schin 			if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
8454887Schin 				expand(&notice, &tmp, &notice.item[i]);
8464887Schin 			else
8474887Schin 				copy(&tmp, "the copyright holder", -1);
8484887Schin 			copy(&tmp, " nor the", -1);
8494887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), -1);
8504887Schin 			COMMENT(&notice, &buf, "      names of its contributors may be used to endorse or", -1);
8514887Schin 			COMMENT(&notice, &buf, "      promote products derived from this software without", -1);
8524887Schin 			COMMENT(&notice, &buf, "      specific prior written permission.", -1);
8534887Schin 			comment(&notice, &buf, NiL, 0, 0);
8544887Schin 			COMMENT(&notice, &buf, "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND", -1);
8554887Schin 			COMMENT(&notice, &buf, "CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,", -1);
8564887Schin 			COMMENT(&notice, &buf, "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF", -1);
8574887Schin 			COMMENT(&notice, &buf, "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE", -1);
8584887Schin 			COMMENT(&notice, &buf, "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS", -1);
8594887Schin 			COMMENT(&notice, &buf, "BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,", -1);
8604887Schin 			COMMENT(&notice, &buf, "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED", -1);
8614887Schin 			COMMENT(&notice, &buf, "TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,", -1);
8624887Schin 			COMMENT(&notice, &buf, "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON", -1);
8634887Schin 			COMMENT(&notice, &buf, "ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,", -1);
8644887Schin 			COMMENT(&notice, &buf, "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY", -1);
8654887Schin 			COMMENT(&notice, &buf, "OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE", -1);
8664887Schin 			COMMENT(&notice, &buf, "POSSIBILITY OF SUCH DAMAGE.", -1);
8674887Schin 			comment(&notice, &buf, NiL, 0, 0);
8684887Schin 		}
8694887Schin 		else if (notice.type == ZLIB)
8704887Schin 		{
8714887Schin 			comment(&notice, &buf, NiL, 0, 0);
8724887Schin 			COMMENT(&notice, &buf, "This software is provided 'as-is', without any express or implied", -1);
8734887Schin 			COMMENT(&notice, &buf, "warranty. In no event will the authors be held liable for any", -1);
8744887Schin 			COMMENT(&notice, &buf, "damages arising from the use of this software.", -1);
8754887Schin 			comment(&notice, &buf, NiL, 0, 0);
8764887Schin 			COMMENT(&notice, &buf, "Permission is granted to anyone to use this software for any", -1);
8774887Schin 			COMMENT(&notice, &buf, "purpose, including commercial applications, and to alter it and", -1);
8784887Schin 			COMMENT(&notice, &buf, "redistribute it freely, subject to the following restrictions:", -1);
8794887Schin 			comment(&notice, &buf, NiL, 0, 0);
8804887Schin 			COMMENT(&notice, &buf, " 1. The origin of this software must not be misrepresented;", -1);
8814887Schin 			COMMENT(&notice, &buf, "    you must not claim that you wrote the original software. If", -1);
8824887Schin 			COMMENT(&notice, &buf, "    you use this software in a product, an acknowledgment in the", -1);
8834887Schin 			COMMENT(&notice, &buf, "    product documentation would be appreciated but is not", -1);
8844887Schin 			COMMENT(&notice, &buf, "    required.", -1);
8854887Schin 			comment(&notice, &buf, NiL, 0, 0);
8864887Schin 			COMMENT(&notice, &buf, " 2. Altered source versions must be plainly marked as such,", -1);
8874887Schin 			COMMENT(&notice, &buf, "    and must not be misrepresented as being the original", -1);
8884887Schin 			COMMENT(&notice, &buf, "    software.", -1);
8894887Schin 			comment(&notice, &buf, NiL, 0, 0);
8904887Schin 			COMMENT(&notice, &buf, " 3. This notice may not be removed or altered from any source", -1);
8914887Schin 			COMMENT(&notice, &buf, "    distribution.", -1);
8924887Schin 			comment(&notice, &buf, NiL, 0, 0);
8934887Schin 		}
8944887Schin 		else if (notice.type == MIT)
8954887Schin 		{
8964887Schin 			comment(&notice, &buf, NiL, 0, 0);
8974887Schin 			COMMENT(&notice, &buf, "Permission is hereby granted, free of charge, to any person", 0);
8984887Schin 			COMMENT(&notice, &buf, "obtaining a copy of this software and associated", 0);
8994887Schin 			COMMENT(&notice, &buf, "documentation files (the \"Software\"), to deal in the", 0);
9004887Schin 			COMMENT(&notice, &buf, "Software without restriction, including without limitation", 0);
9014887Schin 			COMMENT(&notice, &buf, "the rights to use, copy, modify, merge, publish, distribute,", 0);
9024887Schin 			COMMENT(&notice, &buf, "sublicense, and/or sell copies of the Software, and to", 0);
9034887Schin 			COMMENT(&notice, &buf, "permit persons to whom the Software is furnished to do so,", 0);
9044887Schin 			COMMENT(&notice, &buf, "subject to the following conditions:", 0);
9054887Schin 			comment(&notice, &buf, NiL, 0, 0);
9064887Schin 			COMMENT(&notice, &buf, "The above copyright notice and this permission notice shall", 0);
9074887Schin 			COMMENT(&notice, &buf, "be included in all copies or substantial portions of the", 0);
9084887Schin 			COMMENT(&notice, &buf, "Software.", 0);
9094887Schin 			comment(&notice, &buf, NiL, 0, 0);
9104887Schin 			COMMENT(&notice, &buf, "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY", 0);
9114887Schin 			COMMENT(&notice, &buf, "KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE", 0);
9124887Schin 			COMMENT(&notice, &buf, "WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR", 0);
9134887Schin 			COMMENT(&notice, &buf, "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS", 0);
9144887Schin 			COMMENT(&notice, &buf, "OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR", 0);
9154887Schin 			COMMENT(&notice, &buf, "OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR", 0);
9164887Schin 			COMMENT(&notice, &buf, "OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE", 0);
9174887Schin 			COMMENT(&notice, &buf, "SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", 0);
9184887Schin 			comment(&notice, &buf, NiL, 0, 0);
9194887Schin 		}
9204887Schin 		else
9214887Schin 		{
9224887Schin 			if (notice.type == PROPRIETARY)
9234887Schin 			{
9244887Schin 				if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
9254887Schin 				{
9264887Schin 					expand(&notice, &tmp, &notice.item[i]);
9274887Schin 					copy(&tmp, " - ", -1);
9284887Schin 				}
9294887Schin 				else
9304887Schin 					i = -1;
9314887Schin 				copy(&tmp, "Proprietary", -1);
9324887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9334887Schin 				comment(&notice, &buf, NiL, 0, 0);
9344887Schin 				if (notice.item[URL].data)
9354887Schin 				{
9364887Schin 					copy(&tmp, "This is proprietary source code", -1);
9374887Schin 					if (i >= 0)
9384887Schin 						copy(&tmp, " licensed by", -1);
9394887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9404887Schin 					if (notice.item[PARENT].data)
9414887Schin 					{
9424887Schin 						expand(&notice, &tmp, &notice.item[PARENT]);
9434887Schin 						copy(&tmp, " ", -1);
9444887Schin 					}
9454887Schin 					if (notice.item[CORPORATION].data)
9464887Schin 					{
9474887Schin 						expand(&notice, &tmp, &notice.item[CORPORATION]);
9484887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9494887Schin 					}
9504887Schin 					else if (notice.item[COMPANY].data)
9514887Schin 					{
9524887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
9534887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9544887Schin 					}
9554887Schin 				}
9564887Schin 				else
9574887Schin 				{
9584887Schin 					copy(&tmp, "This is unpublished proprietary source code", -1);
9594887Schin 					if (i >= 0)
9604887Schin 						copy(&tmp, " of", -1);
9614887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9624887Schin 					if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
9634887Schin 						expand(&notice, &tmp, &notice.item[i]);
9644887Schin 					if (notice.item[COMPANY].data)
9654887Schin 					{
9664887Schin 						if (SIZ(&tmp))
9674887Schin 							PUT(&tmp, ' ');
9684887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
9694887Schin 					}
9704887Schin 					if (SIZ(&tmp))
9714887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9724887Schin 					COMMENT(&notice, &buf, "and is not to be disclosed or used except in", 1);
9734887Schin 					COMMENT(&notice, &buf, "accordance with applicable agreements", 1);
9744887Schin 				}
9754887Schin 				comment(&notice, &buf, NiL, 0, 0);
9764887Schin 			}
9774887Schin 			else if (notice.type == NONEXCLUSIVE)
9784887Schin 			{
9794887Schin 				COMMENT(&notice, &buf, "For nonexclusive individual use", 1);
9804887Schin 				comment(&notice, &buf, NiL, 0, 0);
9814887Schin 			}
9824887Schin 			else if (notice.type == NONCOMMERCIAL)
9834887Schin 			{
9844887Schin 				COMMENT(&notice, &buf, "For noncommercial use", 1);
9854887Schin 				comment(&notice, &buf, NiL, 0, 0);
9864887Schin 			}
9874887Schin 			if (notice.type >= PROPRIETARY && !notice.item[URL].data)
9884887Schin 			{
9894887Schin 				COMMENT(&notice, &buf, "Unpublished & Not for Publication", 0);
9904887Schin 				comment(&notice, &buf, NiL, 0, 0);
9914887Schin 			}
9924887Schin 			if (notice.item[URL].data)
9934887Schin 			{
9944887Schin 				copy(&tmp, "This software is licensed", -1);
9954887Schin 				if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
9964887Schin 				{
9974887Schin 					copy(&tmp, " by", -1);
9984887Schin 					if ((notice.item[PARENT].size + (notice.item[CORPORATION].data ? (notice.item[CORPORATION].size + notice.item[INCORPORATION].size) : notice.item[COMPANY].size)) >= (COMLONG - 6))
9994887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10004887Schin 					else
10014887Schin 						PUT(&tmp, ' ');
10024887Schin 					if (notice.item[PARENT].data)
10034887Schin 					{
10044887Schin 						expand(&notice, &tmp, &notice.item[PARENT]);
10054887Schin 						copy(&tmp, " ", -1);
10064887Schin 					}
10074887Schin 					if (notice.item[CORPORATION].data)
10084887Schin 					{
10094887Schin 						expand(&notice, &tmp, &notice.item[CORPORATION]);
10104887Schin 						if (notice.item[INCORPORATION].data)
10114887Schin 						{
10124887Schin 							copy(&tmp, " ", -1);
10134887Schin 							expand(&notice, &tmp, &notice.item[INCORPORATION]);
10144887Schin 						}
10154887Schin 					}
10164887Schin 					else if (notice.item[COMPANY].data)
10174887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
10184887Schin 				}
10194887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10204887Schin 				COMMENT(&notice, &buf, "under the terms and conditions of the license in", 0);
10214887Schin 				expand(&notice, &tmp, &notice.item[URL]);
10224887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10234887Schin 				if (notice.item[URLMD5].data)
10244887Schin 				{
10254887Schin 					copy(&tmp, "(with an md5 checksum of ", -1);
10264887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
10274887Schin 					copy(&tmp, ")", -1);
10284887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10294887Schin 				}
10304887Schin 				comment(&notice, &buf, NiL, 0, 0);
10314887Schin 			}
10324887Schin 			else if (notice.type == PROPRIETARY)
10334887Schin 			{
10344887Schin 				COMMENT(&notice, &buf, "The copyright notice above does not evidence any", 0);
10354887Schin 				COMMENT(&notice, &buf, "actual or intended publication of such source code", 0);
10364887Schin 				comment(&notice, &buf, NiL, 0, 0);
10374887Schin 			}
10384887Schin 		}
10394887Schin 		if (v = notice.item[NOTICE].data)
10404887Schin 		{
10414887Schin 			x = v + notice.item[NOTICE].size;
10424887Schin 			if (*v == '\n')
10434887Schin 				v++;
10444887Schin 			item.quote = notice.item[NOTICE].quote;
10454887Schin 			do
10464887Schin 			{
10474887Schin 				for (item.data = v; v < x && *v != '\n'; v++);
10484887Schin 				if ((item.size = v - item.data) && *item.data == '\t')
10494887Schin 				{
10504887Schin 					item.data++;
10514887Schin 					item.size--;
10524887Schin 					h = 0;
10534887Schin 				}
10544887Schin 				else
10554887Schin 					h = -1;
10564887Schin 				expand(&notice, &tmp, &item);
10574887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), h);
10584887Schin 			} while (v++ < x);
10594887Schin 			if (item.size)
10604887Schin 				comment(&notice, &buf, NiL, 0, 0);
10614887Schin 		}
10624887Schin 		if (notice.item[ORGANIZATION].data)
10634887Schin 		{
10644887Schin 			expand(&notice, &tmp, &notice.item[ORGANIZATION]);
10654887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10664887Schin 			if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
10674887Schin 				expand(&notice, &tmp, &notice.item[i]);
10684887Schin 			if (notice.item[COMPANY].data)
10694887Schin 			{
10704887Schin 				if (SIZ(&tmp))
10714887Schin 					PUT(&tmp, ' ');
10724887Schin 				expand(&notice, &tmp, &notice.item[COMPANY]);
10734887Schin 			}
10744887Schin 			if (SIZ(&tmp))
10754887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10764887Schin 			if (notice.item[LOCATION].data)
10774887Schin 			{
10784887Schin 				expand(&notice, &tmp, &notice.item[LOCATION]);
10794887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10804887Schin 			}
10814887Schin 			comment(&notice, &buf, NiL, 0, 0);
10824887Schin 		}
10834887Schin 	}
10844887Schin 	if (v = notice.item[AUTHOR].data)
10854887Schin 	{
10864887Schin 		x = v + notice.item[AUTHOR].size;
10874887Schin 		q = (x - v) == 1 && (*v == '*' || *v == '-');
10884887Schin 		k = q && notice.type != USAGE ? -1 : 0;
10894887Schin 		for (;;)
10904887Schin 		{
10914887Schin 			if (!q)
10924887Schin 			{
10934887Schin 				while (v < x && (*v == ' ' || *v == '\t' || *v == '\r' || *v == '\n' || *v == ',' || *v == '+'))
10944887Schin 					v++;
10954887Schin 				if (v >= x)
10964887Schin 					break;
10974887Schin 				item.data = v;
10984887Schin 				while (v < x && *v != ',' && *v != '+' && *v++ != '>');
10994887Schin 				item.size = v - item.data;
11004887Schin 				item.quote = notice.item[AUTHOR].quote;
11014887Schin 			}
11024887Schin 			h = 0;
11034887Schin 			for (i = 0; i < notice.ids; i++)
11044887Schin 				if (q || item.size == notice.id[i].name.size && !strncmp(item.data, notice.id[i].name.data, item.size))
11054887Schin 				{
11064887Schin 					h = 1;
11074887Schin 					if (notice.type == USAGE)
11084887Schin 					{
11094887Schin 						copy(&buf, "[-author?", -1);
11104887Schin 						expand(&notice, &buf, &notice.id[i].value);
11114887Schin 						PUT(&buf, ']');
11124887Schin 					}
11134887Schin 					else
11144887Schin 					{
11154887Schin 						if (k < 0)
11164887Schin 						{
11174887Schin 							COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
11184887Schin 							comment(&notice, &buf, NiL, 0, 0);
11194887Schin 						}
11204887Schin 						k = 1;
11214887Schin 						expand(&notice, &tmp, &notice.id[i].value);
11224887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
11234887Schin 					}
11244887Schin 					if (!q)
11254887Schin 						break;
11264887Schin 				}
11274887Schin 			if (q)
11284887Schin 				break;
11294887Schin 			if (!h)
11304887Schin 			{
11314887Schin 				if (notice.type == USAGE)
11324887Schin 				{
11334887Schin 					copy(&buf, "[-author?", -1);
11344887Schin 					expand(&notice, &buf, &item);
11354887Schin 					PUT(&buf, ']');
11364887Schin 				}
11374887Schin 				else
11384887Schin 				{
11394887Schin 					if (k < 0)
11404887Schin 					{
11414887Schin 						COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
11424887Schin 						comment(&notice, &buf, NiL, 0, 0);
11434887Schin 					}
11444887Schin 					k = 1;
11454887Schin 					expand(&notice, &tmp, &item);
11464887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
11474887Schin 				}
11484887Schin 			}
11494887Schin 		}
11504887Schin 		if (k > 0)
11514887Schin 			comment(&notice, &buf, NiL, 0, 0);
11524887Schin 	}
11534887Schin 	if (notice.type == USAGE)
11544887Schin 	{
11554887Schin 		copy(&buf, "[-copyright?", -1);
11564887Schin 		copyright(&notice, &buf);
11574887Schin 		PUT(&buf, ']');
11584887Schin 		if (notice.item[URL].data)
11594887Schin 		{
11604887Schin 			copy(&buf, "[-license?", -1);
11614887Schin 			expand(&notice, &buf, &notice.item[URL]);
11624887Schin 			PUT(&buf, ']');
11634887Schin 		}
11644887Schin 		PUT(&buf, '\n');
11654887Schin 	}
11664887Schin 	else
11674887Schin 		comment(&notice, &buf, NiL, -1, 0);
11684887Schin 	return END(&buf);
11694887Schin }
1170