tokline.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-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> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return an Sfio_t* to a file or string that
*
* splices \\n to single lines
* checks for "..." and '...' spanning newlines
* drops #...\n comments
*
* if <arg> is a file and first line matches
* #!!! <level> <message> !!!
* then error(<lev>,"%s: %s",<arg>,<msg>) called
*
* NOTE: seek disabled and string disciplines cannot be composed
* quoted \n translated to \r
*/
#include <ast.h>
#include <error.h>
#include <tok.h>
typedef struct
{
int quote;
int* line;
} Splice_t;
/*
* the splicer
*/
static int
{
register char* b;
register int c;
register int n;
register int q;
register int j;
register char* e;
char* buf;
switch (op)
{
case SF_CLOSING:
return 0;
case SF_DPOP:
free(d);
return 0;
case SF_READ:
do
{
return 0;
q = d->quote;
j = 0;
(*d->line)++;
{
j = 1;
n -= 2;
if (q == '#')
{
n = 0;
continue;
}
}
else if (q == '#')
{
q = 0;
n = 0;
continue;
}
if (n > 0)
{
e = (b = buf) + n;
while (b < e)
{
if ((c = *b++) == '\\')
b++;
else if (c == q)
q = 0;
else if (!q)
{
if (c == '\'' || c == '"')
q = c;
{
{
q = '#';
n = b - buf - 2;
}
else if (n = b - buf - 1)
break;
}
}
}
if (n > 0)
{
buf[n++] = '\n';
}
}
} while (n <= 0);
d->quote = q;
return 1;
default:
return 0;
}
}
/*
* open a stream to parse lines
*
* flags: 0 arg: open Sfio_t*
* flags: SF_READ arg: file name
* flags: SF_STRING arg: null terminated char*
*
* if line!=0 then it points to a line count that starts at 0
* and is incremented for each input line
*/
{
Sfio_t* f;
Sfio_t* s;
Splice_t* d;
char* p;
char* e;
static int hidden;
return 0;
{
free(d);
return 0;
}
{
free(d);
sfclose(s);
return 0;
}
else if ((p = sfreserve(f, 0, 0)) && sfvalue(f) > 11 && strmatch(p, "#!!! +([-0-9]) *([!\n]) !!!\n*") && (e = strchr(p, '\n')))
{
}
d->sp = f;
return s;
}