commit 09886a5fa318213ad21f5c12b6441cfb5088be34
parent 9243fbbbc71594e9f41802bbb3149c22124cd3ad
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Sat, 15 Jun 2019 17:08:02 +1000
headerfile improvements
- header includes into main files
- sort all includes
- change utf8.h comment format
- rename header guards
- define the size of the parser queue with a preprocessor statement
Diffstat:
7 files changed, 29 insertions(+), 52 deletions(-)
diff --git a/main.c b/main.c
@@ -3,7 +3,10 @@
#include <ctype.h>
#include <errno.h>
#include <limits.h>
+#include <stdarg.h>
#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/str.h b/str.h
@@ -1,17 +1,12 @@
-#ifndef _SCDOC_STRING_H
-#define _SCDOC_STRING_H
-#include <stdint.h>
-
-struct str {
+#ifndef _STR_H
+#define _STR_H
+typedef struct str {
char *str;
size_t len, size;
-};
-
-typedef struct str str_t;
+} str_t;
str_t *str_create();
void str_free(str_t *str);
void str_reset(str_t *str);
int str_append_ch(str_t *str, uint32_t ch);
-
#endif
diff --git a/string.c b/string.c
@@ -1,5 +1,7 @@
-#include <stdlib.h>
+#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "str.h"
#include "utf8.h"
diff --git a/utf8.c b/utf8.c
@@ -1,5 +1,6 @@
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
#include "utf8.h"
diff --git a/utf8.h b/utf8.h
@@ -1,43 +1,21 @@
-#ifndef _SCDOC_UNICODE_H
-#define _SCDOC_UNICODE_H
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-
-// Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself
-// doesn't really bother with more than 4.
+#ifndef _UTF8_H
+#define _UTF8_H
+/* Technically UTF-8 supports up to 6 byte codepoints,
+ * but Unicode itself doesn't really bother with more than 4.
+ */
#define UTF8_MAX_SIZE 4
-
#define UTF8_INVALID 0x80
-/**
- * Grabs the next UTF-8 character and advances the string pointer
- */
+/* Grabs the next UTF-8 character and advances the string pointer. */
uint32_t utf8_decode(const char **str);
-
-/**
- * Encodes a character as UTF-8 and returns the length of that character.
- */
+/* Encodes a character as UTF-8 and returns the length of that character. */
size_t utf8_encode(char *str, uint32_t ch);
-
-/**
- * Returns the size of the next UTF-8 character
- */
+/* Return the size of the next UTF-8 character in str */
int utf8_size(const char *str);
-
-/**
- * Returns the size of a UTF-8 character
- */
+/* Return the size of the UTF-8 character ch */
size_t utf8_chsize(uint32_t ch);
-
-/**
- * Reads and returns the next character from the file.
- */
+/* Read and return the next character from f */
uint32_t utf8_fgetch(FILE *f);
-
-/**
- * Writes this character to the file and returns the number of bytes written.
- */
+/* Write ch to f and return the number of bytes written */
size_t utf8_fputch(FILE *f, uint32_t ch);
-
#endif
diff --git a/util.c b/util.c
@@ -1,7 +1,8 @@
#include <stdarg.h>
-#include <stdlib.h>
+#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
#include "utf8.h"
#include "util.h"
diff --git a/util.h b/util.h
@@ -1,14 +1,12 @@
-#ifndef _SCDOC_PARSER_H
-#define _SCDOC_PARSER_H
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
+#ifndef _UTIL_H
+#define _UTIL_H
+#define QUEUELEN 32
struct parser {
FILE *input, *output;
int line, col;
int qhead;
- uint32_t queue[32];
+ uint32_t queue[QUEUELEN];
uint32_t flags;
const char *str;
int fmt_line, fmt_col;
@@ -25,5 +23,4 @@ uint32_t parser_getch(struct parser *parser);
void parser_pushch(struct parser *parser, uint32_t ch);
void parser_pushstr(struct parser *parser, const char *str);
int roff_macro(struct parser *p, char *cmd, ...);
-
#endif