[BACK]Return to gen_hh.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / html_tools

Annotation of OpenXM/src/asir-doc/html_tools/gen_hh.c, Revision 1.4

1.4     ! ohara       1: /* $OpenXM: OpenXM/src/asir-doc/html_tools/gen_hh.c,v 1.3 2013/08/31 13:45:59 ohara Exp $ */
1.2       ohara       2:
1.1       noro        3: #include <stdio.h>
1.2       ohara       4: #include <stdlib.h>
1.1       noro        5: #include <string.h>
1.3       ohara       6: #if !defined(_MSC_VER)
1.1       noro        7: #include <dirent.h>
1.3       ohara       8: #else
                      9: #include <windows.h>
                     10: #endif
1.1       noro       11:
1.4     ! ohara      12: void gen_hhp(char *out, int n, char *indir, char *prefix_, char *help)
1.1       noro       13: {
                     14:        int i;
                     15:        FILE *outf;
                     16:
                     17:        outf = fopen(out,"w");
                     18:        fprintf(outf,"[OPTIONS]\n");
                     19:        fprintf(outf,"Compatibility=1.1 or later\n");
1.4     ! ohara      20:        fprintf(outf,"Compiled file=%s.chm\n",help);
        !            21:        fprintf(outf,"Contents file=%s.hhc\n",help);
        !            22:        fprintf(outf,"Default topic=%s\\%s_toc.html\n",indir,prefix_);
1.1       noro       23:        fprintf(outf,"Display compile progress=No\n");
1.4     ! ohara      24:        fprintf(outf,"Index file=%s.hhk\n",help);
1.1       noro       25:        fprintf(outf,"Language=0x411 “ú–{Œê\n\n\n[FILES]\n");
                     26:
1.4     ! ohara      27:        fprintf(outf,"%s\\%s_toc.html\n",indir,prefix_);
1.1       noro       28:        for ( i = 1; i <= n; i++ )
1.4     ! ohara      29:                fprintf(outf,"%s\\%s_%d.html\n",indir,prefix_,i);
1.1       noro       30:
                     31:        fprintf(outf,"\n[INFOTYPES]\n");
                     32: }
                     33:
1.4     ! ohara      34: void conv_toc(char *in, char *out, char *prefix_, char *indir)
1.1       noro       35: {
                     36:        char buf[BUFSIZ];
                     37:        char *fname,*ptr,*ptr1;
                     38:        int c;
                     39:        FILE *inf,*outf;
                     40:
                     41:        inf = fopen(in,"r");
                     42:        outf = fopen(out,"w");
                     43:        fprintf(outf,"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n");
                     44:        fprintf(outf,"<HTML>\n<HEAD>\n");
                     45:        fprintf(outf,"<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n");
                     46:        fprintf(outf,"<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n");
                     47:        fprintf(outf,"<OBJECT type=\"text/site properties\">\n");
                     48:        fprintf(outf,"<param name=\"ImageType\" value=\"Folder\">\n");
                     49:        fprintf(outf,"</OBJECT>\n<UL>\n");
                     50:
                     51:        while ( 1 ) {
                     52:                c = fgetc(inf);
                     53:                if ( c == EOF )
                     54:                        break;
                     55:                ungetc(c,inf);
                     56:                fgets(buf,BUFSIZ,inf);
                     57:                if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                     58:                        break;
1.4     ! ohara      59:                if ( fname = strstr(buf,prefix_) ) {
1.1       noro       60:                        ptr = strchr(buf,'#');
                     61:                        *ptr = 0;
                     62:                        ptr = strchr(ptr+1,'>');
                     63:                        ptr++;
                     64:                        if ( *ptr == '<' )
                     65:                                ptr = strchr(ptr+1,'>')+1;
                     66:                        ptr1 = strchr(ptr,'<');
                     67:                        *ptr1 = 0;
                     68:                        fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");
                     69:                        fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);
1.4     ! ohara      70:                        fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",indir,fname);
1.1       noro       71:                        fprintf(outf,"</OBJECT>\n");
                     72:                }
                     73:        }
                     74:        fprintf(outf,"</UL>\n</BODY></HTML>\n");
                     75: }
                     76:
1.4     ! ohara      77: void conv_index(char *in, char *out, char *prefix_, char *indir)
1.1       noro       78: {
                     79:        char buf[BUFSIZ];
                     80:        char *fname,*ptr,*ptr1;
                     81:        FILE *inf,*outf;
                     82:
                     83:        inf = fopen(in,"r");
                     84:        outf = fopen(out,"w");
                     85:
                     86:        fprintf(outf,"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n");
                     87:        fprintf(outf,"<HTML>\n<HEAD>\n");
                     88:        fprintf(outf,"<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n");
                     89:        fprintf(outf,"<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n");
                     90:        fprintf(outf,"</HEAD><BODY>\n");
                     91:
                     92:        while ( 1 ) {
                     93:                fgets(buf,BUFSIZ,inf);
                     94:                if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                     95:                        break;
                     96:        }
                     97:        while ( 1 ) {
                     98:                fgets(buf,BUFSIZ,inf);
                     99:                if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                    100:                        break;
1.4     ! ohara     101:                if ( fname = strstr(buf,prefix_) ) {
1.1       noro      102:                        ptr = strchr(buf,'#');
                    103:                        *ptr = 0;
                    104:                        ptr = strchr(ptr+1,'>');
                    105:                        ptr++;
                    106:                        if ( *ptr == '<' )
                    107:                                ptr = strchr(ptr+1,'>')+1;
                    108:                        ptr1 = strchr(ptr,'<');
                    109:                        *ptr1 = 0;
                    110:                        fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");
                    111:                        fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);
1.4     ! ohara     112:                        fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",indir,fname);
1.1       noro      113:                        fprintf(outf,"</OBJECT>\n");
                    114:                }
                    115:        }
                    116:        fprintf(outf,"</BODY></HTML>\n");
                    117: }
                    118:
