pzpart.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1998-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
/*
* partition support
*/
static const char usage[] =
"[-1i?\n@(#)$Id: pz library 2.4 (AT&T Research) 2011-03-07 $\n]"
"[a:append]"
"[c:comment]:[text]"
"[x:crc]"
"[d:debug]#[level]"
"[D:dump]"
"[G!:gzip]"
"[i:include]:[file]"
"[l:library]:[library]"
"[n:name]:[name]"
"[X:prefix?]:[count[*terminator]]]"
"[O:sort]"
"[P!:pzip]"
"[Q:regress]"
"[r:row]#[row-size]"
"[S:split]:?[pattern]"
"[s:summary]"
"[T:test]#[mask]"
"[v:verbose]"
;
#include "pzlib.h"
/*
* return partition pointer given name
*/
{
}
/*
* partition iterator
* return the next partition after pp
* first call should set pp to 0
* 0 returned after all partitions visited
*/
{
}
/*
* set the current partition to pp
* old partition returned
*/
{
return 0;
return op;
}
/*
* parse a column range at s
* return
* -1 error
* 0 not a range
* 1 ok
*/
static int
{
int n;
int m;
char* e;
for (; isspace(*s) || *s == ','; s++);
if (*s == '-')
n = 0;
else
{
n = (int)strtol(s, &e, 10);
if (s == e)
{
if (p)
*p = e;
return 0;
}
{
return -1;
}
for (s = e; isspace(*s); s++);
}
if (*s == '-')
{
if (!*++s || isspace(*s) || *s == ',')
{
e = s;
}
else
{
m = (int)strtol(s, &e, 10);
{
return -1;
}
}
}
else
m = n;
if (p)
{
for (s = e; isspace(*s) || *s == ','; s++);
*p = s;
}
if (beg)
*beg = n;
if (end)
*end = m;
return 1;
}
/*
* parse a character value at s
*/
static int
{
char* e;
int q;
int v;
for (; isspace(*s); s++);
if (!(q = *s++) || ((v = chresc(s, &e)), s == e))
{
return -1;
}
s = e;
if (*s++ != q)
{
return -1;
}
if (*p)
*p = s;
return v;
}
/*
* add fixed column range value to pz
*/
static int
{
int i;
int v;
{
}
v = k < 0 ? ' ' : k;
for (; n <= m; n++)
{
else if (k < 0)
continue;
}
return 0;
}
/*
* initialize the partition map from pp.{<map,nmap>,<grp,ngrp>}
*/
int
{
int i;
int j;
int k;
k = 0;
{
{
return -1;
}
}
{
return -1;
}
return 0;
}
/*
* initialize the partition workspace
*/
int
{
char* s;
int i;
int j;
int k;
size_t m;
size_t n;
m = 0;
{
{
return -1;
}
{
if (!name)
else
{
name = (const char*)s + 1;
n = s - (char*)name;
else
}
return -1;
}
{
}
{
}
{
}
return -1;
j = 1;
/*
* allocate the global tables
*/
{
}
}
{
(*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzpartinit: win=%I*u mwin=%I*u buf=%p", pz->path, sizeof(pz->win), pz->win, sizeof(pz->mwin), pz->mwin, pz->buf);
n *= 2;
}
/*
* the discipline functions may change the partition name
*/
return -1;
return -1;
return 0;
{
}
/*
* update the partition dictionary
* no dictionary if there's only one part
*/
{
{
{
return -1;
}
}
}
else
{
}
return 0;
}
/*
* parse the run time options
*/
int
{
register char* s = options;
char* e;
char* b;
int i;
int k;
int n;
int r;
int x;
int skip;
skip = 0;
for (;;)
{
for (; isspace(*s) || *s == ','; s++);
if (!*s)
break;
{
case -1:
return -1;
case 1:
s = e;
if (*s++ != '=')
s = "";
return -1;
s = e;
return -1;
continue;
}
b = s;
{
case 0:
break;
case '#':
continue;
default:
if (skip)
continue;
/*
* the discipline gets the first crack
*
* -1 error
* 0 noticed but not consumed
* 1 consumed
*/
{
if (x < 0)
return -1;
}
else
x = 0;
if (!x)
{
x = 2;
{
case 'a':
else
break;
case 'c':
break;
case 'x':
else
break;
case 'd':
break;
case 'D':
else
break;
case 'G':
else
break;
case 'i':
{
return 0;
}
break;
case 'l':
{
if (i)
if (r < 0)
return -1;
}
break;
case 'n':
break;
case 'X':
{
if (*e == 'x' || *e == 'X' || *e == '*' || *e == '-')
e++;
if (*e == 'l' || *e == 'L')
else
{
if (*e == '"' || *e == '\'')
{
for (s = e; *s && !isspace(*s) && *s != ','; s++);
}
else if (*e)
{
return -1;
}
}
}
break;
case 'O':
else
break;
case 'P':
else
break;
case 'Q':
else
break;
case 'r':
break;
case 'S':
{
}
else
break;
case 's':
else
break;
case 'T':
break;
case 'v':
else
break;
case '?':
return -1;
case ':':
{
return -1;
}
x = 0;
break;
}
}
/*
* save consumed options for the header and
* clear so they are not processed again
*/
{
{
}
memset(b, ' ', s - b);
}
continue;
}
break;
}
return 0;
}
static char*
{
char* s;
error_info.line++;
return s;
}
/*
* parse and load a partition file
*/
int
{
int i;
int k;
int m;
char* s;
char* e;
char* t;
char* np;
int n;
int g;
int gi;
int x;
int* cv;
int* ce;
int* cp;
int* gv;
int* hv;
int line;
long f;
char* file;
{
}
sp = 0;
vm = 0;
if (!(s = (char*)partition))
{
goto bad;
}
{
else
{
if (e[0] == '/' && !e[1])
else
{
for (s = buf; *s; s++)
if (isspace(*s) || *s == ',')
*s = '\n';
}
}
{
goto bad;
}
}
else
{
/*
* consume url-ish options
*/
{
goto bad;
memcpy(t, s, e - s);
t[e - s] = 0;
s = t;
if (*e == '#' && !(pz->partname = vmstrdup(pz->vm, e + 1)) || *e == '?' && pzoptions(pz, NiL, e + 1, 1))
goto bad;
}
goto bad;
}
{
error_info.file = s;
error_info.line = 0;
}
{
goto bad;
}
np = 0;
pp = 0;
s = "";
do
{
do
{
{
goto bad;
}
for (; isspace(*s); s++);
if (*s == '"')
{
if (np)
{
goto bad;
}
for (e = ++s; *s && *s != '"'; s++);
if (!*s)
{
goto bad;
}
*s++ = 0;
goto bad;
for (; isspace(*s); s++);
}
if (isalpha(*s))
{
goto bad;
s = "";
}
} while (!(n = strtol(s, &t, 10)));
if (*t == '@')
{
{
case 1:
m = 0;
break;
case 2:
m = 1;
break;
case 4:
m = 2;
break;
case 8:
m = 3;
break;
default:
(*pz->disc->errorf)(pz, pz->disc, 2, "%s: %d: invalid size -- power of 2 from 1..8 expected", s, m);
goto bad;
}
n |= (m << 14);
f = PZ_VARIABLE;
}
else
f = 0;
{
{
return 0;
}
np = 0;
do
{
{
goto bad;
}
for (; isspace(*s); s++);
} while (*s != '"');
continue;
}
goto nope;
if (np)
{
np = 0;
}
goto nope;
m = 0;
g = 0;
for (s = t; isspace(*s); s++);
if (*s != '-')
{
for (; isspace(*s); s++);
if (*s == '"')
break;
else if (isalpha(*s))
{
goto bad;
continue;
}
gi = 0;
for (;;)
{
{
if (*e && *e != '#')
goto bad;
break;
}
s = e;
if (*s == '=')
{
return -1;
s = e;
goto bad;
continue;
}
{
goto bad;
}
for (; n <= x; n++)
{
if (hv[n])
{
goto bad;
}
hv[n] = 1;
*cp++ = n;
gv[m] = g;
m++;
gi = 1;
}
}
if (gi)
{
{
goto bad;
}
*cp++ = -1;
g += gi;
}
}
{
goto bad;
}
*cp++ = -1;
/*
* allocate the map data and work space
*/
goto nope;
m = 0;
g = 0;
k = 0;
while ((i = *cp++) >= 0)
do
{
if (g != gv[m])
{
g = gv[m];
k = 0;
}
k++;
m++;
} while ((i = *cp++) >= 0);
goto bad;
} while (s);
sp = 0;
vm = 0;
{
{
goto bad;
}
}
{
}
return 0;
nope:
bad:
if (sp)
if (vm)
{
}
return -1;
}
/*
* allocate and read an array from the input partition header
*/
static int
{
register size_t n;
register size_t m;
register size_t* v;
return -1;
if (pv)
{
if (!n)
v = 0;
*pv = v;
if (pn)
*pn = n;
while (n--)
{
return -1;
*v++ = m;
}
}
else
while (n--)
{
return -1;
}
return 0;
}
/*
* allocate and read a buffer from the input partition header
*/
static int
{
register size_t n;
register char* v;
{
return -1;
}
if (pv)
{
*pv = v;
if (pn)
*pn = n;
}
else
return 0;
}
/*
* read a pz partition header(s) from pz->io
*/
int
{
register int i;
{
return 0;
if (i == EOF)
return -1;
}
{
}
po = 0;
for (;;)
{
{
case EOF:
goto bad;
case 0:
return -1;
break;
case PZ_HDR_comment:
continue;
case PZ_HDR_fix:
goto bad;
{
}
continue;
case PZ_HDR_grp:
goto bad;
continue;
case PZ_HDR_map:
goto bad;
continue;
case PZ_HDR_options:
continue;
case PZ_HDR_prefix:
continue;
case PZ_HDR_part:
{
return -1;
}
if (pz->partdict && (po = (Pzpart_t*)dtsearch(pz->partdict, pp)) || (po = pz->mainpart) && streq(pp->name, po->name))
{
{
}
for (;;)
{
{
case EOF:
break;
case 0:
case PZ_HDR_part:
break;
default:
if (PZ_HDR_ARR(i))
else if (PZ_HDR_BUF(i))
else
goto bad;
continue;
}
break;
}
}
else
po = 0;
continue;
case PZ_HDR_split:
continue;
default:
if (PZ_HDR_ARR(i))
else if (PZ_HDR_BUF(i))
else
goto bad;
continue;
}
break;
}
return 0;
bad:
return -1;
}
/*
* write any new pz partition headers to op
*/
int
{
register int i;
register size_t m;
int all;
{
all = 0;
}
{
all = 1;
}
else
{
all = 0;
}
while (pp)
{
{
{
}
{
}
{
}
}
if (!all)
break;
}
return 0;
}
/*
* pretty print pp on op
*/
int
{
register int i;
register int j;
register int g;
register char* s;
char esc[2];
sfprintf(op, "\n%I*u\t# high frequency %I*u\n", sizeof(pp->row), pp->row, sizeof(pp->nmap), pp->nmap);
{
esc[1] = 0;
{
for (j = i + 1; j < pp->nfix && pp->fix[j] == pp->fix[j - 1] + 1 && pp->value[pp->fix[j]] == pp->value[pp->fix[j - 1]]; j++);
if (j > (i + 2))
{
i = j - 1;
}
j = *s == '\'' ? '"' : '\'';
}
}
g = -1;
{
{
}
else
if (j > (i + 2))
{
i = j - 1;
}
}
}