summaryrefslogtreecommitdiff
path: root/igen/preprocessor.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-02-17 21:15:59 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2022-02-18 10:05:01 -0400
commitab0517cc4a6077c756d03c7c19311f5bd841d856 (patch)
treed1670125b9b9734506392247b9e76979748c764d /igen/preprocessor.c
parent524cfc23b15e1067076e45b056cb1d84e87e66cb (diff)
igen: Fixed some compilation errors, and warnings.
Diffstat (limited to 'igen/preprocessor.c')
-rw-r--r--igen/preprocessor.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/igen/preprocessor.c b/igen/preprocessor.c
index e6a895c..5ee9aa4 100644
--- a/igen/preprocessor.c
+++ b/igen/preprocessor.c
@@ -5,15 +5,18 @@
#include "misc.h"
#include "preprocessor.h"
+
+char *pp_include(source *src, int dbg);
+
static const keyword *preproc_keywords[] = {
- &(const keyword *) {"include", DIR_INCLUDE, pp_include},
+ &(const keyword) {"include", DIR_INCLUDE, (keyword_cb *)pp_include},
NULL
};
char *skip_line(const char *str, int dbg) {
- size_t span = strcspn(str, "\r\n\f");
+ const size_t span = strcspn(str, "\r\n\f");
/*span += strspn(&str[span], "\r\n\f");*/
- return &str[span+strspn(&str[span], "\r\n\f")];
+ return (char *)&str[span+strspn(&str[span], "\r\n\f")];
}
size_t line_span(const char *str, int dbg) {
@@ -74,16 +77,16 @@ char *skip_whitespace(source *src, whitespace *wspace, int count_lines, int coun
size_t span = get_whitespace_span(text, count_lines, count_columns, dbg);
whitespace wsp = {0};
- count_whitespace(&wsp, str, span, count_lines, count_columns, dbg);
+ count_whitespace(&wsp, text, span, count_lines, count_columns, dbg);
if (wsp.tabs) {
const int tab_stop = src->tab_width;
const int extra_tabs = wsp.spaces/tab_stop;
- src->cur.x += ((wsp.tabs+extra_tabs)*tab_stop);
+ src->cur.column += ((wsp.tabs+extra_tabs)*tab_stop);
} else {
- src->cur.x += wsp.spaces;
+ src->cur.column += wsp.spaces;
}
- src->cur.y += wsp.lines;
+ src->cur.line += wsp.lines;
if (wspace != NULL) {
*wspace = wsp;
}
@@ -107,7 +110,7 @@ char *skip_comment(source *src, whitespace *wspace, comment_type *type, int dbg)
count_whitespace(&wsp, &text[span], strspn(&text[span], "\r\n\f"), 0, 1, dbg);
} else {
*type = COMM_SINGLE;
- ++wsp.lines
+ ++wsp.lines;
text -= 2;
}
@@ -118,11 +121,11 @@ char *skip_comment(source *src, whitespace *wspace, comment_type *type, int dbg)
if (wsp.tabs) {
const int tab_stop = src->tab_width;
const int extra_tabs = wsp.spaces/tab_stop;
- src->cur.x += ((wsp.tabs+extra_tabs)*tab_stop);
+ src->cur.column += ((wsp.tabs+extra_tabs)*tab_stop);
} else {
- src->cur.x += wsp.spaces;
+ src->cur.column += wsp.spaces;
}
- src->cur.y += wsp.lines;
+ src->cur.line += wsp.lines;
} else {
--text;
*type = COMM_NONE;
@@ -169,11 +172,11 @@ char *find_comment(source *src, whitespace *wspace, comment_type *type, int dbg)
if (wsp.tabs) {
const int tab_stop = src->tab_width;
const int extra_tabs = wsp.spaces/tab_stop;
- src->cur.x += ((wsp.tabs+extra_tabs)*tab_stop);
+ src->cur.column += ((wsp.tabs+extra_tabs)*tab_stop);
} else {
- src->cur.x += wsp.spaces;
+ src->cur.column += wsp.spaces;
}
- src->cur.y += wsp.lines;
+ src->cur.line += wsp.lines;
return &text[span];
} else {
@@ -240,7 +243,7 @@ keyword **copy_keyword_table(keyword **keywords, size_t *key_count, int dbg) {
*key_count = 0;
return NULL;
} else {
- for (*key_count = 0; keywords[count] != NULL; ++(*key_count));
+ for (*key_count = 0; keywords[*key_count] != NULL; ++(*key_count));
if (!*key_count) {
return NULL;
} else {
@@ -348,7 +351,7 @@ int is_included(source *parent, const char *filename, int dbg) {
}
void free_str_list(struct str_list *list) {
- for (struct str_list *l = list, l2 = l; l != NULL; l = l->next, l2 = l) {
+ for (struct str_list *l = list, *l2 = l; l != NULL; l = l->next, l2 = l) {
free(l2->str);
l2->str = NULL;
free(l2);
@@ -356,7 +359,7 @@ void free_str_list(struct str_list *list) {
}
void free_comment_list(struct comment_list *list) {
- for (struct comment_list *l = list, l2 = l; l != NULL; l = l->next, l2 = l) {
+ for (struct comment_list *l = list, *l2 = l; l != NULL; l = l->next, l2 = l) {
free(l2->com);
l2->com = NULL;
free(l2);
@@ -423,7 +426,7 @@ source *preprocess(source *parent, const char *filename, int dbg) {
src->included = (parent != NULL);
for (char *text = src->text; *text != '\0'; ++text) {
- text = skip_whitespace(src, NULL, 1, 1, dbg)
+ text = skip_whitespace(src, NULL, 1, 1, dbg);
text = skip_comment(src, NULL, NULL, dbg);
if (is_directive) {
@@ -434,7 +437,7 @@ source *preprocess(source *parent, const char *filename, int dbg) {
dir_key = calloc(key_len+1, sizeof(char));
memcpy(dir_key, text, key_len);
- dir_type = find_keyword(dir_key, preproc_keywords, src, &key_data, dbg);
+ dir_type = find_keyword(dir_key, (keyword **)preproc_keywords, src, &key_data, dbg);
free(dir_key);
if (key_data != NULL) {