From a3a60d734b50fa0c0447db0f2f73a9ed7a7ba890 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 15 Jun 2024 01:14:51 +0000 Subject: [PATCH] docgen git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@305 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Document/README.FMT | 2 + Tool/docfmt.c | 93 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/Document/README.FMT b/Document/README.FMT index a20878c..c2cb8c3 100644 --- a/Document/README.FMT +++ b/Document/README.FMT @@ -1 +1,3 @@ +\" $Id$ DataWorks Users' Manual +\hline diff --git a/Tool/docfmt.c b/Tool/docfmt.c index 8043c83..c1ab681 100644 --- a/Tool/docfmt.c +++ b/Tool/docfmt.c @@ -29,7 +29,10 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ +#include #include +#include +#include char* __util_strdup(const char* a) { char* str = malloc(strlen(a) + 1); @@ -46,4 +49,92 @@ char* __util_strcat(const char* a, const char* b) { return str; } -int main(int argc, char** argv) {} +FILE* in; +FILE* out; + +int process_doc(void) { + char cbuf[2]; + cbuf[1] = 0; + char* full = malloc(1); + full[0] = 0; + char* str; + + str = malloc(1); + str[0] = 0; + fseek(in, 0, SEEK_SET); + while(1) { + int len = fread(cbuf, 1, 1, in); + if(len <= 0) break; + { + char* tmp = full; + full = __util_strcat(tmp, cbuf); + free(tmp); + } + if(cbuf[0] == '\n') { + if(str[0] == '\\') { + if(strcmp(str, "\\hline") == 0) { + } else if(str[1] == '"') { + } else { + fprintf(stderr, "Invalid command. Aborted\n"); + free(str); + return 1; + } + } + free(str); + str = malloc(1); + str[0] = 0; + } else if(cbuf[0] != '\r') { + char* tmp = str; + str = __util_strcat(tmp, cbuf); + free(tmp); + } + } + free(str); + + str = malloc(1); + str[0] = 0; + int incr = 0; + while(1) { + cbuf[0] = full[incr++]; + if(cbuf[0] == 0) break; + if(cbuf[0] == '\n') { + if(str[0] == '\\') { + if(strcmp(str, "\\hline") == 0) { + int i; + for(i = 0; i < 79; i++) fprintf(out, "="); + fprintf(out, "\n"); + } else if(str[1] == '"') { + } else { + fprintf(stderr, "Invalid command. Aborted\n"); + free(str); + return 1; + } + } else { + fprintf(out, "%s\n", str); + } + free(str); + str = malloc(1); + str[0] = 0; + } else if(cbuf[0] != '\r') { + char* tmp = str; + str = __util_strcat(tmp, cbuf); + free(tmp); + } + } + free(str); + free(full); + return 0; +} + +int main(int argc, char** argv) { + if(argc < 2) { + fprintf(stderr, "Insufficient arguments\n"); + return 1; + } + in = fopen(argv[1], "r"); + out = stdout; + if(in == NULL) { + fprintf(stderr, "Failed to open the input\n"); + } + return process_doc(); +} -- 2.43.0