xref: /onnv-gate/usr/src/lib/libast/common/port/astlicense.c (revision 10898:1883b621b3ea)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*10898Sroland.mainz@nrubsig.org *          Copyright (c) 1985-2009 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
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 	{
431*10898Sroland.mainz@nrubsig.org 		first = 1;
432*10898Sroland.mainz@nrubsig.org 		while (c = *s)
4334887Schin 		{
4344887Schin 			while (c == ' ' || c == '\t' || c == '\n' && ++line || c == '\r' || c == ',' || c == ';' || c == ')')
4354887Schin 				c = *++s;
4364887Schin 			if (!c)
4374887Schin 				break;
4384887Schin 			if (c == '#')
4394887Schin 			{
4404887Schin 				while (*++s && *s != '\n');
4414887Schin 				if (*s)
4424887Schin 					s++;
4434887Schin 				line++;
4444887Schin 				continue;
4454887Schin 			}
4464887Schin 			if (c == '\n')
4474887Schin 			{
4484887Schin 				s++;
4494887Schin 				line++;
4504887Schin 				continue;
4514887Schin 			}
4524887Schin 			if (c == '[')
4534887Schin 				c = *++s;
4544887Schin 			x = s;
4554887Schin 			n = 0;
4564887Schin 			while (c && c != '=' && c != ']' && c != ')' && c != ',' && c != ' ' && c != '\t' && c != '\n' && c != '\r')
4574887Schin 				c = *++s;
4584887Schin 			n = s - x;
4594887Schin 			h = lookup(key, x, n);
4604887Schin 			if (c == ']')
4614887Schin 				c = *++s;
4624887Schin 			if (c == '=' || first)
4634887Schin 			{
4644887Schin 				if (c == '=')
4654887Schin 				{
4664887Schin 					q = ((c = *++s) == '"' || c == '\'') ? *s++ : 0;
4674887Schin 					if (c == '(')
4684887Schin 					{
4694887Schin 						s++;
4704887Schin 						if (h == LICENSE)
4714887Schin 							contributor = 0;
4724887Schin 						else if (h == CONTRIBUTOR)
4734887Schin 							contributor = 1;
4744887Schin 						else
4754887Schin 						{
4764887Schin 							q = 1;
4774887Schin 							i = 0;
4784887Schin 							for (;;)
4794887Schin 							{
4804887Schin 								switch (*s++)
4814887Schin 								{
4824887Schin 								case 0:
4834887Schin 									s--;
4844887Schin 									break;
4854887Schin 								case '(':
4864887Schin 									if (!i)
4874887Schin 										q++;
4884887Schin 									continue;
4894887Schin 								case ')':
4904887Schin 									if (!i && !--q)
4914887Schin 										break;
4924887Schin 									continue;
4934887Schin 								case '"':
4944887Schin 								case '\'':
4954887Schin 									if (!i)
4964887Schin 										i = *(s - 1);
4974887Schin 									else if (i == *(s - 1))
4984887Schin 										i = 0;
4994887Schin 									continue;
5004887Schin 								case '\\':
5014887Schin 									if (*s == i && i == '"')
5024887Schin 										i++;
5034887Schin 									continue;
5044887Schin 								case '\n':
5054887Schin 									line++;
5064887Schin 									continue;
5074887Schin 								default:
5084887Schin 									continue;
5094887Schin 								}
5104887Schin 								break;
5114887Schin 							}
5124887Schin 						}
5134887Schin 						continue;
5144887Schin 					}
5154887Schin 					quote = 0;
5164887Schin 					v = s;
5174887Schin 					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 != ';'))
5184887Schin 					{
5194887Schin 						if (c == '\n')
5204887Schin 							line++;
5214887Schin 						s++;
5224887Schin 					}
5234887Schin 				}
5244887Schin 				else
5254887Schin 				{
5264887Schin 					h = STYLE;
5274887Schin 					v = x;
5284887Schin 				}
5294887Schin 				if (c == '\n')
5304887Schin 					line++;
5314887Schin 				if (contributor)
5324887Schin 				{
5334887Schin 					for (i = 0; i < notice.ids; i++)
5344887Schin 						if (n == notice.id[i].name.size && !strncmp(x, notice.id[i].name.data, n))
5354887Schin 							break;
5364887Schin 					if (i < IDS)
5374887Schin 					{
5384887Schin 						notice.id[i].name.data = x;
5394887Schin 						notice.id[i].name.size = n;
5404887Schin 						notice.id[i].name.quote = 0;
5414887Schin 						notice.id[i].value.data = v;
5424887Schin 						notice.id[i].value.size = s - v;
5434887Schin 						notice.id[i].value.quote = quote;
5444887Schin 						if (notice.ids <= i)
5454887Schin 							notice.ids = i + 1;
5464887Schin 					}
5474887Schin 				}
5484887Schin 				else if (h == QUERY)
5494887Schin 				{
5504887Schin 					if ((s - v) == 3 && v[0] == 'a' && v[1] == 'l' && v[2] == 'l')
5514887Schin 					{
5524887Schin 						for (i = 0; i < ITEMS; i++)
5534887Schin 							if (notice.item[i].size)
5544887Schin 							{
5554887Schin 								expand(&notice, &buf, &key[i]);
5564887Schin 								PUT(&buf, '=');
5574887Schin 								for (h = 0;; h++)
5584887Schin 									if (h >= notice.item[i].size)
5594887Schin 									{
5604887Schin 										h = 0;
5614887Schin 										break;
5624887Schin 									}
5634887Schin 									else if (notice.item[i].data[h] == ' ' || notice.item[i].data[h] == '\t')
5644887Schin 										break;
5654887Schin 								if (h)
5664887Schin 									PUT(&buf, '\'');
5674887Schin 								expand(&notice, &buf, &notice.item[i]);
5684887Schin 								if (h)
5694887Schin 									PUT(&buf, '\'');
5704887Schin 								PUT(&buf, '\n');
5714887Schin 							}
5724887Schin 					}
5734887Schin 					else
5744887Schin 					{
5754887Schin 						if ((h = lookup(key, v, s - v)) < 0)
5764887Schin 						{
5774887Schin 							item.data = v;
5784887Schin 							item.size = s - v;
5794887Schin 							item.quote = 0;
5804887Schin 							expand(&notice, &buf, &item);
5814887Schin 						}
5824887Schin 						else
5834887Schin 							expand(&notice, &buf, &notice.item[h]);
5844887Schin 						PUT(&buf, '\n');
5854887Schin 					}
5864887Schin 					return END(&buf);
5874887Schin 				}
5884887Schin 				else
5894887Schin 				{
5904887Schin 					if (h == STYLE)
5914887Schin 						switch (c = lookup(lic, v, s - v))
5924887Schin 						{
5934887Schin 						case NONE:
5944887Schin 							return 0;
5954887Schin 						case TEST:
5964887Schin 							notice.test = 1;
5974887Schin 							h = -1;
5984887Schin 							break;
5994887Schin 						case VERBOSE:
6004887Schin 							notice.verbose = 1;
6014887Schin 							h = -1;
6024887Schin 							break;
6034887Schin 						case USAGE:
6044887Schin 							notice.type = c;
6054887Schin 							h = -1;
6064887Schin 							break;
6074887Schin 						case -1:
6084887Schin 							c = SPECIAL;
6094887Schin 							/*FALLTHROUGH*/
6104887Schin 						default:
6114887Schin 							notice.type = c;
6124887Schin 							notice.item[CLASS].data = lic[lic[c].quote].data;
6134887Schin 							notice.item[CLASS].size = lic[lic[c].quote].size;
6144887Schin 							break;
6154887Schin 						}
6164887Schin 					if (h >= 0)
6174887Schin 					{
6184887Schin 						notice.item[h].data = (notice.item[h].size = s - v) ? v : (char*)0;
6194887Schin 						notice.item[h].quote = quote;
6204887Schin 						k = 1;
6214887Schin 					}
6224887Schin 				}
6234887Schin 			}
6244887Schin 			else
6254887Schin 			{
6264887Schin 				if (file)
6274887Schin 				{
6284887Schin 					copy(&buf, "\"", -1);
6294887Schin 					copy(&buf, file, -1);
6304887Schin 					copy(&buf, "\", line ", -1);
6314887Schin 					x = &tmpbuf[sizeof(tmpbuf)];
6324887Schin 					*--x = 0;
6334887Schin 					line++;
6344887Schin 					do *--x = ("0123456789")[line % 10]; while (line /= 10);
6354887Schin 					copy(&buf, x, -1);
6364887Schin 					copy(&buf, ": ", -1);
6374887Schin 				}
6384887Schin 				copy(&buf, "option error: assignment expected", -1);
6394887Schin 				PUT(&buf, 0);
6404887Schin 				return -1;
6414887Schin 			}
6424887Schin 			if (*s)
6434887Schin 				s++;
644*10898Sroland.mainz@nrubsig.org 			first = 0;
6454887Schin 		}
6464887Schin 		if (!options || !*(s = options))
6474887Schin 			break;
6484887Schin 		options = 0;
6494887Schin 	}
6504887Schin 	if (!k)
6514887Schin 		return 0;
6524887Schin 	if (notice.type == INLINE && (!notice.verbose || !notice.item[NOTICE].data))
6534887Schin 		return 0;
6544887Schin 	if (notice.type != USAGE)
6554887Schin 	{
6564887Schin 		if (!notice.type)
6574887Schin 			notice.type = SPECIAL;
6584887Schin 		comment(&notice, &buf, NiL, 1, 0);
6594887Schin 		comment(&notice, &buf, NiL, 0, 0);
6604887Schin 		if (notice.item[PACKAGE].data)
6614887Schin 		{
6624887Schin 			copy(&tmp, "This software is part of the ", -1);
6634887Schin 			expand(&notice, &tmp, &notice.item[PACKAGE]);
6644887Schin 			copy(&tmp, " package", -1);
6654887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6664887Schin 		}
6674887Schin 		if (notice.type >= OPEN)
6684887Schin 		{
6694887Schin 			copyright(&notice, &tmp);
6704887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6714887Schin 			if (notice.type >= SPECIAL)
6724887Schin 				COMMENT(&notice, &buf, "All Rights Reserved", 0);
6734887Schin 		}
6744887Schin 		if (notice.type == CPL)
6754887Schin 		{
6764887Schin 			copy(&tmp, notice.item[PACKAGE].data ? "and" : "This software", -1);
6774887Schin 			copy(&tmp, " is licensed under the", -1);
6784887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6794887Schin 			copy(&tmp, "Common Public License", -1);
6804887Schin 			if (notice.item[VERSION].data)
6814887Schin 			{
6824887Schin 				copy(&tmp, ", Version ", -1);
6834887Schin 				expand(&notice, &tmp, &notice.item[VERSION]);
6844887Schin 			}
6854887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
6864887Schin 			if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
6874887Schin 			{
6884887Schin 				copy(&tmp, "by ", -1);
6894887Schin 				if (notice.item[PARENT].data)
6904887Schin 				{
6914887Schin 					expand(&notice, &tmp, &notice.item[PARENT]);
6924887Schin 					copy(&tmp, " ", -1);
6934887Schin 				}
6944887Schin 				if (notice.item[CORPORATION].data)
6954887Schin 				{
6964887Schin 					expand(&notice, &tmp, &notice.item[CORPORATION]);
6974887Schin 					if (notice.item[INCORPORATION].data)
6984887Schin 					{
6994887Schin 						copy(&tmp, " ", -1);
7004887Schin 						expand(&notice, &tmp, &notice.item[INCORPORATION]);
7014887Schin 					}
7024887Schin 				}
7034887Schin 				else if (notice.item[COMPANY].data)
7044887Schin 					expand(&notice, &tmp, &notice.item[COMPANY]);
7054887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7064887Schin 			}
7074887Schin 			comment(&notice, &buf, NiL, 0, 0);
7084887Schin 			COMMENT(&notice, &buf, "A copy of the License is available at", 0);
7094887Schin 			if (notice.item[URL].data)
7104887Schin 			{
7114887Schin 				expand(&notice, &tmp, &notice.item[URL]);
7124887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7134887Schin 				if (notice.item[URLMD5].data)
7144887Schin 				{
7154887Schin 					copy(&tmp, "(with md5 checksum ", -1);
7164887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
7174887Schin 					copy(&tmp, ")", -1);
7184887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7194887Schin 				}
7204887Schin 			}
7214887Schin 			else
7224887Schin 				COMMENT(&notice, &buf, "http://www.opensource.org/licenses/cpl", 0);
7234887Schin 			comment(&notice, &buf, NiL, 0, 0);
7244887Schin 		}
7254887Schin 		else if (notice.type == OPEN)
7264887Schin 		{
7274887Schin 			copy(&tmp, notice.item[PACKAGE].data ? "and it" : "This software", -1);
7284887Schin 			copy(&tmp, " may only be used by you under license from", -1);
7294887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7304887Schin 			if (notice.item[i = CORPORATION].data)
7314887Schin 			{
7324887Schin 				if (notice.item[PARENT].data)
7334887Schin 				{
7344887Schin 					expand(&notice, &tmp, &notice.item[i = PARENT]);
7354887Schin 					copy(&tmp, " ", -1);
7364887Schin 				}
7374887Schin 				expand(&notice, &tmp, &notice.item[CORPORATION]);
7384887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7394887Schin 			}
7404887Schin 			else if (notice.item[i = COMPANY].data)
7414887Schin 			{
7424887Schin 				if (notice.item[PARENT].data)
7434887Schin 				{
7444887Schin 					expand(&notice, &tmp, &notice.item[i = PARENT]);
7454887Schin 					copy(&tmp, " ", -1);
7464887Schin 				}
7474887Schin 				expand(&notice, &tmp, &notice.item[COMPANY]);
7484887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7494887Schin 			}
7504887Schin 			else
7514887Schin 				i = -1;
7524887Schin 			if (notice.item[URL].data)
7534887Schin 			{
7544887Schin 				COMMENT(&notice, &buf, "A copy of the Source Code Agreement is available", 0);
7554887Schin 				copy(&tmp, "at the ", -1);
7564887Schin 				if (i >= 0)
7574887Schin 					expand(&notice, &tmp, &notice.item[i]);
7584887Schin 				copy(&tmp, " Internet web site URL", -1);
7594887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7604887Schin 				comment(&notice, &buf, NiL, 0, 0);
7614887Schin 				expand(&notice, &tmp, &notice.item[URL]);
7624887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7634887Schin 				if (notice.item[URLMD5].data)
7644887Schin 				{
7654887Schin 					copy(&tmp, "(with an md5 checksum of ", -1);
7664887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
7674887Schin 					copy(&tmp, ")", -1);
7684887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7694887Schin 				}
7704887Schin 				comment(&notice, &buf, NiL, 0, 0);
7714887Schin 			}
7724887Schin 			COMMENT(&notice, &buf, "If you have copied or used this software without agreeing", 0);
7734887Schin 			COMMENT(&notice, &buf, "to the terms of the license you are infringing on", 0);
7744887Schin 			COMMENT(&notice, &buf, "the license and copyright and are violating", 0);
7754887Schin 			if (i >= 0)
7764887Schin 				expand(&notice, &tmp, &notice.item[i]);
7774887Schin 			copy(&tmp, "'s", -1);
7784887Schin 			if (n >= COMLONG)
7794887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7804887Schin 			else
7814887Schin 				PUT(&tmp, ' ');
7824887Schin 			copy(&tmp, "intellectual property rights.", -1);
7834887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
7844887Schin 			comment(&notice, &buf, NiL, 0, 0);
7854887Schin 		}
7864887Schin 		else if (notice.type == GPL)
7874887Schin 		{
7884887Schin 			comment(&notice, &buf, NiL, 0, 0);
7894887Schin 			COMMENT(&notice, &buf, "This is free software; you can redistribute it and/or", 0);
7904887Schin 			COMMENT(&notice, &buf, "modify it under the terms of the GNU General Public License", 0);
7914887Schin 			COMMENT(&notice, &buf, "as published by the Free Software Foundation;", 0);
7924887Schin 			COMMENT(&notice, &buf, "either version 2, or (at your option) any later version.", 0);
7934887Schin 			comment(&notice, &buf, NiL, 0, 0);
7944887Schin 			COMMENT(&notice, &buf, "This software is distributed in the hope that it", 0);
7954887Schin 			COMMENT(&notice, &buf, "will be useful, but WITHOUT ANY WARRANTY;", 0);
7964887Schin 			COMMENT(&notice, &buf, "without even the implied warranty of MERCHANTABILITY", 0);
7974887Schin 			COMMENT(&notice, &buf, "or FITNESS FOR A PARTICULAR PURPOSE.", 0);
7984887Schin 			COMMENT(&notice, &buf, "See the GNU General Public License for more details.", 0);
7994887Schin 			comment(&notice, &buf, NiL, 0, 0);
8004887Schin 			COMMENT(&notice, &buf, "You should have received a copy of the", 0);
8014887Schin 			COMMENT(&notice, &buf, "GNU General Public License", 0);
8024887Schin 			COMMENT(&notice, &buf, "along with this software (see the file COPYING.)", 0);
8034887Schin 			COMMENT(&notice, &buf, "If not, a copy is available at", 0);
8044887Schin 			COMMENT(&notice, &buf, "http://www.gnu.org/copyleft/gpl.html", 0);
8054887Schin 			comment(&notice, &buf, NiL, 0, 0);
8064887Schin 		}
8074887Schin 		else if (notice.type == BSD)
8084887Schin 		{
8094887Schin 			comment(&notice, &buf, NiL, 0, 0);
8104887Schin 			COMMENT(&notice, &buf, "Redistribution and use in source and binary forms, with or", -1);
8114887Schin 			COMMENT(&notice, &buf, "without modification, are permitted provided that the following", -1);
8124887Schin 			COMMENT(&notice, &buf, "conditions are met:", -1);
8134887Schin 			comment(&notice, &buf, NiL, 0, 0);
8144887Schin 			COMMENT(&notice, &buf, "   1. Redistributions of source code must retain the above", -1);
8154887Schin 			COMMENT(&notice, &buf, "      copyright notice, this list of conditions and the", -1);
8164887Schin 			COMMENT(&notice, &buf, "      following disclaimer.", -1);
8174887Schin 			comment(&notice, &buf, NiL, 0, 0);
8184887Schin 			COMMENT(&notice, &buf, "   2. Redistributions in binary form must reproduce the above", -1);
8194887Schin 			COMMENT(&notice, &buf, "      copyright notice, this list of conditions and the", -1);
8204887Schin 			COMMENT(&notice, &buf, "      following disclaimer in the documentation and/or other", -1);
8214887Schin 			COMMENT(&notice, &buf, "      materials provided with the distribution.", -1);
8224887Schin 			comment(&notice, &buf, NiL, 0, 0);
8234887Schin 			copy(&tmp, "   3. Neither the name of ", -1);
8244887Schin 			if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
8254887Schin 				expand(&notice, &tmp, &notice.item[i]);
8264887Schin 			else
8274887Schin 				copy(&tmp, "the copyright holder", -1);
8284887Schin 			copy(&tmp, " nor the", -1);
8294887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), -1);
8304887Schin 			COMMENT(&notice, &buf, "      names of its contributors may be used to endorse or", -1);
8314887Schin 			COMMENT(&notice, &buf, "      promote products derived from this software without", -1);
8324887Schin 			COMMENT(&notice, &buf, "      specific prior written permission.", -1);
8334887Schin 			comment(&notice, &buf, NiL, 0, 0);
8344887Schin 			COMMENT(&notice, &buf, "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND", -1);
8354887Schin 			COMMENT(&notice, &buf, "CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,", -1);
8364887Schin 			COMMENT(&notice, &buf, "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF", -1);
8374887Schin 			COMMENT(&notice, &buf, "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE", -1);
8384887Schin 			COMMENT(&notice, &buf, "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS", -1);
8394887Schin 			COMMENT(&notice, &buf, "BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,", -1);
8404887Schin 			COMMENT(&notice, &buf, "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED", -1);
8414887Schin 			COMMENT(&notice, &buf, "TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,", -1);
8424887Schin 			COMMENT(&notice, &buf, "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON", -1);
8434887Schin 			COMMENT(&notice, &buf, "ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,", -1);
8444887Schin 			COMMENT(&notice, &buf, "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY", -1);
8454887Schin 			COMMENT(&notice, &buf, "OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE", -1);
8464887Schin 			COMMENT(&notice, &buf, "POSSIBILITY OF SUCH DAMAGE.", -1);
8474887Schin 			comment(&notice, &buf, NiL, 0, 0);
8484887Schin 		}
8494887Schin 		else if (notice.type == ZLIB)
8504887Schin 		{
8514887Schin 			comment(&notice, &buf, NiL, 0, 0);
8524887Schin 			COMMENT(&notice, &buf, "This software is provided 'as-is', without any express or implied", -1);
8534887Schin 			COMMENT(&notice, &buf, "warranty. In no event will the authors be held liable for any", -1);
8544887Schin 			COMMENT(&notice, &buf, "damages arising from the use of this software.", -1);
8554887Schin 			comment(&notice, &buf, NiL, 0, 0);
8564887Schin 			COMMENT(&notice, &buf, "Permission is granted to anyone to use this software for any", -1);
8574887Schin 			COMMENT(&notice, &buf, "purpose, including commercial applications, and to alter it and", -1);
8584887Schin 			COMMENT(&notice, &buf, "redistribute it freely, subject to the following restrictions:", -1);
8594887Schin 			comment(&notice, &buf, NiL, 0, 0);
8604887Schin 			COMMENT(&notice, &buf, " 1. The origin of this software must not be misrepresented;", -1);
8614887Schin 			COMMENT(&notice, &buf, "    you must not claim that you wrote the original software. If", -1);
8624887Schin 			COMMENT(&notice, &buf, "    you use this software in a product, an acknowledgment in the", -1);
8634887Schin 			COMMENT(&notice, &buf, "    product documentation would be appreciated but is not", -1);
8644887Schin 			COMMENT(&notice, &buf, "    required.", -1);
8654887Schin 			comment(&notice, &buf, NiL, 0, 0);
8664887Schin 			COMMENT(&notice, &buf, " 2. Altered source versions must be plainly marked as such,", -1);
8674887Schin 			COMMENT(&notice, &buf, "    and must not be misrepresented as being the original", -1);
8684887Schin 			COMMENT(&notice, &buf, "    software.", -1);
8694887Schin 			comment(&notice, &buf, NiL, 0, 0);
8704887Schin 			COMMENT(&notice, &buf, " 3. This notice may not be removed or altered from any source", -1);
8714887Schin 			COMMENT(&notice, &buf, "    distribution.", -1);
8724887Schin 			comment(&notice, &buf, NiL, 0, 0);
8734887Schin 		}
8744887Schin 		else if (notice.type == MIT)
8754887Schin 		{
8764887Schin 			comment(&notice, &buf, NiL, 0, 0);
8774887Schin 			COMMENT(&notice, &buf, "Permission is hereby granted, free of charge, to any person", 0);
8784887Schin 			COMMENT(&notice, &buf, "obtaining a copy of this software and associated", 0);
8794887Schin 			COMMENT(&notice, &buf, "documentation files (the \"Software\"), to deal in the", 0);
8804887Schin 			COMMENT(&notice, &buf, "Software without restriction, including without limitation", 0);
8814887Schin 			COMMENT(&notice, &buf, "the rights to use, copy, modify, merge, publish, distribute,", 0);
8824887Schin 			COMMENT(&notice, &buf, "sublicense, and/or sell copies of the Software, and to", 0);
8834887Schin 			COMMENT(&notice, &buf, "permit persons to whom the Software is furnished to do so,", 0);
8844887Schin 			COMMENT(&notice, &buf, "subject to the following conditions:", 0);
8854887Schin 			comment(&notice, &buf, NiL, 0, 0);
8864887Schin 			COMMENT(&notice, &buf, "The above copyright notice and this permission notice shall", 0);
8874887Schin 			COMMENT(&notice, &buf, "be included in all copies or substantial portions of the", 0);
8884887Schin 			COMMENT(&notice, &buf, "Software.", 0);
8894887Schin 			comment(&notice, &buf, NiL, 0, 0);
8904887Schin 			COMMENT(&notice, &buf, "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY", 0);
8914887Schin 			COMMENT(&notice, &buf, "KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE", 0);
8924887Schin 			COMMENT(&notice, &buf, "WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR", 0);
8934887Schin 			COMMENT(&notice, &buf, "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS", 0);
8944887Schin 			COMMENT(&notice, &buf, "OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR", 0);
8954887Schin 			COMMENT(&notice, &buf, "OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR", 0);
8964887Schin 			COMMENT(&notice, &buf, "OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE", 0);
8974887Schin 			COMMENT(&notice, &buf, "SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", 0);
8984887Schin 			comment(&notice, &buf, NiL, 0, 0);
8994887Schin 		}
9004887Schin 		else
9014887Schin 		{
9024887Schin 			if (notice.type == PROPRIETARY)
9034887Schin 			{
9044887Schin 				if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
9054887Schin 				{
9064887Schin 					expand(&notice, &tmp, &notice.item[i]);
9074887Schin 					copy(&tmp, " - ", -1);
9084887Schin 				}
9094887Schin 				else
9104887Schin 					i = -1;
9114887Schin 				copy(&tmp, "Proprietary", -1);
9124887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9134887Schin 				comment(&notice, &buf, NiL, 0, 0);
9144887Schin 				if (notice.item[URL].data)
9154887Schin 				{
9164887Schin 					copy(&tmp, "This is proprietary source code", -1);
9174887Schin 					if (i >= 0)
9184887Schin 						copy(&tmp, " licensed by", -1);
9194887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9204887Schin 					if (notice.item[PARENT].data)
9214887Schin 					{
9224887Schin 						expand(&notice, &tmp, &notice.item[PARENT]);
9234887Schin 						copy(&tmp, " ", -1);
9244887Schin 					}
9254887Schin 					if (notice.item[CORPORATION].data)
9264887Schin 					{
9274887Schin 						expand(&notice, &tmp, &notice.item[CORPORATION]);
9284887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9294887Schin 					}
9304887Schin 					else if (notice.item[COMPANY].data)
9314887Schin 					{
9324887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
9334887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9344887Schin 					}
9354887Schin 				}
9364887Schin 				else
9374887Schin 				{
9384887Schin 					copy(&tmp, "This is unpublished proprietary source code", -1);
9394887Schin 					if (i >= 0)
9404887Schin 						copy(&tmp, " of", -1);
9414887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9424887Schin 					if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
9434887Schin 						expand(&notice, &tmp, &notice.item[i]);
9444887Schin 					if (notice.item[COMPANY].data)
9454887Schin 					{
9464887Schin 						if (SIZ(&tmp))
9474887Schin 							PUT(&tmp, ' ');
9484887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
9494887Schin 					}
9504887Schin 					if (SIZ(&tmp))
9514887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
9524887Schin 					COMMENT(&notice, &buf, "and is not to be disclosed or used except in", 1);
9534887Schin 					COMMENT(&notice, &buf, "accordance with applicable agreements", 1);
9544887Schin 				}
9554887Schin 				comment(&notice, &buf, NiL, 0, 0);
9564887Schin 			}
9574887Schin 			else if (notice.type == NONEXCLUSIVE)
9584887Schin 			{
9594887Schin 				COMMENT(&notice, &buf, "For nonexclusive individual use", 1);
9604887Schin 				comment(&notice, &buf, NiL, 0, 0);
9614887Schin 			}
9624887Schin 			else if (notice.type == NONCOMMERCIAL)
9634887Schin 			{
9644887Schin 				COMMENT(&notice, &buf, "For noncommercial use", 1);
9654887Schin 				comment(&notice, &buf, NiL, 0, 0);
9664887Schin 			}
9674887Schin 			if (notice.type >= PROPRIETARY && !notice.item[URL].data)
9684887Schin 			{
9694887Schin 				COMMENT(&notice, &buf, "Unpublished & Not for Publication", 0);
9704887Schin 				comment(&notice, &buf, NiL, 0, 0);
9714887Schin 			}
9724887Schin 			if (notice.item[URL].data)
9734887Schin 			{
9744887Schin 				copy(&tmp, "This software is licensed", -1);
9754887Schin 				if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
9764887Schin 				{
9774887Schin 					copy(&tmp, " by", -1);
9784887Schin 					if ((notice.item[PARENT].size + (notice.item[CORPORATION].data ? (notice.item[CORPORATION].size + notice.item[INCORPORATION].size) : notice.item[COMPANY].size)) >= (COMLONG - 6))
9794887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
9804887Schin 					else
9814887Schin 						PUT(&tmp, ' ');
9824887Schin 					if (notice.item[PARENT].data)
9834887Schin 					{
9844887Schin 						expand(&notice, &tmp, &notice.item[PARENT]);
9854887Schin 						copy(&tmp, " ", -1);
9864887Schin 					}
9874887Schin 					if (notice.item[CORPORATION].data)
9884887Schin 					{
9894887Schin 						expand(&notice, &tmp, &notice.item[CORPORATION]);
9904887Schin 						if (notice.item[INCORPORATION].data)
9914887Schin 						{
9924887Schin 							copy(&tmp, " ", -1);
9934887Schin 							expand(&notice, &tmp, &notice.item[INCORPORATION]);
9944887Schin 						}
9954887Schin 					}
9964887Schin 					else if (notice.item[COMPANY].data)
9974887Schin 						expand(&notice, &tmp, &notice.item[COMPANY]);
9984887Schin 				}
9994887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10004887Schin 				COMMENT(&notice, &buf, "under the terms and conditions of the license in", 0);
10014887Schin 				expand(&notice, &tmp, &notice.item[URL]);
10024887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10034887Schin 				if (notice.item[URLMD5].data)
10044887Schin 				{
10054887Schin 					copy(&tmp, "(with an md5 checksum of ", -1);
10064887Schin 					expand(&notice, &tmp, &notice.item[URLMD5]);
10074887Schin 					copy(&tmp, ")", -1);
10084887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10094887Schin 				}
10104887Schin 				comment(&notice, &buf, NiL, 0, 0);
10114887Schin 			}
10124887Schin 			else if (notice.type == PROPRIETARY)
10134887Schin 			{
10144887Schin 				COMMENT(&notice, &buf, "The copyright notice above does not evidence any", 0);
10154887Schin 				COMMENT(&notice, &buf, "actual or intended publication of such source code", 0);
10164887Schin 				comment(&notice, &buf, NiL, 0, 0);
10174887Schin 			}
10184887Schin 		}
10194887Schin 		if (v = notice.item[NOTICE].data)
10204887Schin 		{
10214887Schin 			x = v + notice.item[NOTICE].size;
10224887Schin 			if (*v == '\n')
10234887Schin 				v++;
10244887Schin 			item.quote = notice.item[NOTICE].quote;
10254887Schin 			do
10264887Schin 			{
10274887Schin 				for (item.data = v; v < x && *v != '\n'; v++);
10284887Schin 				if ((item.size = v - item.data) && *item.data == '\t')
10294887Schin 				{
10304887Schin 					item.data++;
10314887Schin 					item.size--;
10324887Schin 					h = 0;
10334887Schin 				}
10344887Schin 				else
10354887Schin 					h = -1;
10364887Schin 				expand(&notice, &tmp, &item);
10374887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), h);
10384887Schin 			} while (v++ < x);
10394887Schin 			if (item.size)
10404887Schin 				comment(&notice, &buf, NiL, 0, 0);
10414887Schin 		}
10424887Schin 		if (notice.item[ORGANIZATION].data)
10434887Schin 		{
10444887Schin 			expand(&notice, &tmp, &notice.item[ORGANIZATION]);
10454887Schin 			comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10464887Schin 			if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
10474887Schin 				expand(&notice, &tmp, &notice.item[i]);
10484887Schin 			if (notice.item[COMPANY].data)
10494887Schin 			{
10504887Schin 				if (SIZ(&tmp))
10514887Schin 					PUT(&tmp, ' ');
10524887Schin 				expand(&notice, &tmp, &notice.item[COMPANY]);
10534887Schin 			}
10544887Schin 			if (SIZ(&tmp))
10554887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10564887Schin 			if (notice.item[LOCATION].data)
10574887Schin 			{
10584887Schin 				expand(&notice, &tmp, &notice.item[LOCATION]);
10594887Schin 				comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
10604887Schin 			}
10614887Schin 			comment(&notice, &buf, NiL, 0, 0);
10624887Schin 		}
10634887Schin 	}
10644887Schin 	if (v = notice.item[AUTHOR].data)
10654887Schin 	{
10664887Schin 		x = v + notice.item[AUTHOR].size;
10674887Schin 		q = (x - v) == 1 && (*v == '*' || *v == '-');
10684887Schin 		k = q && notice.type != USAGE ? -1 : 0;
10694887Schin 		for (;;)
10704887Schin 		{
10714887Schin 			if (!q)
10724887Schin 			{
10734887Schin 				while (v < x && (*v == ' ' || *v == '\t' || *v == '\r' || *v == '\n' || *v == ',' || *v == '+'))
10744887Schin 					v++;
10754887Schin 				if (v >= x)
10764887Schin 					break;
10774887Schin 				item.data = v;
10784887Schin 				while (v < x && *v != ',' && *v != '+' && *v++ != '>');
10794887Schin 				item.size = v - item.data;
10804887Schin 				item.quote = notice.item[AUTHOR].quote;
10814887Schin 			}
10824887Schin 			h = 0;
10834887Schin 			for (i = 0; i < notice.ids; i++)
10844887Schin 				if (q || item.size == notice.id[i].name.size && !strncmp(item.data, notice.id[i].name.data, item.size))
10854887Schin 				{
10864887Schin 					h = 1;
10874887Schin 					if (notice.type == USAGE)
10884887Schin 					{
10894887Schin 						copy(&buf, "[-author?", -1);
10904887Schin 						expand(&notice, &buf, &notice.id[i].value);
10914887Schin 						PUT(&buf, ']');
10924887Schin 					}
10934887Schin 					else
10944887Schin 					{
10954887Schin 						if (k < 0)
10964887Schin 						{
10974887Schin 							COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
10984887Schin 							comment(&notice, &buf, NiL, 0, 0);
10994887Schin 						}
11004887Schin 						k = 1;
11014887Schin 						expand(&notice, &tmp, &notice.id[i].value);
11024887Schin 						comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
11034887Schin 					}
11044887Schin 					if (!q)
11054887Schin 						break;
11064887Schin 				}
11074887Schin 			if (q)
11084887Schin 				break;
11094887Schin 			if (!h)
11104887Schin 			{
11114887Schin 				if (notice.type == USAGE)
11124887Schin 				{
11134887Schin 					copy(&buf, "[-author?", -1);
11144887Schin 					expand(&notice, &buf, &item);
11154887Schin 					PUT(&buf, ']');
11164887Schin 				}
11174887Schin 				else
11184887Schin 				{
11194887Schin 					if (k < 0)
11204887Schin 					{
11214887Schin 						COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
11224887Schin 						comment(&notice, &buf, NiL, 0, 0);
11234887Schin 					}
11244887Schin 					k = 1;
11254887Schin 					expand(&notice, &tmp, &item);
11264887Schin 					comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
11274887Schin 				}
11284887Schin 			}
11294887Schin 		}
11304887Schin 		if (k > 0)
11314887Schin 			comment(&notice, &buf, NiL, 0, 0);
11324887Schin 	}
11334887Schin 	if (notice.type == USAGE)
11344887Schin 	{
11354887Schin 		copy(&buf, "[-copyright?", -1);
11364887Schin 		copyright(&notice, &buf);
11374887Schin 		PUT(&buf, ']');
11384887Schin 		if (notice.item[URL].data)
11394887Schin 		{
11404887Schin 			copy(&buf, "[-license?", -1);
11414887Schin 			expand(&notice, &buf, &notice.item[URL]);
11424887Schin 			PUT(&buf, ']');
11434887Schin 		}
11444887Schin 		PUT(&buf, '\n');
11454887Schin 	}
11464887Schin 	else
11474887Schin 		comment(&notice, &buf, NiL, -1, 0);
11484887Schin 	return END(&buf);
11494887Schin }
1150