#include #include #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #else #include #endif #include "prefs.h" #include "errors.h" #include "version.h" #include "she.h" #ifdef HAS_GLOB # define OPTIONS "hfVdv:" #else # define OPTIONS "hVdv:" #endif static void usage(char *name); static void usage(char *name) { DoError(NO_ERR,INFO_ERR, "Usage: %s [-Vvfh]",name); DoError(NO_ERR,INFO_ERR, "-V: print version"); DoError(NO_ERR,INFO_ERR, "-v: verbose level"); #ifdef HAS_GLOB DoError(NO_ERR,INFO_ERR, "-f: disable glob"); #endif DoError(NO_ERR,INFO_ERR, "-d: ignore eof"); DoError(NO_ERR,INFO_ERR, "-h: this text"); printf("\nPara salir: %s\n", QUIT); printf("Para backgroundear, poner %s al final\n", M_BACK); printf("Para redireccionar, %s %s %s\n", M_RDIRIN, M_RDIROUT, M_RDIRAPP); printf("Para tuberias, usar %s\n", M_PIPELINE); exit(1); } boolean GetPrefs(PrefsType *PrefsPtr, int argc, char *argv[] ) { int opcion,i; extern char *optarg; extern int optind,opterr; PrefsPtr->verbose=2; PrefsPtr->glob=true; PrefsPtr->ignoreeof=false; while ( (opcion=getopt(argc,argv,OPTIONS)) != EOF ) { switch(opcion) { case 'V': DoError(NO_ERR,INFO_ERR,VERS_STR); exit(0); break; case 'h': usage(argv[0]); exit(0); break; case 'd': PrefsPtr->ignoreeof=true; break; #ifdef HAS_GLOB case 'f': PrefsPtr->glob=false; break; #endif case 'v': i = atoi(optarg); if(( i < 0 )||(i>ASK_ERR)) DoError(INPUT_ERR,WARN_ERR,"Verbose: %d-%d,ignored ", 0,ASK_ERR); else PrefsPtr->verbose = i; break; default: usage(argv[0]); break; } } return( true ); }