/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2000-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> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* parameterized on these macros
*
* ITLINT the tuple element integral type
* ITLEXTERNAL convert to external
* ITLINTERNAL convert to internal
*
* macros must be defined before include
* macros undefined after include
*
* Glenn Fowler
* AT&T Research
*/
#include <ctype.h>
/*
* pretty print an ITLINT tuple list from value->buffer into buf
*/
ITLEXTERNAL(Cx_t* cx, Cxtype_t* type, int dots, int tuple, int group, const char* details, Cxformat_t** formats, Cxvalue_t* value, char* buf, size_t size, Cxdisc_t* disc)
{
char* sep;
char* bet;
char* s;
char* t;
ITLINT v;
int def;
int fmt;
int b;
int i;
int j;
int k;
int m;
int n;
int g;
{
{
fmt = 'd';
sep = ",";
def = 1;
}
else if (fmt == 's')
def = 1;
else
if (!*sep)
sep = ",";
bet = ":";
i = 0;
j -= tuple - 1;
g = j + 1 + !group;
while (i < j)
{
if (i > g)
{
g = j + 1;
t = sep;
}
{
i++;
if (ap[i])
{
g = i + ap[i];
t = "{";
}
else
t = sep;
i++;
}
else
t = sep;
{
if (def && formats && formats[k] && formats[k]->map && !cxnum2str(cx, formats[k], (Cxinteger_t)ap[i], &s))
else if (ap[i])
switch (fmt)
{
case 'd':
break;
case 'o':
break;
case 'x':
break;
case '.':
n = 8;
goto dotted;
case '1':
case '2':
case '4':
case '8':
n = (n - '0') * 8;
v = ap[i];
m = (1 << n) - 1;
b = sizeof(ITLINT) * 8;
if ((b / n) == 2 && !((v >> n) & m))
b = n;
while ((b -= n) >= 0)
break;
default:
if (dots)
{
n = dots * 8;
goto dotted;
}
break;
}
else
}
}
if (g < (j + 1))
{
return -1;
}
{
s += j;
i -= j;
}
}
else
{
s = "";
i = 0;
}
if ((i + 1) > size)
return i + 1;
return i;
}
/*
* parse an ITLINT tuple list from buf into value->buffer
* return the number of bytes consumed from buf
*/
ITLINTERNAL(Cx_t* cx, Cxvalue_t* value, int dots, int tuple, int group, const char* buf, size_t size, Vmalloc_t* vm, Cxdisc_t* disc)
{
register char* s;
register char* e;
register int t;
char* p;
ITLINT n;
ITLINT m;
size_t o;
size_t z;
o = 0;
t = 0;
s = (char*)buf;
e = s + size;
if (!dots)
dots = 1;
dots *= 8;
m = 1;
m = (m << dots) - 1;
for (; s < e; s++)
if (*s == ':' || isdigit(*s))
{
t++;
if (*s == ':')
n = 0;
else
{
n = strntol(s, e - s, &p, 0);
for (;;)
{
s = p;
if (s >= e || *s != '.')
break;
}
}
{
n = 0;
n = (ITLINT)(~0);
}
if (s < e && *s != ':')
{
s--;
n = 0;
while (t++ < tuple)
t = 0;
}
}
else if (*s == '{')
{
if (group)
{
n = (ITLINT)(~0);
}
}
else if (isalpha(*s) || *s == '?')
break;
{
if (!vm)
{
return -1;
}
if (o)
vp[o] = z - o;
}
else
vp = 0;
return s - (char*)buf;
}