/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* generate a license comment -- see proto(1)
*
* NOTE: coded for minimal library dependence
* not so for the legal department
*/
#ifndef _PPLIB_H
#include <ast.h>
#include <time.h>
#endif
#define NONE 0
#define AUTHOR 0
#ifndef NiL
#define NiL ((char*)0)
#endif
typedef struct Buffer_s
{
char* buf;
char* nxt;
char* end;
int siz;
} Buffer_t;
typedef struct Item_s
{
char* data;
int size;
int quote;
} Item_t;
typedef struct Id_s
{
} Id_t;
/*
* NOTE: key[] element order must match the corresponding macro
*/
{
KEY("author"),
KEY("class"),
KEY("company"),
KEY("contributor"),
KEY("corporation"),
KEY("domain"),
KEY("incorporation"),
KEY("license"),
KEY("location"),
KEY("notice"),
KEY("organization"),
KEY("package"),
KEY("parent"),
KEY("query"),
KEY("since"),
KEY("type"),
KEY("url"),
KEY("urlmd5"),
KEY("version"),
{0}
};
{
{0}
};
typedef struct Notice_s
{
int test;
int type;
int verbose;
int ids;
} Notice_t;
/*
* return index given <name,size>
*/
static int
{
register int c;
register int i;
c = name[0];
return i;
return -1;
}
/*
* copy s of size n to b
* n<0 means 0 terminated string
*/
static void
{
if (n < 0)
n = strlen(s);
while (n--)
PUT(b, *s++);
}
/*
* center and copy comment line s to p
* if s==0 then
* n>0 first frame line
* n=0 blank line
* n<0 last frame line
* if u>0 then s converted to upper case
* if u<0 then s is left justified
*/
static void
{
register int i;
register int m;
register int x;
int cc;
if (!s)
{
if (n)
{
for (i = 0; i < COMDATA; i++)
}
else
s = "";
}
if (s)
{
if (n > COMDATA)
n = COMDATA;
if ((x = COMDATA - m - n) < 0)
n--;
while (m-- > 0)
PUT(b, ' ');
while (n-- > 0)
{
i = *s++;
if (u > 0 && i >= 'a' && i <= 'z')
i = i - 'a' + 'A';
PUT(b, i);
}
while (x-- > 0)
PUT(b, ' ');
}
PUT(b, '\n');
}
/*
* expand simple ${...}
*/
static void
{
register char* t;
register char* e;
register int q;
register char* x;
register char* z;
register int c;
int m;
{
while (t < e)
{
if (*t == '$' && t < (e + 2) && *(t + 1) == '{')
{
m = 0;
x = t += 2;
while (t < e && (c = *t++) != '}')
if (c == '.')
x = t;
else if (c == '/')
{
m = 1;
break;
}
{
while (x < z)
{
c = *x++;
if (!m || c >= '0' && c <= '9')
PUT(b, c);
}
}
if (m)
while (t < e && *t++ != '}');
}
else if (q > 0 && *t == '\\' && (*(t + 1) == q || *(t + 1) == '\\'))
t++;
else
PUT(b, *t++);
}
}
}
/*
* generate a copright notice
*/
static void
{
register char* x;
register char* t;
else
{
PUT(b, '-');
}
copy(b, t, 4);
{
PUT(b, ' ');
}
{
PUT(b, ' ');
{
PUT(b, ' ');
}
}
{
PUT(b, ' ');
}
}
/*
* read the license file and generate a comment in p, length size
* license length in p returned, -1 on error
* -1 return places 0 terminated error string in p
*/
int
{
register char* s;
register char* v;
register char* x;
register int c;
int i;
int h;
int k;
int n;
int q;
int contributor;
int first;
int line;
int quote;
{
{
return -1;
}
close(i);
if (n < 0)
{
return -1;
}
s = info;
s[n] = 0;
}
else if (!options)
return 0;
else
{
s = options;
options = 0;
}
for (i = 0; i < ITEMS; i++)
contributor = i = k = 0;
line = 0;
for (;;)
{
first = 1;
while (c = *s)
{
while (c == ' ' || c == '\t' || c == '\n' && ++line || c == '\r' || c == ',' || c == ';' || c == ')')
c = *++s;
if (!c)
break;
if (c == '#')
{
while (*++s && *s != '\n');
if (*s)
s++;
line++;
continue;
}
if (c == '\n')
{
s++;
line++;
continue;
}
if (c == '[')
c = *++s;
x = s;
n = 0;
while (c && c != '=' && c != ']' && c != ')' && c != ',' && c != ' ' && c != '\t' && c != '\n' && c != '\r')
c = *++s;
n = s - x;
if (c == ']')
c = *++s;
quote = 0;
if (c == '=' || first)
{
if (c == '=')
{
q = ((c = *++s) == '"' || c == '\'') ? *s++ : 0;
if (c == '(')
{
s++;
if (h == LICENSE)
contributor = 0;
else if (h == CONTRIBUTOR)
contributor = 1;
else
{
q = 1;
i = 0;
for (;;)
{
switch (*s++)
{
case 0:
s--;
break;
case '(':
if (!i)
q++;
continue;
case ')':
if (!i && !--q)
break;
continue;
case '"':
case '\'':
if (!i)
i = *(s - 1);
else if (i == *(s - 1))
i = 0;
continue;
case '\\':
if (*s == i && i == '"')
i++;
continue;
case '\n':
line++;
continue;
default:
continue;
}
break;
}
}
continue;
}
v = s;
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 != ';'))
{
if (c == '\n')
line++;
s++;
}
}
else
{
h = STYLE;
v = x;
}
if (c == '\n')
line++;
if (contributor)
{
break;
if (i < IDS)
{
}
}
else if (h == QUERY)
{
if ((s - v) == 3 && v[0] == 'a' && v[1] == 'l' && v[2] == 'l')
{
for (i = 0; i < ITEMS; i++)
{
for (h = 0;; h++)
{
h = 0;
break;
}
break;
if (h)
if (h)
}
}
else
{
{
}
else
}
}
else
{
if (h == STYLE)
{
case NONE:
return 0;
case TEST:
h = -1;
break;
case VERBOSE:
h = -1;
break;
case USAGE:
h = -1;
break;
case -1:
c = SPECIAL;
/*FALLTHROUGH*/
default:
break;
}
if (h >= 0)
{
k = 1;
}
}
}
else
{
if (file)
{
*--x = 0;
line++;
}
return -1;
}
if (*s)
s++;
first = 0;
}
break;
options = 0;
}
if (!k)
return 0;
return 0;
{
{
}
{
}
{
else
{
}
{
{
}
{
{
}
}
}
{
{
}
}
else
}
{
{
{
}
}
{
{
}
}
else
i = -1;
{
if (i >= 0)
{
}
}
if (i >= 0)
if (n >= COMLONG)
else
}
{
}
{
if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
else
}
{
}
{
}
else
{
{
if (notice.item[i = PARENT].data || notice.item[i = CORPORATION].data || notice.item[i = COMPANY].data)
{
}
else
i = -1;
{
if (i >= 0)
{
}
{
}
{
}
}
else
{
if (i >= 0)
{
}
}
}
{
}
{
}
{
}
{
{
if ((notice.item[PARENT].size + (notice.item[CORPORATION].data ? (notice.item[CORPORATION].size + notice.item[INCORPORATION].size) : notice.item[COMPANY].size)) >= (COMLONG - 6))
else
{
}
{
{
}
}
}
{
}
}
{
}
}
{
if (*v == '\n')
v++;
do
{
{
h = 0;
}
else
h = -1;
} while (v++ < x);
}
{
{
}
{
}
}
}
{
q = (x - v) == 1 && (*v == '*' || *v == '-');
for (;;)
{
if (!q)
{
while (v < x && (*v == ' ' || *v == '\t' || *v == '\r' || *v == '\n' || *v == ',' || *v == '+'))
v++;
if (v >= x)
break;
while (v < x && *v != ',' && *v != '+' && *v++ != '>');
}
h = 0;
if (q || item.size == notice.id[i].name.size && !strncmp(item.data, notice.id[i].name.data, item.size))
{
h = 1;
{
}
else
{
if (k < 0)
{
}
k = 1;
}
if (!q)
break;
}
if (q)
break;
if (!h)
{
{
}
else
{
if (k < 0)
{
}
k = 1;
}
}
}
if (k > 0)
}
{
{
}
}
else
}