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

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

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

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