# 2021q1 Week7 Test(2021-04-06) contributed by <`RainbowEye0486`> ## 測驗一 這邊關鍵的部份是要知道 `u` 、 `v` 是什麼,在 main 中把讀取進來的字串 \*c 移動到最尾端 ```cpp for (; *++c;) /* skip to end of line */ ; ``` 根據 [Tutorial - Write a Shell in C](https://brennan.io/2015/01/16/write-a-shell-in-c/) 實做的方法,我們需要有一個 buffer 去紀錄每一個 token ,而這個 token 不能是已經預先定義好的特殊字元,像是 " " 、 " | " 、 " > " 等等。因為字串是倒著讀回去的,所以先用 `v` 來當作"字串的 buffer ",之後再拿 `u` 當作"指令的 buffer "。 ```cpp static void run(char *c, int t) { char *redir_stdin = NULL, *redir_stdout = NULL; int pipefds[2] = {0, 0}, outfd = 0; char *v[99] = {0}; char **u = &v[98]; /* end of words */ for (;;) { c--; if (is_delim(*c)) /* if NULL (start of string) or pipe: break */ break; if (!is_special(*c)) { c++; /* Copy word of regular chars into previous u */ XXXXX /* 在此補上你的實作 */ } if (is_redir(*c)) { /* If < or > */ if (*c == '<') redir_stdin = *u; else redir_stdout = *u; if ((u - v) != 98) u++; } } if ((u - v) == 98) /* empty input */ return; ... ``` ==**Ans:**== ## 測驗二 ==**Ans:**== ## 測驗三 ==**Ans:**== ## 測驗四 ==**Ans:**== ###### tags: `linux2021`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up