~fkfd/fcc

a42aeb259bc610b5d1547b2286319f3657e2d805 — Frederick Yin 11 months ago bed8b5a
provide -t, remove -a
3 files changed, 14 insertions(+), 13 deletions(-)

M main.c
M quiz.c
M quiz.h
M main.c => main.c +8 -8
@@ 7,33 7,33 @@

static const char arg_help[] =
    "  -h        display this help message and quit\n"
    "  -t        simulate test (ignore -r/-w)\n"
    "  -r        random mode\n"
    "  -a        show answers\n"
    "  -w        give extra weight to hard questions\n"
    "  -w        give extra weight to hard questions (-r only)\n"
    "  -p POOL   set question pool JSON file\n"
    "  -l LOG    set study log JSON file\n";

int main(int argc, char *argv[]) {
	bool random_mode = false;
	bool show_answer = false;
	bool simulate_test = false;
	bool weight_enable = false;
	char *pool_fp = "technician.json";
	char *log_fp = "technician.log.json";
	// handle CLI arguments
	int opt = 0;
	while (opt != -1) {
		opt = getopt(argc, argv, "hrawp:l:");
		opt = getopt(argc, argv, "htrwp:l:");
		switch (opt) {
		case 'h':
			printf("USAGE: %s [-h] [-a] [-w] [-p POOL] [-l LOG]\n", argv[0]);
			printf(arg_help);
			return 0;
		case 't':
			simulate_test = true;
			break;
		case 'r':
			random_mode = true;
			break;
		case 'a':
			show_answer = true;
			break;
		case 'w':
			weight_enable = true;
			break;


@@ 45,6 45,6 @@ int main(int argc, char *argv[]) {
			break;
		}
	}
	quiz(pool_fp, log_fp, random_mode, show_answer, weight_enable);
	quiz(pool_fp, log_fp, simulate_test, random_mode, weight_enable);
	return 0;
}

M quiz.c => quiz.c +4 -3
@@ 5,8 5,8 @@
#include <json-c/json_util.h>
#include <stdio.h>

void quiz(const char *pool_fp, const char *log_fp, const bool random_mode,
          const bool show_answer, const bool weight_enable) {
void quiz(const char *pool_fp, const char *log_fp, const bool simulate_test,
          const bool random_mode, const bool weight_enable) {
	json_object *pool = json_object_from_file(pool_fp);
	if (pool == NULL) {
		fprintf(stderr, "Cannot open/parse question pool file: %s\n", pool_fp);


@@ 51,7 51,8 @@ void quiz(const char *pool_fp, const char *log_fp, const bool random_mode,
	json_object_put(log);
}

void quiz_sequential();
void quiz_sequential(const json_object *pool, const json_object *log) {
}

int ask_question(const question_t question) {
	print_question(question);

M quiz.h => quiz.h +2 -2
@@ 19,8 19,8 @@ enum {
#define BLUE   "\033[34m"
#define RESET  "\033[0m"

void quiz(const char *pool_fp, const char *log_fp, const bool random_mode,
          const bool show_answer, const bool weight_enable);
void quiz(const char *pool_fp, const char *log_fp, const bool simulate_test,
          const bool random_mode, const bool weight_enable);
int ask_question(const question_t question);
void print_question(const question_t question);
#endif