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

Annotation of OpenXM/src/asir-doc/html_tools/gen_hh_new.c, Revision 1.6

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

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