Machine Problem III, due Feb. 26
Part of
the homework for CS:3620, Spring 2018
|
Begin with the solution to MP2 that was distributed to the class.
a) Break it up into multiple source files. You will probably want to use a Makefile to compile it, but this will not be turned in, so you are free to compile it by hand if you want.
The defined constants LINE_LENGTH and MAX_ARGS, plus the arrays command and argv should be declared in a file called globals.h. The function launch must be in a file called launch.c. It would be sensible to put other functions in other source files, but this is not required. It would be sensible to build your project in its own project directory, but this is not required.
Each source file should have include directives for the files it relies on, and none others. For example, don't write #include <stdio.h> in a file that does not rely on any of the definitions in the standard I/O library.
Each source file should have header comments that indicate what it is, its provenance, etc.
b) Make sure that the launch() routine passes the environment to the called program. (See Homework 3, problem 1)
c) Before launch() uses argv, it should scan all the arguments in argv and, if the first character of the argument is '$' it should use getenv() to get the value associated with the environment variable named by the remainder of that argument. If the value returned by getenv() was non-null, the value of the environment variable should replace the argument. Otherwise, the argument should remain unchanged. So, if the argument is $USER, it is replaced with your HawkID, but if the argument is $gribble, it stays unchanged (unless someone defines $gribble in the environment).
d) Make the launch() routine use the search path from the environment. You'll have to use getenv() function to extract PATH from the environment. See the notes for Jan. 26 for hints about how to do this. Only if none of the path options lead to the command should there be an error message.
All of your code must conform, as much as is possible, to the manual of style:
-- http://homepage.cs.uiowa.edu/~dwjones/syssoft/style.html
Your solution must be in a file named launch.c (all lower case). Submit your solution using the coursework submission tools documented at:
-- https://clas.uiowa.edu/linux/help/start/submit
In short, you will type the shell command submit, with no arguments, and when it prompts for a file name, you will type launch.c. and then an extra carriage return to indicate that there is only one file in your submission. When it prompts for a course, type CS3620 and when it prompts for an assignment directory, enter mp3.
Note, file names on Unix/Linux systems are case sensitive! That includes the course name. If you type cs3620, it will not work.