4 Command-Line Options

      Available Options
      Scanning the Options

Available Options

   dvips -mode ibmvga -D 110 -f foo.idv -pp 92  > tmp.ps 
   convert -crop 0x0 -density 110x110 -transparent ’#FFFFFF’ tmp.ps foo.gif 
   mv foo.gif /WWW/temp/. 
   cp foo.html /WWW/temp/. 
   chmod 644 /WWW/temp/foo.* 

<..command line options..>
 "\n--------------------------------------------------------------------\n"
 "t4ht [-f<dir char>]filename ...\n"
 "  -b     ignore -d -m -M for bitmaps\n"
 "  -c...  choose named segment in env file\n"
 "  -d...  directory for output files       (default:  current)\n"
 "  -e...  location of tex4ht.env\n"
 "  -i     debugging info\n"
 "  -g     ignore errors in system calls\n"
 "  -m...  chmod ... of new output files (reused bitmaps excluded)\n"
 "  -p     don’t convert pictures           (default:  convert)\n"
 "  -r     replace bitmaps of all glyphs    (default:  reuse old ones)\n"
 "  -M...  chmod ... of all output files\n"
 "  -Q     quit, if tex4ht.c had problems\n"
 "  -S...  permission for system calls: *-always, filter\n"
 "  -X...  content for field %%3 in X scripts\n"
 "  -....  content for field %%2 in . scripts\n\n"
 "Example: \n"
 "   t4ht name -d/WWW/temp/ -etex4ht-32.env -m644\n"
 "--------------------------------------------------------------------\n"
 -_-_-

If option ‘-e’ is present, empty pictures are replaced with the named file (e.g., ‘empty.gif’).

Scanning the Options

<..vars..>+
 static Q_CHAR *ch_mod = Q_NULL;
 static Q_CHAR *debug = Q_NULL;
 static Q_CHAR *Xfield = Q_NULL;
 static Q_CHAR *Dotfield = Q_NULL;
 static Q_CHAR *dir = Q_NULL;
 static Q_CHAR *lg_name  = Q_NULL, tmp_name[255], job_name[255];
 static Q_CHAR *nopict = Q_NULL;
 static Q_CHAR *bitmaps_no_dm = Q_NULL;
 static BOOL newchmod = FALSE;
 static Q_CHAR *noreuse = Q_NULL;
 -_-_-

<..scan job args..>
 {      int i;
        Q_CHAR *p, *q;
   <.kpathsea arg 0.>
   <.default args.>
   if( argc == 1 ){ bad_arg; }
   for(i=1; i<argc; i++){
     if( *( p=argv[i] ) == ’-’ ){ <.scan flaged args.> }
     else
     {  lg_name = argv[i];  }
   }
   if( lg_name == NULL ){ bad_arg; }
   <.set tmp file name.>
   <.set job file name.>
 }
 -_-_-

