xref: /original-bsd/sys/luna68k/stand/parse.c (revision ea3a8ee8)
1 /*
2  * Copyright (c) 1992 OMRON Corporation.
3  * Copyright (c) 1992 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * OMRON Corporation.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)parse.c	7.1 (Berkeley) 12/13/92
12  */
13 
14 /*
15  * parse.c -- command parser
16  * by A.Fujita, JAN-30-1992
17  */
18 
19 #include <luna68k/stand/status.h>
20 
21 /* for scsi.c */
22 
23 int scsi();
24 
25 /* for disklabel.c */
26 
27 int disklabel();
28 
29 /* for boot.c */
30 
31 int boot();
32 
33 int load();
34 
35 int how_to_boot();
36 
37 /* for tape.c */
38 
39 int tape();
40 
41 /* for fsdump.c */
42 
43 int fsdump();
44 int fsrestore();
45 
46 /* for screen.c */
47 
48 int screen();
49 
50 int
51 check_args(argc, argv)
52 	int   argc;
53 	char *argv[];
54 {
55 	register int i;
56 
57 	for ( i = 0; i < argc; i++)
58 		printf("argv[%d] = \"%s\"\n", i, argv[i]);
59 
60 	return(ST_NORMAL);
61 }
62 
63 int
64 exit_program(argc, argv)
65 	int   argc;
66 	char *argv[];
67 {
68 	return(ST_EXIT);
69 }
70 
71 struct command_entry {
72 	char *name;
73 	int (*func)();
74 };
75 
76 struct command_entry entries[] = {
77 { "b",		boot         },
78 { "boot",	boot         },
79 { "chkargs",	check_args   },
80 { "disklabel",	disklabel    },
81 { "exit",	exit_program },
82 { "fsdump",	fsdump       },
83 { "fsrestore",	fsrestore    },
84 { "howto",	how_to_boot  },
85 { "load",       load         },
86 { "screen",	screen	     },
87 { "tape",	tape	     },
88 { "tp",		tape	     },
89 { "scsi",	scsi         },
90 { "quit",	exit_program },
91 { 0, 0 }
92 };
93 
94 
95 int
96 parse(argc, argv)
97 	int   argc;
98 	char *argv[];
99 {
100 	register int i, status = ST_NOTFOUND;
101 
102 	for (i = 0; entries[i].name != (char *) 0; i++) {
103 		if (!strcmp(argv[0], entries[i].name)) {
104 			status = (*entries[i].func)(argc, argv);
105 			break;
106 		}
107 	}
108 
109 	return(status);
110 }
111 
112 
113 
114 /*
115  * getargs -- make argument arrays
116  */
117 
118 getargs(buffer, argv, maxargs)
119 	char buffer[], *argv[];
120 	int  maxargs;
121 {
122 	register int   n = 0;
123 	register char *p = buffer;
124 
125 	argv[n++] = p;
126 	while (*p != '\0') {
127 		if ( *p == ' ' ) {
128 			*p = '\0';
129 		} else if (p != buffer && *(p-1) == '\0') {
130 			if ( n < maxargs )
131 				argv[n++] = p;
132 		}
133 		p++;
134 	}
135 
136 	return(n);
137 }
138