[BACK]Return to oxgentexi.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / util

Annotation of OpenXM/src/util/oxgentexi.c, Revision 1.6

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>