Annotation of OpenXM/src/util/oxgentexi.c, Revision 1.14
1.14 ! ohara 1: /* $OpenXM: OpenXM/src/util/oxgentexi.c,v 1.13 2005/07/21 11:29:16 takayama Exp $ */
1.1 takayama 2:
3: #include <stdio.h>
1.12 ohara 4: #include <stdlib.h>
5: #include <string.h>
1.1 takayama 6: int Debug = 0;
7: #define VMAX 20
1.2 takayama 8: #define LIMIT 65536
1.1 takayama 9: #define ITEMMAX 1024
10: struct item {
11: char *category; /* base */
12: char *category2; /* taka_base */
13: char *name; /* base_replace */
14: int argc;
15: char *argv[VMAX]; /* A and Rule of base_replace(A,Rule) */
16: int optc;
17: char *optv[VMAX];
18: char *shortDescription;
19: char *description;
20: char *algorithm;
1.9 takayama 21: char *changelog;
1.1 takayama 22: char *examplev[VMAX];
23: char *exampleDescv[VMAX];
24: int examplec;
25: int refc;
26: char *refv[VMAX];
27: char *author;
1.2 takayama 28: char *sortKey;
29: int type;
1.1 takayama 30: };
31: struct item *getItem(void);
32: char *str(char *key);
33: char *str2(char *key,int size);
34: int cmpItem(struct item *it,struct item *it2);
35:
36: char *S;
37: int Ssize = 256;
38: int Sp = 0;
39: char *Upnode;
40: char *Category=NULL;
41: char *Lang="en";
42: int Include = 0;
43: int GenExample = 0;
1.2 takayama 44: int DebugItem = 0;
1.3 takayama 45: char *Title = NULL;
46: char *Author = NULL;
1.7 takayama 47: char *InfoName = NULL;
1.4 takayama 48: int NoSorting = 0;
1.1 takayama 49:
50: main(int argc,char *argv[]) {
51: char *t;
52: int p,c,n,i;
53: struct item *tt;
54: struct item *items[ITEMMAX];
55:
56: Upnode = str("UNKNOWN");
57: for (i=1; i<argc; i++) {
58: if (strcmp(argv[i],"--upnode") == 0) {
59: i++; if (i >= argc) { fprintf(stderr,"--upnode node-name\n"); exit(1);}
60: Upnode = str(argv[i]);
61: }else if (strcmp(argv[i],"--category") == 0) {
62: i++; if (i >= argc) { fprintf(stderr,"--category category-name\n"); exit(1);}
63: Category = str(argv[i]);
64: }else if (strcmp(argv[i],"--en") == 0) {
65: Lang = "en";
66: }else if (strcmp(argv[i],"--ja") == 0) {
67: Lang = "ja";
68: }else if (strcmp(argv[i],"--include") == 0) {
69: Include = 1;
70: }else if (strcmp(argv[i],"--example") == 0) {
71: GenExample = 1;
72: }else if (strcmp(argv[i],"--debug") == 0) {
73: Debug = 1;
1.2 takayama 74: }else if (strcmp(argv[i],"--debugItem") == 0) {
75: DebugItem = 1;
1.3 takayama 76: }else if (strcmp(argv[i],"--title") == 0) {
77: i++; Title = str(argv[i]);
1.7 takayama 78: }else if (strcmp(argv[i],"--infoName") == 0) {
79: i++; InfoName = str(argv[i]);
1.3 takayama 80: }else if (strcmp(argv[i],"--author") == 0) {
81: i++; Author = str(argv[i]);
1.4 takayama 82: }else if (strcmp(argv[i],"--noSorting") == 0) {
83: NoSorting = 1;
1.1 takayama 84: }else {
85: fprintf(stderr,"Unknown option\n"); exit(1);
86: }
87: }
88: S = (char *)malloc(Ssize);
89: /* Read data from stdin to the string buffer S */
90: while ((c=getchar()) != EOF) {
91: S[Sp++] = c; S[Sp] = 0;
92: if (Sp >= Ssize-3) {
93: Ssize = 2*Ssize;
94: t = S;
95: S = (char *)malloc(Ssize);
96: if (S == NULL) {
97: fprintf(stderr,"No more memory to allocate S.\n");
98: exit(20);
99: }
100: strcpy(S,t);
101: }
102: }
103:
104: /* Read items */
105: n = 0;
106: while ((tt = getItem()) != NULL) {
107: if (Debug) printItem(tt);
108: if (n >= ITEMMAX) {
109: fprintf(stderr,"Too many entries.\n"); exit(1);
110: }
111: if (Category != NULL) {
112: if (strcmp(Category,tt->category) == 0 ||
113: strcmp(Category,tt->category2) == 0) {
114: items[n++] = tt;
115: }
116: }else{
117: items[n++] = tt;
118: }
119: }
1.4 takayama 120:
121: if (!NoSorting) {
122: if (Debug) fprintf(stderr,"Sorting...\n");
123: shell(items,n);
124: if (Debug) fprintf(stderr,"Done.\n");
125: }
1.2 takayama 126:
127: if (DebugItem) {
128: for (i=0; i<n; i++) {
129: printItem(items[i]);
130: }
131: exit(0);
132: }
133:
1.7 takayama 134: if (Title) printTitlePage(Title,Author,InfoName);
1.3 takayama 135:
1.1 takayama 136: printMenu(stdout,items,n);
137:
138: for (i=0; i<n; i++) {
139: printTexi(stdout,items[i]);
140: }
1.3 takayama 141:
142: if (Title) printBye();
1.1 takayama 143: exit(0);
144: }
145:
146: genInclude(char *name) {
147: char fname[4098];
148: FILE *fp;
149: int c;
150:
151: sprintf(fname,"tmp/%s-auto-%s.texi",name,Lang);
152: fp = fopen(fname,"r");
153: if (fp == NULL) {
154: /* fprintf(stderr,"No file %s\n",fname); */
155: return 0;
156: }
157: while ((c=fgetc(fp)) != EOF) {
158: putchar(c);
159: }
160: putchar('\n');
161: fclose(fp);
162: return 0;
163: }
164:
165: cmpItem(struct item *it,struct item *it2) {
1.2 takayama 166: return strcmp(it->sortKey,it2->sortKey);
1.1 takayama 167: }
168: struct item * newItem(){
169: struct item *a;
170: a = (struct item *)malloc(sizeof(struct item));
171: if (a == NULL) {
172: fprintf(stderr,"newItem: No more memory.\n");
173: exit(20);
174: }
1.14 ! ohara 175: memset(a, 0, sizeof(struct item));
1.1 takayama 176: return a;
177: }
178:
179: nextToken(char *key,int n) {
180: static int pos = 0;
181: int i = 0;
182: if (pos >= Ssize) return -1;
183: while (S[pos] <= ' ') {
184: pos++;
185: if (pos >= Ssize) return -1;
186: }
187: while (S[pos] > ' ') {
188: key[i++] = S[pos++]; key[i] = 0;
189: if (i >= n-1) {
190: fprintf(stderr,"Too big key word.\n");
191: fprintf(stderr,"key=%s\n",key);
192: exit(10);
193: }
194: if (S[pos-1] == '(' ||
195: S[pos-1] == ')' ||
196: S[pos-1] == ',' ||
197: S[pos-1] == '{' ||
198: S[pos-1] == '}' ||
199: S[pos-1] == '|' ) {
200: return pos;
201: }
202: if (S[pos] == '(' ||
203: S[pos] == ')' ||
204: S[pos] == ',' ||
205: S[pos] == '{' ||
206: S[pos] == '}' ||
207: S[pos] == '|' ) {
208: return pos;
209: }
210:
211: }
212: if (Debug) fprintf(stderr,"token=%s\n",key);
213: return pos;
214: }
215:
216: printItem(struct item *it) {
217: int i;
218: if (it == NULL) return;
219: if (it->category != NULL)
220: printf("category=%s\n",it->category);
221: if (it->category2 != NULL)
222: printf("category2=%s\n",it->category2);
223: if (it->name != NULL)
224: printf("name=%s\n",it->name);
225: for (i=0; i<it->argc; i++)
226: printf(" argv[%d]=%s\n",i,it->argv[i]);
227: for (i=0; i<it->optc; i++)
228: printf(" optv[%d]=%s\n",i,it->optv[i]);
229: if (it->shortDescription != NULL)
230: printf("shortDescription=%s\n",it->shortDescription);
231: if (it->description != NULL)
232: printf("description=%s\n",it->description);
233: if (it->algorithm != NULL)
234: printf("algorithm=%s\n",it->algorithm);
235: for (i=0; i <it->examplec; i++)
236: printf("examplev[%d]=%s\n",i,it->examplev[i]);
237: for (i=0; i <it->examplec; i++)
238: printf("exampleDescv[%d]=%s\n",i,it->exampleDescv[i]);
1.9 takayama 239: if (it->changelog != NULL)
240: printf("changelog=%s\n",it->changelog);
1.1 takayama 241: for (i=0; i<it->refc; i++)
242: printf(" refv[%d]=%s\n",i,it->refv[i]);
243: if (it->author != NULL)
244: printf("author=%s\n",it->author);
1.2 takayama 245: if (it->sortKey != NULL)
246: printf("sortKey=%s\n",it->sortKey);
1.1 takayama 247: printf("\n");
248: }
249:
250: char *str(char *key) {
251: char *s;
252: s = (char *)malloc(strlen(key)+1);
253: if (s == NULL) {
254: fprintf(stderr,"str: No more memory.\n");
255: exit(20);
256: }
257: strcpy(s,key);
258: return s;
259: }
260: char *str2(char *key,int size) {
261: char *s;
262: int i;
263: s = (char *)malloc(size+1);
264: if (s == NULL) {
265: fprintf(stderr,"str2: No more memory.\n");
266: exit(20);
267: }
268: for (i=0; i<size; i++) {
269: s[i] = key[i]; s[i+1] = 0;
270: }
271: return s;
272: }
273: char *getCategory(char *key) {
274: int i,n;
275: char *s;
276: s = str(key);
277: for (i=0; i<strlen(s); i++) {
278: if ((s[i] == '_') || s[i] == '.') {
279: s[i] = 0;
280: return s;
281: }
282: }
283: return s;
284: }
285: char *getCategory2(char *key) {
286: int i,n;
287: char *s;
288: int count;
289: s = str(key);
290: for (i=0; i<strlen(s); i++) {
291: if ((s[i] == '_') || (s[i] == '.')) count++;
292: if (count == 2) {
293: s[i] = 0; return s;
294: }
295: }
296: return s;
297: }
298:
299:
300: struct item *getItem() {
301: char key[LIMIT];
302: char key2[LIMIT];
303: struct item *it;
304: int p;
305: int pp,pOld;
306: int argc;
307: int examplec = 0;
1.6 takayama 308: int i;
1.1 takayama 309: it = newItem();
310: do {
311: p = nextToken(key,LIMIT);
312: /* printf("%s\n",key); */
313: if (strcmp(key,"begin:") == 0) break;
314: }while (p >= 0);
315: if (p < 0) {
316: /* fprintf(stderr,"gentexi: End of input file.\n"); */
317: return NULL;
318: }
319: p = nextToken(key,LIMIT);
1.2 takayama 320: it->name = it->sortKey = str(key);
1.1 takayama 321: it->category = getCategory(key);
322: it->category2 = getCategory2(key);
323: nextToken(key,LIMIT);
324: if (strcmp(key,"(") != 0) {
1.2 takayama 325: pp = p+1;
326: it->type = 1; /* For non-functions */
1.3 takayama 327: goto LL ;
1.2 takayama 328: }else{
329: it->type = 0; /* For functions */
330: argc = 0;
331: while ((pp=nextToken(key,LIMIT)) >= 0) {
332: if (strcmp(key,"|") == 0) {
333: /* options */
334: argc = 0;
335: while ((pp=nextToken(key,LIMIT)) >= 0) {
336: if (strcmp(key,")") == 0) {
337: break;
338: }
339: if (strcmp(key,",") != 0) {
340: it->optv[argc] = str(key);
341: argc++; it->optc = argc;
342: }
343: if (argc >+ VMAX -1) {
344: fprintf(stderr,"Too many opt args at %s\n",it->name);
345: exit(10);
346: }
1.1 takayama 347: }
348: }
1.2 takayama 349: if (strcmp(key,")") == 0) {
350: break;
351: }else if (strcmp(key,",") != 0) {
352: it->argv[argc] = str(key);
353: argc++; it->argc=argc;
354: }
355: if (argc >= VMAX-1) {
356: fprintf(stderr,"Too many args at %s\n",it->name);
357: exit(10);
358: }
1.1 takayama 359: }
360: }
361:
362: /* Getting the short Description */
363: p = pp;
364: do {
365: pOld = p;
366: p = nextToken(key,LIMIT);
367: /* printf("%s\n",key); */
368: if (key[strlen(key)-1] == ':') break; /* Next keyword. */
369: }while (p >= 0);
370: it->shortDescription = str2(&(S[pp]),pOld-pp);
371:
1.3 takayama 372: LL: ;
373: if (it->type == 1 ) {strcpy(key,"description:"); p++; }
1.1 takayama 374: do {
375: /* Get Description or Examples */
376: if (strcmp(key,"end:") == 0) break;
377: if (strcmp(key,"description:") == 0 ||
378: strcmp(key,"algorithm:") == 0 ||
379: strcmp(key,"author:") == 0 ||
1.9 takayama 380: strcmp(key,"changelog:") == 0 ||
1.2 takayama 381: strcmp(key,"sortKey:") == 0 ||
1.1 takayama 382: strcmp(key,"example:") == 0 ||
1.2 takayama 383: strcmp(key,"example_description:") ==0 ) {
1.1 takayama 384: pp = p;
385: strcpy(key2,key);
386: do {
387: pOld = p;
388: p = nextToken(key,LIMIT);
1.5 takayama 389: /* printf("key=%s\n",key); */
390: if (key[strlen(key)-1] == ':') {
391: pOld = p-strlen(key);
392: break; /* Next keyword. */
393: }
1.1 takayama 394: }while (p >= 0);
395: if (strcmp(key2,"description:") == 0) {
396: it->description = str2(&(S[pp]),pOld-pp);
397: }
398: if (strcmp(key2,"example:") == 0) {
399: it->examplev[examplec++] = str2(&(S[pp]),pOld-pp);
400: it->exampleDescv[examplec-1] = "";
401: it->examplec = examplec;
402: if (examplec > VMAX-1) {
403: fprintf(stderr,"Too many examples. \n");
404: exit(20);
405: }
406: }
407: if (strcmp(key2,"example_description:") == 0) {
408: it->exampleDescv[examplec-1] = str2(&(S[pp]),pOld-pp);
409: }
410: if (strcmp(key2,"author:") == 0) {
411: it->author = str2(&(S[pp]),pOld-pp);
412: }
1.2 takayama 413: if (strcmp(key2,"sortKey:") == 0) {
414: while (S[pp] <= ' ') pp++;
415: it->sortKey = str2(&(S[pp]),pOld-pp);
416: }
1.1 takayama 417: if (strcmp(key2,"algorithm:") == 0) {
418: it->algorithm = str2(&(S[pp]),pOld-pp);
419: }
1.9 takayama 420: if (strcmp(key2,"changelog:") == 0) {
421: it->changelog = str2(&(S[pp]),pOld-pp);
422: }
1.1 takayama 423: }else if (strcmp(key,"ref:") == 0) {
424: argc = 0;
425: while ((pp=nextToken(key,LIMIT)) >= 0) {
426: p = pp;
427: if (key[strlen(key)-1] == ':') break;
428: if (strcmp(key,",") != 0) {
429: it->refv[argc] = str(key);
430: argc++; it->refc = argc;
431: }
432: if (argc >= VMAX-1) {
433: fprintf(stderr,"Too many args for Ref at %s\n",it->name);
434: exit(10);
435: }
436: }
437: }else{
1.6 takayama 438: fprintf(stderr,"Error: unknown keyword << %s >> at %s.\n",key, it->name);
439: fprintf(stderr," The error occurs around ");
440: for (i=pp ; i < p; i++) fputc(S[i],stderr);
441: fprintf(stderr,"\n\n");
442: exit(1);
1.1 takayama 443: p = nextToken(key,LIMIT);
444: }
445: }while (p >= 0);
446:
447: return it;
448: }
449:
450: shell(struct item *v[],int n) {
451: int gap,i,j;
452: struct item *temp;
453:
454: for (gap = n/2; gap > 0; gap /= 2) {
455: for (i = gap; i<n; i++) {
456: for (j=i-gap ; j>=0 && cmpItem(v[j],v[j+gap])>0 ; j -= gap) {
457: temp = v[j];
458: v[j] = v[j+gap];
459: v[j+gap] = temp;
460: }
461: }
462: }
463: }
464:
465: printMenu(FILE *fp, struct item **it, int n) {
1.2 takayama 466: int i,m;
1.1 takayama 467:
1.2 takayama 468: m = 0;
1.1 takayama 469: for ( i = 0; i < n; i++ )
1.2 takayama 470: if (it[i]->type != 1) m++;
471: if (m != 0) {
472: fprintf(fp,"@menu\n");
473: for ( i = 0; i < n; i++ )
474: if (it[i]->type != 1) fprintf(fp,"* %s::\n",it[i]->name);
475: fprintf(fp,"@end menu\n");
476: }
1.1 takayama 477: }
478:
479: printTexi(FILE *fp, struct item *it) {
480: int i;
1.2 takayama 481: if (it->type == 1) return printTexi1(fp,it);
482: else return printTexi0(fp,it);
483: }
484:
485: printTexi_common(FILE *fp,struct item *it) {
486: int i;
1.10 takayama 487: if ((it->shortDescription != NULL) || (it->refc >0)
488: || (it->examplec > 0)) {
489: if (it->description != NULL) {
1.11 takayama 490: fprintf(fp,"\nDescription:\n");
1.10 takayama 491: fprintf(fp,"@quotation\n%s\n@end quotation\n\n",it->description);
492: }
493: }else {
494: if (it->description != NULL) {
495: fprintf(fp,"%s\n\n",it->description);
496: }
1.2 takayama 497: }
498:
499: if (it->algorithm != NULL) {
1.9 takayama 500: fprintf(fp,"\n\n@noindent\nAlgorithm: \n@quotation\n");
501: fprintf(fp,"%s\n@end quotation\n",it->algorithm);
1.2 takayama 502: }
503:
504: if (it->examplec > 0) {
505: for (i=0; i<it->examplec; i++) {
506: if (it->examplec == 1) {
507: fprintf(fp,"Example:\n");
508: }else{
509: fprintf(fp,"Example %d:\n",i);
510: }
511: fprintf(fp,"@example\n");
1.3 takayama 512: outputExample(fp,it->examplev[i]);
1.2 takayama 513: if (GenExample) {
514: outputOfExample(it->examplev[i]);
515: }
516: fprintf(fp,"@end example\n");
517: if (it->exampleDescv[i] != NULL && strlen(it->exampleDescv[i]) > 0) {
518: fprintf(fp,"%s\n\n",it->exampleDescv[i]);
519: }
520: }
521: }
522: if (it->author != NULL) {
523: fprintf(fp,"Author : %s\n\n",it->author);
524: }
1.9 takayama 525: if (it->changelog != NULL) {
526: fprintf(fp,"\n\nChange Log:\n@quotation\n");
527: fprintf(fp,"%s\n@end quotation\n",it->changelog);
528: }
1.2 takayama 529: if (it->refc > 0) {
1.9 takayama 530: fprintf(fp,"\n\nReferences:\n@quotation\n");
1.2 takayama 531: for (i=0; i <it->refc; i++) {
1.9 takayama 532: fprintf(fp," @code{%s} ",it->refv[i]);
533: if (i != it->refc-1) fprintf(fp,", \n");
1.2 takayama 534: }
1.9 takayama 535: fprintf(fp,"\n@end quotation\n");
1.2 takayama 536: }
537: fprintf(fp,"\n");
538: }
539:
540: printTexi0(FILE *fp, struct item *it) {
541: int i;
542:
1.5 takayama 543: fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for asir function item.\n");
1.1 takayama 544: if (it == NULL) {
545: fprintf(fp,"@c item is NULL.\n");
546: return ;
547: }
1.3 takayama 548: fprintf(fp,"@c sortKey: %s\n",it->sortKey);
1.1 takayama 549: if (it->name == NULL) {
550: fprintf(fp,"@c item name is missing.\n");
551: return ;
552: }
553:
554: #if 0
555: fprintf(fp,"@menu\n");
556: fprintf(fp,"* %s::\n",it->name);
557: fprintf(fp,"@end menu\n");
558: #endif
559: fprintf(fp,"@node %s,,, %s\n",it->name,Upnode);
560: fprintf(fp,"@subsection @code{%s}\n",it->name);
561: fprintf(fp,"@findex %s\n",it->name);
562: fprintf(fp,"@table @t\n");
563: fprintf(fp,"@item %s(",it->name);
564: for (i=0; i<it->argc; i++) {
565: fprintf(fp,"@var{%s}",it->argv[i]);
566: if (i != it->argc-1) fprintf(fp,",");
567: }
568: fprintf(fp,")\n");
569: if (it->shortDescription != NULL) {
570: fprintf(fp,": ");
571: for (i=0; i<strlen(it->shortDescription); i++) {
572: if (it->shortDescription[i] == '{') {
573: fprintf(fp,"@var{");
574: }else {
575: fprintf(fp,"%c",it->shortDescription[i]);
576: }
577: }
578: fprintf(fp," \n");
579: }
580: if (it->optc > 0) {
581: fprintf(fp,"@item %s(",it->name);
582: for (i=0; i<it->argc; i++) {
583: fprintf(fp,"@var{%s}",it->argv[i]);
584: if (i != it->argc-1) fprintf(fp,",");
585: }
586: fprintf(fp," | ");
587: for (i=0; i<it->optc; i++) {
588: fprintf(fp,"@var{%s}=key%d",it->optv[i],i);
589: if (i != it->optc-1) fprintf(fp,",");
590: }
591: fprintf(fp,")\n");
592: fprintf(fp,": This function allows optional variables \n ");
593: for (i=0; i<it->optc; i++) {
594: fprintf(fp,"@var{%s}",it->optv[i]);
595: if (i != it->optc-1) fprintf(fp,", ");
596: }
597: fprintf(fp,"\n");
598: }
599: fprintf(fp,"@end table\n");
600:
601: /* include file */
602: if (Include) {
603: if (genInclude(it->name))
604: fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name);
605: }
606: fprintf(fp,"@c @itemize @bullet \n");
607: fprintf(fp,"@c @item \n");
608: fprintf(fp,"@c @end itemize\n");
609:
1.2 takayama 610: printTexi_common(fp,it);
611: }
612:
613: printTexi1(FILE *fp, struct item *it) {
614: int i;
615: /* For it->type == 1 */
616:
1.5 takayama 617: fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for verbose item.\n");
1.2 takayama 618: if (it == NULL) {
619: fprintf(fp,"@c item is NULL.\n");
620: return ;
1.1 takayama 621: }
1.3 takayama 622: fprintf(fp,"@c sortKey: %s\n",it->sortKey);
1.1 takayama 623:
1.2 takayama 624: if (it->shortDescription != NULL) {
625: for (i=0; i<strlen(it->shortDescription); i++) {
626: fprintf(fp,"%c",it->shortDescription[i]);
1.1 takayama 627: }
1.2 takayama 628: fprintf(fp," \n");
1.1 takayama 629: }
1.2 takayama 630:
631: /* include file */
632: if (Include) {
633: if (genInclude(it->name))
634: fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name);
1.1 takayama 635: }
1.2 takayama 636:
637: printTexi_common(fp,it);
1.1 takayama 638: }
639:
1.3 takayama 640: outputExample(FILE *fp,char *s) {
641: int i;
1.13 takayama 642: /* Remove unnecessary spaces at the tail. */
643: for (i=strlen(s)-1; i>=0; i--) {
644: if (s[i] == '\n') break;
645: else if (s[i] <= ' ') {s[i] = 0;}
646: else break;
647: }
1.3 takayama 648: for (i=0; s[i] != 0; i++) {
1.4 takayama 649: if (s[i] == '@') {
650: if (s[i+1] == '{') {fprintf(fp,"%s","@{"); i += 1;}
651: else if (s[i+1] == '}') {fprintf(fp,"%s","@}"); i += 1;}
652: else if (s[i+1] == '@') {fprintf(fp,"%s","@@"); i += 1;}
653: else if (strncmp(&(s[i+1]),"colon",5)==0) {
654: fprintf(fp,":"); i += 5;
655: }else fprintf(fp,"@@");
656: }else{
1.6 takayama 657: if (s[i] == '{') {fprintf(fp,"%s","@{"); }
658: else if (s[i] == '}') {fprintf(fp,"%s","@}");}
659: else fputc(s[i],fp);
1.4 takayama 660: }
1.3 takayama 661: }
662: }
663:
1.1 takayama 664: outputOfExample(char *com) {
665: FILE *fp2;
666: int c;
667: fp2 = fopen("gentexi-in.tmp","w");
668: if (fp2 == NULL) {
669: fprintf(stderr,"Cannot open tentexi-in.tmp\n");
670: exit(10);
671: }
672: system("rm -f gentexi-out.tmp");
673: fprintf(fp2,"output(\"gentexi-out.tmp\")$\n");
674: fprintf(fp2,"%s\n",com);
675: fprintf(fp2,"output()$\n");
676: fprintf(fp2,"quit;");
677: fclose(fp2);
678: system("asir <gentexi-in.tmp >/dev/null");
679:
680: fp2 = fopen("gentexi-out.tmp","r");
681: if (fp2 == NULL) {
682: fprintf(stderr,"Cannot open tentexi-in.tmp\n");
683: exit(10);
684: }
685: while ((c=fgetc(fp2)) != EOF) {
686: putchar(c);
687: }
688: putchar('\n');
689: }
690:
1.7 takayama 691: printTitlePage(char *title, char *author,char *infoName) {
1.3 takayama 692: printf("\\input texinfo\n");
693: printf("@def@colon{:}\n\n");
694: printf("@iftex\n");
695: printf("@catcode`@#=6\n");
696: printf("@def@b#1{{@bf@gt #1}}\n");
697: printf("@catcode`@#=@other\n");
698: printf("@end iftex\n");
699: printf("@overfullrule=0pt\n");
700:
1.7 takayama 701: if (infoName != NULL) printf("@setfilename %s\n",infoName);
1.8 takayama 702: else printf("@setfilename asir-contrib-infoName-is-not-set\n");
1.3 takayama 703: printf("@settitle %s\n",Title);
704:
705: printf("@titlepage\n");
706: printf("@title %s\n",Title);
707: printf("@subtitle Edition : auto generated by oxgentexi on @today{}\n");
708: if (author != NULL) printf("@author %s\n",author);
709: printf("@end titlepage\n\n");
710: printf("@synindex vr fn\n");
711: printf("@node Top,, (dir), (dir)\n\n");
712: }
713:
714: printBye() {
1.7 takayama 715: printf("@node Index,,, Top\n");
716: printf("@unnumbered Index\n");
717: printf("@printindex fn\n");
718: printf("@printindex cp\n");
719: printf("@iftex\n");
720: printf("@vfill @eject\n");
721: printf("@end iftex\n");
722: printf("@summarycontents\n");
723: printf("@contents\n");
1.3 takayama 724: printf("\n@bye\n");
725: }
1.1 takayama 726: /* Old file was OpenXM/src/asir-contrib/packages/doc/gentexi.c */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>