1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A/*
1N/A * Glenn Fowler
1N/A * AT&T Research
1N/A *
1N/A * generate a license comment -- see proto(1)
1N/A *
1N/A * NOTE: coded for minimal library dependence
1N/A * not so for the legal department
1N/A */
1N/A
1N/A#ifndef _PPLIB_H
1N/A#include <ast.h>
1N/A#include <time.h>
1N/A#endif
1N/A
1N/A#undef copy
1N/A#undef BSD /* guess who defines this */
1N/A#undef END
1N/A#undef INLINE
1N/A#undef TEST
1N/A#undef VERBOSE
1N/A
1N/A#define NONE 0
1N/A#define INLINE 1
1N/A#define TEST 2
1N/A#define VERBOSE 3
1N/A#define USAGE 4
1N/A#define OPEN 5
1N/A#define CPL 6
1N/A#define EPL 7
1N/A#define BSD 8
1N/A#define ZLIB 9
1N/A#define MIT 10
1N/A#define GPL 11
1N/A#define SPECIAL 12
1N/A#define NONEXCLUSIVE 13
1N/A#define NONCOMMERCIAL 14
1N/A#define PROPRIETARY 15
1N/A
1N/A#define AUTHOR 0
1N/A#define CLASS 1
1N/A#define COMPANY 2
1N/A#define CONTRIBUTOR 3
1N/A#define CORPORATION 4
1N/A#define DOMAIN 5
1N/A#define INCORPORATION 6
1N/A#define LICENSE 7
1N/A#define LOCATION 8
1N/A#define NOTICE 9
1N/A#define ORGANIZATION 10
1N/A#define PACKAGE 11
1N/A#define PARENT 12
1N/A#define QUERY 13
1N/A#define SINCE 14
1N/A#define STYLE 15
1N/A#define URL 16
1N/A#define URLMD5 17
1N/A#define VERSION 18
1N/A
1N/A#define IDS 64
1N/A
1N/A#define COMDATA 70
1N/A#define COMLINE (COMDATA+4)
1N/A#define COMLONG (COMDATA-32)
1N/A#define COMMENT(x,b,s,u) comment(x,b,s,sizeof(s)-1,u)
1N/A
1N/A#define PUT(b,c) (((b)->nxt<(b)->end)?(*(b)->nxt++=(c)):((c),(-1)))
1N/A#define BUF(b) ((b)->buf)
1N/A#define USE(b) ((b)->siz=(b)->nxt-(b)->buf,(b)->nxt=(b)->buf,(b)->siz)
1N/A#define SIZ(b) ((b)->nxt-(b)->buf)
1N/A#define END(b) (*((b)->nxt>=(b)->end?((b)->nxt=(b)->end-1):(b)->nxt)=0,(b)->nxt-(b)->buf)
1N/A
1N/A#ifndef NiL
1N/A#define NiL ((char*)0)
1N/A#endif
1N/A
1N/Atypedef struct Buffer_s
1N/A{
1N/A char* buf;
1N/A char* nxt;
1N/A char* end;
1N/A int siz;
1N/A} Buffer_t;
1N/A
1N/Atypedef struct Item_s
1N/A{
1N/A char* data;
1N/A int size;
1N/A int quote;
1N/A} Item_t;
1N/A
1N/Atypedef struct Id_s
1N/A{
1N/A Item_t name;
1N/A Item_t value;
1N/A} Id_t;
1N/A
1N/A/*
1N/A * NOTE: key[] element order must match the corresponding macro
1N/A */
1N/A
1N/A#define KEY(s) {s,sizeof(s)-1,0}
1N/A
1N/Astatic const Item_t key[] =
1N/A{
1N/A KEY("author"),
1N/A KEY("class"),
1N/A KEY("company"),
1N/A KEY("contributor"),
1N/A KEY("corporation"),
1N/A KEY("domain"),
1N/A KEY("incorporation"),
1N/A KEY("license"),
1N/A KEY("location"),
1N/A KEY("notice"),
1N/A KEY("organization"),
1N/A KEY("package"),
1N/A KEY("parent"),
1N/A KEY("query"),
1N/A KEY("since"),
1N/A KEY("type"),
1N/A KEY("url"),
1N/A KEY("urlmd5"),
1N/A KEY("version"),
1N/A {0}
1N/A};
1N/A
1N/A#define ITEMS (sizeof(key)/sizeof(key[0])-1)
1N/A
1N/A#define LIC(s,c) {s,sizeof(s)-1,c}
1N/A
1N/Astatic const Item_t lic[] =
1N/A{
1N/A LIC("none", NONE),
1N/A LIC("inline", SPECIAL),
1N/A LIC("test", TEST),
1N/A LIC("verbose", VERBOSE),
1N/A LIC("usage", USAGE),
1N/A LIC("open", OPEN),
1N/A LIC("cpl", OPEN),
1N/A LIC("epl", OPEN),
1N/A LIC("bsd", OPEN),
1N/A LIC("zlib", OPEN),
1N/A LIC("mit", OPEN),
1N/A LIC("gpl", GPL),
1N/A LIC("special", SPECIAL),
1N/A LIC("nonexclusive", SPECIAL),
1N/A LIC("noncommercial", SPECIAL),
1N/A LIC("proprietary", PROPRIETARY),
1N/A {0}
1N/A};
1N/A
1N/Atypedef struct Notice_s
1N/A{
1N/A int test;
1N/A int type;
1N/A int verbose;
1N/A int ids;
1N/A Item_t item[ITEMS];
1N/A Id_t id[IDS];
1N/A char cc[3];
1N/A} Notice_t;
1N/A
1N/A/*
1N/A * return index given <name,size>
1N/A */
1N/A
1N/Astatic int
1N/Alookup(register const Item_t* item, const char* name, int size)
1N/A{
1N/A register int c;
1N/A register int i;
1N/A
1N/A c = name[0];
1N/A for (i = 0; item[i].data; i++)
1N/A if (c == item[i].data[0] && size == item[i].size && !strncmp(name, item[i].data, size))
1N/A return i;
1N/A return -1;
1N/A}
1N/A
1N/A/*
1N/A * copy s of size n to b
1N/A * n<0 means 0 terminated string
1N/A */
1N/A
1N/Astatic void
1N/Acopy(register Buffer_t* b, register char* s, int n)
1N/A{
1N/A if (n < 0)
1N/A n = strlen(s);
1N/A while (n--)
1N/A PUT(b, *s++);
1N/A}
1N/A
1N/A/*
1N/A * center and copy comment line s to p
1N/A * if s==0 then
1N/A * n>0 first frame line
1N/A * n=0 blank line
1N/A * n<0 last frame line
1N/A * if u>0 then s converted to upper case
1N/A * if u<0 then s is left justified
1N/A */
1N/A
1N/Astatic void
1N/Acomment(Notice_t* notice, register Buffer_t* b, register char* s, register int n, int u)
1N/A{
1N/A register int i;
1N/A register int m;
1N/A register int x;
1N/A int cc;
1N/A
1N/A cc = notice->cc[1];
1N/A if (!s)
1N/A {
1N/A if (n)
1N/A {
1N/A PUT(b, notice->cc[n > 0 ? 0 : 1]);
1N/A for (i = 0; i < COMDATA; i++)
1N/A PUT(b, cc);
1N/A PUT(b, notice->cc[n > 0 ? 1 : 2]);
1N/A }
1N/A else
1N/A s = "";
1N/A }
1N/A if (s)
1N/A {
1N/A if (n > COMDATA)
1N/A n = COMDATA;
1N/A PUT(b, cc);
1N/A m = (u < 0) ? 1 : (COMDATA - n) / 2;
1N/A if ((x = COMDATA - m - n) < 0)
1N/A n--;
1N/A while (m-- > 0)
1N/A PUT(b, ' ');
1N/A while (n-- > 0)
1N/A {
1N/A i = *s++;
1N/A if (u > 0 && i >= 'a' && i <= 'z')
1N/A i = i - 'a' + 'A';
1N/A PUT(b, i);
1N/A }
1N/A while (x-- > 0)
1N/A PUT(b, ' ');
1N/A PUT(b, cc);
1N/A }
1N/A PUT(b, '\n');
1N/A}
1N/A
1N/A/*
1N/A * expand simple ${...}
1N/A */
1N/A
1N/Astatic void
1N/Aexpand(Notice_t* notice, register Buffer_t* b, const Item_t* item)
1N/A{
1N/A register char* t;
1N/A register char* e;
1N/A register int q;
1N/A register char* x;
1N/A register char* z;
1N/A register int c;
1N/A int m;
1N/A
1N/A if (t = item->data)
1N/A {
1N/A q = item->quote;
1N/A e = t + item->size;
1N/A while (t < e)
1N/A {
1N/A if (*t == '$' && t < (e + 2) && *(t + 1) == '{')
1N/A {
1N/A m = 0;
1N/A x = t += 2;
1N/A while (t < e && (c = *t++) != '}')
1N/A if (c == '.')
1N/A x = t;
1N/A else if (c == '/')
1N/A {
1N/A m = 1;
1N/A break;
1N/A }
1N/A if ((c = lookup(key, x, t - x - 1)) >= 0 && (x = notice->item[c].data))
1N/A {
1N/A z = x + notice->item[c].size;
1N/A while (x < z)
1N/A {
1N/A c = *x++;
1N/A if (!m || c >= '0' && c <= '9')
1N/A PUT(b, c);
1N/A }
1N/A }
1N/A if (m)
1N/A while (t < e && *t++ != '}');
1N/A }
1N/A else if (q > 0 && *t == '\\' && (*(t + 1) == q || *(t + 1) == '\\'))
1N/A t++;
1N/A else
1N/A PUT(b, *t++);
1N/A }
1N/A }
1N/A}
1N/A
1N/A/*
1N/A * generate a copright notice
1N/A */
1N/A
1N/Astatic void
1N/Acopyright(Notice_t* notice, register Buffer_t* b)
1N/A{
1N/A register char* x;
1N/A register char* t;
1N/A time_t clock;
1N/A
1N/A copy(b, "Copyright (c) ", -1);
1N/A if (notice->test)
1N/A clock = (time_t)1000212300;
1N/A else
1N/A time(&clock);
1N/A t = ctime(&clock) + 20;
1N/A if ((x = notice->item[SINCE].data) && strncmp(x, t, 4))
1N/A {
1N/A expand(notice, b, &notice->item[SINCE]);
1N/A PUT(b, '-');
1N/A }
1N/A copy(b, t, 4);
1N/A if (notice->item[PARENT].data)
1N/A {
1N/A PUT(b, ' ');
1N/A expand(notice, b, &notice->item[PARENT]);
1N/A }
1N/A if (notice->item[CORPORATION].data)
1N/A {
1N/A PUT(b, ' ');
1N/A expand(notice, b, &notice->item[CORPORATION]);
1N/A if (notice->item[INCORPORATION].data)
1N/A {
1N/A PUT(b, ' ');
1N/A expand(notice, b, &notice->item[INCORPORATION]);
1N/A }
1N/A }
1N/A else if (notice->item[COMPANY].data)
1N/A {
1N/A PUT(b, ' ');
1N/A expand(notice, b, &notice->item[COMPANY]);
1N/A }
1N/A}
1N/A
1N/A/*
1N/A * read the license file and generate a comment in p, length size
1N/A * license length in p returned, -1 on error
1N/A * -1 return places 0 terminated error string in p
1N/A */
1N/A
1N/Aint
1N/Aastlicense(char* p, int size, char* file, char* options, int cc1, int cc2, int cc3)
1N/A{
1N/A register char* s;
1N/A register char* v;
1N/A register char* x;
1N/A register int c;
1N/A int i;
1N/A int h;
1N/A int k;
1N/A int n;
1N/A int q;
1N/A int contributor;
1N/A int first;
1N/A int line;
1N/A int quote;
1N/A char tmpbuf[COMLINE];
1N/A char info[8 * 1024];
1N/A Notice_t notice;
1N/A Item_t item;
1N/A Buffer_t buf;
1N/A Buffer_t tmp;
1N/A
1N/A buf.end = (buf.buf = buf.nxt = p) + size;
1N/A tmp.end = (tmp.buf = tmp.nxt = tmpbuf) + sizeof(tmpbuf);
1N/A if (file && *file)
1N/A {
1N/A if ((i = open(file, O_RDONLY)) < 0)
1N/A {
1N/A copy(&buf, file, -1);
1N/A copy(&buf, ": cannot open", -1);
1N/A PUT(&buf, 0);
1N/A return -1;
1N/A }
1N/A n = read(i, info, sizeof(info) - 1);
1N/A close(i);
1N/A if (n < 0)
1N/A {
1N/A copy(&buf, file, -1);
1N/A copy(&buf, ": cannot read", -1);
1N/A PUT(&buf, 0);
1N/A return -1;
1N/A }
1N/A s = info;
1N/A s[n] = 0;
1N/A }
1N/A else if (!options)
1N/A return 0;
1N/A else
1N/A {
1N/A s = options;
1N/A options = 0;
1N/A }
1N/A notice.test = 0;
1N/A notice.type = NONE;
1N/A notice.verbose = 0;
1N/A notice.ids = 0;
1N/A notice.cc[0] = cc1;
1N/A notice.cc[1] = cc2;
1N/A notice.cc[2] = cc3;
1N/A for (i = 0; i < ITEMS; i++)
1N/A notice.item[i].data = 0;
1N/A notice.item[STYLE] = notice.item[CLASS] = lic[notice.type];
1N/A notice.item[STYLE].quote = notice.item[CLASS].quote = 0;
1N/A contributor = i = k = 0;
1N/A line = 0;
1N/A for (;;)
1N/A {
1N/A first = 1;
1N/A while (c = *s)
1N/A {
1N/A while (c == ' ' || c == '\t' || c == '\n' && ++line || c == '\r' || c == ',' || c == ';' || c == ')')
1N/A c = *++s;
1N/A if (!c)
1N/A break;
1N/A if (c == '#')
1N/A {
1N/A while (*++s && *s != '\n');
1N/A if (*s)
1N/A s++;
1N/A line++;
1N/A continue;
1N/A }
1N/A if (c == '\n')
1N/A {
1N/A s++;
1N/A line++;
1N/A continue;
1N/A }
1N/A if (c == '[')
1N/A c = *++s;
1N/A x = s;
1N/A n = 0;
1N/A while (c && c != '=' && c != ']' && c != ')' && c != ',' && c != ' ' && c != '\t' && c != '\n' && c != '\r')
1N/A c = *++s;
1N/A n = s - x;
1N/A h = lookup(key, x, n);
1N/A if (c == ']')
1N/A c = *++s;
1N/A quote = 0;
1N/A if (c == '=' || first)
1N/A {
1N/A if (c == '=')
1N/A {
1N/A q = ((c = *++s) == '"' || c == '\'') ? *s++ : 0;
1N/A if (c == '(')
1N/A {
1N/A s++;
1N/A if (h == LICENSE)
1N/A contributor = 0;
1N/A else if (h == CONTRIBUTOR)
1N/A contributor = 1;
1N/A else
1N/A {
1N/A q = 1;
1N/A i = 0;
1N/A for (;;)
1N/A {
1N/A switch (*s++)
1N/A {
1N/A case 0:
1N/A s--;
1N/A break;
1N/A case '(':
1N/A if (!i)
1N/A q++;
1N/A continue;
1N/A case ')':
1N/A if (!i && !--q)
1N/A break;
1N/A continue;
1N/A case '"':
1N/A case '\'':
1N/A if (!i)
1N/A i = *(s - 1);
1N/A else if (i == *(s - 1))
1N/A i = 0;
1N/A continue;
1N/A case '\\':
1N/A if (*s == i && i == '"')
1N/A i++;
1N/A continue;
1N/A case '\n':
1N/A line++;
1N/A continue;
1N/A default:
1N/A continue;
1N/A }
1N/A break;
1N/A }
1N/A }
1N/A continue;
1N/A }
1N/A v = s;
1N/A 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 != ';'))
1N/A {
1N/A if (c == '\n')
1N/A line++;
1N/A s++;
1N/A }
1N/A }
1N/A else
1N/A {
1N/A h = STYLE;
1N/A v = x;
1N/A }
1N/A if (c == '\n')
1N/A line++;
1N/A if (contributor)
1N/A {
1N/A for (i = 0; i < notice.ids; i++)
1N/A if (n == notice.id[i].name.size && !strncmp(x, notice.id[i].name.data, n))
1N/A break;
1N/A if (i < IDS)
1N/A {
1N/A notice.id[i].name.data = x;
1N/A notice.id[i].name.size = n;
1N/A notice.id[i].name.quote = 0;
1N/A notice.id[i].value.data = v;
1N/A notice.id[i].value.size = s - v;
1N/A notice.id[i].value.quote = quote;
1N/A if (notice.ids <= i)
1N/A notice.ids = i + 1;
1N/A }
1N/A }
1N/A else if (h == QUERY)
1N/A {
1N/A if ((s - v) == 3 && v[0] == 'a' && v[1] == 'l' && v[2] == 'l')
1N/A {
1N/A for (i = 0; i < ITEMS; i++)
1N/A if (notice.item[i].size)
1N/A {
1N/A expand(&notice, &buf, &key[i]);
1N/A PUT(&buf, '=');
1N/A for (h = 0;; h++)
1N/A if (h >= notice.item[i].size)
1N/A {
1N/A h = 0;
1N/A break;
1N/A }
1N/A else if (notice.item[i].data[h] == ' ' || notice.item[i].data[h] == '\t')
1N/A break;
1N/A if (h)
1N/A PUT(&buf, '\'');
1N/A expand(&notice, &buf, &notice.item[i]);
1N/A if (h)
1N/A PUT(&buf, '\'');
1N/A PUT(&buf, '\n');
1N/A }
1N/A }
1N/A else
1N/A {
1N/A if ((h = lookup(key, v, s - v)) < 0)
1N/A {
1N/A item.data = v;
1N/A item.size = s - v;
1N/A item.quote = 0;
1N/A expand(&notice, &buf, &item);
1N/A }
1N/A else
1N/A expand(&notice, &buf, &notice.item[h]);
1N/A PUT(&buf, '\n');
1N/A }
1N/A return END(&buf);
1N/A }
1N/A else
1N/A {
1N/A if (h == STYLE)
1N/A switch (c = lookup(lic, v, s - v))
1N/A {
1N/A case NONE:
1N/A return 0;
1N/A case TEST:
1N/A notice.test = 1;
1N/A h = -1;
1N/A break;
1N/A case VERBOSE:
1N/A notice.verbose = 1;
1N/A h = -1;
1N/A break;
1N/A case USAGE:
1N/A notice.type = c;
1N/A h = -1;
1N/A break;
1N/A case -1:
1N/A c = SPECIAL;
1N/A /*FALLTHROUGH*/
1N/A default:
1N/A notice.type = c;
1N/A notice.item[CLASS].data = lic[lic[c].quote].data;
1N/A notice.item[CLASS].size = lic[lic[c].quote].size;
1N/A break;
1N/A }
1N/A if (h >= 0)
1N/A {
1N/A notice.item[h].data = (notice.item[h].size = s - v) ? v : (char*)0;
1N/A notice.item[h].quote = quote;
1N/A k = 1;
1N/A }
1N/A }
1N/A }
1N/A else
1N/A {
1N/A if (file)
1N/A {
1N/A copy(&buf, "\"", -1);
1N/A copy(&buf, file, -1);
1N/A copy(&buf, "\", line ", -1);
1N/A x = &tmpbuf[sizeof(tmpbuf)];
1N/A *--x = 0;
1N/A line++;
1N/A do *--x = ("0123456789")[line % 10]; while (line /= 10);
1N/A copy(&buf, x, -1);
1N/A copy(&buf, ": ", -1);
1N/A }
1N/A copy(&buf, "option error: assignment expected", -1);
1N/A PUT(&buf, 0);
1N/A return -1;
1N/A }
1N/A if (*s)
1N/A s++;
1N/A first = 0;
1N/A }
1N/A if (!options || !*(s = options))
1N/A break;
1N/A options = 0;
1N/A }
1N/A if (!k)
1N/A return 0;
1N/A if (notice.type == INLINE && (!notice.verbose || !notice.item[NOTICE].data))
1N/A return 0;
1N/A if (notice.type != USAGE)
1N/A {
1N/A if (!notice.type)
1N/A notice.type = SPECIAL;
1N/A comment(&notice, &buf, NiL, 1, 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A if (notice.item[PACKAGE].data)
1N/A {
1N/A copy(&tmp, "This software is part of the ", -1);
1N/A expand(&notice, &tmp, &notice.item[PACKAGE]);
1N/A copy(&tmp, " package", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A if (notice.type >= OPEN)
1N/A {
1N/A copyright(&notice, &tmp);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.type >= SPECIAL)
1N/A COMMENT(&notice, &buf, "All Rights Reserved", 0);
1N/A }
1N/A if (notice.type == CPL || notice.type == EPL)
1N/A {
1N/A copy(&tmp, notice.item[PACKAGE].data ? "and" : "This software", -1);
1N/A copy(&tmp, " is licensed under the", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.type == EPL)
1N/A copy(&tmp, "Eclipse Public License", -1);
1N/A else
1N/A copy(&tmp, "Common Public License", -1);
1N/A if (notice.item[VERSION].data)
1N/A {
1N/A copy(&tmp, ", Version ", -1);
1N/A expand(&notice, &tmp, &notice.item[VERSION]);
1N/A }
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
1N/A {
1N/A copy(&tmp, "by ", -1);
1N/A if (notice.item[PARENT].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[PARENT]);
1N/A copy(&tmp, " ", -1);
1N/A }
1N/A if (notice.item[CORPORATION].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[CORPORATION]);
1N/A if (notice.item[INCORPORATION].data)
1N/A {
1N/A copy(&tmp, " ", -1);
1N/A expand(&notice, &tmp, &notice.item[INCORPORATION]);
1N/A }
1N/A }
1N/A else if (notice.item[COMPANY].data)
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "A copy of the License is available at", 0);
1N/A if (notice.item[URL].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[URL]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[URLMD5].data)
1N/A {
1N/A copy(&tmp, "(with md5 checksum ", -1);
1N/A expand(&notice, &tmp, &notice.item[URLMD5]);
1N/A copy(&tmp, ")", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A }
1N/A else if (notice.type == EPL)
1N/A COMMENT(&notice, &buf, "http://www.eclipse.org/org/documents/epl-v10.html", 0);
1N/A else
1N/A COMMENT(&notice, &buf, "http://www.opensource.org/licenses/cpl", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == OPEN)
1N/A {
1N/A copy(&tmp, notice.item[PACKAGE].data ? "and it" : "This software", -1);
1N/A copy(&tmp, " may only be used by you under license from", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[i = CORPORATION].data)
1N/A {
1N/A if (notice.item[PARENT].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[i = PARENT]);
1N/A copy(&tmp, " ", -1);
1N/A }
1N/A expand(&notice, &tmp, &notice.item[CORPORATION]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A else if (notice.item[i = COMPANY].data)
1N/A {
1N/A if (notice.item[PARENT].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[i = PARENT]);
1N/A copy(&tmp, " ", -1);
1N/A }
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A else
1N/A i = -1;
1N/A if (notice.item[URL].data)
1N/A {
1N/A COMMENT(&notice, &buf, "A copy of the Source Code Agreement is available", 0);
1N/A copy(&tmp, "at the ", -1);
1N/A if (i >= 0)
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A copy(&tmp, " Internet web site URL", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A expand(&notice, &tmp, &notice.item[URL]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[URLMD5].data)
1N/A {
1N/A copy(&tmp, "(with an md5 checksum of ", -1);
1N/A expand(&notice, &tmp, &notice.item[URLMD5]);
1N/A copy(&tmp, ")", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A COMMENT(&notice, &buf, "If you have copied or used this software without agreeing", 0);
1N/A COMMENT(&notice, &buf, "to the terms of the license you are infringing on", 0);
1N/A COMMENT(&notice, &buf, "the license and copyright and are violating", 0);
1N/A if (i >= 0)
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A copy(&tmp, "'s", -1);
1N/A if (n >= COMLONG)
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A else
1N/A PUT(&tmp, ' ');
1N/A copy(&tmp, "intellectual property rights.", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == GPL)
1N/A {
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "This is free software; you can redistribute it and/or", 0);
1N/A COMMENT(&notice, &buf, "modify it under the terms of the GNU General Public License", 0);
1N/A COMMENT(&notice, &buf, "as published by the Free Software Foundation;", 0);
1N/A COMMENT(&notice, &buf, "either version 2, or (at your option) any later version.", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "This software is distributed in the hope that it", 0);
1N/A COMMENT(&notice, &buf, "will be useful, but WITHOUT ANY WARRANTY;", 0);
1N/A COMMENT(&notice, &buf, "without even the implied warranty of MERCHANTABILITY", 0);
1N/A COMMENT(&notice, &buf, "or FITNESS FOR A PARTICULAR PURPOSE.", 0);
1N/A COMMENT(&notice, &buf, "See the GNU General Public License for more details.", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "You should have received a copy of the", 0);
1N/A COMMENT(&notice, &buf, "GNU General Public License", 0);
1N/A COMMENT(&notice, &buf, "along with this software (see the file COPYING.)", 0);
1N/A COMMENT(&notice, &buf, "If not, a copy is available at", 0);
1N/A COMMENT(&notice, &buf, "http://www.gnu.org/copyleft/gpl.html", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == BSD)
1N/A {
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "Redistribution and use in source and binary forms, with or", -1);
1N/A COMMENT(&notice, &buf, "without modification, are permitted provided that the following", -1);
1N/A COMMENT(&notice, &buf, "conditions are met:", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, " 1. Redistributions of source code must retain the above", -1);
1N/A COMMENT(&notice, &buf, " copyright notice, this list of conditions and the", -1);
1N/A COMMENT(&notice, &buf, " following disclaimer.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, " 2. Redistributions in binary form must reproduce the above", -1);
1N/A COMMENT(&notice, &buf, " copyright notice, this list of conditions and the", -1);
1N/A COMMENT(&notice, &buf, " following disclaimer in the documentation and/or other", -1);
1N/A COMMENT(&notice, &buf, " materials provided with the distribution.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A copy(&tmp, " 3. Neither the name of ", -1);
1N/A if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A else
1N/A copy(&tmp, "the copyright holder", -1);
1N/A copy(&tmp, " nor the", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), -1);
1N/A COMMENT(&notice, &buf, " names of its contributors may be used to endorse or", -1);
1N/A COMMENT(&notice, &buf, " promote products derived from this software without", -1);
1N/A COMMENT(&notice, &buf, " specific prior written permission.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND", -1);
1N/A COMMENT(&notice, &buf, "CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,", -1);
1N/A COMMENT(&notice, &buf, "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF", -1);
1N/A COMMENT(&notice, &buf, "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE", -1);
1N/A COMMENT(&notice, &buf, "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS", -1);
1N/A COMMENT(&notice, &buf, "BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,", -1);
1N/A COMMENT(&notice, &buf, "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED", -1);
1N/A COMMENT(&notice, &buf, "TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,", -1);
1N/A COMMENT(&notice, &buf, "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON", -1);
1N/A COMMENT(&notice, &buf, "ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,", -1);
1N/A COMMENT(&notice, &buf, "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY", -1);
1N/A COMMENT(&notice, &buf, "OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE", -1);
1N/A COMMENT(&notice, &buf, "POSSIBILITY OF SUCH DAMAGE.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == ZLIB)
1N/A {
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "This software is provided 'as-is', without any express or implied", -1);
1N/A COMMENT(&notice, &buf, "warranty. In no event will the authors be held liable for any", -1);
1N/A COMMENT(&notice, &buf, "damages arising from the use of this software.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "Permission is granted to anyone to use this software for any", -1);
1N/A COMMENT(&notice, &buf, "purpose, including commercial applications, and to alter it and", -1);
1N/A COMMENT(&notice, &buf, "redistribute it freely, subject to the following restrictions:", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, " 1. The origin of this software must not be misrepresented;", -1);
1N/A COMMENT(&notice, &buf, " you must not claim that you wrote the original software. If", -1);
1N/A COMMENT(&notice, &buf, " you use this software in a product, an acknowledgment in the", -1);
1N/A COMMENT(&notice, &buf, " product documentation would be appreciated but is not", -1);
1N/A COMMENT(&notice, &buf, " required.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, " 2. Altered source versions must be plainly marked as such,", -1);
1N/A COMMENT(&notice, &buf, " and must not be misrepresented as being the original", -1);
1N/A COMMENT(&notice, &buf, " software.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, " 3. This notice may not be removed or altered from any source", -1);
1N/A COMMENT(&notice, &buf, " distribution.", -1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == MIT)
1N/A {
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "Permission is hereby granted, free of charge, to any person", 0);
1N/A COMMENT(&notice, &buf, "obtaining a copy of this software and associated", 0);
1N/A COMMENT(&notice, &buf, "documentation files (the \"Software\"), to deal in the", 0);
1N/A COMMENT(&notice, &buf, "Software without restriction, including without limitation", 0);
1N/A COMMENT(&notice, &buf, "the rights to use, copy, modify, merge, publish, distribute,", 0);
1N/A COMMENT(&notice, &buf, "sublicense, and/or sell copies of the Software, and to", 0);
1N/A COMMENT(&notice, &buf, "permit persons to whom the Software is furnished to do so,", 0);
1N/A COMMENT(&notice, &buf, "subject to the following conditions:", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "The above copyright notice and this permission notice shall", 0);
1N/A COMMENT(&notice, &buf, "be included in all copies or substantial portions of the", 0);
1N/A COMMENT(&notice, &buf, "Software.", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A COMMENT(&notice, &buf, "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY", 0);
1N/A COMMENT(&notice, &buf, "KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE", 0);
1N/A COMMENT(&notice, &buf, "WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR", 0);
1N/A COMMENT(&notice, &buf, "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS", 0);
1N/A COMMENT(&notice, &buf, "OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR", 0);
1N/A COMMENT(&notice, &buf, "OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR", 0);
1N/A COMMENT(&notice, &buf, "OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE", 0);
1N/A COMMENT(&notice, &buf, "SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else
1N/A {
1N/A if (notice.type == PROPRIETARY)
1N/A {
1N/A if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A copy(&tmp, " - ", -1);
1N/A }
1N/A else
1N/A i = -1;
1N/A copy(&tmp, "Proprietary", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A if (notice.item[URL].data)
1N/A {
1N/A copy(&tmp, "This is proprietary source code", -1);
1N/A if (i >= 0)
1N/A copy(&tmp, " licensed by", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A if (notice.item[PARENT].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[PARENT]);
1N/A copy(&tmp, " ", -1);
1N/A }
1N/A if (notice.item[CORPORATION].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[CORPORATION]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A }
1N/A else if (notice.item[COMPANY].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A }
1N/A }
1N/A else
1N/A {
1N/A copy(&tmp, "This is unpublished proprietary source code", -1);
1N/A if (i >= 0)
1N/A copy(&tmp, " of", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A if (notice.item[COMPANY].data)
1N/A {
1N/A if (SIZ(&tmp))
1N/A PUT(&tmp, ' ');
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A }
1N/A if (SIZ(&tmp))
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 1);
1N/A COMMENT(&notice, &buf, "and is not to be disclosed or used except in", 1);
1N/A COMMENT(&notice, &buf, "accordance with applicable agreements", 1);
1N/A }
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == NONEXCLUSIVE)
1N/A {
1N/A COMMENT(&notice, &buf, "For nonexclusive individual use", 1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == NONCOMMERCIAL)
1N/A {
1N/A COMMENT(&notice, &buf, "For noncommercial use", 1);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A if (notice.type >= PROPRIETARY && !notice.item[URL].data)
1N/A {
1N/A COMMENT(&notice, &buf, "Unpublished & Not for Publication", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A if (notice.item[URL].data)
1N/A {
1N/A copy(&tmp, "This software is licensed", -1);
1N/A if (notice.item[CORPORATION].data || notice.item[COMPANY].data)
1N/A {
1N/A copy(&tmp, " by", -1);
1N/A if ((notice.item[PARENT].size + (notice.item[CORPORATION].data ? (notice.item[CORPORATION].size + notice.item[INCORPORATION].size) : notice.item[COMPANY].size)) >= (COMLONG - 6))
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A else
1N/A PUT(&tmp, ' ');
1N/A if (notice.item[PARENT].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[PARENT]);
1N/A copy(&tmp, " ", -1);
1N/A }
1N/A if (notice.item[CORPORATION].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[CORPORATION]);
1N/A if (notice.item[INCORPORATION].data)
1N/A {
1N/A copy(&tmp, " ", -1);
1N/A expand(&notice, &tmp, &notice.item[INCORPORATION]);
1N/A }
1N/A }
1N/A else if (notice.item[COMPANY].data)
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A }
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A COMMENT(&notice, &buf, "under the terms and conditions of the license in", 0);
1N/A expand(&notice, &tmp, &notice.item[URL]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[URLMD5].data)
1N/A {
1N/A copy(&tmp, "(with an md5 checksum of ", -1);
1N/A expand(&notice, &tmp, &notice.item[URLMD5]);
1N/A copy(&tmp, ")", -1);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A else if (notice.type == PROPRIETARY)
1N/A {
1N/A COMMENT(&notice, &buf, "The copyright notice above does not evidence any", 0);
1N/A COMMENT(&notice, &buf, "actual or intended publication of such source code", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A }
1N/A if (v = notice.item[NOTICE].data)
1N/A {
1N/A x = v + notice.item[NOTICE].size;
1N/A if (*v == '\n')
1N/A v++;
1N/A item.quote = notice.item[NOTICE].quote;
1N/A do
1N/A {
1N/A for (item.data = v; v < x && *v != '\n'; v++);
1N/A if ((item.size = v - item.data) && *item.data == '\t')
1N/A {
1N/A item.data++;
1N/A item.size--;
1N/A h = 0;
1N/A }
1N/A else
1N/A h = -1;
1N/A expand(&notice, &tmp, &item);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), h);
1N/A } while (v++ < x);
1N/A if (item.size)
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A if (notice.item[ORGANIZATION].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[ORGANIZATION]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data)
1N/A expand(&notice, &tmp, &notice.item[i]);
1N/A if (notice.item[COMPANY].data)
1N/A {
1N/A if (SIZ(&tmp))
1N/A PUT(&tmp, ' ');
1N/A expand(&notice, &tmp, &notice.item[COMPANY]);
1N/A }
1N/A if (SIZ(&tmp))
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A if (notice.item[LOCATION].data)
1N/A {
1N/A expand(&notice, &tmp, &notice.item[LOCATION]);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A }
1N/A if (v = notice.item[AUTHOR].data)
1N/A {
1N/A x = v + notice.item[AUTHOR].size;
1N/A q = (x - v) == 1 && (*v == '*' || *v == '-');
1N/A k = q && notice.type != USAGE ? -1 : 0;
1N/A for (;;)
1N/A {
1N/A if (!q)
1N/A {
1N/A while (v < x && (*v == ' ' || *v == '\t' || *v == '\r' || *v == '\n' || *v == ',' || *v == '+'))
1N/A v++;
1N/A if (v >= x)
1N/A break;
1N/A item.data = v;
1N/A while (v < x && *v != ',' && *v != '+' && *v++ != '>');
1N/A item.size = v - item.data;
1N/A item.quote = notice.item[AUTHOR].quote;
1N/A }
1N/A h = 0;
1N/A for (i = 0; i < notice.ids; i++)
1N/A if (q || item.size == notice.id[i].name.size && !strncmp(item.data, notice.id[i].name.data, item.size))
1N/A {
1N/A h = 1;
1N/A if (notice.type == USAGE)
1N/A {
1N/A copy(&buf, "[-author?", -1);
1N/A expand(&notice, &buf, &notice.id[i].value);
1N/A PUT(&buf, ']');
1N/A }
1N/A else
1N/A {
1N/A if (k < 0)
1N/A {
1N/A COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A k = 1;
1N/A expand(&notice, &tmp, &notice.id[i].value);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A if (!q)
1N/A break;
1N/A }
1N/A if (q)
1N/A break;
1N/A if (!h)
1N/A {
1N/A if (notice.type == USAGE)
1N/A {
1N/A copy(&buf, "[-author?", -1);
1N/A expand(&notice, &buf, &item);
1N/A PUT(&buf, ']');
1N/A }
1N/A else
1N/A {
1N/A if (k < 0)
1N/A {
1N/A COMMENT(&notice, &buf, "CONTRIBUTORS", 0);
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A k = 1;
1N/A expand(&notice, &tmp, &item);
1N/A comment(&notice, &buf, BUF(&tmp), USE(&tmp), 0);
1N/A }
1N/A }
1N/A }
1N/A if (k > 0)
1N/A comment(&notice, &buf, NiL, 0, 0);
1N/A }
1N/A if (notice.type == USAGE)
1N/A {
1N/A copy(&buf, "[-copyright?", -1);
1N/A copyright(&notice, &buf);
1N/A PUT(&buf, ']');
1N/A if (notice.item[URL].data)
1N/A {
1N/A copy(&buf, "[-license?", -1);
1N/A expand(&notice, &buf, &notice.item[URL]);
1N/A PUT(&buf, ']');
1N/A }
1N/A PUT(&buf, '\n');
1N/A }
1N/A else
1N/A comment(&notice, &buf, NiL, -1, 0);
1N/A return END(&buf);
1N/A}