Introduction
Introduction Statistics Contact Development Disclaimer Help
add pledge support, remove file argument option - smu - smu - simple markup (Ma…
git clone git://git.codemadness.org/smu
Log
Files
Refs
README
LICENSE
---
commit dc715a83638a2c710c99718d9ae7a95478913395
parent 044e25311d769ca36be0d82b1f942d487023aa01
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 11 May 2021 02:01:52 +0200
add pledge support, remove file argument option
- fix possible fclose(stdin).
- add usage() function and print it also on passing "-h".
Diffstat:
M smu.1 | 1 -
M smu.c | 25 ++++++++++++++++++-------
2 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/smu.1 b/smu.1
@@ -6,7 +6,6 @@ smu \- simple markup
.RB [ \-h ]
.RB [ \-v ]
.RB [ \-n ]
-.RB [ file ]
.SH DESCRIPTION
smu is a simple interpreter for a simplified markdown dialect.
.SH OPTIONS
diff --git a/smu.c b/smu.c
@@ -4,6 +4,12 @@
#include <stdlib.h>
#include <string.h>
+#ifdef __OpenBSD__
+#include <unistd.h>
+#else
+#define pledge(p1,p2) 0
+#endif
+
#define LENGTH(x) sizeof(x)/sizeof(x[0])
#define ADDC(b,i) if(i % BUFSIZ == 0) { b = realloc(b, (i + BUFSIZ) * sizeof(…
@@ -655,6 +661,11 @@ process(const char *begin, const char *end, int newblock) {
}
}
+void
+usage(char **argv) {
+ eprint("usage: %s [-n]\n\t-n escape HTML strictly\n", argv[0]);
+}
+
int
main(int argc, char *argv[]) {
char *buffer = NULL;
@@ -662,22 +673,23 @@ main(int argc, char *argv[]) {
unsigned long len, bsize;
FILE *source = stdin;
+ if (pledge("stdio", NULL) == -1)
+ eprint("pledge");
+
for(i = 1; i < argc; i++) {
if(!strcmp("-v", argv[i]))
- eprint("simple markup %s (C) Enno Boland\n",VERSION);
+ eprint("simple markup %s\n",VERSION);
else if(!strcmp("-n", argv[i]))
nohtml = 1;
- else if(argv[i][0] != '-')
- break;
+ else if(argv[i][0] != '-' || !strcmp("-h", argv[i]))
+ usage(argv);
else if(!strcmp("--", argv[i])) {
i++;
break;
}
else
- eprint("Usage %s [-n] [file]\n -n escape html strictly…
+ usage(argv);
}
- if(i < argc && !(source = fopen(argv[i], "r")))
- eprint("Cannot open file `%s`\n",argv[i]);
bsize = 2 * BUFSIZ;
buffer = ereallocz(buffer, bsize);
len = 0;
@@ -691,7 +703,6 @@ main(int argc, char *argv[]) {
}
buffer[len] = '\0';
process(buffer, buffer + len, 1);
- fclose(source);
free(buffer);
return EXIT_SUCCESS;
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.