/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-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
/*
* text method
*
* Glenn Fowler
* AT&T Research
*/
static const char usage[] =
"[+DESCRIPTION?The \bdss\b text method describes newline-terminated"
" field-delimited text file data. The method schema is a \bscanf\b(3)"
" style format string with embedded field names of the form"
" \b%(\b\afield\a\b)\b\aformat-char\a \adelimiter\a ...]"
"[+?Use the \bdss\b \bflat\b method for generic record-oriented flat "
"file data.]"
"[+EXAMPLES]{"
" [+dss -x text::::\b\"%(name)s::%(passwd::Encrypted\\ password.)s::%(uid)d::%(gid)d::%(comment)s::%(home)s::%(shell)s\"\\ 'passwd==\"\"&&uid==0'\\ "
" password.]"
"}"
"\n"
"\n--method=text[,option...]\n"
"\n"
;
#include <dsslib.h>
#include <tm.h>
{
char* format;
int vars;
};
extern Dsslib_t dss_lib_text;
/*
* text identf
*/
static int
{
return 1;
}
/*
* text fopenf
*/
static int
{
if (!(file->data = vmnewof(file->dss->vm, 0, Cxvalue_t, ((Text_t*)file->dss->meth->data)->vars, 0)))
{
return -1;
}
return 0;
}
/*
* text fclosef
*/
static int
{
return -1;
return 0;
}
/*
* get one string token into p
*/
static char*
{
register char* t;
register int q;
char* b;
char* u;
b = s;
q = 0;
t = 0;
for (;;)
{
if (!*s)
{
if (!q)
{
if (c && c != ' ')
{
s = b;
b = null;
break;
}
}
if (t)
*t = 0;
break;
}
else if (*s == '\\')
{
u = s;
if (!*++s)
continue;
if (b == u)
b = s;
else if (!t)
t = u;
}
else if (q)
{
if (*s == q)
{
q = 0;
if (!t)
t = s;
s++;
continue;
}
else if (*s == '\r')
*s = 0;
}
else if (*s == '"' || *s == '\'')
{
q = *s++;
if (b == (s - 1))
b = s;
else if (!t)
t = s - 1;
continue;
}
else if (*s == c || c == ' ' && *s == '\t')
{
*s++ = 0;
if (t)
*t = 0;
if (c == ' ')
while (*s == ' ' || *s == '\t')
s++;
break;
}
if (t)
*t++ = *s;
s++;
}
p->data = b;
p->size = *b ? (s - b) : 0;
return s;
}
/*
* text readf
*/
static int
{
register char* s;
register char* f;
register int c;
char* t;
int num;
int q;
Ipaddr_t a;
return 0;
num = 0;
for (;;)
{
switch (c = *f++)
{
case 0:
break;
case ' ':
while (*s == ' ' || *s == '\t')
s++;
break;
case '%':
switch (c = *f++)
{
case 'h':
case 'l':
q = c;
c = *f++;
break;
default:
q = 0;
break;
}
switch (c)
{
case 0:
f--;
continue;
case '%':
if (*s++ != c)
s = null;
continue;
case 'c':
s++;
num++;
break;
case 'd':
c = 10;
goto number;
case 'i':
if (!*s)
else
{
s = t;
}
num++;
break;
case 'n':
case 'u':
c = 0;
goto number;
case 'o':
c = 8;
goto number;
case 'x':
c = 16;
if (!*s)
else
{
s = t;
}
num++;
break;
case 'f':
case 'g':
if (!*s)
else
{
s = t;
}
num++;
break;
case 's':
if (q = *f)
f++;
if (!*s)
{
}
else
num++;
break;
case 't':
if (!*s)
else
{
if (*t && *t != *f && *t != '\n')
s = t;
}
num++;
break;
}
continue;
case '\n':
break;
default:
if (*s++ != c)
s = null;
continue;
}
break;
}
return 1;
}
/*
* text writef
*/
static int
{
register char* f;
register int c;
int num;
num = 0;
for (;;)
{
switch (c = *f++)
{
case 0:
break;
case ' ':
break;
case '%':
switch (c = *f++)
{
case 'h':
case 'l':
c = *f++;
break;
}
switch (c)
{
case 0:
f--;
continue;
case '%':
continue;
case 'c':
num++;
break;
case 'd':
case 'n':
case 'u':
num++;
break;
case 'i':
num++;
break;
case 'f':
case 'g':
num++;
break;
case 'o':
num++;
break;
case 'x':
num++;
break;
case 's':
num++;
break;
case 't':
num++;
break;
}
continue;
case '\n':
break;
default:
continue;
}
break;
}
return 0;
}
{
"text",
"text format (2010-05-28)",
CXH,
0,
0,
0,
0
};
static int
op_get(Cx_t* cx, Cxinstruction_t* pc, Cxoperand_t* r, Cxoperand_t* a, Cxoperand_t* b, void* data, Cxdisc_t* disc)
{
return 0;
}
{
};
/*
* methf
*/
static Dssmeth_t*
textmeth(const char* name, const char* options, const char* schema, Dssdisc_t* disc, Dssmeth_t* ometh)
{
register char* s;
register char* t;
register char* f;
register int c;
char* d;
int p;
int index;
if (options)
{
goto drop;
for (;;)
{
{
case '?':
goto drop;
case ':':
goto drop;
}
break;
}
}
return ometh;
{
return 0;
}
index = 0;
s = (char*)schema;
for (;;)
{
switch (c = *s++)
{
case 0:
break;
case '%':
*f++ = '%';
var = 0;
switch (c = *s++)
{
case 0:
goto invalid;
case 'h': case 'l': case 'L':
case '+': case '-': case '.': case '_':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
continue;
case '%':
*f++ = '%';
continue;
case '(':
t = f;
d = 0;
p = 1;
for (;;)
{
switch (c = *s++)
{
case 0:
goto invalid;
case '(':
p++;
*t++ = c;
continue;
case ')':
if (!--p)
break;
*t++ = c;
continue;
case ':':
if (d)
*t++ = c;
else
{
*t++ = 0;
d = t;
}
continue;
default:
*t++ = c;
continue;
}
break;
}
*t = 0;
{
goto drop;
}
{
goto drop;
}
if (d)
break;
}
for (;;)
{
switch (c = *s++)
{
case 0:
goto invalid;
case 'h': case 'l': case 'L':
case '+': case '-': case '.': case '_':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
continue;
}
break;
}
if (var)
{
switch (c)
{
case 'd':
case 'f':
case 'g':
case 'n':
case 'o':
case 'u':
case 'x':
break;
case 'i':
break;
case 's':
break;
case 't':
break;
default:
goto drop;
}
goto drop;
}
index++;
*f++ = c;
continue;
case ' ':
case '\t':
case '\n':
*f++ = ' ';
continue;
default:
*f++ = c;
continue;
}
break;
}
goto invalid;
*f = 0;
for (c = 0; c < elementsof(local_callouts); c++)
return 0;
return meth;
drop:
return 0;
}
/*
* openf
*/
static int
{
}
{
"text",
"Newline-terminated field-delimited text file; the method schema is"
" a scanf(3) like format string with embedded field names of the form:"
" %(field1)format-char delimiter ...",
CXH,
0,
0
};
{
"text",
"text method"
"[-1ls5Pp0?\n@(#)$Id: dss text method (AT&T Research) 2002-12-17 $\n]"
CXH,
0,
&method,
};