summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-07-28 20:01:03 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-07-28 20:42:46 -0300
commitd98868fa4d03659aad9ad2d858ee51e414d54ce4 (patch)
tree7e1ce8604cb6dad2949065dfe50bf4cfe80dd2e3
parent052e06fd16f5ef161a10fc7880e32827c814bea2 (diff)
everywhere: Fix compiler errors, compiler warnings, and correct typos
-rw-r--r--git.c56
-rw-r--r--git.h36
-rw-r--r--index.c36
-rw-r--r--keyword.c7
4 files changed, 79 insertions, 56 deletions
diff --git a/git.c b/git.c
index e13b787..579df11 100644
--- a/git.c
+++ b/git.c
@@ -80,7 +80,7 @@ static linked_list *parse_dsv_str(const char *str, const char *delm) {
/* Create the token. */
char *tok = calloc(tok_len+1, sizeof(char));
/* Get the token from the string. */
- memcpy(tok, tmp, tok_len);
+ memcpy(tok, str, tok_len);
/* Add the token to the list.. */
tail = add_node(&tail, tok);
/* Move over the token. */
@@ -89,7 +89,7 @@ static linked_list *parse_dsv_str(const char *str, const char *delm) {
return tail;
}
-static int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val) {
+int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val) {
/* Do we actually have a "patches" keyword? */
if (key->type == TYPE_STRING) {
const char *root = (const char *)ctx;
@@ -119,18 +119,18 @@ static int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_va
return -1;
}
-static int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val) {
+int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val) {
linked_list *comment_list = *(linked_list **)ctx;
- comment *comment = (comment *)ret;
+ comment *comm = (comment *)ret;
/* Do we already have a reply? */
- if (comment->reply != NULL) {
+ if (comm->reply != NULL) {
/* Check if this reply matches any other comment in the list. */
for (linked_list *node = get_tail(comment_list); node != NULL; node = node->prev) {
comment *reply = (comment *)node->data;
/* Do we have a match? */
- if (comment->reply == reply) {
+ if (comm->reply == reply) {
return 1;
}
}
@@ -146,13 +146,13 @@ static int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword
/* Do we have a match? */
if (reply->id == val.i) {
/* Does this comment already have a reply? */
- if (comment->reply != NULL) {
+ if (comm->reply != NULL) {
/* Free the reply. */
- free(comment->reply);
+ free(comm->reply);
}
/* Set our reply comment to the matched comment. */
- comment->reply = reply;
+ comm->reply = reply;
found_reply = 1;
break;
}
@@ -165,28 +165,29 @@ static int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword
}
/* Do we not have a reply? */
- if (comment->reply == NULL) {
+ if (comm->reply == NULL) {
/* Create one. */
- comment->reply = calloc(1, sizeof(comment));
+ comm->reply = calloc(1, sizeof(comment));
}
/* Which keyword do we have? */
switch (key->type) {
/* reply-to */
- case TYPE_INT : comment->reply->id = val.i; break;
+ case TYPE_INT : comm->reply->id = val.i; break;
/* reply-author */
- case TYPE_STRING: comment->reply->author = val.str; break;
+ case TYPE_STRING: comm->reply->author = val.str; break;
/* reply-date */
- case TYPE_TIME : comment->reply->date = val.t; break;
- default : break;
+ case TYPE_TIME : comm->reply->date = val.t; break;
+ default : return -1; break;
}
+ return 1;
}
typedef int (parse_callback)(void **ret, void *ctx, char *buf);
static int parse_colon_key_value_file(void *ret, void *ctx, const keyword **keywords, char *buf, parse_callback *parse_cb) {
if (buf != NULL) {
- int ret = 0;
+ int ret_val = 0;
for (;;) {
char *lhs, *rhs;
/* Find the keyword before the colon. */
@@ -198,11 +199,12 @@ static int parse_colon_key_value_file(void *ret, void *ctx, const keyword **keyw
if (lhs == NULL) {
break;
} else {
+ int error;
char *tmp = skip_whitespace(buf);
/* Does the right hand side start with a double, or single quote? */
if (*tmp == '\"' || *tmp == '\'') {
- const char *delm = (delm == '\"') ? "\"" : "\'";
+ const char *delm = (*delm == '\"') ? "\"" : "\'";
/* Get the string in between the start, and end qoute. */
rhs = get_str_delm_range(tmp, delm, delm, &buf);
} else {
@@ -211,9 +213,9 @@ static int parse_colon_key_value_file(void *ret, void *ctx, const keyword **keyw
}
/* Did we fail to parse the keyword? */
- if (int error = parse_keywords(keywords, lhs, rhs, ret, ctx)) {
+ if (error = parse_keywords(keywords, lhs, rhs, ret, ctx)) {
log(LOG_WARNING, "Failed to parse keyword \"%s\". Error code: %i", lhs, error);
- ret = error;
+ ret_val = error;
}
}
@@ -221,14 +223,14 @@ static int parse_colon_key_value_file(void *ret, void *ctx, const keyword **keyw
if (parse_cb != NULL) {
/* Did the callback return an error. */
if (parse_cb(&ret, ctx, buf) < 0) {
- ret = 5;
+ ret_val = 7;
break;
}
}
}
- return ret;
+ return ret_val;
} else {
- return 6;
+ return 8;
}
}
@@ -252,19 +254,19 @@ static int is_end_of_comment(void **ret, void *ctx, char *buf) {
static int parse_comments_file(comment ***comments, char *buf) {
if (comments == NULL) {
- return 7;
+ return 9;
} else {
linked_list *comment_list = NULL;
int ret = parse_colon_key_value_file(calloc(1, sizeof(comment)), &comment_list, comment_keywords, buf, is_end_of_comment);
- *comments = linked_list_to_array(comment_list);
- cleanup_linked_list(comments_list);
+ *comments = (comment **)linked_list_to_array(comment_list);
+ cleanup_linked_list(comment_list);
return ret;
}
}
static int parse_info_file(pull_request *pr, char *buf, const char *root) {
- return parse_colon_key_value_file(pr, root, info_keywords, buf, NULL);
+ return parse_colon_key_value_file(pr, (void *)root, info_keywords, buf, NULL);
}
static int parse_comments_file_path(comment ***comments, const char *root) {
@@ -533,7 +535,7 @@ int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root) {
}
/* Use the index as the directory path. */
- pr_dir = make_index_path(root, idx);
+ pr_dir = make_index_path(root, idx, 0);
/* Did we fail to make an indexed path? */
if (pr_dir == NULL) {
diff --git a/git.h b/git.h
index 29fec4b..17b3658 100644
--- a/git.h
+++ b/git.h
@@ -47,32 +47,32 @@ struct pull_request {
extern void cleanup_git(git_repository **repos);
extern git_repository **init_git(config *cfg);
extern int add_comment(comment *comment, const char *pr_root);
-extern int create_pull_request_dir(pull_request *pr, index *idx, const char *root);
+extern int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root);
-void parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val);
-void parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val);
+int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val);
+int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val);
#define offset_list(...) (size_t []){__VA_ARGS__, -1}
static const keyword *info_keywords[] = {
- &(const keyword *){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL},
- &(const keyword *){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL},
- &(const keyword *){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL},
- &(const keyword *){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL},
- &(const keyword *){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL},
- &(const keyword *){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), NULL},
- &(const keyword *){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), NULL},
- &(const keyword *){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list},
+ &(const keyword){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL},
+ &(const keyword){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL},
+ &(const keyword){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL},
+ &(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL},
+ &(const keyword){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL},
+ &(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), NULL},
+ &(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), NULL},
+ &(const keyword){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list},
NULL,
};
static const keyword *comment_keywords[] = {
- &(const keyword *){"id", "ID of Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, id)), NULL},
- &(const keyword *){"author", "Author of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, author)), NULL},
- &(const keyword *){"date", "Date of Comment's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, date)), NULL},
- &(const keyword *){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply},
- &(const keyword *){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply},
- &(const keyword *){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply},
- &(const keyword *){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL},
+ &(const keyword){"id", "ID of Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, id)), NULL},
+ &(const keyword){"author", "Author of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, author)), NULL},
+ &(const keyword){"date", "Date of Comment's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, date)), NULL},
+ &(const keyword){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply},
+ &(const keyword){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply},
+ &(const keyword){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply},
+ &(const keyword){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL},
NULL,
};
#undef offset_list
diff --git a/index.c b/index.c
index 2ea8971..3505d73 100644
--- a/index.c
+++ b/index.c
@@ -1,17 +1,25 @@
+#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
#include <sys/stat.h>
#include "index.h"
#include "macros.h"
+#include "misc.h"
static int index_strlen(index_t *idx) {
int len = 0;
/* Get the length of the index. */
for (index_t *i = idx; i != NULL; i = i->next) {
const int is_last = (i->next == NULL);
- const char *fmt = (i->type) "%llu" : "%s";
- len += format_len(fmt, (i->type) ? i->num : i->name) + !is_last;
+ if (i->type) {
+ len += format_len("%"PRIu64, i->num) + !is_last;
+ } else {
+ len += format_len("%s", i->name) + !is_last;
+ }
}
return len;
}
@@ -35,7 +43,7 @@ int is_valid_index(index_t *idx) {
/* Did we get an error? */
if (err_str != NULL) {
- log_reason(LOG_ERR, "Invalid index.", reason);
+ log_reason(LOG_ERR, "Invalid index.", err_str);
if (did_alloc) {
free(err_str);
}
@@ -62,8 +70,11 @@ char *make_index_path(const char *root, index_t *idx, int path_type) {
/* Get the length of the path. */
for (index_t *i = idx; i != NULL; i = i->next) {
const int is_last = (i->next == NULL);
- const char *fmt = (i->type) "%llu" : "%s";
- path_len += format_len(fmt, (i->type) ? i->num : i->name) + !is_last;
+ if (i->type) {
+ path_len += format_len("%"PRIu64, i->num) + !is_last;
+ } else {
+ path_len += format_len("%s", i->name) + !is_last;
+ }
}
path = calloc(path_len+1, sizeof(char));
@@ -74,8 +85,11 @@ char *make_index_path(const char *root, index_t *idx, int path_type) {
for (index_t *i = idx; i != NULL; i = i->next) {
const int is_last = (i->next == NULL);
const char *delm = (path_type) ? "-" : "/";
- const char *fmt = (i->type) "%llu%s" : "%s%s";
- tmp += sprintf(tmp, fmt, (i->type) ? i->num : i->name, (!is_last) ? delm : "");
+ if (i->type) {
+ tmp += sprintf(tmp, "%"PRIu64"%s", i->num, (!is_last) ? delm : "");
+ } else {
+ tmp += sprintf(tmp, "%s%s", i->name, (!is_last) ? delm : "");
+ }
}
return path;
@@ -88,9 +102,11 @@ char *index_to_str(index_t *idx) {
/* Create the index. */
for (index_t *i = idx; i != NULL; i = i->next) {
const int is_last = (i->next == NULL);
- const char *fmt = (i->type) "%llu%s" : "%s%s";
-
- tmp += sprintf(tmp, fmt, (i->type) ? i->num : i->name, (!is_last) ? "-" : "");
+ if (i->type) {
+ tmp += sprintf(tmp, "%"PRIu64"%s", i->num, (!is_last) ? "-" : "");
+ } else {
+ tmp += sprintf(tmp, "%s%s", i->name, (!is_last) ? "-" : "");
+ }
}
return idx_str;
} else {
diff --git a/keyword.c b/keyword.c
index b536820..dffd422 100644
--- a/keyword.c
+++ b/keyword.c
@@ -1,5 +1,10 @@
+#define _XOPEN_SOURCE
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include "keyword.h"
+#include "misc.h"
void *get_keyword_offset_ptr(const keyword *key, void *ptr) {
char *ret = (char *)(ptr+key->offsets[0]);
@@ -44,7 +49,7 @@ int set_keyword(const keyword *key, keyword_val val, void *ret, void *ctx) {
} else {
char *tmp_ret = (char *)get_keyword_offset_ptr(key, ret);
- switch (type) {
+ switch (key->type) {
case TYPE_INT :
case TYPE_BOOL : *(int *)tmp_ret = val.i; break;
case TYPE_TIME : *(time_t *)tmp_ret = val.t; break;