/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1996-2012 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> *
* Phong Vo <kpv@research.att.com> *
* Doug McIlroy <doug@research.bell-labs.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* sfopen file suffix match intercept
* export SFOPEN_INTERCEPT with one or more suffix map entries
*
* option<del>[no]verbose<del>
* program<del><pattern><del>
* input<del><pattern><del>command<del>
* output<del><pattern><del>command<del>
* ...
*
* space between entries ignored
* program patterns matched against error_info.id
* io patterns matched against the file path
* (literal) \0 in command expands to the file path
* (literal) \<n> in command expands to the <n>th subexpression in the file path pattern match
*/
#include <ast.h>
#include <ctype.h>
#include <error.h>
struct Io_s
{
char* command;
char* pattern;
};
struct Match_s
{
char* pattern;
};
static struct State_s
{
int dump;
int init;
int verbose;
} state;
static Match_t*
initialize(void)
{
register char* s;
register char* t;
register char* v;
register char* x;
register int n;
register int d;
for (;;)
{
while (isspace(*s))
s++;
for (t = s; isalnum(*s); s++);
if (s == t || !(d = *s))
break;
*s++ = 0;
for (v = s; *s && *s != d; s++);
if (*s)
*s++ = 0;
{
if (mp)
{
for (x = s; *s && *s != d; s++);
if (*s)
*s++ = 0;
break;
if (*v)
if (*x)
n = *t == 'o';
if (ie[n])
else
}
}
else if (streq(t, "program"))
{
break;
if (*v)
if (me)
else
}
else if (streq(t, "option"))
{
if (*v == 'n' && *(v + 1) == 'o')
{
v += 2;
n = 0;
}
else
n = 1;
if (streq(v, "dump"))
else if (streq(v, "verbose"))
}
}
return mp;
}
{
register const char* s;
register ssize_t r;
register int c;
register int n;
register int m;
{
{
{
{
}
}
}
{
n = 0;
s = mode;
for (;;)
{
switch (*s++)
{
case 0:
break;
case 'b':
n = -1;
break;
case 'w':
case '+':
n = 1;
continue;
default:
continue;
}
break;
}
do
{
{
do
{
if (!io->pattern && !(m = 0) || (m = strgrpmatch(path, io->pattern, sub, elementsof(sub) / 2, STR_MAXIMAL|STR_LEFT|STR_RIGHT)))
break;
if (io)
{
{
m *= 2;
r = 1;
while (c = *s++)
{
if (c == '\\' && *s && (c = *s++) >= '0' && c <= '9')
{
c = 2 * (c - '0');
r = 0;
}
else
}
if (r)
return 0;
return f;
}
break;
}
}
}
}
}