123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /* $OpenBSD: parse.c,v 1.1 2013/10/28 22:13:13 miod Exp $ */
- /* $NetBSD: parse.c,v 1.4 2013/01/22 15:48:40 tsutsui Exp $ */
- /*
- * Copyright (c) 1992 OMRON Corporation.
- *
- * This code is derived from software contributed to Berkeley by
- * OMRON Corporation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)parse.c 8.1 (Berkeley) 6/10/93
- */
- /*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * OMRON Corporation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)parse.c 8.1 (Berkeley) 6/10/93
- */
- /*
- * parse.c -- command parser
- * by A.Fujita, JAN-30-1992
- */
- #include <lib/libkern/libkern.h>
- #include <luna88k/stand/boot/samachdep.h>
- #include <luna88k/stand/boot/status.h>
- static int cmd_help(int, char *[]);
- int
- exit_program(int argc, char *argv[])
- {
- return(ST_EXIT);
- }
- static const char helpmsg[] =
- "commands are:\n"
- "boot [device(unit,part)filename]\n"
- " (ex. \"boot sd(0,0)bsd\", \"boot le(0,0)obsd\" etc.)\n"
- "help\n"
- "exit\n"
- ;
- static int
- cmd_help(int argc, char *argv[])
- {
- printf(helpmsg);
- return ST_NORMAL;
- }
- struct command_entry {
- char *name;
- int (*func)(int, char **);
- };
- struct command_entry entries[] = {
- { "b", boot },
- { "boot", boot },
- { "exit", exit_program },
- { "help", cmd_help },
- { "quit", exit_program },
- { 0, 0 }
- };
- int
- parse(int argc, char *argv[])
- {
- int i, status = ST_NOTFOUND;
- for (i = 0; entries[i].name != (char *) 0; i++) {
- if (!strcmp(argv[0], entries[i].name)) {
- status = (*entries[i].func)(argc, argv);
- break;
- }
- }
- return(status);
- }
- /*
- * getargs -- make argument arrays
- */
- int
- getargs(char buffer[], char *argv[], int maxargs)
- {
- int n = 0;
- char *p = buffer;
- argv[n++] = p;
- while (*p != '\0') {
- if ( *p == ' ' ) {
- *p = '\0';
- } else if (p != buffer && *(p-1) == '\0') {
- if ( n < maxargs )
- argv[n++] = p;
- }
- p++;
- }
- return(n);
- }
|