/*-------------------------------------------------------------------------------------------------------------- * FUNCTION: ControllerRun * DESCR: Called after the Controller is initialized in ControllerBegin and after the command line has been * parsed. Reads the key from the specified key file name. Calls ControllerEncryptDecrypt to encrypt * or decrypt a message. Finally calls ViewPrintStr to print the encrypted or decrypted message. * RETURNS: Nothing. * PSEUDOCODE: * Define a char array named key which is of length MAX_MSG_LEN+1. * Define a char array named msgOut which is of length MAX_MSG_LEN+1. * Call ModelGetKeyFilename() to get the key file name that was parsed from the command line. * Call FileReadStr() and pass the key file name and the key array as parameters. This will read the key * from the file. * Call ModelSetKey() to store the key that was read from the file. * Call ModelGetMode() to get the mode from the Model (the mode was parsed from the command line). * Call ControllerEncryptDecrypt() and pass the mode and msgOut as parameters. * Call ViewPrintStr() and pass msgOut as the parameter. *------------------------------------------------------------------------------------------------------------*/ void ControllerRun() { char *key[MAX_MSG_LEN+1]; char *msgOut[MAX_MSG_LEN+1]; *key=ModelGetKeyFilename(); FileReadStr(*key,*msgOut); ModelSetKey(*msgOut); ControllerEncryptDecrypt(ModelGetMode(),*msgOut); ViewPrintStr(*msgOut); }
/*-------------------------------------------------------------------------------------------------------------- * FUNCTION: ControllerRun * DESCR: Called after the Controller is initialized in ControllerBegin and after the command line has been * parsed. Reads the key from the specified key file name. Calls ControllerEncryptDecrypt to encrypt * or decrypt a message. Finally calls ViewPrintStr to print the encrypted or decrypted message. * RETURNS: Nothing. * PSEUDOCODE: * Define a char array named key which is of length MAX_MSG_LEN+1. * Define a char array named msgOut which is of length MAX_MSG_LEN+1. * Call ModelGetKeyFilename() to get the key file name that was parsed from the command line. * Call FileReadStr() and pass the key file name and the key array as parameters. This will read the key * from the file. * Call ModelSetKey() to store the key that was read from the file. * Call ModelGetMode() to get the mode from the Model (the mode was parsed from the command line). * Call ControllerEncryptDecrypt() and pass the mode and msgOut as parameters. * Call ViewPrintStr() and pass msgOut as the parameter. *------------------------------------------------------------------------------------------------------------*/ void ControllerRun ( ) { char key[MAX_MSG_LEN+1]; char msgOut[MAX_MSG_LEN+1]; strcpy(key,ModelGetKeyFilename()); FileReadStr(key,key); ModelSetKey(key); ControllerEncryptDecrypt(ModelGetMode(), msgOut); ViewPrintStr(msgOut); }
int main(int argc, char **argv){ int i; FILE* f=NULL; int v=0; int needlen=0,haystackn=0,num=0; char* s; if (argc<3 || argc>4) { //fprintf(stderr,"USAGE: grep [-v] haystack needlefile\n"); return 1; } for (i=1; i<argc; i++){ /*if (strlen(s>1)&&sscanf(s,"%d",&num)==1){ nonum=0; for (i=1; i<strlen(s); i++) if (s[i]<'0' || s[i]>'9') nonum++; if (!nonum){ if (num<0) minusn=-num; else plusn=num; if (minusn && plusn) { fprintf(stderr,"+n and -n not acceptable\b"); exit(1); } } }*/ if (!strcmp(argv[i],"-v")) { v=1; num=i;} } if (argc==4 && v==0) { //fprintf(stderr,"USAGE: grep [-v] haystack needlefile\n"); return 1; } if (num==0) {needlen=2; haystackn=1;} if (num==1) {needlen=3; haystackn=2;} if (num==2) {needlen=3; haystackn=1;} if (num==3) {needlen=2; haystackn=1;} f=fopen(argv[needlen],"r"); if (f==NULL){ perror(argv[needlen]); exit(1); } while ((s=FileReadStr(f))!=NULL){ if (v) if (strstr(s,argv[haystackn])==NULL) printf("%s\n",s); if (!v) if (strstr(s,argv[haystackn])!=NULL) printf("%s\n",s); free(s); } fclose(f); return 0; }