DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T r

⟦eb54818e5⟧ TextFile

    Length: 2299 (0x8fb)
    Types: TextFile
    Names: »rd_buf.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Lib/io/rd_buf.c« 

TextFile

/* rd_buf.c: low level line reading of Control and DR Txt Files */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/io/RCS/rd_buf.c,v 5.0 90/09/20 16:06:38 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Lib/io/RCS/rd_buf.c,v 5.0 90/09/20 16:06:38 pp Exp Locker: pp $
 *
 * $Log:	rd_buf.c,v $
 * Revision 5.0  90/09/20  16:06:38  pp
 * rcsforce : 5.0 public release
 * 
 */



#include "head.h"

#define COMMENTCHAR     '#'
int                     protocol_mode = 0;

static int glinread ();


/* ---------------------  Begin  Routines  -------------------------------- */




int txt2buf (linebuf, fp)
FILE           *fp;
char           *linebuf;
{
	int             n;

	PP_DBG (("Lib/io/txt2buf()"));

	if ((n = glinread (fp, linebuf, BUFSIZ)) < 0)
		return (RP_EOF);
	if (n == 0)             /* time for a resync */
		return (RP_PARM);
	if (n == 1)
		return (RP_DONE);
	if (linebuf[--n] != '\n')
		return (RP_MECH);
	linebuf[n] = '\0';
	return (RP_OK);
}



/* ---------------------  Static  Routines  ------------------------------- */



static int glinread (fp, buf, size)
register FILE  *fp;
char           *buf;
int	size;
{
	register int    c;
	register int    i;
	extern  int protocol_mode;

	PP_DBG (("Lib/io/glinread()"));

	if (feof(fp))
		return EOF;

	for (--size, i = 0; i < size; i++)
		switch (c = getc (fp)) {
		case EOF:
			return (EOF);

		case '\0':
			return (0);

		case '\n':
			*buf++ = c;
			if (protocol_mode == 0) {
				/* -- first char on next line -- */
				(void) ungetc (c = getc (fp), fp);
				if (c == COMMENTCHAR) {
					/*
					check for comments within folding.
					Ignore everything up to and
					including new line character which
					is not followed by COMMENTCHAR,
					this could probably be recursive and
					clever - but what the hell
					*/
					while (42) {
						if ((c = getc (fp)) == '\n') {
							(void) ungetc (c =
							       getc (fp), fp);
							if (c != COMMENTCHAR)
								break;
						}
					}
				}

				if (c == ' ' || c == '\t') {
					/* continuation line */
					c = getc (fp);
					*(buf - 1) = ' ';
					break;
				}
			}
			*buf = 0;
			return (++i);

		default:
			*buf++ = c;
		}

	/*
	 * if ever get here then line too long
	 */
	*buf = 0;
	return (i);
}