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

1.5     ! ohara       1: /* $OpenXM: OpenXM/src/asir-doc/html_tools/gen_hh.c,v 1.4 2013/09/02 20:08:41 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:
                     91:        while ( 1 ) {
                     92:                fgets(buf,BUFSIZ,inf);
                     93:                if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                     94:                        break;
                     95:        }
                     96:        while ( 1 ) {
                     97:                fgets(buf,BUFSIZ,inf);
                     98:                if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                     99:                        break;
1.4       ohara     100:                if ( fname = strstr(buf,prefix_) ) {
1.1       noro      101:                        ptr = strchr(buf,'#');
                    102:                        *ptr = 0;
                    103:                        ptr = strchr(ptr+1,'>');
                    104:                        ptr++;
                    105:                        if ( *ptr == '<' )
                    106:                                ptr = strchr(ptr+1,'>')+1;
                    107:                        ptr1 = strchr(ptr,'<');
                    108:                        *ptr1 = 0;
                    109:                        fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");
                    110:                        fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);
1.4       ohara     111:                        fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",indir,fname);
1.1       noro      112:                        fprintf(outf,"</OBJECT>\n");
                    113:                }
                    114:        }
                    115:        fprintf(outf,"</BODY></HTML>\n");
                    116: }
                    117:
1.3       ohara     118: #if !defined(_MSC_VER)
1.4       ohara     119: int find_files(char *indir,char *base)
1.1       noro      120: {
                    121:        DIR *d;
                    122:        struct dirent *dent;
1.3       ohara     123:        int n=0,n1;
1.1       noro      124:        char *ptr,*ptr1;
1.3       ohara     125:        char name[BUFSIZ];
1.4       ohara     126:        int len=strlen(base);
1.1       noro      127:        d = opendir(indir);
1.3       ohara     128:        if(!d) {
                    129:                exit(1);
                    130:        }
1.1       noro      131:        while ( dent = readdir(d) ) {
                    132:                strcpy(name,dent->d_name);
1.3       ohara     133:                ptr = name+len;
                    134:                ptr = strchr(ptr,'_');
1.1       noro      135:                if ( !ptr )
                    136:                        continue;
                    137:                ptr++;
                    138:                ptr1 = strchr(ptr,'.');
                    139:                if ( !ptr1 )
                    140:                        continue;
                    141:                *ptr1 = 0;
                    142:                if ( !strcmp(ptr,"toc") )
                    143:                        continue;
                    144:                n1 = atoi(ptr);
                    145:                if ( n1 > n )
                    146:                        n = n1;
                    147:        }
1.3       ohara     148:        closedir(d);
                    149:        return n;
                    150: }
                    151: #else
1.4       ohara     152: int find_files(char *indir,char *base)
1.3       ohara     153: {
                    154:     HANDLE h;
                    155:     WIN32_FIND_DATA fd;
                    156:     char *ptr,*ptr1;
                    157:     char pattern[BUFSIZ];
                    158:     char name[BUFSIZ];
                    159:        int n=0,n1;
1.4       ohara     160:     int len=strlen(base);
                    161:     sprintf(pattern, "%s\\%s_*.*", indir, base);
1.3       ohara     162:     h = FindFirstFileEx(pattern, FindExInfoStandard, &fd, FindExSearchNameMatch, NULL, 0);
                    163:     if(h == INVALID_HANDLE_VALUE) {
                    164:         exit(1);
                    165:     }
                    166:     do {
                    167:         strcpy(name,fd.cFileName);
                    168:         ptr = name+len;
                    169:         ptr = strchr(ptr,'_') + 1;
                    170:         ptr1 = strchr(ptr,'.');
                    171:         *ptr1 = 0;
                    172:         if ( !strcmp(ptr,"toc") )
                    173:             continue;
                    174:         n1 = atoi(ptr);
                    175:         if ( n1 > n )
                    176:             n = n1;
                    177:     } while(FindNextFile(h, &fd));
                    178:     return n;
                    179: }
                    180: #endif
                    181:
                    182: int main(int argc, char *argv[])
                    183: {
                    184:        int n;
                    185:        char *indir,*outdir;
1.4       ohara     186:        char in[BUFSIZ],out[BUFSIZ],prefix_[BUFSIZ];
                    187:        char *prefix,*lang;
                    188:        char help[BUFSIZ],base[BUFSIZ];
                    189:
                    190:     indir = argv[1];
                    191:     outdir = argv[2];
                    192:     prefix = indir;
                    193:     if(argc>3) {
                    194:         lang = argv[3];
                    195:         sprintf(base,"%s-%s",prefix,lang);
                    196:     }else {
                    197:         sprintf(base,"%s", "man");
                    198:     }
                    199:        sprintf(help,"%shelp",prefix);
                    200:        sprintf(prefix_,"%s_", base);
                    201:        sprintf(in,"%s/%s_toc.html",indir,base);
                    202:        sprintf(out,"%s/%s.hhc",outdir,help);
                    203:        conv_toc(in,out,prefix_,indir);
                    204:        n = find_files(indir, base);
                    205:        sprintf(in,"%s/%s_%d.html",indir,base,n);
                    206:        sprintf(out,"%s/%s.hhk",outdir,help);
                    207:        conv_index(in,out,prefix_,indir);
                    208:        sprintf(out,"%s/%s.hhp",outdir,help);
                    209:        gen_hhp(out,n,indir,base,help);
                    210:        return 0;
1.1       noro      211: }

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