contributed by < uccuser159
>
作業系統:Ubuntu 18.04.2 LTS
queue.h
有宣告兩個結構:value
會指向字串的一個指標
next
會指向下一個 linked-list
head
為 queue 中的第一個 linked-list
定義 NULL queue 和 empty queue :
NULL queue 表示沒有 queue
empty queue 表示的是一個空的 queue
在queue.c
中要執行下列這些 task:
q_insert_tail
和 q_size
的時間複雜度為 ,所以在queue.h
中加入指向 queue 尾端的 pointer 以及儲存 size 大小。make test
指令來跑評分系統,所以進入 Makefile 檔中的test
部分:可以得知進行自動評分,需要scripts/driver.py
來執行qtest
。
scripts/driver.py
看:在optlist, args = getopt.getopt(args, 'hp:t:v:A', ['valgrind'])
中:
getopt.getopt
回傳的是兩個陣列: optlist 和 args : optlist是分析出的格式,而 args 為不屬於格式訊息的剩下參數。'hp:t:v:A'
此處為短選項。沒有" : "的短選項就像一個開關,若有在 optlist 中有回傳此格式即觸發;而有" : "的短選項表示後面帶一個參數 arg。['valgrind']
此處為長選項。沒有" = "的長選項就像一個開關,若有在 optlist 中有回傳此格式即觸發;而有" = "的長選項表示後面帶一個參數 arg。在if
條件式中有各項功能。
在函式usage(name)
中有個短選項的各項功能,而['valgrind']
這個長選項是在決定useValgrind
功能要不要開啟:
最後在呼叫Tracer
這個 class,來做自動評分:
7.14.1 Synopsis
7.14.2 Description
The signal function chooses one of three ways in which receipt of the signal number sig is to be subsequently handled. If the value of func is SIG_DFL, default handling for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored. Otherwise, func shall point to a function to be called when that signal occurs. An invocation of such a function because of a signal, or (recursively) of any further functions called by that invocation (other than functions in the standard library), is called a signal handler.
在harness.h
中有exception_setup
. exception_cancel
. trigger_exception
三個函式:
所以bool exception_setup(bool limit_time)
是用來判別程序執行時是否超過指定時間( time_limit = 1)。
jmp_ready == true
→ 呼叫trigger_exception
儲存錯誤訊息( error_message )且將 error_occurred 設成 true → 由 siglongjmp
返回 exception_setup
進入 if 迴圈 重新計時且顯示錯誤訊息,最後回傳false。time_limited == true
→ 呼叫exception_cancel
重新計時且將jmp_ready
設回 false , error_message 也設為空白字元使其不顯示