1.3       ohara     119: #if !defined(_MSC_VER)
1.4     ! ohara     120: int find_files(char *indir,char *base)
1.1       noro      121: {
                    122:        DIR *d;
                    123:        struct dirent *dent;
1.3       ohara     124:        int n=0,n1;
1.1       noro      125:        char *ptr,*ptr1;
1.3       ohara     126:        char name[BUFSIZ];
1.4     ! ohara     127:        int len=strlen(base);
1.1       noro      128:        d = opendir(indir);
1.3       ohara     129:        if(!d) {
                    130:                exit(1);
                    131:        }
1.1       noro      132:        while ( dent = readdir(d) ) {
                    133:                strcpy(name,dent->d_name);
1.3       ohara     134:                ptr = name+len;
                    135:                ptr = strchr(ptr,'_');
1.1       noro      136:                if ( !ptr )
                    137:                        continue;
                    138:                ptr++;
                    139:                ptr1 = strchr(ptr,'.');
                    140:                if ( !ptr1 )
                    141:                        continue;
                    142:                *ptr1 = 0;
                    143:                if ( !strcmp(ptr,"toc") )
                    144:                        continue;
                    145:                n1 = atoi(ptr);
                    146:                if ( n1 > n )
                    147:                        n = n1;
                    148:        }
1.3       ohara     149:        closedir(d);
                    150:        return n;
                    151: }
                    152: #else
1.4     ! ohara     153: int find_files(char *indir,char *base)
1.3       ohara     154: {
                    155:     HANDLE h;
                    156:     WIN32_FIND_DATA fd;
                    157:     char *ptr,*ptr1;
                    158:     char pattern[BUFSIZ];
                    159:     char name[BUFSIZ];
                    160:        int n=0,n1;
1.4     ! ohara     161:     int len=strlen(base);
        !           162:     sprintf(pattern, "%s\\%s_*.*", indir, base);
1.3       ohara     163:     h = FindFirstFileEx(pattern, FindExInfoStandard, &fd, FindExSearchNameMatch, NULL, 0);
                    164:     if(h == INVALID_HANDLE_VALUE) {
                    165:         exit(1);
                    166:     }
                    167:     do {
                    168:         strcpy(name,fd.cFileName);
                    169:         ptr = name+len;
                    170:         ptr = strchr(ptr,'_') + 1;
                    171:         ptr1 = strchr(ptr,'.');
                    172:         *ptr1 = 0;
                    173:         if ( !strcmp(ptr,"toc") )
                    174:             continue;
                    175:         n1 = atoi(ptr);
                    176:         if ( n1 > n )
                    177:             n = n1;
                    178:     } while(FindNextFile(h, &fd));
                    179:     return n;
                    180: }
                    181: #endif
                    182:
                    183: int main(int argc, char *argv[])
                    184: {
                    185:        int n;
                    186:        char *indir,*outdir;
1.4     ! ohara     187:        char in[BUFSIZ],out[BUFSIZ],prefix_[BUFSIZ];
        !           188:        char *prefix,*lang;
        !           189:        char help[BUFSIZ],base[BUFSIZ];
        !           190:
        !           191:     indir = argv[1];
        !           192:     outdir = argv[2];
        !           193:     prefix = indir;
        !           194:     if(argc>3) {
        !           195:         lang = argv[3];
        !           196:         sprintf(base,"%s-%s",prefix,lang);
        !           197:     }else {
        !           198:         sprintf(base,"%s", "man");
        !           199:     }
        !           200:        sprintf(help,"%shelp",prefix);
        !           201:        sprintf(prefix_,"%s_", base);
        !           202:        sprintf(in,"%s/%s_toc.html",indir,base);
        !           203:        sprintf(out,"%s/%s.hhc",outdir,help);
        !           204:        conv_toc(in,out,prefix_,indir);
        !           205:        n = find_files(indir, base);
        !           206:        sprintf(in,"%s/%s_%d.html",indir,base,n);
        !           207:        sprintf(out,"%s/%s.hhk",outdir,help);
        !           208:        conv_index(in,out,prefix_,indir);
        !           209:        sprintf(out,"%s/%s.hhp",outdir,help);
        !           210:        gen_hhp(out,n,indir,base,help);
        !           211:        return 0;
1.1       noro      212: }

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