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

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

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

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