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

⟦7a404e4b1⟧ TextFile

    Length: 3254 (0xcb6)
    Types: TextFile
    Notes: UNIX file
    Names: »input.c«

Derivation

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

TextFile

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

/*
 * Function:	get_choice(menu)
 *
 * Purpose:	Decide what the user typed.
 *
 * Passed:	A menu pointer, (it modifies the data to which
 *		the menu points.)
 *
 * Returns:	1) (via return) The type of choice.
 *		2) (via *menu)  The choice itself, in m_current
 *
 * Called by:	main
 *
 * Calls:	List to be compiled.
 *
 * History:	Original code June 84, Robert Adams.
 *
 * Notes:	This code should do smart abbreviation stuff.
 */

#include "defs.h"

int     get_choice (menu)			/* returns a type */
struct menu_f  *menu;				/* and sets menu -> m_current */
{
struct choice_f *chp;			/* pointer to possible choices */
int     chnum;				/* value for choice */
int	chtype;
int     i;				/* just a counter */

	chp = menu->m_list;		/* list of choices */
	/*
	 * in the select system we return the number of
	 * the choice they were on when they quit
	 * chtype is set to the operation to perform
	 * depending on which key they terminated the select with
	 * 	<ret> 	= CHEXEC
	 *	? 	= CHELP
	 *	<esc> 	= CHEXIT
	 */
	chnum = select(menu, &chtype);	/* select takes care of input */

	for ( i = 1; i < chnum && chp; i++ )
		chp = chp->c_next;

	if ( !chp )
		chtype = CHINVLD;
		
	switch (chtype)
	{
		case CHEXEC: 
			if (chp -> c_exec)
				menu -> m_current = chp -> c_Exec;
			else
				menu -> m_current = 
				"/bin/echo No \"Exec:\" spec. in input file.";
			break;
		case CHHELP: 
			if (chp -> c_help)
				menu -> m_current = chp -> c_Help;
			else
				menu->m_current = "/bin/echo No help.";
			break;
		case CHDUMP: 
		case CHINVLD: 
		case CHRPLOT: 
			menu -> m_current = NULL;
			break;
		case CHEXIT: 
			cls();
			_exit (-chnum);
			break;
		default: 
			x (TRUE, "get_choice II: switch (bad chtype)");
			break;
	}
	return (chtype);
}

#ifdef LONGMATCH
struct	choice_f *best_match(chp, str)
struct	choice_f *chp;
char	*str;
{
struct	choice_f *this_one = 0;		/* the best match we could find */
int	nmatched = 0;			/* max chars we matched */
int	cnt0, cnt1, cnt2;		/* for counting matches */
int	i;
char	*op, *p;

	while ( chp )
	{
		op = chp->c_Text;
		p = str;
		cnt0 = 0;
		while ( *op && *p )
		{
			if ( (*op++ | 0x20) == (*p++ | 0x20) )
				cnt0++;
		}

		if ( cnt0 == strlen(chp->c_Text) )
		{
			this_one = chp;
			break;
		}
		cnt0 += cnt0;		/* give this count higher priority */

		cnt1 = match2(chp->c_Text, str);	/* count matches */
		cnt2 = match2(str, chp->c_Text);

		/*
		 * take the greatest number of matching chars 
		 */
		if ( cnt1 < cnt2 )
			cnt1 = cnt2;
		if ( cnt1 < cnt0 )
			cnt1 = cnt0;

		if ( cnt1 > nmatched )
		{
			nmatched = cnt1;
			this_one = chp;
		}
		chp = chp->c_next;
	}

	return ( this_one );
}

/*
 * match2 - in this match if the chars don't match 
 * we only increment string 1. This allows extra chars in
 * one of the strings. e.g: "strings one" and "string one"
 * will match.
 */
match2(s1, s2)
char	*s1;
char	*s2;
{
int	cnt = 0;

	while ( *s1 && *s2 )
	{
		while ( *s2 == ' ' )
			s2++;
		while ( *s1 == ' ' )
			s1++;
		if ( (*s1 | 0x20) == (*s2 | 0x20) )
		{
			cnt++;
			s2++;
			s1++;
		}
		else
			s1++;
	}

	return ( cnt );
}
#endif