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

Diff for /OpenXM/src/asir-doc/html_tools/gen_hh.c between version 1.1 and 1.6

version 1.1, 2001/03/15 03:33:09 version 1.6, 2017/08/31 06:42:51
Line 1 
Line 1 
   /* $OpenXM: OpenXM/src/asir-doc/html_tools/gen_hh.c,v 1.5 2017/08/31 03:53:00 ohara Exp $ */
   
 #include <stdio.h>  #include <stdio.h>
   #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #if !defined(_MSC_VER)
 #include <dirent.h>  #include <dirent.h>
   #else
   #include <windows.h>
   #endif
   
 gen_hhp(out,n)  #define HEADER_INDEX \
 char *out;    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" \
 int n;    "<HTML>\n<HEAD>\n" \
     "<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n" \
     "<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n"
   
   #define HEADER_TOC \
     "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" \
     "<HTML>\n<HEAD>\n" \
     "<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n" \
     "<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n" \
     "<OBJECT type=\"text/site properties\">\n" \
     "<param name=\"ImageType\" value=\"Folder\">\n" \
     "</OBJECT>\n<UL>\n"
   
   void gen_hhp(char *out, int n, char *indir, char *prefix_, char *help)
 {  {
         int i;          int i;
         FILE *outf;          FILE *outf;
Line 12  int n;
Line 32  int n;
         outf = fopen(out,"w");          outf = fopen(out,"w");
         fprintf(outf,"[OPTIONS]\n");          fprintf(outf,"[OPTIONS]\n");
         fprintf(outf,"Compatibility=1.1 or later\n");          fprintf(outf,"Compatibility=1.1 or later\n");
         fprintf(outf,"Compiled file=asirhelp.chm\n");          fprintf(outf,"Compiled file=%s.chm\n",help);
         fprintf(outf,"Contents file=asirhelp.hhc\n");          fprintf(outf,"Contents file=%s.hhc\n",help);
         fprintf(outf,"Default topic=html\\man_toc.html\n");          fprintf(outf,"Default topic=%s\\%s_toc.html\n",indir,prefix_);
         fprintf(outf,"Display compile progress=No\n");          fprintf(outf,"Display compile progress=No\n");
         fprintf(outf,"Index file=asirhelp.hhk\n");          fprintf(outf,"Index file=%s.hhk\n",help);
         fprintf(outf,"Language=0x411 日本語\n\n\n[FILES]\n");          fprintf(outf,"Language=0x411 日本語\n\n\n[FILES]\n");
   
         fprintf(outf,"html\\man_toc.html\n");          fprintf(outf,"%s\\%s_toc.html\n",indir,prefix_);
         for ( i = 1; i <= n; i++ )          for ( i = 1; i <= n; i++ )
                 fprintf(outf,"html\\man_%d.html\n",i);                  fprintf(outf,"%s\\%s_%d.html\n",indir,prefix_,i);
   
         fprintf(outf,"\n[INFOTYPES]\n");          fprintf(outf,"\n[INFOTYPES]\n");
 }  }
   
 conv_toc(in,out)  void conv_toc(char *in, char *out, char *prefix_, char *indir)
 char *in,*out;  
 {  {
         char buf[BUFSIZ];          char buf[BUFSIZ];
         char *fname,*ptr,*ptr1;          char *fname,*ptr,*ptr1;
Line 36  char *in,*out;
Line 55  char *in,*out;
   
         inf = fopen(in,"r");          inf = fopen(in,"r");
         outf = fopen(out,"w");          outf = fopen(out,"w");
         fprintf(outf,"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n");          fputs(HEADER_TOC,outf);
         fprintf(outf,"<HTML>\n<HEAD>\n");  
         fprintf(outf,"<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n");  
         fprintf(outf,"<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n");  
         fprintf(outf,"<OBJECT type=\"text/site properties\">\n");  
         fprintf(outf,"<param name=\"ImageType\" value=\"Folder\">\n");  
         fprintf(outf,"</OBJECT>\n<UL>\n");  
   
         while ( 1 ) {          while ( 1 ) {
                 c = fgetc(inf);                  c = fgetc(inf);
Line 52  char *in,*out;
Line 65  char *in,*out;
                 fgets(buf,BUFSIZ,inf);                  fgets(buf,BUFSIZ,inf);
                 if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )                  if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                         break;                          break;
                 if ( fname = strstr(buf,"man_") ) {                  if ( fname = strstr(buf,prefix_) ) {
                         ptr = strchr(buf,'#');                          ptr = strchr(buf,'#');
                           if(!ptr) continue;
                         *ptr = 0;                          *ptr = 0;
                         ptr = strchr(ptr+1,'>');                          ptr = strchr(ptr+1,'>');
                         ptr++;                          ptr++;
                         if ( *ptr == '<' )                          if ( *ptr == '<' )
                                 ptr = strchr(ptr+1,'>')+1;                                  ptr = strchr(ptr+1,'>')+1;
                         ptr1 = strchr(ptr,'<');                          ptr1 = strchr(ptr,'<');
                         *ptr1 = 0;                          if(ptr1) *ptr1 = 0;
                         fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");                          fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");
                         fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);                          fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);
                         fprintf(outf,"<param name=\"Local\" value=\"html\\%s\">\n",fname);                          fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",indir,fname);
                         fprintf(outf,"</OBJECT>\n");                          fprintf(outf,"</OBJECT>\n");
                 }                  }
         }          }
         fprintf(outf,"</UL>\n</BODY></HTML>\n");          fprintf(outf,"</UL>\n</BODY></HTML>\n");
 }  }
   
 conv_index (in,out)  void conv_index(char *in, char *out, char *prefix_, char *indir)
 char *in,*out;  
 {  {
         char buf[BUFSIZ];          char buf[BUFSIZ];
         char *fname,*ptr,*ptr1;          char *fname,*ptr,*ptr1;
Line 80  char *in,*out;
Line 93  char *in,*out;
         inf = fopen(in,"r");          inf = fopen(in,"r");
         outf = fopen(out,"w");          outf = fopen(out,"w");
   
         fprintf(outf,"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n");          fputs(HEADER_INDEX, outf);
         fprintf(outf,"<HTML>\n<HEAD>\n");  
         fprintf(outf,"<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n");  
         fprintf(outf,"<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n");  
         fprintf(outf,"</HEAD><BODY>\n");  
   
         while ( 1 ) {          while ( 1 ) {
                 fgets(buf,BUFSIZ,inf);                  fgets(buf,BUFSIZ,inf);
Line 95  char *in,*out;
Line 104  char *in,*out;
                 fgets(buf,BUFSIZ,inf);                  fgets(buf,BUFSIZ,inf);
                 if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )                  if ( !strncmp(buf,"Jump to:",strlen("Jump to:")) )
                         break;                          break;
                 if ( fname = strstr(buf,"man_") ) {                  if ( fname = strstr(buf,prefix_) ) {
                         ptr = strchr(buf,'#');                          ptr = strchr(buf,'#');
                           if(!ptr) continue;
                         *ptr = 0;                          *ptr = 0;
                         ptr = strchr(ptr+1,'>');                          ptr = strchr(ptr+1,'>');
                         ptr++;                          ptr++;
                         if ( *ptr == '<' )                          if ( *ptr == '<' )
                                 ptr = strchr(ptr+1,'>')+1;                                  ptr = strchr(ptr+1,'>')+1;
                         ptr1 = strchr(ptr,'<');                          ptr1 = strchr(ptr,'<');
                         *ptr1 = 0;                          if(ptr1) *ptr1 = 0;
                         fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");                          fprintf(outf,"<LI><OBJECT type=\"text/sitemap\">\n");
                         fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);                          fprintf(outf,"<param name=\"Name\" value=\"%s\">\n",ptr);
                         fprintf(outf,"<param name=\"Local\" value=\"html\\%s\">\n",fname);                          fprintf(outf,"<param name=\"Local\" value=\"%s\\%s\">\n",indir,fname);
                         fprintf(outf,"</OBJECT>\n");                          fprintf(outf,"</OBJECT>\n");
                 }                  }
         }          }
         fprintf(outf,"</BODY></HTML>\n");          fprintf(outf,"</BODY></HTML>\n");
 }  }
   
 main(argc,argv)  #if !defined(_MSC_VER)
 int argc;  int find_files(char *indir,char *base)
 char **argv;  
 {  {
         DIR *d;          DIR *d;
         struct dirent *dent;          struct dirent *dent;
         int i,n,n1;          int n=0,n1;
         char *ptr,*ptr1;          char *ptr,*ptr1;
         char *indir,*outdir;          char name[BUFSIZ];
         char in[BUFSIZ],out[BUFSIZ],name[BUFSIZ];          int len=strlen(base);
   
         indir = argv[1];  
         outdir = argv[2];  
         sprintf(in,"%s/man_toc.html",indir);  
         sprintf(out,"%s/asirhelp.hhc",outdir);  
         conv_toc(in,out);  
         d = opendir(indir);          d = opendir(indir);
         n = 0;          if(!d) {
                   exit(1);
           }
         while ( dent = readdir(d) ) {          while ( dent = readdir(d) ) {
                 strcpy(name,dent->d_name);                  strcpy(name,dent->d_name);
                 ptr = strchr(name,'_');                  ptr = name+len;
                   ptr = strchr(ptr,'_');
                 if ( !ptr )                  if ( !ptr )
                         continue;                          continue;
                 ptr++;                  ptr++;
Line 147  char **argv;
Line 153  char **argv;
                 if ( n1 > n )                  if ( n1 > n )
                         n = n1;                          n = n1;
         }          }
         sprintf(in,"%s/man_%d.html",indir,n);          closedir(d);
         sprintf(out,"%s/asirhelp.hhk",outdir);          return n;
         conv_index(in,out);  }
         sprintf(out,"%s/asirhelp.hhp",outdir);  #else
         gen_hhp(out,n);  int find_files(char *indir,char *base)
         exit(0);  {
       HANDLE h;
       WIN32_FIND_DATA fd;
       char *ptr,*ptr1;
       char pattern[BUFSIZ];
       char name[BUFSIZ];
           int n=0,n1;
       int len=strlen(base);
       sprintf(pattern, "%s\\%s_*.*", indir, base);
       h = FindFirstFileEx(pattern, FindExInfoStandard, &fd, FindExSearchNameMatch, NULL, 0);
       if(h == INVALID_HANDLE_VALUE) {
           exit(1);
       }
       do {
           strcpy(name,fd.cFileName);
           ptr = name+len;
           ptr = strchr(ptr,'_') + 1;
           ptr1 = strchr(ptr,'.');
           *ptr1 = 0;
           if ( !strcmp(ptr,"toc") )
               continue;
           n1 = atoi(ptr);
           if ( n1 > n )
               n = n1;
       } while(FindNextFile(h, &fd));
       return n;
   }
   #endif
   
   int main(int argc, char *argv[])
   {
           int n;
           char *indir,*outdir;
           char in[BUFSIZ],out[BUFSIZ],prefix_[BUFSIZ];
           char *prefix,*lang;
           char help[BUFSIZ],base[BUFSIZ];
   
       indir = argv[1];
       outdir = argv[2];
       prefix = indir;
       if(argc>3) {
           lang = argv[3];
           sprintf(base,"%s-%s",prefix,lang);
       }else {
           sprintf(base,"%s", "man");
       }
           sprintf(help,"%shelp",prefix);
           sprintf(prefix_,"%s_", base);
           sprintf(in,"%s/%s_toc.html",indir,base);
           sprintf(out,"%s/%s.hhc",outdir,help);
           conv_toc(in,out,prefix_,indir);
           n = find_files(indir, base);
           sprintf(in,"%s/%s_%d.html",indir,base,n);
           sprintf(out,"%s/%s.hhk",outdir,help);
           conv_index(in,out,prefix_,indir);
           sprintf(out,"%s/%s.hhp",outdir,help);
           gen_hhp(out,n,indir,base,help);
           return 0;
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

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