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