# 2021-04-06 yuchun1214 ## 測驗 `1` ```c= 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 /* 在此提交你的程式碼 */ /****************************/ --u; if (is_blank(*c)) *c = '\0'; while (!is_special(*--c)) *u = c; /***************************/ } 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; ``` 輸出結果: ```shell= ➜ quiz7 gcc picosh.c ➜ quiz7 ./a.out $ mkdir dir $ ls a.out dir http picosh.c $ echo hello world > x $ cat < x | grep hello hello world $ ls /dev | wc -l 243 $ ``` :::warning 文字訊息不要用圖片展現! :notes: jserv ::: ## 測驗 `2` <!-- ```c= static void dequeue(queue_t *q, int *fd) { node_t *old_head; pthread_mutex_lock(q->head_lock); /* Wait until signaled that queue is non_empty. * Need while loop in case a new thread manages to steal the queue * element after the waiting thread is signaled, but before it can * re-acquire head_lock. */ // XXXXX /* 在此提交你的程式碼 */; pthread_cond_wait(q->non_empty, q->tail_lock); old_head = q->head; q->head = q->head->next; *fd = old_head->fd; free(old_head); pthread_mutex_unlock(q->head_lock); } ``` -->