=================================================================== RCS file: /home/cvs/OpenXM/src/util/oxgentexi.c,v retrieving revision 1.1 retrieving revision 1.19 diff -u -p -r1.1 -r1.19 --- OpenXM/src/util/oxgentexi.c 2005/04/04 06:10:58 1.1 +++ OpenXM/src/util/oxgentexi.c 2020/10/03 08:24:14 1.19 @@ -1,9 +1,11 @@ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/util/oxgentexi.c,v 1.18 2017/03/28 12:00:04 takayama Exp $ */ #include +#include +#include int Debug = 0; #define VMAX 20 -#define LIMIT 1024 +#define LIMIT 65536 #define ITEMMAX 1024 struct item { char *category; /* base */ @@ -16,17 +18,33 @@ struct item { char *shortDescription; char *description; char *algorithm; + char *changelog; char *examplev[VMAX]; char *exampleDescv[VMAX]; + char *options; int examplec; int refc; char *refv[VMAX]; char *author; + char *sortKey; + int type; }; struct item *getItem(void); char *str(char *key); char *str2(char *key,int size); int cmpItem(struct item *it,struct item *it2); +void printItem(struct item *it); +void shell(struct item *v[],int n); +void printMenu(FILE *fp, struct item **it, int n); +void printBye(); +void printTitlePage(char *title, char *author,char *infoName); +void printItem(struct item *it); +void printTexi(FILE *fp, struct item *it); +void printTexi_common(FILE *fp,struct item *it); +void printTexi0(FILE *fp, struct item *it); +void printTexi1(FILE *fp, struct item *it); +void outputExample(FILE *fp,char *s); +void outputOfExample(char *com); char *S; int Ssize = 256; @@ -36,10 +54,16 @@ char *Category=NULL; char *Lang="en"; int Include = 0; int GenExample = 0; +int DebugItem = 0; +char *Title = NULL; +char *Author = NULL; +char *InfoName = NULL; +int NoSorting = 0; +int main(int argc,char *argv[]) { char *t; - int p,c,n,i; + int c,n,i; struct item *tt; struct item *items[ITEMMAX]; @@ -61,6 +85,16 @@ main(int argc,char *argv[]) { GenExample = 1; }else if (strcmp(argv[i],"--debug") == 0) { Debug = 1; + }else if (strcmp(argv[i],"--debugItem") == 0) { + DebugItem = 1; + }else if (strcmp(argv[i],"--title") == 0) { + i++; Title = str(argv[i]); + }else if (strcmp(argv[i],"--infoName") == 0) { + i++; InfoName = str(argv[i]); + }else if (strcmp(argv[i],"--author") == 0) { + i++; Author = str(argv[i]); + }else if (strcmp(argv[i],"--noSorting") == 0) { + NoSorting = 1; }else { fprintf(stderr,"Unknown option\n"); exit(1); } @@ -97,18 +131,33 @@ main(int argc,char *argv[]) { items[n++] = tt; } } - if (Debug) fprintf(stderr,"Sorting...\n"); - shell(items,n); - if (Debug) fprintf(stderr,"Done.\n"); + if (!NoSorting) { + if (Debug) fprintf(stderr,"Sorting...\n"); + shell(items,n); + if (Debug) fprintf(stderr,"Done.\n"); + } + + if (DebugItem) { + for (i=0; iname,it2->name); + return strcmp(it->sortKey,it2->sortKey); } struct item * newItem(){ struct item *a; @@ -138,12 +188,11 @@ struct item * newItem(){ fprintf(stderr,"newItem: No more memory.\n"); exit(20); } - a->argc = 0; a->optc = 0; a->refc=0; a->examplec = 0; - a->category = a->category2 = a->name = a->shortDescription - = a->description = a->author = a->algorithm = NULL; + memset(a, 0, sizeof(struct item)); return a; } - + +int nextToken(char *key,int n) { static int pos = 0; int i = 0; @@ -181,6 +230,7 @@ nextToken(char *key,int n) { return pos; } +void printItem(struct item *it) { int i; if (it == NULL) return; @@ -204,10 +254,16 @@ printItem(struct item *it) { printf("examplev[%d]=%s\n",i,it->examplev[i]); for (i=0; i examplec; i++) printf("exampleDescv[%d]=%s\n",i,it->exampleDescv[i]); + if (it->changelog != NULL) + printf("changelog=%s\n",it->changelog); + if (it->options != NULL) + printf("options=%s\n",it->options); for (i=0; irefc; i++) printf(" refv[%d]=%s\n",i,it->refv[i]); if (it->author != NULL) printf("author=%s\n",it->author); + if (it->sortKey != NULL) + printf("sortKey=%s\n",it->sortKey); printf("\n"); } @@ -235,7 +291,7 @@ char *str2(char *key,int size) { return s; } char *getCategory(char *key) { - int i,n; + int i; char *s; s = str(key); for (i=0; iname = str(key); + it->name = it->sortKey = str(key); it->category = getCategory(key); it->category2 = getCategory2(key); nextToken(key,LIMIT); if (strcmp(key,"(") != 0) { - fprintf(stderr," ( is expected at %s\n",it->name); - exit(10); - } - argc = 0; - while ((pp=nextToken(key,LIMIT)) >= 0) { - if (strcmp(key,"|") == 0) { - /* options */ - argc = 0; - while ((pp=nextToken(key,LIMIT)) >= 0) { - if (strcmp(key,")") == 0) { - break; + pp = p+1; + it->type = 1; /* For non-functions */ + goto LL ; + }else{ + it->type = 0; /* For functions */ + argc = 0; + while ((pp=nextToken(key,LIMIT)) >= 0) { + if (strcmp(key,"|") == 0) { + /* options */ + argc = 0; + while ((pp=nextToken(key,LIMIT)) >= 0) { + if (strcmp(key,")") == 0) { + break; + } + if (strcmp(key,",") != 0) { + it->optv[argc] = str(key); + argc++; it->optc = argc; + } + if (argc >+ VMAX -1) { + fprintf(stderr,"Too many opt args at %s\n",it->name); + exit(10); + } } - if (strcmp(key,",") != 0) { - it->optv[argc] = str(key); - argc++; it->optc = argc; - } - if (argc >+ VMAX -1) { - fprintf(stderr,"Too many opt args at %s\n",it->name); - exit(10); - } } + if (strcmp(key,")") == 0) { + break; + }else if (strcmp(key,",") != 0) { + it->argv[argc] = str(key); + argc++; it->argc=argc; + } + if (argc >= VMAX-1) { + fprintf(stderr,"Too many args at %s\n",it->name); + exit(10); + } } - if (strcmp(key,")") == 0) { - break; - }else if (strcmp(key,",") != 0) { - it->argv[argc] = str(key); - argc++; it->argc=argc; - } - if (argc >= VMAX-1) { - fprintf(stderr,"Too many args at %s\n",it->name); - exit(10); - } } /* Getting the short Description */ @@ -329,27 +389,37 @@ struct item *getItem() { }while (p >= 0); it->shortDescription = str2(&(S[pp]),pOld-pp); - + LL: ; + if (it->type == 1 ) {strcpy(key,"description:"); p++; } do { /* Get Description or Examples */ if (strcmp(key,"end:") == 0) break; if (strcmp(key,"description:") == 0 || strcmp(key,"algorithm:") == 0 || strcmp(key,"author:") == 0 || + strcmp(key,"changelog:") == 0 || + strcmp(key,"sortKey:") == 0 || strcmp(key,"example:") == 0 || - strcmp(key,"example_description:") ==0 ) { + strcmp(key,"example_description:") ==0 || + strcmp(key,"options:") ==0 || + strcmp(key,"Options:") ==0 || + strcmp(key,"Example:") ==0 + ) { pp = p; strcpy(key2,key); do { pOld = p; p = nextToken(key,LIMIT); - /* printf("%s\n",key); */ - if (key[strlen(key)-1] == ':') break; /* Next keyword. */ + /* printf("key=%s\n",key); */ + if (key[strlen(key)-1] == ':') { + pOld = p-strlen(key); + break; /* Next keyword. */ + } }while (p >= 0); if (strcmp(key2,"description:") == 0) { it->description = str2(&(S[pp]),pOld-pp); } - if (strcmp(key2,"example:") == 0) { + if ((strcmp(key2,"example:") == 0) || (strcmp(key2,"Example:") == 0)) { it->examplev[examplec++] = str2(&(S[pp]),pOld-pp); it->exampleDescv[examplec-1] = ""; it->examplec = examplec; @@ -364,9 +434,19 @@ struct item *getItem() { if (strcmp(key2,"author:") == 0) { it->author = str2(&(S[pp]),pOld-pp); } + if (strcmp(key2,"sortKey:") == 0) { + while (S[pp] <= ' ') pp++; + it->sortKey = str2(&(S[pp]),pOld-pp); + } if (strcmp(key2,"algorithm:") == 0) { it->algorithm = str2(&(S[pp]),pOld-pp); } + if (strcmp(key2,"changelog:") == 0) { + it->changelog = str2(&(S[pp]),pOld-pp); + } + if ((strcmp(key2,"options:") == 0) || (strcmp(key2,"Options:")==0)) { + it->options = str2(&(S[pp]),pOld-pp); + } }else if (strcmp(key,"ref:") == 0) { argc = 0; while ((pp=nextToken(key,LIMIT)) >= 0) { @@ -382,7 +462,10 @@ struct item *getItem() { } } }else{ - fprintf(stderr,"Warning: unknown keyword << %s >> at %s. Ignored.\n",key, it->name); + fprintf(stderr,"Warning: unknown keyword << %s >> at %s.\n",key, it->name); + fprintf(stderr," The error occurs around "); + for (i=pp ; i < p; i++) fputc(S[i],stderr); + fprintf(stderr,"\n\n"); p = nextToken(key,LIMIT); } }while (p >= 0); @@ -390,6 +473,7 @@ struct item *getItem() { return it; } +void shell(struct item *v[],int n) { int gap,i,j; struct item *temp; @@ -405,22 +489,101 @@ shell(struct item *v[],int n) { } } +void printMenu(FILE *fp, struct item **it, int n) { - int i; + int i,m; - fprintf(fp,"@menu\n"); + m = 0; for ( i = 0; i < n; i++ ) - fprintf(fp,"* %s::\n",it[i]->name); - fprintf(fp,"@end menu\n"); + if (it[i]->type != 1) m++; + if (m != 0) { + fprintf(fp,"@menu\n"); + for ( i = 0; i < n; i++ ) + if (it[i]->type != 1) fprintf(fp,"* %s::\n",it[i]->name); + fprintf(fp,"@end menu\n"); + } } +void printTexi(FILE *fp, struct item *it) { + if (it->type == 1) printTexi1(fp,it); + else printTexi0(fp,it); + return; +} + +void +printTexi_common(FILE *fp,struct item *it) { int i; - fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi.\n"); + int elen; + if ((it->shortDescription != NULL) || (it->refc >0) + || (it->examplec > 0)) { + if (it->description != NULL) { + fprintf(fp,"\nDescription:\n"); + fprintf(fp,"@quotation\n%s\n@end quotation\n\n",it->description); + } + }else { + if (it->description != NULL) { + fprintf(fp,"%s\n\n",it->description); + } + } + + if (it->algorithm != NULL) { + fprintf(fp,"\n\n@noindent\nAlgorithm: \n@quotation\n"); + fprintf(fp,"%s\n@end quotation\n",it->algorithm); + } + + if (it->examplec > 0) { + for (i=0; iexamplec; i++) { + if (it->examplec == 1) { + fprintf(fp,"Example:\n"); + }else{ + fprintf(fp,"Example %d:\n",i); + } + fprintf(fp,"@example\n"); + outputExample(fp,it->examplev[i]); + if (GenExample) { + outputOfExample(it->examplev[i]); + } + elen=strlen(it->examplev[i]); + if ((it->examplev[i])[elen-1] == '\n') fprintf(fp,"@end example\n"); + else fprintf(fp,"\n@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->changelog != NULL) { + fprintf(fp,"\n\nChange Log:\n@quotation\n"); + fprintf(fp,"%s\n@end quotation\n",it->changelog); + } + if (it->options != NULL) { + fprintf(fp,"\nOptinal variabes:"); + fprintf(fp,"%s\n\n",it->options); + } + if (it->refc > 0) { + fprintf(fp,"\n\nReferences:\n@quotation\n"); + for (i=0; i refc; i++) { + fprintf(fp," @code{%s} ",it->refv[i]); + if (i != it->refc-1) fprintf(fp,", \n"); + } + fprintf(fp,"\n@end quotation\n"); + } + fprintf(fp,"\n"); +} + +void +printTexi0(FILE *fp, struct item *it) { + int i; + + fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for asir function item.\n"); if (it == NULL) { fprintf(fp,"@c item is NULL.\n"); return ; } + fprintf(fp,"@c sortKey: %s\n",it->sortKey); if (it->name == NULL) { fprintf(fp,"@c item name is missing.\n"); return ; @@ -481,64 +644,80 @@ printTexi(FILE *fp, struct item *it) { 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); + printTexi_common(fp,it); +} + +void +printTexi1(FILE *fp, struct item *it) { + int i; + /* For it->type == 1 */ + + fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for verbose item.\n"); + if (it == NULL) { + fprintf(fp,"@c item is NULL.\n"); + return ; } + fprintf(fp,"@c sortKey: %s\n",it->sortKey); - if (it->examplec > 0) { - for (i=0; iexamplec; 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->shortDescription != NULL) { + for (i=0; ishortDescription); i++) { + fprintf(fp,"%c",it->shortDescription[i]); } + fprintf(fp," \n"); } - if (it->author != NULL) { - fprintf(fp,"Author : %s\n\n",it->author); + + /* include file */ + if (Include) { + if (genInclude(it->name)) + fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name); } - if (it->refc > 0) { - fprintf(fp,"@table @t\n"); - fprintf(fp,"@item References\n"); - for (i=0; i refc; i++) { - fprintf(fp,"@code{%s} ",it->refv[i]); - if (i != it->refc-1) fprintf(fp,", "); + + printTexi_common(fp,it); +} + +void +outputExample(FILE *fp,char *s) { + int i; + /* Remove unnecessary spaces at the tail. */ + for (i=strlen(s)-1; i>=0; i--) { + if (s[i] == '\n') break; + else if (s[i] <= ' ') {s[i] = 0;} + else break; + } + for (i=0; s[i] != 0; i++) { + if (s[i] == '@') { + if (s[i+1] == '{') {fprintf(fp,"%s","@{"); i += 1;} + else if (s[i+1] == '}') {fprintf(fp,"%s","@}"); i += 1;} + else if (s[i+1] == '@') {fprintf(fp,"%s","@@"); i += 1;} + else if (strncmp(&(s[i+1]),"colon",5)==0) { + fprintf(fp,":"); i += 5; + }else fprintf(fp,"@@"); + }else{ + if (s[i] == '{') {fprintf(fp,"%s","@{"); } + else if (s[i] == '}') {fprintf(fp,"%s","@}");} + else fputc(s[i],fp); } - fprintf(fp,"\n@end table\n"); } - fprintf(fp,"\n"); } +void outputOfExample(char *com) { FILE *fp2; int c; + int r; 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"); + r=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 /dev/null"); + r=system("asir /dev/null"); fp2 = fopen("gentexi-out.tmp","r"); if (fp2 == NULL) { @@ -551,4 +730,41 @@ outputOfExample(char *com) { putchar('\n'); } +void +printTitlePage(char *title, char *author,char *infoName) { + printf("\\input texinfo\n"); + printf("@def@colon{:}\n\n"); + printf("@iftex\n"); + printf("@catcode`@#=6\n"); + printf("@def@b#1{{@bf@gt #1}}\n"); + printf("@catcode`@#=@other\n"); + printf("@end iftex\n"); + printf("@overfullrule=0pt\n"); + + if (infoName != NULL) printf("@setfilename %s\n",infoName); + else printf("@setfilename asir-contrib-infoName-is-not-set\n"); + printf("@settitle %s\n",Title); + + printf("@titlepage\n"); + printf("@title %s\n",Title); + printf("@subtitle Edition : auto generated by oxgentexi on @today{}\n"); + if (author != NULL) printf("@author %s\n",author); + printf("@end titlepage\n\n"); + printf("@synindex vr fn\n"); + printf("@node Top,, (dir), (dir)\n\n"); +} + +void +printBye() { + printf("@node Index,,, Top\n"); + printf("@unnumbered Index\n"); + printf("@printindex fn\n"); + printf("@printindex cp\n"); + printf("@iftex\n"); + printf("@vfill @eject\n"); + printf("@end iftex\n"); + printf("@summarycontents\n"); + printf("@contents\n"); + printf("\n@bye\n"); +} /* Old file was OpenXM/src/asir-contrib/packages/doc/gentexi.c */