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