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

⟦8c942f1da⟧ TextFile

    Length: 2792 (0xae8)
    Types: TextFile
    Notes: UNIX file
    Names: »inquire.c«

Derivation

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

TextFile

/*
 * @(#)inquire.c	1.1 15:34:52 4/6/85
 *
 * input routines:	inquire(), rd_line()
 *
 * inquire uses window calls to do output then does a line of input
 * rd_line is used to read a line of input in raw mode
 */
#include	"defs.h"
#include	<sys/dir.h>

extern	int	*Scrnbuf;
extern	int	Runwin;
extern	int	Top;
extern	int	Ls;
extern	int	Pcur;
extern	char	Curdir[];

char	*inquire(str)
char	*str;
{
static	int	buf[40];
int	len;
int	line1;
	
	len = strlen(str);
	fillw(Scrnbuf + (SCR_WID * Top), SCR_WID * (SCR_LEN - Top), V_SPACE);
	bputattr(Scrnbuf, SCR_SIZ.word, Top + 2, 0, 1, len + 2, 0x70);
	bputstr(Scrnbuf, SCR_SIZ.word, Top + 2, 1, str);

	if ( Pcur )
	{
		bputstr(Scrnbuf, SCR_SIZ.word, Top + 1, 1, "Current Directory: ");
		bputstr(Scrnbuf, SCR_SIZ.word, Top + 1, 20, Curdir);
		bputattr(Scrnbuf, SCR_SIZ.word, Top + 1, 0, 1, 
			20 + strlen(Curdir), 0x70);
	}

	if ( Ls )
		ls_dir(".", Scrnbuf + ((Top + 4) * SCR_WID), Top + 4);

	if (  wr_blck(Scrnbuf, 0, 0, SCR_LEN, SCR_WID) )
	{
		pcurs(24,1);
		printf(str);
	}
	else
		pcurs(Top + 3, len + 4);

	if ( rd_line(buf, 40) < 0 )		/* 40 is not arbitrary */
		return (0);

	/* pcurs(24, 79); */
	return (&buf[0]);
}

/*
 * rd_line(bufp, max)
 * a get line that does it's own processing of backspaces
 * newlines, etc., and does its own echoing. This
 * routine is used when the terminal is in RAW mode. 
 * Newlines are put into the buffer.
 *
 * passed	pointer to a buffer to put chars into
 *		maximum number of chars. to read
 * returns	number of chars read
 */

char	KILL_CH = 0x15;		/* ^u */

rd_line(bufp, maxline)
char	*bufp;
int	maxline;
{
int	cnt = 0;
char	c;
char	*orig;
static	char	*backup = "\b \b";

	orig = bufp;

	to_raw();

	while ( cnt < maxline )
	{
		read(0, bufp, 1);
		c = *bufp;

		if ( (c == '\n') || (c == '\r') )
			break;

		if ( c == '\b')
		{
			if ( cnt > 0 )
			{
				write(1, backup, 3);
				bufp--;
				cnt--;
			}
		}

		else if ( c == KILL_CH )
		{
			while ( cnt )
			{
				bufp--;
				write(1, backup, 3);
				cnt--;
			}
		}
		else if ( c == '\033' )		/* treat as EOF */
		{
			bufp = orig;
			cnt = -1;
			break;
		}
		else
		{
			write(1, bufp, 1);
			cnt++;
			bufp++;
		}
	}
	*bufp = '\0';

	to_cooked();
	return (cnt);
}

ls_dir(name, p, row)
char	*name;
W2B	*p;
int	row;
{
struct	direct	dir;
int	cnt = 0;
int	i;
int	fd;
W2B	*s;
char	*n;

	if ( row >= SCR_LEN )
		return;

	if ( (fd = open(name, 0)) < 0 )
		return;

	cnt = 0;
	while (  read(fd, &dir, sizeof(struct direct)) > 0 )
	{
		if ( dir.d_ino == 0 || dir.d_name[0] == '.' )
			continue;

		if ( ++cnt % 5 == 0 )
		{
			if ( ++row >= SCR_LEN )
				break;
		}

		fillw(p, 16, V_SPACE);
		for ( i = 0, s = p, n = dir.d_name; *n && i < 14; i++ )
		{
			s->bytes.low = *n++;
			s->bytes.high = 0x07;
			s++;
		}

		p += 16;
	}
	close(fd);
}