[BACK]Return to kmon.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / test / kmon

Annotation of prex-old/usr/test/kmon/kmon.c, Revision 1.1.1.1

1.1       nbrk        1: /*
                      2:  * Copyright (c) 2005, Kohsuke Ohtani
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. Neither the name of the author nor the names of any co-contributors
                     14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  */
                     29:
                     30: /*
                     31:  * kmon.c - main routine for kernel monitor
                     32:  */
                     33:
                     34: #include <prex/prex.h>
                     35: #include <prex/keycode.h>
                     36: #include <ctype.h>
                     37: #include <stdio.h>
                     38: #include <limits.h>
                     39:
                     40: extern int dispatch_cmd(int argc, char **arg_list);
                     41:
                     42: static char *arg_list[LINE_MAX];
                     43:
                     44: /*
                     45:  * Read a line.
                     46:  */
                     47: void
                     48: read_line(char *line)
                     49: {
                     50:        int c, len = 0;
                     51:        char *p = line;
                     52:
                     53:        for (;;) {
                     54:                c = getchar();
                     55:                if (c == '\n' || len > LINE_MAX) {
                     56:                        *p = '\0';
                     57:                        return;
                     58:                }
                     59:                *p = (char)c;
                     60:                p++;
                     61:                len++;
                     62:        }
                     63: }
                     64:
                     65: /*
                     66:  * Parse an entire given line.
                     67:  */
                     68: int
                     69: parse_line(char *line)
                     70: {
                     71:        char *p = line;
                     72:        int argc = 0;
                     73:
                     74:        for (;;) {
                     75:                /* Skip space */
                     76:                while (*p && *p == ' ')
                     77:                        p++;
                     78:                if (*p == 0)
                     79:                        break;
                     80:                arg_list[argc++] = p;
                     81:
                     82:                /* Skip word */
                     83:                while (*p && *p != ' ')
                     84:                        p++;
                     85:                if (*p == 0)
                     86:                        break;
                     87:                *p++ = 0;
                     88:        }
                     89:        arg_list[argc] = NULL;
                     90:        return argc;
                     91: }
                     92:
                     93: int
                     94: main(int argc, char *argv[])
                     95: {
                     96:        char line[LINE_MAX];
                     97:        int c;
                     98:
                     99:        printf("Prex kernel monitor - type 'help' to list commands\n");
                    100:
                    101:        for (;;) {
                    102:                printf("[kmon]$ ");
                    103:                read_line(line);
                    104:                c = parse_line(line);
                    105:                if (c) {
                    106:                        if (dispatch_cmd(c, arg_list))
                    107:                                break;
                    108:                }
                    109:        }
                    110:        return 0;
                    111: }

CVSweb