From 2a0a683d0decd5433ed98b1a0428d356e2bab4c2 Mon Sep 17 00:00:00 2001 From: brunoczim Date: Sat, 7 Nov 2020 09:55:57 -0300 Subject: [PATCH] helping comments on shell --- src/shell/tags.c | 6 ++++++ src/shell/topn.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shell/tags.c b/src/shell/tags.c index af1c074..84aaf49 100644 --- a/src/shell/tags.c +++ b/src/shell/tags.c @@ -6,8 +6,13 @@ bool shell_run_tags(struct shell *restrict shell, struct error *restrict error) struct tags_query_input query_input; struct tags_query_buf query_buf; + /* Initializes tags query's input tags with initial capacity for 2. */ tags_query_input_init(&query_input, 2, error); + /* + * Reads all arguments from the command line, and adds tags corresponding + * to each argument to the query input. + */ while (error->code == error_none) { shell_read_quoted_arg(shell, error); if (error->code == error_none) { @@ -25,6 +30,7 @@ bool shell_run_tags(struct shell *restrict shell, struct error *restrict error) error_set_code(error, error_none); } + /* Checks the error code and executes the query if everything is ok. */ switch (error->code) { case error_none: tags_query_init(&query_buf); diff --git a/src/shell/topn.c b/src/shell/topn.c index fadfd9b..82c9fc4 100644 --- a/src/shell/topn.c +++ b/src/shell/topn.c @@ -13,26 +13,31 @@ bool shell_run_topn(struct shell *restrict shell, struct error *restrict error) start = shell->buf->ptr + (sizeof("top") - 1); + /* Converts the "N" string into the maximum unsigned integer. */ converted = strtoumax(start, &end, 10); + /* If the end pointer is not at the end, an error happened. */ if (*end != 0) { error_set_code(error, error_topn_count); error->data.topn_count.string = start; error->data.topn_count.free_string = false; } + /* + * Reads the quoted argument, expects the end of the line, and turns it into + * string. + */ if (error->code == error_none) { shell_read_quoted_arg(shell, error); } - if (error->code == error_none) { shell_read_end(shell, error); } - if (error->code == error_none) { strbuf_make_cstr(shell->buf, error); } + /* Initializes the query buffer with fixed capacity as N. */ if (error->code == error_none) { if (converted > shell->database->movies.length) { count = shell->database->movies.length; @@ -43,6 +48,7 @@ bool shell_run_topn(struct shell *restrict shell, struct error *restrict error) topn_query_init(&query_buf, count, error); } + /* Checks the error code and if OK executes the query. */ switch (error->code) { case error_none: topn_query(shell->database,