DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

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

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦b8985bff2⟧ TextFile

    Length: 1664 (0x680)
    Types: TextFile
    Notes: UNIX file
    Names: »getlin.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »unimenu/src/menu/getlin.c« 

TextFile

static char *SCCSid = "@(#)getlin.c	1.1 15:34:40 4/6/85";
/*
 *			Copyright (c) 1984
 *
 *		LANTECH Systems, Incoroporated
 *
 *			All rights reserved
 */

# include "defs.h"

/*
 * function:	getlin(fp)
 *
 * returns:	returns a character pointer to static data
 *		which is the next logical line.
 *
 * side effect:	reads in  a line or few from fp.
 *
 * history:	Original coding by Rob Adams July 84.
 */

#define	MAXLINE	512

char   *getlin (fd)
int 	fd;
{
static char     line[MAXLINE];		/* where to put the line */
char   *avail = line;			/* pointer to space in line[]. */
char   *fgets ();			/* how to read the file */
char   *strchr ();			/* USG only. v7 should be index() */
char   *strrchr ();			/* USG only. v7 should be rindex() */
int     length = MAXLINE;		/* decremented as each line is read */
int     ichar = 0;			/* for return from getc */

	do
	{
		if (ichar)
			ungetc(ichar);

		if ( length <= 2 )
		{	
			printf("Input line too long\n");
			break;
		}
		avail = fgets (avail, length, fd);	/* read a line */

		if (avail == NULL)		/* failed */
			continue;
#ifdef DEBUG
		printf("getlin: Read in: %s", avail);
#endif
		length -= strlen(avail);

		avail = strchr (avail, '\n');	/* find the next available
						   part overwrite newline */
		if ( avail == NULL )
			x (1, "getln: strchr");/* should be there */

		ichar = getc (fd);		/* continuation ? */

	} while (ichar == ' ' || ichar == '\t');

	if (avail == NULL)			/* first read failed */
		return NULL;

	if (ichar != EOF)			/* a read failed */
		ungetc ((char) ichar);

	/* 
	 * Before we return, lets blow off the final newline
	 */
	*avail = '\0';
	return (line);				/* every time */
}