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

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

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

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