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

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

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