===================================================================
RCS file: /home/cvs/OpenXM/src/asir-contrib/packages/doc/Attic/gentexi.c,v
retrieving revision 1.1
retrieving revision 1.6
diff -u -p -r1.1 -r1.6
--- OpenXM/src/asir-contrib/packages/doc/Attic/gentexi.c	2002/01/27 07:13:28	1.1
+++ OpenXM/src/asir-contrib/packages/doc/Attic/gentexi.c	2002/10/23 01:11:41	1.6
@@ -1,4 +1,4 @@
-/*  $OpenXM$  */
+ /*  $OpenXM: OpenXM/src/asir-contrib/packages/doc/gentexi.c,v 1.5 2002/08/23 03:26:16 noro Exp $  */
 
 #include <stdio.h>
 int Debug = 0;
@@ -15,10 +15,13 @@ struct item {
   char *optv[VMAX];
   char *shortDescription;
   char *description;
+  char *algorithm;
   char *examplev[VMAX];
+  char *exampleDescv[VMAX];
   int examplec;
   int refc;
   char *refv[VMAX];
+  char *author;
 };
 struct item *getItem(void);
 char *str(char *key);
@@ -31,12 +34,13 @@ int Sp = 0;
 char *Upnode;
 char *Category=NULL;
 char *Lang="en";
