Assignment 8, due July 12

Machine Prolbem 4, due July 16

Part of the homework for 22C:50, Summer 2004
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Machine Problem 4, due July 16

An example command language interpreter

For your starting point, use the extremely minimal shell provided:

This little shell supports only the most rudimentary form of command, with only one advanced feature, a search path. It works perfectly, and it even contains, in its header comments, pretty good documentation of what it does. The only thing is, it's written for minimality, not as a clean foundation for developing a bigger shell. Most of the program is in main(), and that's classic evidence of poor programming even in a file this size! It hasn't got a clean parser at all!

Modifications to the example

Break the example apart, so that the routine to process one command line is a separate routine from main(), which should be modified to repeatedly call that routine, once per command line.

Break the application-launch code out from the command-line parsing routine, so that the command-line parser calls the application launcher and passes it the new argument vector.

Break the applicaton launcher into a routine that recognizes built-in commands (there is only one, initially), a second that launches applicatons for commands that aren't built-in, and one routine per built-in that actually performs that built-in.

Once you've re-organized this command line interpreter, as suggested, you will understand the code very much more than initially, and you will be in a position to cleanly add some new features.

Modifications to the interpreter

Modify exit so it accepts a numeric parameter (argv[1]) and passes the value of this exit(i). By convention, the value 0 means success. Values larger than 255 should be reported with an error message and the value 255 should then be passed to exit().

Implement the built-in commands then, else, and endif. After execution of any command, the exit status of the command is saved (see man 2 wait for how to get this information). If the previous command was successful, the then command is a no-op, but if the previous command reported failure, the then command causes all input lines up to and including the next else command to be skipped. Normal execution of the else command causes all input lines up to and including the next endif to be skipped. Normal execution of the endif command is a no-op.

As a final feature, figure out how to skip conditionals embedded in conditionals. Also note, the test applicaton (man 1 test) is a useful command to use to control else-endif constructs.

Turn in

Assignment 8, due July 12

  1. Given a disk with 5 sectors per track, where the physical sector numbers are 0-1-2-3-4, if 2-way interleaving is used, the corresponding logical sector numbers are 0-3-1-4-2. For this problem, assume a disk with 16 sectors per track.

    a) What is the order of logical sectors with 5-way interleaving?

    b) How many distinct interleaving factors are there for this disk? That is, interleaving factors that lead to distinct sector orders.

  2. Do problem 5 from chapter 11 in the notes.

  3. Do problem 11 from chapter 11 in the notes.

    Do problem 14 from chapter 11 in the notes.