[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.6

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

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