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

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

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

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