Skip to content

Commit

Permalink
helping comments on shell
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoczim committed Nov 7, 2020
1 parent 3f8c60c commit 2a0a683
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/shell/tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/shell/topn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 2a0a683

Please sign in to comment.