/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-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
/*
* jcl path map
*/
#include "jcllib.h"
#include <tok.h>
typedef struct Map_s
{
char* prefix;
char* map;
char* tail;
char* suffix;
int length;
int same;
} Map_t;
typedef struct Match_s
{
const char* string;
int length;
} Match_t;
typedef struct Suf_s
{
int length;
} Suf_t;
typedef struct State_s
{
int mapped;
int matched;
int matches;
} State_t;
static const char usage[] =
"[-?\n@(#)$Id: libjcl (AT&T Research) 2007-12-10 $\n]"
"[i:import]"
"[I:include]:[directory]"
"[k:marklength]"
"[p:parameterize]"
"[s:subdirectory]"
"[w:warn]"
;
static int
{
unsigned long f;
switch (c)
{
case 'i':
f = JCL_IMPORT;
break;
case 'I':
return 1;
case 'k':
f = JCL_MARKLENGTH;
break;
case 'p':
f = JCL_PARAMETERIZE;
break;
case 's':
f = JCL_SUBDIR;
break;
case 'w':
f = JCL_WARN;
break;
case ':':
return 0;
case '?':
return 0;
}
{
else
}
return 1;
}
/*
* return a pointer to the next delimiter
* 0 if no more delimiters
*/
static const char*
nextdelim(register const char* s)
{
register int c;
while (c = *s++)
if (delimiter(c))
return s - 1;
return 0;
}
/*
* return a pointer to the last delimiter
* 0 if no more delimiters
*/
static const char*
lastdelim(register const char* s)
{
register int c;
register const char* r;
r = 0;
while (c = *s++)
r = s - 1;
return r;
}
/*
* return the pointer to the matched subexpression n
* string length returned in *z
*/
char*
{
{
return 0;
}
}
/*
* match tail pattern t to s
* set sets state.matched
*/
static int
{
register const char* u;
const char* b;
b = s;
for (;;)
{
if (*t == '*')
{
if (!*++t)
{
if (set)
{
return (s - b) + (state.match[state.matched].length = strlen(state.match[state.matched].string = s));
}
return 1;
}
else
{
t++;
if (!(u = nextdelim(s)))
break;
if (set)
{
}
s = u + 1;
}
}
else if (*t != *s++)
break;
else if (!*t++)
return s - b - 1;
}
return 0;
}
/*
* longest matching prefix match function
* we don't expect many map entries
*/
static Map_t*
{
register int i;
register int j;
register int n;
int all;
const char* s;
buf[1] = 0;
n = 0;
all = -1;
for (;;)
{
lp = 0;
{
i = 0;
{
if (!name[j])
{
break;
return mp;
}
{
i = j;
}
}
}
if (lp)
{
return lp;
}
break;
{
break;
}
name = s + 1;
}
if (all >= 0)
{
switch (all)
{
case 0:
all++;
break;
case 1:
break;
default:
state.match[all].length = strlen(state.match[all].string = state.match[all-1].string + state.match[all-1].length + 1);
break;
}
return mp;
}
return 0;
}
/*
* add s to the mapped suffix dictionary
*/
static int
{
int n;
{
{
return -1;
}
}
{
n = strlen(s);
{
return -1;
}
}
return 0;
}
/*
* add maps in file to dataset map
*/
int
{
register char* s;
register char* t;
char* op;
char* ofile;
char* tail;
long oline;
int c;
int n;
int k;
int dontcare;
{
file = JCL_MAPFILE;
dontcare = 1;
}
return 0;
else
dontcare = 0;
{
sp = 0;
{
{
if (dontcare)
return 0;
return -1;
}
}
if (!sp)
{
return -1;
}
}
error_info.line = 0;
{
error_info.line++;
{
{
n = 0;
while (s = arg[n++])
}
{
{
continue;
}
k = 0;
{
s += 2;
k++;
}
if (*s == '*')
{
if (*(s + 1))
{
(*disc->errorf)(NiL, disc, 2, "%s: %s: only \"*.\" at beginning, \".*.\" in middle, or \".*\" at end supported", op, s);
return -1;
}
s++;
k++;
}
{
(*disc->errorf)(NiL, disc, 2, "%s: %s: only %d *. prefixes supported", op, arg[0], elementsof(state.match) - 1);
return -1;
}
tail = 0;
for (t = s; *t; t++)
if (*t == '*')
{
{
(*disc->errorf)(NiL, disc, 2, "%s: %s: only \"*[./]\" at beginning, \"[./]*[./]\" in middle, or \"[./]*\" at end supported", op, s);
return -1;
}
if (!tail)
tail = t;
}
if (n = t - s)
{
{
{
return -1;
}
}
if (tail)
*tail = 0;
if (tail)
*tail = '*';
if (c)
{
continue;
}
}
else
{
if (!*(s = arg[0]))
s = "*";
{
continue;
}
}
{
return -1;
}
if (tail)
n = tail - s;
*s++ = 0;
if (tail)
if (arg[2])
else
else
return -1;
}
{
const char* use;
{
}
n = 0;
while (s = arg[n++])
if (*s == '-' || *s == '+')
{
}
}
{
n = 0;
while (s = arg[n++])
if (!delimiter(*s))
{
}
return -1;
}
}
}
{
for (pp = 0, mp = (Map_t*)dtfirst(state.match[k].map); mp; pp = mp, mp = (Map_t*)dtnext(state.match[k].map, mp))
{
if (pp)
message((-9, "map[%d] %2d %2d %s%s%s", k, mp->length, mp->same, mp->prefix, mp->tail ? " " : "", mp->tail ? mp->tail : ""));
}
}
return 0;
}
/*
* return the length of the mapped suffix in path
* 0 returned if path has no mapped suffix
*/
int
{
const char* s;
return (state.suf && (s = strrchr(path, '.')) && (xp = (Suf_t*)dtmatch(state.suf, s))) ? xp->length : 0;
}
/*
* converted name returned in jcl->vp
* jcl->tp may be clobbered
*/
char*
{
register char* s;
register char* t;
register Map_t* m;
char* e;
int n;
name = (const char*)s;
{
{
}
{
}
else
}
else
m = 0;
{
{
}
strtol(s + 1, &e, 0);
if (*e == ')' && !*(e + 1))
{
*s++ = '/';
if (*(s + 1) == '0' && (s + 2) == e || *(s + 1) == '+' && *(s + 2) == '0' && (s + 3) == e)
{
*s++ = '0';
*s = 0;
}
else
{
*e = 0;
{
if (!(pp = sfpopen(NiL, s, "r")) || !(t = sfgetr(pp, '\n', 0)) || sfprintf(jcl->vp, "%s", t) || sfclose(pp))
{
}
}
else
{
}
}
}
else
{
*s = '/';
*strrchr(s, ')') = 0;
}
}
name = (const char*)s;
return (char*)name;
}