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

⟦8a8cad375⟧ TextFile

    Length: 3729 (0xe91)
    Types: TextFile
    Notes: UNIX file
    Names: »subs.c«

Derivation

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

TextFile


#include "defs.h"

#ifdef XENIX
#include <termio.h>
#include <sys/ioctl.h>
#endif

#ifdef COHERENT
#include	<sgtty.h>
#endif

/*
 *    And now, direct from Urbana, Illinois, and the RBE School of
 *	Software Engineering,
 *
 *    The management of Ceasar's Palace, proudly presents,
 *
 *    x !
 *
 * x(bool,string)	If <bool> is true, then something has gone wrong,
 *			and we should exit.
 *
 * returns:		only if <bool> is false.
 */
x (bool, s)
int     bool;
char   *s;
{
	if (bool)
	{
		printf ("menu internal error: %s\n", s);
		abort ();
	}
}

/* 
 * function:	isdigit
 *
 * History:	Original Coding June 1984 by Robert Adams && Randy Wright.
 *
 */
int     isdigit (c)				/* return BOOL value */
char    c;
{
	return (c >= '0' && c <= '9');
}

/*
 * ncmp(string, string, count)
 *
 * just like strncmp EXCEPT that the strings are case-insensitive
 */
int     ncmp (s, t, count)			/* return 0 <==> True */
char   *s,
       *t;
int     count;
{
	while (--count && *s && *t && (*s | ' ') == (*t | ' '))/* hack */
		s++, t++;
	return ((*s | ' ') - (*t | ' '));
}


cls ()
{
	write (1, "\033[H\033[J", 6);
}

/*
 * Function:	CRblk(str)
 *
 * What-it-does: Print the string and block waiting for a CR.
 */
CRblk(s)
char *s;
{
	char buf[40];
	if ( s == 0 )
		s = "\n-- Press return --";
	write(1, s, strlen(s));
	read(0, buf, 1);
	return(0);
}

char	*strchr(s, c)
char	*s;
char	c;
{
	while ( *s && *s != c )
		s++;
	if ( *s )
		return (s);

	return ( (char *) 0);
}

char	*strrchr(s, c)
char	*s;
char	c;
{
char	*p;

	for (p = s; *p; p++)
		;

	while ( p != s && *p != c )
		p--;

	if ( *p == c )
		return (p);

	return ((char *) 0);
}

strncmp(s1, s2, len)
char	*s1, *s2;
int	len;
{

	while ( len && *s1 && *s1 == *s2 ) /* implies && *s2 */
	{
		s1++; s2++; len--;
	}

	if ( !len )		/* len chars matched exactly */
		return (0);
	
	return ( *s1 - *s2 );
}

atoi(s)
char	*s;
{
int	n = 0;
int	minus = 0;

	while (*s == ' ' || *s == '\t')
		s++;

	if ( *s == '-' )
	{
		s++;
		minus++;
	}

	while ( *s >= '0' && *s <= '9' )
		n = (n * 10) + (*s++ - '0');

	if ( minus )
		return ( -n );
	return ( n );
}

/*
 * cursor positioning  
 * vt100 style, which is what the window system looks like
 */
pcurs(row, col)
int	row, col;
{
static	char	cpstr[] = "\033[00;00H";

	cpstr[2] = (row / 10) + '0';
	cpstr[3] = (row % 10) + '0';
	cpstr[5] = (col / 10) + '0';
	cpstr[6] = (col % 10) + '0';
	write(1, cpstr, sizeof(cpstr) - 1);
}

/*
 * two routines to handle gettting in and out of single char. input mode
 * these are inherently non portable
 */
#ifdef XENIX
static	struct	termio	ttybuf = {0};
static	struct	termio	savbuf = {0};
#endif

#ifdef COHERENT
static struct sgttyb ttybuf = {0};
static struct sgttyb savbuf = {0};
#endif

static	int	inraw = 0;
static	int	got_buf = 0;

to_raw()
{
	if ( inraw )
		return;

	if ( !got_buf )
	{
#ifdef XENIX
		if ( ioctl(0, TCGETA, &ttybuf) )
#endif
#ifdef COHERENT
		if (ioctl (0, TIOCGETP, &ttybuf))
#endif
		{
			printf("ioctl error: getting ttybuf\n");
			exit(1);
		}

		got_buf = 1;
#ifdef XENIX
		ioctl(0, TCGETA, &savbuf);	/* extra copy for restore */
		ttybuf.c_iflag = 0;
		ttybuf.c_lflag = 0;
		ttybuf.c_cc[VTIME] = 0;
		ttybuf.c_cc[VMIN] = 1;
#endif

#ifdef COHERENT
		ioctl (0, TIOCGETP, &savbuf);
		ttybuf.sg_flags &= ~(CRMOD | ECHO | LCASE | TANDEM | XTABS);
		ttybuf.sg_flags |= (CBREAK | RAW);
#endif

	}


#ifdef XENIX
	if ( !ioctl(0, TCSETAW, &ttybuf) )
#endif
#ifdef COHERENT
	if (!ioctl (0, TIOCSETP, &ttybuf))
#endif
		inraw = 1;
	else
	{
		printf("ioctl error: setting raw mode\n");
		exit(1);
	}
}

to_cooked()
{
	if ( !inraw )
		return;

#ifdef XENIX
	if ( !ioctl(0, TCSETAW, &savbuf) )
#endif
#ifdef COHERENT
	if (!ioctl (0, TIOCSETP, &savbuf))
#endif
		inraw = 0;
}