// Restrict.cmm Allow user to only enter commands from the list provided here. Count = 0; Valid[Count++] = "dir" Valid[Count++] = "chkdsk" Valid[Count++] = "type" Valid[Count++] = "cd" Valid[Count++] = "set" Valid[Count++] = "IsItFri" Valid[Count++] = "DiskFree" main() { while ( True ) { // True is always true, and so this will loop forever ShowAvailableCommands() Command = GetCommand() // check if this command is in our list for ( i = 0; i < Count; i++ ) { if ( !strcmpi(Command.Root,Valid[i]) ) break } if ( i < Count ) { system(Command.Full) } else { // The command was not found printf("\"%s\" is not an available command!\a\n",Command.Root) } } } ShowAvailableCommands() { printf("\nYour available commands are:\n") for ( i = 0; i < Count; i++ ) printf("%s\t",Valid[i]) } GetCommand() // Get command from user, return a structure with two elements // .Root root name of the command entered // .Full complete line of input as entered { printf("\nWhaddya want? ") input.Full = gets() // now figure out what the root was, first copy all of input, then remove space from // beginning, then go to first space character strcpy(input.Root,input.Full) // then remove andy whitespace from beginning of command while( input.Root[0] != 0 && isspace(input.Root[0] ) ) input.Root++ // end this string at the first whitespace character for ( c = input.Root; c[0] != 0 && !isspace(c[0]); c++ ) ; c[0] = 0 return(input) }