11Additional notes on the lab assignment based on existing implementations.
22
33--------------------------------------------------------------------------------
4- Split the program into (potentially many ) .c files. For example one for command
5- line parsing, another for utility functions, one for execution/pipe handling,
6- etc. etc.
4+ You may want to split the program into (potentially several ) .c files. For
5+ example one for command line parsing, another for utility functions, one for
6+ execution/pipe handling, etc.
77
88The program becomes better structured with a room for expansion/growth.
99
1010--------------------------------------------------------------------------------
1111Do not blindly accept potentially unlimited user input. It probably does not
12- make sense for command line to be millions of characters long.
12+ make sense for a command line to be millions of characters long.
1313
1414--------------------------------------------------------------------------------
1515Check return values of any call that can fail.
1616
1717Yes, malloc() can fail too.
1818
19- Reacting on failures needs to be sensitive, though. Exiting the shell
20- when malloc() fails is safe thing to do. On the other hand, failing to read a
21- file in interactive mode should not tear down the shell.
19+ Reacting on failures needs to be sensitive, though. Exiting the shell
20+ when malloc() fails is a safe thing to do. On the other hand, failing to read a
21+ file in an interactive mode should not tear down the shell.
2222
2323--------------------------------------------------------------------------------
2424The shell should not assume it is being run from another shell.
@@ -41,14 +41,15 @@ if (pipe(pd) == -1) {
4141Speaking of style, try to refactor as much as possible (while using function
4242names easily readable by humans - and stick to consistent casing style).
4343
44- When is function too long ? (so that it can be called "spaghetti code")
45- If it spans multiple screens of wide screen terminal (let's say 80 lines
46- printed in the font usually used in your environment for source code) it is
47- probably time to do some refactoring.
44+ When is function too long? (so that it can be called "spaghetti code") If it
45+ spans multiple screens of a wide screen terminal (let's say 80 lines printed in
46+ the font usually used in your environment for source code) it is probably time
47+ to do some refactoring.
4848
4949--------------------------------------------------------------------------------
50- Refuse special characters that you do not implement yet. For example, if you do
51- not implement pipes (as in the 1st phase), refuse it. It cannot work like this:
50+ Refuse special characters that you do not implement yet, or treat them as normal
51+ characters. For example, if you do not implement pipes (as in the 1st phase),
52+ refuse it. It cannot work like this:
5253
5354$ date | cat | sort | wc -l
5455Mon Dec 31 13:06:56 CET 2018
@@ -61,27 +62,29 @@ If you did accept '|' as a normal character, it should have worked like this:
6162$ echo hello | wc -l
6263hello | wc -l
6364
64- And in case of date(1), it should have printed out an error, similar to this:
65+ And in case of date(1) above, it should have printed out an error, similar to
66+ this:
6567
66- $ date xxx
68+ $ date |
6769date: illegal time format
6870usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
6971 [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
7072
71- So, do something like the following:
73+ So, you can do something like the following:
7274
7375$ echo hello | wc -l
7476(default rule matched) error:1: syntax error near unexpected token '|'
7577
7678Also, refuse redirections unless you already implemented those. The following
77- is not correct in the 1st phase:
79+ is not correct in the 1st phase (again, you can treat it as a normal character,
80+ too, until implemented):
7881
7982$ echo hello > out
8083hello
8184
8285--------------------------------------------------------------------------------
83- Please do implement command line history. In case of readline, it's really just
84- calling one function, like this, for example:
86+ Please do implement a command line history. In case of readline, it is really
87+ just calling one function, like this, for example:
8588
8689if ((input = readline(prompt) ...
8790 ...
0 commit comments