/* * Looks better at 4 spaces/tab * */ #include #include #include #include #include #include #include #ifdef HAS_GLOB #include #endif #include "errors.h" #include "prefs.h" #include "she.h" #include "rdir.h" #include "shield.h" #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif /* globales */ char* g_ProgName; PrefsType Prefs; int parate; aProcesar lista; int shields[32] = { SIGINT, SIGQUIT, SIGALRM, SIGTERM, -1}; extern int optind; extern void obito(int quien, int restos_mortales); int main(int argc, char **argv); void launch(int nproc); int glob_err(const char *path, int err); int main(int argc, char **argv) { char s[ BUFSIZE ]; char Prompt[ BUFSIZE ]; char *argt[MAXTERM]; /* user input */ char *arg; char *home; int i, j, k; static int fdstdin; int restos_mortales; #ifdef HAS_GLOB glob_t sglob; #endif g_ProgName=argv[0]; GetPrefs(&Prefs,argc,argv); home = getenv("HOME"); shield(); while(1) { *s = 0x00; fprintf( stderr, "%s:%s > ", g_ProgName, getcwd(Prompt, sizeof(Prompt))); gets( s ); if(feof(stdin)) { if(!Prefs.ignoreeof) { exit(0); } else { clearerr(stdin); puts(""); } } if ( *s == 0x00 ) continue; #ifdef HAS_GLOB if(!Prefs.glob) { #endif argt [0] = strtok( s, " \t" ); if ((argt[0] != NULL) && (NULL != strstr(QUIT, argt[0]) )) { write ( 2, LOGOUT, strlen(LOGOUT)) ; exit ( 0 ); } for (i = 1; (argt[i] = strtok(NULL, " \t")) != NULL; i++) ; #ifdef HAS_GLOB } else { globfree(&sglob); for ( i = 0, arg = strtok( s, " \t" ); arg != NULL; arg = strtok(NULL, " \t") ) { switch(glob(arg, i==0 ? GLOB_NOCHECK : GLOB_NOCHECK | GLOB_APPEND, glob_err, &sglob)) { case GLOB_NOSPACE: DoError(SYS_ERR, ABORT_ERR, "Glob: No space"); break; #ifdef GLOB_ABORTED case GLOB_ABORTED: DoError(PROG_ERR, ABORT_ERR, "Glob: Aborted"); break; #endif case GLOB_NOMATCH: DoError(PROG_ERR, ABORT_ERR, "Glob: No Match"); break; default: i++; break; } } for(j=0; j