SCRIBE: Jessica Codr Thoughts/Notes/Sketch for Project A and Homework 4 CSE 422 Wednesday September 27, 2006 Updated: Monday October 9, 2006 Refer to A.txt ---Special functionality to come--- c1; c2; c3; c1& c2& c3& c1, c2, c3, c < F1 > F2 (Don't worry about this stuff just yet) ---Basic code we have to work with--- while(there is a cmd){ word[] = parse xword[] = substitute if (-x flag) display xword[] ....code.... (see below) } ---Flags--- -x -> mostly there, need to do substitution xword is all variables with their values substituted in -d DebugLevel Filename -> redirect stdin program is finished after evaluating script, no interactive mode if Filename given ---....code....--- if built in then eval built in (2) else eval non-built in (1) (1) eval non-built in -> already done! (2) eval built in -> "Case" [strcmp] function for each cmd (3) (3) functions for each cmd: echo W1 W2 ... -> W1, W2, etc are meta symbols -> Have code! quit w -> w is a number -> easy??? [exit] -> what about: <> background processes? <> clean up? <> $? undef? quit -> same as quit w, except must record status Assume a nice user who only gives correct input (for now) More notes on Project A: --------------------- NOTE on waitpid(pid, &status, options): status is not the exit status, but the exit status is contained within 'status' and can be obtained by calling: WEXITSTATUS(status) --------------------- Redirection: (A big part of Project A) ---The File Descriptor Table:--- A File Descriptor Table stores a mapping of numbers to io components. The initial table gives the following mapping: 0 -> stdin 1 -> stdout 2 -> stderr As files are created and opened, they are added to the table. For example, if we create/open a file called 'myFile' the above table will have this mapping added to it: 3 -> myFile ---Methods to deal with io:--- We will be using unbuffered io in our project, so we will be using commands such as read, write, open, and close. Include the following flags when calling the following methods: method flags read O_RDONLY write O_CREAT | O_WRONLY ---The actual redirection:--- To redirect io, call this method: dup2(from, to); In this method call: -'from' is the number in the file descriptor table of the io component from which we want to take io (for reading) or into which we want to place the io (for writing) in place of using 'to'. -'to' is the number in the file descriptor table of the io component we want to override/replace with 'from'. -This method call will cause 'from' to be used in place of 'to' whenever 'to' is referenced. Example: With the file descriptor table given above, -dup2(3,1) would redirect from the file myFile to stdout, meaning what would be printed to stdout will now be printed to myFile. -dup2(3,0) would redirect myFile to stdin, meaning that a request for a read from stdin will read from myFile instead. See the man pages for more information.