home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / bin / texi2dvi.cmd < prev    next >
Encoding:
Text File  |  1992-08-12  |  4.4 KB  |  199 lines

  1. /* texi2dvi.cmd */
  2.  
  3. '@echo off'
  4.  
  5. /* Change the next line to have_diff = 1 if you have GNU diff */
  6.  
  7. have_diff = 0
  8. tex_prog = 'tex386'
  9.  
  10. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  11. call SysLoadFuncs
  12.  
  13. debug = 0
  14. force = 0
  15.  
  16. parse arg arg1 rest
  17. do while (length( arg1) >= 2) & (substr( arg1, 1, 1) = '-')
  18.   if arg1 = '-h' then
  19.     call Usage
  20.   else if arg1 = '-d' then
  21.     debug = 1
  22.   else if arg1 = '-f' then
  23.     force = 1
  24.   else
  25.   do
  26.     say arg1 'is not a valid option'
  27.     exit 1
  28.   end
  29.   options = options arg1
  30.   parse var rest arg1 rest
  31. end
  32. if arg1 = '' then
  33. do
  34.   say 'Missing file name; use -h for help'
  35.   exit 1
  36. end
  37. if \ (rest = '') then
  38. do
  39.   say 'Too many command line arguments:' rest
  40.   exit 1
  41. end
  42.  
  43. inputfile = arg1
  44. if debug then say 'Input file:' inputfile
  45. if \ exists( inputfile) then
  46. do
  47.   say inputfile 'does not exist'
  48.   exit 1
  49. end
  50.  
  51. parse var inputfile basename '.' ext
  52. if debug then say inputfile 'time:' gettime( inputfile)
  53.  
  54. dvifile = basename'.dvi'
  55. if (\ force) & exists( dvifile) then
  56. do
  57.   if debug then say dvifile 'time:' gettime( dvifile)
  58.   if newer( dvifile, inputfile) then
  59.   do
  60.     say dvifile 'is up-to-date'
  61.     exit 0
  62.   end
  63. end
  64.  
  65. call get_index_files 'orig_index_files'
  66. delete_files = ''
  67. do i = 1 to words( orig_index_files)
  68.   src = word( orig_index_files, i)
  69.   parse var src indexbase '.' ext
  70.   dst = 'texi2dvi.'ext
  71.   if debug then say 'Copying' src 'to' dst
  72.   'copy' src dst '>nul'
  73.   delete_files = delete_files dst
  74. end
  75.  
  76. changed = 0
  77. if run_texindex_and_tex( 'orig_index_files_sans_aux') then
  78. do
  79.   call get_index_files 'new_index_files'
  80.   if \ (orig_index_files = new_index_files) then
  81.     changed = 1
  82.   else
  83.   do i = 1 to words( orig_index_files) until changed
  84.     src = word( orig_index_files, i)
  85.     dst = word( delete_files, i)
  86.     if debug then say 'Comparing ' src 'to' dst
  87.     changed = \ compare( src, dst)
  88.   end
  89. end
  90.  
  91. if length( delete_files) > 0 then
  92. do
  93.   if debug then say 'Deleting' delete_files
  94.   'del' delete_files
  95. end
  96.  
  97. if changed then
  98.   call run_texindex_and_tex 'new_index_files_sans_aux'
  99.  
  100. exit 0
  101.  
  102. Usage: procedure
  103.   say 'Usage: texi2dvi [-d] [-f] [-h] filename'
  104.   say ''
  105.   say '-d   turn on debugging output'
  106.   say '-f   force; run TeX even if DVI file is newer than input file'
  107.   say '-h   display this message'
  108.   exit 1
  109.  
  110. exists: procedure
  111. arg fname
  112.   return \ (stream( fname, 'C', 'QUERY EXISTS') = '')
  113.  
  114. newer: procedure
  115. arg fname1, fname2
  116. return gettime( fname1) > gettime( fname2)
  117.  
  118. gettime: procedure
  119. arg fname
  120.   datetime = stream( fname, 'C', 'QUERY DATETIME')
  121.   return substr( datetime, 7, 2)'/'substr( datetime, 1, 2)'/'substr( datetime, 4, 2),
  122.          substr( datetime, 11, 8)
  123.  
  124. get_index_files:
  125. arg files
  126.   call value files, ''
  127.   call SysFileTree basename'.??', filelist, 'F'
  128.   do i = 1 to filelist.0
  129.     if debug then say filelist.i
  130.     fname = filespec( 'name', substr( filelist.i, 38))
  131.     parse var fname indexbase '.' ext
  132.     if length( ext) = 2 then
  133.       call checkindex fname, files
  134.   end
  135.   call value files'_sans_aux', value( files)
  136.   call checkindex basename'.aux', files
  137.   if debug then say value( files)
  138.   return
  139.  
  140. checkindex:
  141. arg fname, files
  142.   line = linein( fname)
  143.   call stream fname, 'C', 'CLOSE'
  144.   if length( line) > 0 then
  145.   do
  146.     firstchar = substr( line, 1, 1)
  147.     if (firstchar = '\') | (firstchar = "'") then
  148.     do
  149.       if debug then say fname 'is an index file'
  150.       call value files, value( files) fname
  151.     end
  152.   end
  153.   return
  154.  
  155. compare: procedure expose have_diff
  156. arg fname1, fname2
  157.   if have_diff then
  158.     return compare_diff( fname1, fname2)
  159.   else
  160.     return compare_rexx( fname1, fname2)
  161.  
  162. compare_diff: procedure
  163. arg fname1, fname2
  164.   'diff -q' fname1 fname2
  165.   return RC = 0
  166.  
  167. compare_rexx: procedure
  168. arg fname1, fname2
  169.   different = 0
  170.   identical = 0
  171.   do until different | identical
  172.     ok1 = lines( fname1)
  173.     ok2 = lines( fname2)
  174.     if \ (ok1 = ok2) then
  175.       different = 1
  176.     else if \ ok1 then
  177.       identical = 1
  178.     else
  179.     do
  180.       line1 = linein( fname1)
  181.       line2 = linein( fname2)
  182.       if \ (line1 = line2) then
  183.         different = 1
  184.     end
  185.   end
  186.   call stream fname1, 'C', 'CLOSE'
  187.   call stream fname2, 'C', 'CLOSE'
  188.   return identical
  189.  
  190. run_texindex_and_tex:
  191. arg files
  192.   if words( value( files)) > 0 then
  193.   do
  194.     if debug then say 'Running texinfo' value( files)
  195.     'texindex' value( files)
  196.   end
  197.   tex_prog inputfile
  198.   return RC < 2
  199.