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

1.3     ! ohara       1: /* $OpenXM: OpenXM/src/asir-doc/html_tools/gen_hh.c,v 1.2 2009/02/22 22:48:15 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.3     ! ohara      12: void gen_hhp(char *out, int n, char *htmldir)
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");
                     20:        fprintf(outf,"Compiled file=asirhelp.chm\n");
                     21:        fprintf(outf,"Contents file=asirhelp.hhc\n");
1.3     ! ohara      22:        fprintf(outf,"Default topic=%s\\man_toc.html\n",htmldir);
1.1       noro       23:        fprintf(outf,"Display compile progress=No\n");
                     24:        fprintf(outf,"Index file=asirhelp.hhk\n");
                     25:        fprintf(outf,"Language=0x411 “ú–{Œê\n\n\n[FILES]\n");
                     26:
1.3     ! ohara      27:        fprintf(outf,"%s\\man_toc.html\n",htmldir);
1.1       noro       28:        for ( i = 1; i <= n; i++ )
1.3     ! ohara      29:                fprintf(outf,"%s\\man_%d.html\n",htmldir,i);
1.1       noro       30:
                     31:        fprintf(outf,"\n[INFOTYPES]\n");
                     32: }
                     33:
1.3     ! ohara      34: void conv_toc(char *in,char *out, char *htmldir)
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;
                     59:                if ( fname = strstr(buf,"man_") ) {
                     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.3     ! ohara      70:                        fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",htmldir,fname);
1.1       noro       71:                        fprintf(outf,"</OBJECT>\n");
                     72:                }
                     73:        }
                     74:        fprintf(outf,"</UL>\n</BODY></HTML>\n");
                     75: }
                     76:
1.3     ! ohara      77: void conv_index(char *in, char *out, char *htmldir)
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;
                    101:                if ( fname = strstr(buf,"man_") ) {
                    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.3     ! ohara     112:                        fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",htmldir,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)
        !           120: int find_files(char *indir,char *prefix)
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];
        !           127:        int len=strlen(prefix);
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
        !           153: int find_files(char *indir,char *prefix)
        !           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;
        !           161:     int len=strlen(prefix);
        !           162:     sprintf(pattern, "%s\\%s*_*.*", indir, prefix);
        !           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;
        !           187:        char in[BUFSIZ],out[BUFSIZ];
        !           188:        char *htmldir="html";
        !           189:
        !           190:        indir = argv[1];
        !           191:        outdir = argv[2];
        !           192:        if(argc>3) {
        !           193:                htmldir=argv[3];
        !           194:        }
        !           195:
        !           196:        sprintf(in,"%s/man_toc.html",indir);
        !           197:        sprintf(out,"%s/asirhelp.hhc",outdir);
        !           198:        conv_toc(in,out,htmldir);
        !           199:        n = find_files(indir, "");
        !           200:
1.1       noro      201:        sprintf(in,"%s/man_%d.html",indir,n);
                    202:        sprintf(out,"%s/asirhelp.hhk",outdir);
1.3     ! ohara     203:        conv_index(in,out,htmldir);
1.1       noro      204:        sprintf(out,"%s/asirhelp.hhp",outdir);
1.3     ! ohara     205:        gen_hhp(out,n,htmldir);
1.1       noro      206:        exit(0);
                    207: }

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