CSE 490c - Homework 2

Due: Friday, April 16, 2:30 pm, by email.

This homework picks up where the last one left off, covering a few more advanced Unix commands and shell scripts.

Write your answers in a plain Unix text file and send it in the body of an email message to Charlie with a subject that begins with the string: 490c-hw2. For those answers that require you to write scripts, use some prominent marker in your text file (e.g., -----BEGIN----- and -----END-----) to indicate where the script begins and ends. You should also indicate whether you are using csh or bash. Finally, make sure you indicate clearly which answer goes to which question.

The same collaboration rules from homework 1 apply: You should write your answer to this homework alone, but feel free to consult with your friends about Unix in general.

Questions

  1. From your cse490c/hw1/jEdit directory, print out a list of all the files ending in .txt or .html (update: in that directory or any of its subdirectories). (Submit the command you used, not the output of the command.)

  2. How many items are in this list? What command did you use to find out?

  3. There are a collection of C source files in jEdit/jeditshell and its subdirectories. Some of these files define and use functions that end in the word "Command". Suppose we are interested in finding the definitions (not uses) of these functions, but only those that are declared to return an int value. For example, the following (fake) definition would match:

    int DisplayResultsCommand(int resultCode);
    

    What command could you use? What are the names of the functions that match this description, and in which files do the definitions appear? (Remember that C source code is stored in files that end in .c and .h.)

  4. Note: The following questions make changes to the jEdit source, so you may want to recursively copy your jEdit directory to a new hw2 directory. This step is optional, and you don't need to say how you did it.

    Now we'll do a little refactoring of the Java source. There's a class called DummyTokenHandler somewhere inside jEdit/org/gjt/sp/jedit, which we will rename to IgnoreTokensHandler. Find all the .java files that talk about this class (hint: there's only two) and use sed to substitute in the new name. You should actually change these two files (not just print the output), but be careful-- you can't directly overwrite the file you're reading when redirecting output, so you might have to use some temporary files which you can rename after creating. Don't forget to change the name of the source file for DummyTokenHandler so that it will compile, since public classes in Java must be saved in a file with the same name as the class. You do not need to use a script for this question, and you can work on each of the two files separately; just turn in the commands you used.

  5. To add more flexibility and power to the tasks we're performing, we can write shell scripts that take arguments at the command line. For example, suppose we want to augment some or all of the @author Javadoc tags in the source code with the email address of the author. To be general, though, we realize that we might want to add additional information to other types of tags, like @deprecated or @since tags. The common behavior will be searching for some string in a particular type of Javadoc tag, and appending a suffix to that string anywhere it appears. Our script should take in several arguments:

    tag-augmenter [dir] [tag] [matchstring] [suffix]
    

    For our example, suppose we want to append " (sp@email.net)" for every @author tag for Slava Pestov, looking for Java files in a src/ directory. We could run the script as:

    tag-augmenter src "author" "Slava Pestov" " (sp@email.net)"
    

    The effect should be similar to the lines below.

    // before:
     * @author Slava Pestov, mike dillon
    
    // after:
     * @author Slava Pestov (sp@email.net), mike dillon
    

    If the script is run with the wrong number of arguments, it should print a short message showing the proper usage. Your script should modify any matching Java files in dir or its subdirectories; if you need to create many temporary files, mktemp might be useful (though don't forget to delete them).