Wild Thing

Command interfaces to modern operating systems often include a number of metacharacters which provide powerful features that allow a user to accomplish a lot of work without resorting to traditional programming. One of the most common metacharacters is a wildcard character. Wildcard characters are used within filenames to permit the user to generically specify a group of files that a command should act upon. A wildcard character itself matches zero or more characters in the same position as the wildcard. Suppose a user wanted to print all files ending in .c, delete all files beginning with old_ , and copy all files (no matther what they are named) to a floppy disk. With wildcard metacharacters, all of this can be done using only three commands instead of using a separate command for each file involved. The metacharacter sequences for these commands would be as follows: .c old_ * Write a program that will accept an input pattern which may contain wildcard characters and decide whether or not each of the filenames that follow it matches the pattern. Input The input file will contain a series of datasets. Each dataset will consist of a pattern line followed by a list of filenames to compare against the pattern. For the purposes of this program, a filename may consist of any group of one to twenty characters, not including asterisks. None of these characters should receive special treatment (periods, for example, should behave as any other characters matched). The pattern line may include zero or more wildcard characters. A wildcard character will be represented by an asterisk (). The list of filenames will appear one per line following the pattern line. There will be an unknown number of filenames in the list. All lines of input will be one to twenty characters in length, including the pattern line. The input file will contain an unknown number of datasets, each separated by a blank line. Output The output for this program will be a short report showing the pattern and the filenames from the subsequent list that match the pattern. Filenames that do not match the pattern should not be printed out. The results from each input dataset should be separated by one blank line. See the example for the exact format. Notice that ‘MATCHES FOR PATTERN: HELLO’ was not displayed, because there were no matches in its filename list. Sample Input CAT COMFILE.DAT COST.DATA CAT %XCAT COAT

2/2 CATCH A MOUNTAIN.TXT ALFRED PROG1A SECOND.ED PROG1A.PAS HELLO NOTHING BN* NIBBLE.BIT BANANA BNXJ.25 BORN ABNORMAL.LIS BRANDISH.SRD BITNET Sample Output MATCHES FOR THE PATTERN: C*AT COMFILE.DAT CAT COAT MATCHES FOR THE PATTERN: A MOUNTAIN.TXT ALFRED PROG1A PROG1A.PAS MATCHES FOR THE PATTERN: BN* BANANA BNXJ.25 BORN BRANDISH.SRD BITNET