#include /* for standard I/O */ #include /* for stuff in stdlib */ #include /* read() and whatnot */ #include /* for sighandlers */ #include /* lame */ #include /* and lame */ #include "mysh.h" /* header for this file */ /****************************************************************************** * Name: Chris Mooney, chris@dod.net * * Course: COS350, T-Th 2:45 - 4:00 * * Project: #5 * * File Name: mysh.c * * * * Specification: * * Just a basic shell. * * * * You can find these files at: * * - [http://chris.dod.net/src/cos350/hw5/] * * * * GNU Public License Information: * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation; either version 2, or (at your option) any later * * version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * For a copy of the GPL, write to the Free Software Foundation, * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * * Chris Mooney ....................... UNIX Systems Engineer * * Project DoD ........................ http://home.dod.net/ * * P.O. Box 7012 ...................... Tel: (207) 450-2332 * * Portland, ME 04112 ................. chris@dod.net * * * * My PGP Public Key Block can be found at: * * http://chris.dod.net/pgp-public-key.asc * * * * Fingerprint: E5C2 E88A CED4 02CB 9D3C 8316 1001 E946 B592 F11C * *******************************************************************************/ #define DFL_PROMPT "mysh% " /* changed this to my fancy */ int proc_count = 0; /* number of processes */ int main() { char *cmdline, *prompt, **arglist; int result; int child_info = -1; /* for background processes */ void setup(); prompt = DFL_PROMPT ; setup(); while((cmdline = (char *)next_cmd(prompt, stdin)) != NULL) { if ( (arglist = (char **)splitline(cmdline)) != NULL ){ result = execute(arglist); freelist(arglist); } /* the following is a check to see if a background process exitsts, did it exit */ while((result = waitpid(-1, &child_info, WNOHANG)) > 0) { /* if there is a process and it completes or throws an error, then do the following */ if(proc_count != 0) { printf("[%d]\tDone\n", result); proc_count--; } } free(cmdline); } return 0; } void setup() /* * purpose: initialize shell * returns: nothing. calls fatal() if trouble */ { signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); } void fatal(char *s1, char *s2, int n) { fprintf(stderr,"Error: %s,%s\n", s1, s2); exit(n); }