/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1984-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* convert single char edit ops to long form
*/
#include <ast.h>
#include <error.h>
#include <debug.h>
#include <ctype.h>
#include "expand.h"
#define DELETE ((char*)0)
static struct Convstate_s
{
int delimiter;
int function;
const char* longflag;
} state;
static char* expand(char*, char*);
static char*
{
register char* s;
s += strlen(s);
strcpy(s, "<<<");
return(buf);
}
static char*
{
register int c;
register char* s;
register int op;
char* dir;
char* bas;
char* suf;
char* val;
char* oldp;
char* newp;
char* eb;
char* dp;
char* vp;
int glob;
int cnt;
int cntlim;
int qual;
int n;
int m;
int e;
int sep;
int arg;
int aux;
int bound = 0;
int delimited = 0;
op = 0;
for (;;)
{
{
break;
}
switch (op)
{
case '@':
case 'V':
sep = 1;
switch (op)
{
case '@':
sep = 0;
val = "join";
break;
case 'V':
val = "literal";
switch (*ed)
{
case 'A':
ed++;
val = "auxilliary";
break;
case 'P':
ed++;
val = "primary";
break;
}
break;
}
*xp++ = ' ';
if (!delimited)
{
delimited = 1;
if (del != ':')
*xp++ = '`';
}
*xp++ = ' ';
if (!sep)
delimited = -1;
continue;
}
/*
* collect the operands
*/
{
/*
* substitute: <delim><old><delim><new><delim>[g]
* conditional: <delim><non-null><delim><null><delim>
*/
n = op;
switch (op)
{
case 'C':
case 'Y':
break;
case '/':
op = 'C';
val--;
break;
case '?':
op = 'Y';
val--;
break;
}
{
if (c == '(') cnt++;
else if (c == ')' && !--n) cnt = 0;
else if (cnt <= 0)
{
if (c == n)
{
ed++;
break;
}
if (c == '\\' && !*++ed)
error(3, "unterminated lhs of %s: %s", op == 'C' ? "substitution" : "conditional", editcontext(eb, ed));
}
}
{
if (c == '(') cnt++;
else if (c == ')' && !--n) cnt = 0;
else if (cnt <= 0)
{
if (c == n)
{
ed++;
break;
}
if (c == '\\' && !*++ed)
error(3, "unterminated rhs of %s: %s", op == 'C' ? "substitution" : "conditional", editcontext(eb, ed));
}
}
glob = 0;
{
case 'G':
/*FALLTHROUGH*/
case 'g':
break;
case 'L':
/*FALLTHROUGH*/
case 'l':
break;
case 'O':
/*FALLTHROUGH*/
case 'o':
break;
case 'U':
/*FALLTHROUGH*/
case 'u':
break;
default:
break;
}
s = ed;
*s = 0;
}
{
ed++;
}
else if (*ed)
{
/*
* value: [!<>=][=][<val>]
*/
{
case '!':
if (*ed == '=')
{
ed++;
}
break;
case '=':
break;
case '<':
if (*ed == '=')
{
ed++;
}
else if (*ed == '>')
{
ed++;
}
break;
case '>':
if (*ed == '=')
{
ed++;
}
break;
default:
break;
}
{
if (cnt)
{
if (c == cnt) n++;
}
else if (c == '(')
{
cnt = '(';
cntlim = ')';
n++;
}
else if (c == '[')
{
cnt = '[';
cntlim = ']';
n++;
}
else if (c == del && n <= 0)
{
*ed++ = 0;
break;
}
}
}
*xp++ = ' ';
if (!delimited)
{
delimited = 1;
if (del != ':')
*xp++ = '`';
}
if (delimited < 0)
delimited = 1;
else
{
*xp++ = ' ';
}
/*
* B, D and S are grouped before application
*/
switch (op)
{
case '$':
val--;
continue;
case 'B':
case 'D':
case 'S':
switch (op)
{
case 'B':
break;
case 'D':
break;
case 'S':
break;
}
switch (*ed)
{
case 'B':
{
continue;
}
break;
case 'D':
{
continue;
}
break;
case 'S':
{
continue;
}
break;
}
sep = 0;
{
sep = 1;
}
else
{
{
sep = 1;
}
}
{
if (sep)
{
*xp++ = ' ';
*xp++ = ' ';
}
else sep = 1;
}
else
{
{
if (sep)
{
*xp++ = ' ';
*xp++ = ' ';
}
else sep = 1;
}
}
{
if (sep)
{
*xp++ = ' ';
*xp++ = ' ';
}
else sep = 1;
}
else
{
{
if (sep)
{
*xp++ = ' ';
*xp++ = ' ';
}
else sep = 1;
}
}
break;
default:
qual = 0;
if (op == 'T')
{
for (;; val++)
{
switch (*val)
{
case 'R':
op = 0;
break;
case 'W':
continue;
case 'X':
continue;
}
break;
}
{
}
}
if (!op) break;
{
val = "";
arg = 0;
aux = 0;
}
else
{
}
zp = 0;
{
{
{
continue;
break;
continue;
}
m = 0;
{
case 0:
continue;
break;
case '<':
continue;
break;
case '>':
continue;
break;
case '*':
if (arg)
{
continue;
val++;
}
break;
default:
continue;
{
continue;
{
val++;
if (*val)
val++;
}
}
else if (arg)
{
m = 1;
if (*val)
val++;
}
break;
}
if (op == 'T')
{
{
bound = 1;
break;
}
}
{
n = sep;
{
else if (fp->cmd.type == ED_QUAL && (sep & fp->cmd.op) || fp->cmd.type == ED_OP && (fp->cmd.op && op == fp->cmd.op || !fp->cmd.op && arg == fp->cmd.arg && (!fp->cmd.aux || aux == fp->cmd.aux)))
{
e = 1;
else
{
if (!m) m = 1;
{
m = -1;
val++;
val++;
}
*xp++ = ' ';
}
}
}
if (!m)
{
if (e)
{
}
{
sep = n;
continue;
}
}
}
val++;
if (*val)
{
*xp++ = ' ';
if (*val == '-')
{
*xp++ = '-';
*xp++ = '-';
*xp++ = ' ';
}
else
{
while (c = *val++)
*xp = 0;
}
}
break;
}
}
{
if (zp)
{
if (*val)
{
*xp++ = ' ';
}
}
else
{
}
}
break;
}
}
*xp = 0;
return(xp);
}
/*
* expand var name into xp
*/
static char*
{
register int c;
register char* s;
switch (c = *v++)
{
case 0:
break;
case '$':
case '"':
case '-':
case '+':
if (c == '+')
break;
case '=':
break;
case '#':
s = "argc";
goto internal;
case ';':
s = "data";
goto internal;
case '<':
s = "target";
goto internal;
case '>':
s = "prereqs new";
goto internal;
case '*':
s = "prereqs";
goto internal;
case '~':
s = "prereqs all";
goto internal;
case '@':
s = "action";
goto internal;
case '%':
goto internal;
case '!':
s = "prereqs implicit";
goto internal;
case '&':
s = "prereqs implicit state";
goto internal;
case '?':
s = "prereqs all implicit";
goto internal;
case '^':
s = "target original";
goto internal;
while (*v == c)
{
v++;
}
for (;;)
{
switch (*xp++ = *s++)
{
case 0:
xp--;
break;
case ' ':
continue;
default:
continue;
}
break;
}
if (*v)
{
*xp++ = ' ';
}
break;
case '.':
if (v[0] != '.' || v[1] != '.')
goto normal;
break;
default:
if (!isalnum(c))
/*FALLTHROUGH*/
case '_':
case '(':
break;
}
*xp = 0;
return(xp);
}
/*
* expand `$(...)' from a into xp
*/
static char*
{
register int c;
register char* s;
int del;
int p;
int q;
char* ed;
char* var;
char* vp;
if (!(s = strchr(a, '$')))
xp += s - a;
a = s;
while (*a)
{
if (*a != '$') *xp++ = *a++;
else if (*++a == '(')
{
*xp++ = '$';
*xp++ = '(';
if (isspace(*++a))
*xp++ = *a++;
else
{
var = a;
ed = 0;
vp = 0;
del = ':';
q = 0;
p = 1;
while (c = *a++)
{
if (c == '"') q = !q;
else if (q) /* quoted */;
else if (c == '(') p++;
else if (c == ')')
{
if (!--p) break;
}
else if (!ed && p == 1)
{
if (c == '|')
{
*(a - 1) = 0;
else *vp++ = ' ';
var = a;
*(a - 1) = c;
c = 0;
}
else if (c == del)
{
c = 0;
ed = a - 1;
}
else if (c == '`')
{
c = 0;
ed = a - 1;
if (!(del = *a++))
{
ed--;
break;
}
}
}
}
if (q || !c)
{
a--;
}
if (vp)
{
if (*var == '"')
{
c = *(a - 1);
*(a - 1) = 0;
*(a - 1) = c;
var = 0;
}
}
{
*ed = 0;
switch (*(ed + 2))
{
case 'A':
ed += 3;
break;
case 'P':
ed += 3;
break;
default:
ed += 2;
break;
}
if (ed == (a - 1))
ed = 0;
}
if (ed)
{
else
{
c = *ed;
*ed = 0;
if (vp)
{
}
*ed = c;
c = *(a - 1);
*(a - 1) = 0;
*(a - 1) = c;
}
}
else
{
c = *(a - 1);
*(a - 1) = 0;
if (vp)
{
}
*(a - 1) = c;
}
}
*xp++ = ')';
}
else *xp++ = '$';
}
*xp = 0;
return(xp);
}
static int
byop(const char* a, const char* b)
{
return(0);
}
{
register char* s;
register int c;
{
case 'd':
break;
case 'o':
break;
case 'D':
break;
case '?':
break;
case ':':
break;
}
if (error_info.errors)
for (;;)
{
s = *argv++;
{
continue;
}
error_info.file = s;
error_info.line = 0;
{
error_info.line++;
if (*s && !isspace(*s))
}
error_info.file = 0;
error_info.line = 0;
if (!s) break;
}
}