aboutsummaryrefslogtreecommitdiff
path: root/g2x.c
diff options
context:
space:
mode:
authorInqiyad Sabr <sabr@ariamath.xyz>2025-11-03 01:48:24 +0600
committerInqiyad Sabr <sabr@ariamath.xyz>2025-11-03 01:48:24 +0600
commite9f7393a80b0c256ac5c5cab6d5458e5e610c3a5 (patch)
treebf6154c14371ce288731917586f3aa4aa2ea3193 /g2x.c
parentd83a53beb823f9e1cbd73ea214fe99a1511f5f59 (diff)
Removing dangling continue's and fixing broken link checks
Diffstat (limited to 'g2x.c')
-rw-r--r--g2x.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/g2x.c b/g2x.c
index d2d7cef..8ac18a8 100644
--- a/g2x.c
+++ b/g2x.c
@@ -2,19 +2,19 @@
#include <string.h>
#define BUFSIZE 4096
+#define html(s) fputs(s,stdout)
+#define getbuf() fgets(buf,BUFSIZE,stdin)
#define xmlput(n)\
for(pos = n; buf[pos] != '\n'; pos++) {\
switch(buf[pos]) {\
default: putchar(buf[pos]); break;\
- case '>' : fputs("&gt;",stdout); break;\
- case '<' : fputs("&lt;",stdout); break;\
- case '&' : fputs("&amp;",stdout); break;\
- case '\'': fputs("&apos;",stdout); break;\
- case '"' : fputs("&quot;",stdout); break;\
+ case '>' : html("&gt;"); break;\
+ case '<' : html("&lt;"); break;\
+ case '&' : html("&amp;"); break;\
+ case '\'': html("&apos;"); break;\
+ case '"' : html("&quot;"); break;\
}\
}
-#define html(s) fputs(s,stdout)
-#define getbuf() fgets(buf,BUFSIZE,stdin)
int main(void)
{
@@ -33,44 +33,42 @@ int main(void)
while (getbuf() != NULL)
{
if (!strncmp(buf,"###",3)) {
- html("<h3>"); xmlput(4); html("</h3>"); continue;
+ html("<h3>"); xmlput(4); html("</h3>");
} else if (!strncmp(buf,"##",2)) {
- html("<h2>"); xmlput(3); html("</h3>"); continue;
+ html("<h2>"); xmlput(3); html("</h2>");
} else if (buf[0] == '#') {
- html("<h1>"); xmlput(2); html("</h1>"); continue;
+ html("<h1>"); xmlput(2); html("</h1>");
}
else if (buf[0] == '>') {
fputs("<blockquote>",stdout); xmlput(2);
- fputs("</blockquote>\n",stdout); continue;
+ fputs("</blockquote>\n",stdout);
}
else if (buf[0] == '*') {
if (list_state == 0) html("<ul>\n");
html("<li>"); xmlput(2); html("</li>\n");
list_state = 1;
- continue;
} else if (list_state == 1) {
html("</ul>\n");
list_state = 0;
- continue;
}
else if (!strncmp(buf,"=>",2)) {
html("<p><a href=\"");
for (pos = 3; buf[pos] != '.' && buf[pos] != ' ';)
putchar(buf[pos++]);
if (buf[pos] == '.') {
- int i = 0; char suffix[4];
- while ((suffix[i++] = buf[pos++]) != ' ');
+ int i = 0; char suffix[12];
+ for (i = 0; buf[pos] != ' ';)
+ suffix[i++] = buf[pos++];
+ suffix[i] = '\0';
if (!strncmp(suffix,".gmi",4)) html(".html");
else html(suffix);
- } html("\">"); xmlput(pos); html("</a></p>\n");
- continue;
+ } html("\">"); xmlput(pos+1); html("</a></p>\n");
}
else if (!strncmp(buf,"```",3)) {
getbuf(); html("<pre><code>");
while (strncmp(buf,"```",3)) {
xmlput(0); putchar('\n'); getbuf();
} html("</code></pre>\n");
- continue;
- } html("<p>"); xmlput(0); html("</p>\n");
+ } else { html("<p>"); xmlput(0); html("</p>\n"); }
} html("</body>"); html("</html>");
}