Assignment 1, due Feb 8

Part of the homework for 22C:112, Spring 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: SED is a very crummy little editor that can be used to automate processing of text files. For example, the command:
            sed 's/xxx/yyy/' < a > b
    

    will take input from file a and copy it to b while changing the first occurance of xxx on each line to yyy.

            sed -e 's/xxx/yyy/' -e 's/x/X/g' < a > b
    

    The above converts the first xxx on each line to yyy and then capitalizes all remaining x characters on each line.

    a) Write a shell script that lists all files in the current directory, one per line, with a leading tab on each line and quotation marks around the filename. (0.5 points)

    b) Write a shell script that echoes all of its command line arguments, one per line, where each argument is in quotes and is preceeded by its argument number and an equals sign. (0.5 points)

  2. Background: Fat binary files are object files including support for multiple architectures.

    a) How did Apple handle fat binary files in the transition to the Power PC from the older Motorola 68000? (0.5 points)

    b) Consider the alternative of storing fat binaries as directories of thin binaries with one directory entry for each architecture, versus the alternative of creating a new file type for fat binaries. What would make you prefer one model over the other? (Note, each has its own appeal.) (0.5 points)

  3. Background: The Unix model for parameters to programs is very limited. When you launch a program, you pass it an array of strings (argv and argc). A second mechanism allows passing an array of open files (standard input is file zero, standard output is file one, standard error is file 2), and yet a third mechanism allows passing a set of envrionment variables, each of which has a textual name with a string for a value. The environment variables behave, in some ways, like global variables, except that a copy of the environment is passed to the launched program, so it may not alter them.

    In fact, the textual parameters in the array of strings and in the environment may be file names, numbers, or just strings, but the Unix model leaves it entirely up to the launched program to check its parameters and the values of environment variables.

    a) It would be nice if the shell, on launching a program, could check the types of some or all of the program's parameters. Briefly suggest a change to the object file content to allow type checking of program parameters. Please, don't go into details about the data formats, just give a high-level description of the information to be stored. (0.3 points)

    b) In strongly typed languages such as Pascal and Java, user-defined types are allowed. What barriers are there to extending your solution in part a) to user defined types? (0.4 points)

    c) Discuss how the notion of a resource-fork, as in the Apple Macintosh file system, might be used to uniformly enforce parameter type rules for both executable object files and shell scripts. (0.3 points)