Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/sysprogs/shell.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "syscall.h"
0019 
0020 void
0021 putx (unsigned long l)
0022 {
0023 
0024   int i, li;
0025 
0026   for (i = 7; i >= 0; i--)
0027     if ((li = (l >> (i << 2)) & 0x0F) > 9)
0028       putchar ('A' + li - 0x0A);
0029     else
0030       putchar ('0' + li);
0031 }
0032 
0033 static int
0034 scanline (char *line)
0035 {
0036 
0037   char c;
0038   int count = 0;
0039 
0040   while ((c = getchar ()) != '\n' && count < 80) {
0041     *line++ = c;
0042     count++;
0043     putchar (c);
0044   }
0045 
0046   *line = '\0';
0047 
0048   putchar ('\n');
0049 
0050   return 1;
0051 }
0052 
0053 
0054 void
0055 _start ()
0056 {
0057 
0058   char line[80];
0059   char *command_line_args = line;
0060   char *p;
0061   unsigned child_pid;
0062 
0063   while (1) {
0064 
0065     /* The shell prompt */
0066 
0067     putchar ('>');
0068 
0069     /* Wait for command line input */
0070     /* --??-- Assume user has entered command via keyboard */
0071 
0072     if (scanline (line)) {      /* Got input */
0073       /* --??-- Parse input and verify it is meaningful */
0074 
0075       if (*line == '\0')
0076         continue;
0077 
0078       /* Fork new process */
0079       if ((child_pid = fork ())) {      /* Parent */
0080 
0081 #if DEBUG
0082         for (p = "parent!\n"; *p; p++)
0083           putchar (*p);
0084 #endif
0085         /* switch_to( child_pid ); */
0086         waitpid (child_pid);
0087       } else {                  /* Child */
0088 
0089 #if DEBUG
0090         for (p = "child!\n"; *p; p++)
0091           putchar (*p);
0092 #endif
0093         exec (line, &command_line_args);
0094 
0095         /* Got here due to exec failing on an ext2fs_dir call  */
0096         for (p = "Error: file not found\n"; *p; p++)
0097           putchar (*p);
0098 
0099         _exit (1);
0100       }
0101     }
0102   }
0103 }
0104 
0105 /* 
0106  * Local Variables:
0107  * indent-tabs-mode: nil
0108  * mode: C
0109  * c-file-style: "gnu"
0110  * c-basic-offset: 2
0111  * End: 
0112  */
0113 
0114 /* vi: set et sw=2 sts=2: */