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

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

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

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