Pete's Log: shell-o-rama. woohoo
Entry #591, (Coding, Hacking, & CS stuff)(posted when I was 22 years old.)
Wow. I got real lucky with OS-p2. I was reading over some of the code for my shell during comp arch today, and noticed a fair number of mistakes. Luckily they're all pretty obscure, and thus none of them were discovered by the test cases used when p2 was graded. Woohoo! Code review is a good thing. I've pretty much concluded I'm gonna completely ditch all my p2 code and rewrite my shell from scratch for p5. I'm also gonna ditch the parser Dr Freeh gave us and write my own. I've decided I can rewrite the parser such that it 1: actually works correctly, 2: has a better interface, 3: is more efficient, and 4: is coded better stylewise and such.
W. Richard Stevens rules. Chapter 9 of Advanced Programming in the UNIX environment is gonna be pretty much the only reference I'll need to add job control to my shell. Amazing. God bless that man.
Another advantage to rewriting the parser would be the ability to do something cool on SIGINT. Currently by just ignoring SIGINT I end up with annoying '^C' characters on the command line when I hit control-c. But I wanna be cool. I wanna do what tcsh does! ctrl-c should set status to 1, kill the current input line, and drop me to a new prompt. Easy enough. But what I really want to figure out is how do I get it to not print out the '^C'? Now one easy thing to do is simply to have the SIGINT signal handler do a putchar(8); but this don't work so well on things like Linux which doesn't echo a '^C' when you type control-c. Hrmmm... I think I've messed with that enough for now, we'll renice that to a lower priority until I've gotten other stuff working.
Hrmmm... playing with tcsh... another 'interesting' shell feature I've discovered. If you do something such as 'foo > a b c' then the output of foo will be redirected to a, but b and c will be argv[1] and argv[2] respectively. Definitely something that'll make parsing more entertaining. I never knew you were allowed to give more arguments after a redirect. hrmmm... and apparently in tcsh it is also legal to do something like '< foo bar' which is the same as 'bar < foo'. Which is yet another thing that Freeh's parser doesn't handle properly. But thinking about it, this actually makes parsing easier, since there's gonna be less state to keep track of.