commit 90709a072f94c742c7b85a0e50c5390e7071e364 (patch)
parent f64a1a60edde970676a54e31fbc333c58ea38893
Author: Alex Karle <alex@alexkarle.com>
Date: Thu, 23 Dec 2021 20:40:51 -0500
refactor: Use bool's over int's for true/false
Diffstat:
M | blag.c | | | 37 | +++++++++++++++++++------------------ |
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/blag.c b/blag.c
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <err.h>
#include <unistd.h>
+#include <stdbool.h>
enum Block {
NONE,
@@ -31,18 +32,18 @@ typedef struct State {
enum Block in;
enum Link in_link;
int hlvl;
- int in_code;
- int in_ital;
- int in_bold;
- int escape;
+ bool in_code;
+ bool in_ital;
+ bool in_bold;
+ bool escape;
char lnkbuf[2048];
int lnkidx;
int indent;
int previndent;
int listdepth;
int lastc;
- int ol;
- int linestarted;
+ bool ol;
+ bool linestarted;
} state;
void putesc(int c) {
@@ -80,7 +81,7 @@ void maybe_startp(state *s) {
void handle_lf(state *s) {
s->indent = 0;
- s->linestarted = 0;
+ s->linestarted = false;
/* single line types (one lf to close) */
if (s->in == HEADER) {
@@ -127,22 +128,22 @@ int parse() {
/* Mini state machine (home grown spaghetti code) */
int c;
state s = {
- .c = 0,
+ .c = '0',
.in = NONE,
.in_link = NOL,
.hlvl = 0,
- .in_code = 0,
- .in_ital = 0,
- .in_bold = 0,
- .escape = 0,
+ .in_code = false,
+ .in_ital = false,
+ .in_bold = false,
+ .escape = false,
.lnkbuf = {0},
.lnkidx = 0,
.indent = 0,
.previndent = 0,
.listdepth = 0,
- .lastc = 0,
- .linestarted = 0,
- .ol = 0,
+ .lastc = '0',
+ .linestarted = false,
+ .ol = false,
};
while ((c = getchar()) != EOF) {
@@ -155,7 +156,7 @@ int parse() {
printf("<p>\n");
}
putesc(c);
- s.escape = 0;
+ s.escape = false;
continue;
}
@@ -173,7 +174,7 @@ int parse() {
/* Handle unique state changes by char */
switch (c) {
case '\\':
- s.escape = 1;
+ s.escape = true;
break;
case '#':
if (s.in == NONE) {
@@ -287,7 +288,7 @@ int parse() {
}
s.lastc = c;
if (c != '\n') {
- s.linestarted = 1;
+ s.linestarted = true;
}
}
/* pretend there's a final LF to close any blocks */