Annotation of OpenXM/src/util/oxgentexi.c, Revision 1.12
1.12 ! ohara 1: /* $OpenXM: OpenXM/src/util/oxgentexi.c,v 1.11 2005/06/15 02:38:01 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: }
175: a->argc = 0; a->optc = 0; a->refc=0; a->examplec = 0;
1.2 takayama 176: a->type=0;
1.1 takayama 177: a->category = a->category2 = a->name = a->shortDescription
1.2 takayama 178: = a->description = a->author = a->algorithm = a->sortKey = NULL;
1.1 takayama 179: return a;
180: }
181:
182: nextToken(char *key,int n) {
183: static int pos = 0;
184: int i = 0;
185: if (pos >= Ssize) return -1;
186: while (S[pos] <= ' ') {
187: pos++;
188: if (pos >= Ssize) return -1;
189: }
190: while (S[pos] > ' ') {
191: key[i++] = S[pos++]; key[i] = 0;
192: if (i >= n-1) {
193: fprintf(stderr,"Too big key word.\n");
194: fprintf(stderr,"key=%s\n",key);
195: exit(10);
196: }
197: if (S[pos-1] == '(' ||
198: S[pos-1] == ')' ||
199: S[pos-1] == ',' ||
200: S[pos-1] == '{' ||
201: S[pos-1] == '}' ||
202: S[pos-1] == '|' ) {
203: return pos;
204: }
205: if (S[pos] == '(' ||
206: S[pos] == ')' ||
207: S[pos] == ',' ||
208: S[pos] == '{' ||
209: S[pos] == '}' ||
210: S[pos] == '|' ) {
211: return pos;
212: }
213:
214: }
215: if (Debug) fprintf(stderr,"token=%s\n",key);
216: return pos;
217: }
218:
219: printItem(struct item *it) {
220: int i;
221: if (it == NULL) return;
222: if (it->category != NULL)
223: printf("category=%s\n",it->category);
224: if (it->category2 != NULL)
225: printf("category2=%s\n",it->category2);
226: if (it->name != NULL)
227: printf("name=%s\n",it->name);
228: for (i=0; i<it->argc; i++)
229: printf(" argv[%d]=%s\n",i,it->argv[i]);
230: for (i=0; i<it->optc; i++)
231: printf(" optv[%d]=%s\n",i,it->optv[i]);
232: if (it->shortDescription != NULL)
233: printf("shortDescription=%s\n",it->shortDescription);
234: if (it->description != NULL)
235: printf("description=%s\n",it->description);
236: if (it->algorithm != NULL)
237: printf("algorithm=%s\n",it->algorithm);
238: for (i=0; i <it->examplec; i++)
239: printf("examplev[%d]=%s\n",i,it->examplev[i]);
240: for (i=0; i <it->examplec; i++)
241: printf("exampleDescv[%d]=%s\n",i,it->exampleDescv[i]);
1.9 takayama 242: if (it->changelog != NULL)
243: printf("changelog=%s\n",it->changelog);
1.1 takayama 244: for (i=0; i<it->refc; i++)
245: printf(" refv[%d]=%s\n",i,it->refv[i]);
246: if (it->author != NULL)
247: printf("author=%s\n",it->author);
1.2 takayama 248: if (it->sortKey != NULL)
249: printf("sortKey=%s\n",it->sortKey);
1.1 takayama 250: printf("\n");
251: }
252:
253: char *str(char *key) {
254: char *s;
255: s = (char *)malloc(strlen(key)+1);
256: if (s == NULL) {
257: fprintf(stderr,"str: No more memory.\n");
258: exit(20);
259: }
260: strcpy(s,key);
261: return s;
262: }
263: char *str2(char *key,int size) {
264: char *s;
265: int i;
266: s = (char *)malloc(size+1);
267: if (s == NULL) {
268: fprintf(stderr,"str2: No more memory.\n");
269: exit(20);
270: }
271: for (i=0; i<size; i++) {
272: s[i] = key[i]; s[i+1] = 0;
273: }
274: return s;
275: }
276: char *getCategory(char *key) {
277: int i,n;
278: char *s;
279: s = str(key);
280: for (i=0; i<strlen(s); i++) {
281: if ((s[i] == '_') || s[i] == '.') {
282: s[i] = 0;
283: return s;
284: }
285: }
286: return s;
287: }
288: char *getCategory2(char *key) {
289: int i,n;
290: char *s;
291: int count;
292: s = str(key);
293: for (i=0; i<strlen(s); i++) {
294: if ((s[i] == '_') || (s[i] == '.')) count++;
295: if (count == 2) {
296: s[i] = 0; return s;
297: }
298: }
299: return s;
300: }
301:
302:
303: struct item *getItem() {
304: char key[LIMIT];
305: char key2[LIMIT];
306: struct item *it;
307: int p;
308: int pp,pOld;
309: int argc;
310: int examplec = 0;
1.6 takayama 311: int i;
1.1 takayama 312: it = newItem();
313: do {
314: p = nextToken(key,LIMIT);
315: /* printf("%s\n",key); */
316: if (strcmp(key,"begin:") == 0) break;
317: }while (p >= 0);
318: if (p < 0) {
319: /* fprintf(stderr,"gentexi: End of input file.\n"); */
320: return NULL;
321: }
322: p = nextToken(key,LIMIT);
1.2 takayama 323: it->name = it->sortKey = str(key);
1.1 takayama 324: it->category = getCategory(key);
325: it->category2 = getCategory2(key);
326: nextToken(key,LIMIT);
327: if (strcmp(key,"(") != 0) {
1.2 takayama 328: pp = p+1;
329: it->type = 1; /* For non-functions */
1.3 takayama 330: goto LL ;
1.2 takayama 331: }else{
332: it->type = 0; /* For functions */
333: argc = 0;
334: while ((pp=nextToken(key,LIMIT)) >= 0) {
335: if (strcmp(key,"|") == 0) {
336: /* options */
337: argc = 0;
338: while ((pp=nextToken(key,LIMIT)) >= 0) {
339: if (strcmp(key,")") == 0) {
340: break;
341: }
342: if (strcmp(key,",") != 0) {
343: it->optv[argc] = str(key);
344: argc++; it->optc = argc;
345: }
346: if (argc >+ VMAX -1) {
347: fprintf(stderr,"Too many opt args at %s\n",it->name);
348: exit(10);
349: }
1.1 takayama 350: }
351: }
1.2 takayama 352: if (strcmp(key,")") == 0) {
353: break;
354: }else if (strcmp(key,",") != 0) {
355: it->argv[argc] = str(key);
356: argc++; it->argc=argc;
357: }
358: if (argc >= VMAX-1) {
359: fprintf(stderr,"Too many args at %s\n",it->name);
360: exit(10);
361: }
1.1 takayama 362: }
363: }
364:
365: /* Getting the short Description */
366: p = pp;
367: do {
368: pOld = p;
369: p = nextToken(key,LIMIT);
370: /* printf("%s\n",key); */
371: if (key[strlen(key)-1] == ':') break; /* Next keyword. */
372: }while (p >= 0);
373: it->shortDescription = str2(&(S[pp]),pOld-pp);
374:
1.3 takayama 375: LL: ;
376: if (it->type == 1 ) {strcpy(key,"description:"); p++; }
1.1 takayama 377: do {
378: /* Get Description or Examples */
379: if (strcmp(key,"end:") == 0) break;
380: if (strcmp(key,"description:") == 0 ||
381: strcmp(key,"algorithm:") == 0 ||
382: strcmp(key,"author:") == 0 ||
1.9 takayama 383: strcmp(key,"changelog:") == 0 ||
1.2 takayama 384: strcmp(key,"sortKey:") == 0 ||
1.1 takayama 385: strcmp(key,"example:") == 0 ||
1.2 takayama 386: strcmp(key,"example_description:") ==0 ) {
1.1 takayama 387: pp = p;
388: strcpy(key2,key);
389: do {
390: pOld = p;
391: p = nextToken(key,LIMIT);
1.5 takayama 392: /* printf("key=%s\n",key); */
393: if (key[strlen(key)-1] == ':') {
394: pOld = p-strlen(key);
395: break; /* Next keyword. */
396: }
1.1 takayama 397: }while (p >= 0);
398: if (strcmp(key2,"description:") == 0) {
399: it->description = str2(&(S[pp]),pOld-pp);
400: }
401: if (strcmp(key2,"example:") == 0) {
402: it->examplev[examplec++] = str2(&(S[pp]),pOld-pp);
403: it->exampleDescv[examplec-1] = "";
404: it->examplec = examplec;
405: if (examplec > VMAX-1) {
406: fprintf(stderr,"Too many examples. \n");
407: exit(20);
408: }
409: }
410: if (strcmp(key2,"example_description:") == 0) {
411: it->exampleDescv[examplec-1] = str2(&(S[pp]),pOld-pp);
412: }
413: if (strcmp(key2,"author:") == 0) {
414: it->author = str2(&(S[pp]),pOld-pp);
415: }
1.2 takayama 416: if (strcmp(key2,"sortKey:") == 0) {
417: while (S[pp] <= ' ') pp++;
418: it->sortKey = str2(&(S[pp]),pOld-pp);
419: }
1.1 takayama 420: if (strcmp(key2,"algorithm:") == 0) {
421: it->algorithm = str2(&(S[pp]),pOld-pp);
422: }
1.9 takayama 423: if (strcmp(key2,"changelog:") == 0) {
424: it->changelog = str2(&(S[pp]),pOld-pp);
425: }
1.1 takayama 426: }else if (strcmp(key,"ref:") == 0) {
427: argc = 0;
428: while ((pp=nextToken(key,LIMIT)) >= 0) {
429: p = pp;
430: if (key[strlen(key)-1] == ':') break;
431: if (strcmp(key,",") != 0) {
432: it->refv[argc] = str(key);
433: argc++; it->refc = argc;
434: }
435: if (argc >= VMAX-1) {
436: fprintf(stderr,"Too many args for Ref at %s\n",it->name);
437: exit(10);
438: }
439: }
440: }else{
1.6 takayama 441: fprintf(stderr,"Error: unknown keyword << %s >> at %s.\n",key, it->name);
442: fprintf(stderr," The error occurs around ");
443: for (i=pp ; i < p; i++) fputc(S[i],stderr);
444: fprintf(stderr,"\n\n");
445: exit(1);
1.1 takayama 446: p = nextToken(key,LIMIT);
447: }
448: }while (p >= 0);
449:
450: return it;
451: }
452:
453: shell(struct item *v[],int n) {
454: int gap,i,j;
455: struct item *temp;
456:
457: for (gap = n/2; gap > 0; gap /= 2) {
458: for (i = gap; i<n; i++) {
459: for (j=i-gap ; j>=0 && cmpItem(v[j],v[j+gap])>0 ; j -= gap) {
460: temp = v[j];
461: v[j] = v[j+gap];
462: v[j+gap] = temp;
463: }
464: }
465: }
466: }
467:
468: printMenu(FILE *fp, struct item **it, int n) {
1.2 takayama 469: int i,m;
1.1 takayama 470:
1.2 takayama 471: m = 0;
1.1 takayama 472: for ( i = 0; i < n; i++ )
1.2 takayama 473: if (it[i]->type != 1) m++;
474: if (m != 0) {
475: fprintf(fp,"@menu\n");
476: for ( i = 0; i < n; i++ )
477: if (it[i]->type != 1) fprintf(fp,"* %s::\n",it[i]->name);
478: fprintf(fp,"@end menu\n");
479: }
1.1 takayama 480: }
481:
482: printTexi(FILE *fp, struct item *it) {
483: int i;
1.2 takayama 484: if (it->type == 1) return printTexi1(fp,it);
485: else return printTexi0(fp,it);
486: }
487:
488: printTexi_common(FILE *fp,struct item *it) {
489: int i;
1.10 takayama 490: if ((it->shortDescription != NULL) || (it->refc >0)
491: || (it->examplec > 0)) {
492: if (it->description != NULL) {
1.11 takayama 493: fprintf(fp,"\nDescription:\n");
1.10 takayama 494: fprintf(fp,"@quotation\n%s\n@end quotation\n\n",it->description);
495: }
496: }else {
497: if (it->description != NULL) {
498: fprintf(fp,"%s\n\n",it->description);
499: }
1.2 takayama 500: }
501:
502: if (it->algorithm != NULL) {
1.9 takayama 503: fprintf(fp,"\n\n@noindent\nAlgorithm: \n@quotation\n");
504: fprintf(fp,"%s\n@end quotation\n",it->algorithm);
1.2 takayama 505: }
506:
507: if (it->examplec > 0) {
508: for (i=0; i<it->examplec; i++) {
509: if (it->examplec == 1) {
510: fprintf(fp,"Example:\n");
511: }else{
512: fprintf(fp,"Example %d:\n",i);
513: }
514: fprintf(fp,"@example\n");
1.3 takayama 515: outputExample(fp,it->examplev[i]);
1.2 takayama 516: if (GenExample) {
517: outputOfExample(it->examplev[i]);
518: }
519: fprintf(fp,"@end example\n");
520: if (it->exampleDescv[i] != NULL && strlen(it->exampleDescv[i]) > 0) {
521: fprintf(fp,"%s\n\n",it->exampleDescv[i]);
522: }
523: }
524: }
525: if (it->author != NULL) {
526: fprintf(fp,"Author : %s\n\n",it->author);
527: }
1.9 takayama 528: if (it->changelog != NULL) {
529: fprintf(fp,"\n\nChange Log:\n@quotation\n");
530: fprintf(fp,"%s\n@end quotation\n",it->changelog);
531: }
1.2 takayama 532: if (it->refc > 0) {
1.9 takayama 533: fprintf(fp,"\n\nReferences:\n@quotation\n");
1.2 takayama 534: for (i=0; i <it->refc; i++) {
1.9 takayama 535: fprintf(fp," @code{%s} ",it->refv[i]);
536: if (i != it->refc-1) fprintf(fp,", \n");
1.2 takayama 537: }
1.9 takayama 538: fprintf(fp,"\n@end quotation\n");
1.2 takayama 539: }
540: fprintf(fp,"\n");
541: }
542:
543: printTexi0(FILE *fp, struct item *it) {
544: int i;
545:
1.5 takayama 546: fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for asir function item.\n");
1.1 takayama 547: if (it == NULL) {
548: fprintf(fp,"@c item is NULL.\n");
549: return ;
550: }
1.3 takayama 551: fprintf(fp,"@c sortKey: %s\n",it->sortKey);
1.1 takayama 552: if (it->name == NULL) {
553: fprintf(fp,"@c item name is missing.\n");
554: return ;
555: }
556:
557: #if 0
558: fprintf(fp,"@menu\n");
559: fprintf(fp,"* %s::\n",it->name);
560: fprintf(fp,"@end menu\n");
561: #endif
562: fprintf(fp,"@node %s,,, %s\n",it->name,Upnode);
563: fprintf(fp,"@subsection @code{%s}\n",it->name);
564: fprintf(fp,"@findex %s\n",it->name);
565: fprintf(fp,"@table @t\n");
566: fprintf(fp,"@item %s(",it->name);
567: for (i=0; i<it->argc; i++) {
568: fprintf(fp,"@var{%s}",it->argv[i]);
569: if (i != it->argc-1) fprintf(fp,",");
570: }
571: fprintf(fp,")\n");
572: if (it->shortDescription != NULL) {
573: fprintf(fp,": ");
574: for (i=0; i<strlen(it->shortDescription); i++) {
575: if (it->shortDescription[i] == '{') {
576: fprintf(fp,"@var{");
577: }else {
578: fprintf(fp,"%c",it->shortDescription[i]);
579: }
580: }
581: fprintf(fp," \n");
582: }
583: if (it->optc > 0) {
584: fprintf(fp,"@item %s(",it->name);
585: for (i=0; i<it->argc; i++) {
586: fprintf(fp,"@var{%s}",it->argv[i]);
587: if (i != it->argc-1) fprintf(fp,",");
588: }
589: fprintf(fp," | ");
590: for (i=0; i<it->optc; i++) {
591: fprintf(fp,"@var{%s}=key%d",it->optv[i],i);
592: if (i != it->optc-1) fprintf(fp,",");
593: }
594: fprintf(fp,")\n");
595: fprintf(fp,": This function allows optional variables \n ");
596: for (i=0; i<it->optc; i++) {
597: fprintf(fp,"@var{%s}",it->optv[i]);
598: if (i != it->optc-1) fprintf(fp,", ");
599: }
600: fprintf(fp,"\n");
601: }
602: fprintf(fp,"@end table\n");
603:
604: /* include file */
605: if (Include) {
606: if (genInclude(it->name))
607: fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name);
608: }
609: fprintf(fp,"@c @itemize @bullet \n");
610: fprintf(fp,"@c @item \n");
611: fprintf(fp,"@c @end itemize\n");
612:
1.2 takayama 613: printTexi_common(fp,it);
614: }
615:
616: printTexi1(FILE *fp, struct item *it) {
617: int i;
618: /* For it->type == 1 */
619:
1.5 takayama 620: fprintf(fp,"@c DO NOT EDIT THIS FILE. Generated by gentexi for verbose item.\n");
1.2 takayama 621: if (it == NULL) {
622: fprintf(fp,"@c item is NULL.\n");
623: return ;
1.1 takayama 624: }
1.3 takayama 625: fprintf(fp,"@c sortKey: %s\n",it->sortKey);
1.1 takayama 626:
1.2 takayama 627: if (it->shortDescription != NULL) {
628: for (i=0; i<strlen(it->shortDescription); i++) {
629: fprintf(fp,"%c",it->shortDescription[i]);
1.1 takayama 630: }
1.2 takayama 631: fprintf(fp," \n");
1.1 takayama 632: }
1.2 takayama 633:
634: /* include file */
635: if (Include) {
636: if (genInclude(it->name))
637: fprintf(fp,"@c @include tmp/%s-auto-en.texi\n",it->name);
1.1 takayama 638: }
1.2 takayama 639:
640: printTexi_common(fp,it);
1.1 takayama 641: }
642:
1.3 takayama 643: outputExample(FILE *fp,char *s) {
644: int i;
645: for (i=0; s[i] != 0; i++) {
1.4 takayama 646: if (s[i] == '@') {
647: if (s[i+1] == '{') {fprintf(fp,"%s","@{"); i += 1;}
648: else if (s[i+1] == '}') {fprintf(fp,"%s","@}"); i += 1;}
649: else if (s[i+1] == '@') {fprintf(fp,"%s","@@"); i += 1;}
650: else if (strncmp(&(s[i+1]),"colon",5)==0) {
651: fprintf(fp,":"); i += 5;
652: }else fprintf(fp,"@@");
653: }else{
1.6 takayama 654: if (s[i] == '{') {fprintf(fp,"%s","@{"); }
655: else if (s[i] == '}') {fprintf(fp,"%s","@}");}
656: else fputc(s[i],fp);
1.4 takayama 657: }
1.3 takayama 658: }
659: }
660:
1.1 takayama 661: outputOfExample(char *com) {
662: FILE *fp2;
663: int c;
664: fp2 = fopen("gentexi-in.tmp","w");
665: if (fp2 == NULL) {
666: fprintf(stderr,"Cannot open tentexi-in.tmp\n");
667: exit(10);
668: }
669: system("rm -f gentexi-out.tmp");
670: fprintf(fp2,"output(\"gentexi-out.tmp\")$\n");
671: fprintf(fp2,"%s\n",com);
672: fprintf(fp2,"output()$\n");
673: fprintf(fp2,"quit;");
674: fclose(fp2);
675: system("asir <gentexi-in.tmp >/dev/null");
676:
677: fp2 = fopen("gentexi-out.tmp","r");
678: if (fp2 == NULL) {
679: fprintf(stderr,"Cannot open tentexi-in.tmp\n");
680: exit(10);
681: }
682: while ((c=fgetc(fp2)) != EOF) {
683: putchar(c);
684: }
685: putchar('\n');
686: }
687:
1.7 takayama 688: printTitlePage(char *title, char *author,char *infoName) {
1.3 takayama 689: printf("\\input texinfo\n");
690: printf("@def@colon{:}\n\n");
691: printf("@iftex\n");
692: printf("@catcode`@#=6\n");
693: printf("@def@b#1{{@bf@gt #1}}\n");
694: printf("@catcode`@#=@other\n");
695: printf("@end iftex\n");
696: printf("@overfullrule=0pt\n");
697:
1.7 takayama 698: if (infoName != NULL) printf("@setfilename %s\n",infoName);
1.8 takayama 699: else printf("@setfilename asir-contrib-infoName-is-not-set\n");
1.3 takayama 700: printf("@settitle %s\n",Title);
701:
702: printf("@titlepage\n");
703: printf("@title %s\n",Title);
704: printf("@subtitle Edition : auto generated by oxgentexi on @today{}\n");
705: if (author != NULL) printf("@author %s\n",author);
706: printf("@end titlepage\n\n");
707: printf("@synindex vr fn\n");
708: printf("@node Top,, (dir), (dir)\n\n");
709: }
710:
711: printBye() {
1.7 takayama 712: printf("@node Index,,, Top\n");
713: printf("@unnumbered Index\n");
714: printf("@printindex fn\n");
715: printf("@printindex cp\n");
716: printf("@iftex\n");
717: printf("@vfill @eject\n");
718: printf("@end iftex\n");
719: printf("@summarycontents\n");
720: printf("@contents\n");
1.3 takayama 721: printf("\n@bye\n");
722: }
1.1 takayama 723: /* Old file was OpenXM/src/asir-contrib/packages/doc/gentexi.c */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>