<..handle quoted arguments..>
 { int i, count = 0;
  for(i=0; i<argc; i++){
    Q_CHAR *p = argv[i];
    count++;
    if( (*p == ’\’’) || (*p == ’\"’) ){
      int cnt;
      int len = 0;
      for( cnt=i; cnt < argc; cnt++ ){
        len += (int) strlen((char *) argv[cnt]);
        if( *(argv[cnt] + (int) strlen((char *) argv[cnt]) -1) == *p ){
            Q_CHAR * arg = m_alloc(char, len + cnt - i + 1);
            Q_CHAR * toArg = arg;
            Q_CHAR *pp;
            i--;
            do {
              pp = argv[++i];
              while( *pp != ’\0’ ){
                 if( *pp != *p ){ *(toArg++) = *pp; }
                 pp++;
              }
              *(toArg++) =  ’;
            } while ( i != cnt );
            *(toArg-1) = ’\0’;
            argv[count-1] = arg;
            break;
  } } } }
  argc = count;
 }
 -_-_-

<..set tmp file name..>
 {                                 Q_CHAR   *p, *q;
                                   FILE*    file;
    (IGNORED) strcpy((char *) (char *) tmp_name, (char *) (char *) lg_name);
    p = q = tmp_name + strlen((char *)  tmp_name );
    while( p != tmp_name ){
       if( *p == ’.’ ){
           if( eq_str( p+1,LG_EXT ) ) { *p = ’\0’; }
           else {
             (IGNORED) strct( tmp_name, LG_EXT);
             file =  fopen( tmp_name, READ_TEXT_FLAGS );
             if( file ){
               (IGNORED) fclose(file); *q = ’\0’;
             } else {  *p = ’\0’; }
           }
           break;
       }
       p--;
    }
    (IGNORED) strct(tmp_name, ".tmp");
 }
 -_-_-

<..set job file name..>
 (IGNORED) strcpy((char *)  job_name, (char *) tmp_name);
 *(job_name + strlen((char *) job_name) - 4) = ’\0’;
 -_-_-

I found that I couldn’t compile t4ht.c with KPATHSEA defined, and then noticed 
that it doesn’t include any of the kpathsea headers.  So I have patched t4ht.c 
to create two versions:  one with the necessary kpathsea headers and one 
without.  This is the output produced by ’diff’.  Let me know if you want to 
merge my changes into your t4ht.c, and/or if you notice any errors!  I have 
changed the second argument of ’kpse_set_program_name’ from NULL (which would 
effectively mean argv[0]) to ’tex4ht’, as that saves having to add a 
’T4HTINPUTS’ (or ’T4HTKINPUTS’) variable into the kpathsea configuration file 
’texmf.cnf’ pointing to the same place for ’tex4ht.env’ as the ’TEX4HTINPUTS’ 
variable. 
 
For t4ht.c, the kpathsea library is only useful for locating the tex4ht.env 
configuration file.  But as it can be used for this purpose for tex4ht.c, it 
seems a pity not to enable it for its companion program too. 
 
> 94a99,102 
> > #ifdef KPATHSEA 
> > #include <kpathsea/progname.h> 
> > #include <kpathsea/tex-file.h> 
> > #endif 
> 943c951 
> <    kpse_set_program_name (argv[0], NULL); 
> --- 
> >    kpse_set_program_name (argv[0], "tex4ht"); 

<..kpathsea arg 0..>
 #ifdef KPATHSEA
    kpse_set_program_name (argv[0], "tex4ht");
 #endif
 -_-_-

If ‘strlen((char *) argv[i] ) == 2’ the switch is followed by a space to be deleted when more input is awaited.

<..scan flaged args..>
 if( (int) strlen((char *)  argv[i] ) == 2 ){
    if( <.not a single char option?.> )
      { if( ++i == argc ) bad_arg; }
    q = argv[i];
 } else q = p+2;
 switch( *(p+1) ){
   case ’M’:{ ch_mod = q;  newchmod = TRUE; break; }
   case ’S’:{ <.permission for system calls.> break; }
   case ’X’:{ Xfield = q;  break;}
   case ’b’:{ bitmaps_no_dm = q-1;  break;}
   case ’c’:{ <.env blocks selector.>  break;}
   case ’d’:{ dir = (*q==’~’)? abs_addr(q,NULL) : q;  break; }
   case ’e’:{ <.get .env directory from com ln.> break; }
   case ’f’:{ <.get file name wo dir.> break; }
   case ’i’:{ debug = q-1;  break;}
   case ’g’:{ always_call_sys = TRUE;  break;}
   case ’m’:{ ch_mod = q;  break; }
   case ’p’:{ nopict = q-1;  break;}
   case ’Q’:{ check_tex4ht_c_err = TRUE;  break;}
   case ’r’:{ noreuse = q-1;  break;}
   case ’.’:{ Dotfield = q;  break;}
    default:{ bad_arg;  }
 }
 -_-_-

<..not a single char option?..>
    (*(p+1) != ’i’)
 && (*(p+1) != ’p’)
 && (*(p+1) != ’r’)
 && (*(p+1) != ’b’)
 && (*(p+1) != ’g’)
 && (*(p+1) != ’Q’)
 -_-_-

The following is to allow for commands ‘htlatex -f/../source/foo.tex’ which draw files from other directories for latex, but use the current directory for tex4ht.c (and t4ht.c). The character immediately after ‘-f’ is a directory indicator character.

<..get file name wo dir..>
 p = p + 2;
 lg_name = p + (int) strlen((char *)  p );
 while( *lg_name != *p ){ lg_name--; }
 lg_name++;
 -_-_-

<..header functions..>+
 static char *  abs_addr( ARG_II( U_CHAR *, U_CHAR *) );
 -_-_-

<..functions..>+
 
 static char *  abs_addr( dir, base)
                                                  U_CHAR  *dir;
                                                  U_CHAR  *base
 
 ;{                                         U_CHAR  *p;
    p = m_alloc(char, (int) strlen((char *)  dir ) +
                      (base? (int) strlen((char *)  base ):0) +
                      (int) strlen((char *)  HOME_DIR  ));
    *p = ’\0’;
    if( (*(dir+1) == ’~’) && base ){
      if( *base == ’~’ ){
        (IGNORED) strct(p, HOME_DIR);
        (IGNORED) strct(p, base+1);
      } else {
        (IGNORED) strct(p, base);
      }
      (IGNORED) strct(p, dir+2);
    } else {
      (IGNORED) strct(p, HOME_DIR);
      (IGNORED) strct(p, dir+1);
    }
    return p;
 }
 -_-_-

<..vars..>+
 U_CHAR *HOME_DIR;
 -_-_-

<..main’s init..>
 HOME_DIR = getenv("HOME");
 -_-_-