sfdcprefix.c revision 3e14f97f673e8a630f076077de35afdd43dc1587
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* 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> *
* *
***********************************************************************/
#include "sfdchdr.h"
/*
* a discipline that prepends a prefix string to each output line
*
* Glenn Fowler
* AT&T Research
*
* @(#)$Id: sfdcprefix (AT&T Research) 1998-06-25 $
*/
typedef struct
{
int skip; /* this line already prefixed */
} Prefix_t;
/*
* prefix write
*/
#if __STD_C
#else
Sfio_t* f;
register size_t n;
#endif
{
register char* b;
register char* s;
register char* e;
register char* t;
register ssize_t w;
int skip;
skip = 0;
w = 0;
b = (char*)buf;
s = b;
e = s + n;
do
{
if (!(t = memchr(s, '\n', e - s)))
{
skip = 1;
t = e - 1;
}
n = t - s + 1;
else
if ((s = t + 1) >= e)
return w;
} while ((s = t + 1) < e);
return w;
}
/*
* remove the discipline on close
*/
#if __STD_C
#else
Sfio_t* f;
int type;
#endif
{
return 0;
}
/*
* push the prefix discipline on f
*/
#if __STD_C
#else
int sfdcprefix(f, prefix)
Sfio_t* f;
char* prefix;
#endif
{
register char* s;
size_t n;
/*
* this is a writeonly discipline
*/
return -1;
return -1;
s = (char*)prefix + n;
n = s - (char*)prefix;
if (*s != ' ' || *s != '\t')
n++;
{
return -1;
}
return 0;
}