]> Nishi Git Mirror - dataworks.git/commitdiff
docgen
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Sat, 15 Jun 2024 01:14:51 +0000 (01:14 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Sat, 15 Jun 2024 01:14:51 +0000 (01:14 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@305 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Document/README.FMT
Tool/docfmt.c

index a20878c30bb132850aa88b259a1d9b2c04fb809d..c2cb8c389d83f4db7b7584f6ea328fc9c69e4200 100644 (file)
@@ -1 +1,3 @@
+\" $Id$
 DataWorks Users' Manual
+\hline
index 8043c83bd743caabc6eb230d510731e4ca52be90..c1ab681397a4cbad54dec3c1db7c829cbd906331 100644 (file)
 /* -------------------------------------------------------------------------- */
 /* --- END LICENSE --- */
 
+#include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 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();
+}