menuutils.c revision 1.3
11.2Schristos/*	$NetBSD: menuutils.c,v 1.3 2008/12/14 18:46:33 christos Exp $	*/
21.1Sdrochner
31.1Sdrochner/*
41.1Sdrochner * Copyright (c) 1996, 1997
51.1Sdrochner * 	Matthias Drochner.  All rights reserved.
61.1Sdrochner * Copyright (c) 1996, 1997
71.1Sdrochner * 	Perry E. Metzger.  All rights reserved.
81.1Sdrochner * Copyright (c) 1997
91.1Sdrochner *	Jason R. Thorpe.  All rights reserved
101.1Sdrochner *
111.1Sdrochner * Redistribution and use in source and binary forms, with or without
121.1Sdrochner * modification, are permitted provided that the following conditions
131.1Sdrochner * are met:
141.1Sdrochner * 1. Redistributions of source code must retain the above copyright
151.1Sdrochner *    notice, this list of conditions and the following disclaimer.
161.1Sdrochner * 2. Redistributions in binary form must reproduce the above copyright
171.1Sdrochner *    notice, this list of conditions and the following disclaimer in the
181.1Sdrochner *    documentation and/or other materials provided with the distribution.
191.1Sdrochner * 3. All advertising materials mentioning features or use of this software
201.1Sdrochner *    must display the following acknowledgements:
211.1Sdrochner *	This product includes software developed for the NetBSD Project
221.1Sdrochner *	by Matthias Drochner.
231.1Sdrochner *	This product includes software developed for the NetBSD Project
241.1Sdrochner *	by Perry E. Metzger.
251.1Sdrochner * 4. The names of the authors may not be used to endorse or promote products
261.1Sdrochner *    derived from this software without specific prior written permission.
271.1Sdrochner *
281.1Sdrochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
291.1Sdrochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
301.1Sdrochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
311.1Sdrochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
321.1Sdrochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
331.1Sdrochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
341.1Sdrochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
351.1Sdrochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
361.1Sdrochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
371.1Sdrochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
381.1Sdrochner */
391.1Sdrochner
401.1Sdrochner#include <lib/libkern/libkern.h>
411.1Sdrochner#include <lib/libsa/stand.h>
421.1Sdrochner
431.1Sdrochner#include "libi386.h"
441.1Sdrochner
451.1Sdrochnervoid
461.2Schristosdocommand(char *arg)
471.1Sdrochner{
481.1Sdrochner	char *options;
491.1Sdrochner	int i;
501.1Sdrochner
511.1Sdrochner	options = gettrailer(arg);
521.1Sdrochner
531.1Sdrochner	for (i = 0; commands[i].c_name != NULL; i++) {
541.1Sdrochner		if (strcmp(arg, commands[i].c_name) == 0) {
551.1Sdrochner			(*commands[i].c_fn)(options);
561.1Sdrochner			return;
571.1Sdrochner		}
581.1Sdrochner	}
591.1Sdrochner
601.1Sdrochner	printf("unknown command\n");
611.1Sdrochner	command_help(NULL);
621.1Sdrochner}
631.1Sdrochner
641.1Sdrochnervoid
651.2Schristosbootmenu(void)
661.1Sdrochner{
671.1Sdrochner	char input[80];
681.1Sdrochner
691.1Sdrochner	for (;;) {
701.1Sdrochner		char *c = input;
711.1Sdrochner
721.1Sdrochner		input[0] = '\0';
731.1Sdrochner		printf("> ");
741.1Sdrochner		gets(input);
751.1Sdrochner
761.1Sdrochner		/*
771.1Sdrochner		 * Skip leading whitespace.
781.1Sdrochner		 */
791.3Schristos		while (*c == ' ')
801.3Schristos			c++;
811.3Schristos		if (*c)
821.1Sdrochner			docommand(c);
831.1Sdrochner	}
841.1Sdrochner}
85