+int Include = 0;
+int GenExample = 0;
 
 main(int argc,char *argv[]) {
   char *t;
   int p,c,n,i;
   struct item *tt;
-  int Template = 0;
   struct item *items[ITEMMAX];
 
   Upnode = str("UNKNOWN");
@@ -51,8 +55,10 @@ main(int argc,char *argv[]) {
       Lang = "en";
     }else if (strcmp(argv[i],"--ja") == 0) {
       Lang = "ja";
-    }else if (strcmp(argv[i],"--template") == 0) {
-      Template = 1;
+    }else if (strcmp(argv[i],"--include") == 0) {
+      Include = 1;
+    }else if (strcmp(argv[i],"--example") == 0) {
+      GenExample = 1;
     }else if (strcmp(argv[i],"--debug") == 0) {
       Debug = 1;
     }else {
@@ -95,24 +101,31 @@ main(int argc,char *argv[]) {
   shell(items,n);
   if (Debug) fprintf(stderr,"Done.\n");
   
+  printMenu(stdout,items,n);
+
   for (i=0; i<n; i++) {
-    if (Template) {
-      genTemplate(items[i]->name);
-    }
     printTexi(stdout,items[i]);
   }
-  
+  exit(0);  
 }
 
-genTemplate(char *name) {
+genInclude(char *name) {
   char fname[4098];
   FILE *fp;
+  int c;
   
   sprintf(fname,"tmp/%s-auto-%s.texi",name,Lang);
-  if (fopen(fname,"r") == NULL) {
-    fp = fopen(fname,"w");
-    fclose(fp);
+  fp = fopen(fname,"r");
+  if (fp == NULL) {
+    /* fprintf(stderr,"No file %s\n",fname); */
+    return 0;
   }
+  while ((c=fgetc(fp)) != EOF) {
+    putchar(c);
+  }
+  putchar('\n');
+  fclose(fp);
+  return 0;
 }
 
 cmpItem(struct item *it,struct item *it2) {
@@ -127,7 +140,7 @@ struct item * newItem(){
   }
   a->argc = 0; a->optc = 0; a->refc=0; a->examplec = 0;
   a->category = a->category2 = a->name = a->shortDescription
-    = a->description = NULL;
+    = a->description = a->author = a->algorithm = NULL; 
   return a;
 }
   
@@ -185,10 +198,16 @@ printItem(struct item *it) {
     printf("shortDescription=%s\n",it->shortDescription);
   if (it->description != NULL)
     printf("description=%s\n",it->description);
+  if (it->algorithm != NULL)
+    printf("algorithm=%s\n",it->algorithm);
   for (i=0; i <it->examplec; i++) 
     printf("examplev[%d]=%s\n",i,it->examplev[i]);
+  for (i=0; i <it->examplec; i++) 
+    printf("exampleDescv[%d]=%s\n",i,it->exampleDescv[i]);
   for (i=0; i<it->refc; i++)
     printf("  refv[%d]=%s\n",i,it->refv[i]);
+  if (it->author != NULL)
+    printf("author=%s\n",it->author);
   printf("\n");
 }
 
@@ -315,7 +334,10 @@ struct item *getItem() {
     /* Get Description or Examples */
     if (strcmp(key,"end:") == 0) break;
     if (strcmp(key,"description:") == 0 ||
-        strcmp(key,"example:") == 0) {
+        strcmp(key,"algorithm:") == 0 ||
+        strcmp(key,"author:") == 0 ||
+        strcmp(key,"example:") == 0 ||
+		strcmp(key,"example_description:") ==0 ) {
       pp = p;
       strcpy(key2,key);
       do {
@@ -329,12 +351,22 @@ struct item *getItem() {
       }
       if (strcmp(key2,"example:") == 0) {
         it->examplev[examplec++] = str2(&(S[pp]),pOld-pp);
+        it->exampleDescv[examplec-1] = "";
         it->examplec = examplec;
         if (examplec > VMAX-1) {
           fprintf(stderr,"Too many examples. \n");
           exit(20);
         }
       }
+      if (strcmp(key2,"example_description:") == 0) {
+        it->exampleDescv[examplec-1] = str2(&(S[pp]),pOld-pp);
+      }
+      if (strcmp(key2,"author:") == 0) {
+        it->author = str2(&(S[pp]),pOld-pp);
+      }
+      if (strcmp(key2,"algorithm:") == 0) {
+        it->algorithm = str2(&(S[pp]),pOld-pp);
+      }
     }else if (strcmp(key,"ref:") == 0) {
       argc = 0;
       while ((pp=nextToken(key,LIMIT)) >= 0) {
@@ -350,8 +382,8 @@ struct item *getItem() {
         }
       }
     }else{
-      fprintf(stderr,"Unknown keyword at %s\n",it->name);
-      exit(10);
+      fprintf(stderr,"Warning: unknown keyword << %s >> at %s. Ignored.\n",key, it->name);
+      p = nextToken(key,LIMIT);
     }
   }while (p >= 0);
 
@@ -373,6 +405,15 @@ shell(struct item *v[],int n) {
   }
 }
 
+printMenu(FILE *fp, struct item **it, int n) {
+  int i;
+
+  fprintf(fp,"@menu\n");
+  for ( i = 0; i < n; i++ )
+  	fprintf(fp,"* %s::\n",it[i]->name);
+  fprintf(fp,"@end menu\n");
+}
+
 printTexi(FILE *fp, struct item *it) {
   int i;
   fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi.\n");
@@ -385,9 +426,11 @@ printTexi(FILE *fp, struct item *it) {
     return ;
   }
 
+#if 0
   fprintf(fp,"@menu\n");
-  fprintf(fp,"* %s\n",it->name);
+  fprintf(fp,"* %s::\n",it->name);
   fprintf(fp,"@end menu\n");
+#endif
   fprintf(fp,"@node %s,,, %s\n",it->name,Upnode);
   fprintf(fp,"@subsection @code{%s}\n",it->name);
   fprintf(fp,"@findex %s\n",it->name);
@@ -431,18 +474,44 @@ printTexi(FILE *fp, struct item *it) {
   fprintf(fp,"@end table\n");
 
   /* include file */
-  fprintf(fp,"@include tmp/%s-auto-en.texi\n",it->name);
+  if (Include) {
+    if (genInclude(it->name)) 
+      fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name);
+  }
   fprintf(fp,"@c @itemize @bullet \n");
   fprintf(fp,"@c @item \n");
   fprintf(fp,"@c @end itemize\n");
   
+  if (it->description != NULL) {
+    fprintf(fp,"%s\n\n",it->description);
+  }
+
+  if (it->algorithm != NULL) {
+    fprintf(fp,"\n\n@noindent\nAlgorithm: \n");
+    fprintf(fp,"%s\n\n",it->algorithm);
+  }
+
   if (it->examplec > 0) {
     for (i=0; i<it->examplec; i++) {
+	  if (it->examplec == 1) {
+        fprintf(fp,"Example:\n");
+	  }else{
+        fprintf(fp,"Example %d:\n",i);
+	  }
       fprintf(fp,"@example\n");
       fprintf(fp,"%s\n",it->examplev[i]);
+      if (GenExample) {
+        outputOfExample(it->examplev[i]);
+      }
       fprintf(fp,"@end example\n");
+	  if (it->exampleDescv[i] != NULL && strlen(it->exampleDescv[i]) > 0) {
+		fprintf(fp,"%s\n\n",it->exampleDescv[i]);
+	  }
     }
   }
+  if (it->author != NULL) {
+    fprintf(fp,"Author : %s\n\n",it->author);
+  }
   if (it->refc > 0) {
     fprintf(fp,"@table @t\n");
     fprintf(fp,"@item References\n");
@@ -455,3 +524,29 @@ printTexi(FILE *fp, struct item *it) {
   fprintf(fp,"\n");
 }
 
+outputOfExample(char *com) {
+  FILE *fp2;
+  int c;
+  fp2 = fopen("gentexi-in.tmp","w");
+  if (fp2 == NULL) {
+    fprintf(stderr,"Cannot open tentexi-in.tmp\n");
+    exit(10);
+  }
+  system("rm -f gentexi-out.tmp");
+  fprintf(fp2,"output(\"gentexi-out.tmp\")$\n");
+  fprintf(fp2,"%s\n",com);
+  fprintf(fp2,"output()$\n");
+  fprintf(fp2,"quit;");
+  fclose(fp2);
+  system("asir <gentexi-in.tmp >/dev/null");
+
+  fp2 = fopen("gentexi-out.tmp","r");
+  if (fp2 == NULL) {
+    fprintf(stderr,"Cannot open tentexi-in.tmp\n");
+    exit(10);
+  }
+  while ((c=fgetc(fp2)) != EOF) {
+    putchar(c);
+  }
+  putchar('\n');
+}