home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / latexutl.zip / PICFMT.CMD next >
OS/2 REXX Batch file  |  1994-07-26  |  3KB  |  125 lines

  1. /*  PICFMT.CMD
  2.     Copyright 1994, Myron Uecker
  3.  
  4.     Rexx script to reformat PIC files created by TeXcad.
  5.  
  6.     When TeXcad creates a file, it adds extra spaces to the left and top to
  7.     match the location where the drawing was placed.  PICFMT will take out
  8.     the extra spaces.
  9. */
  10.  
  11. /*  Change the following lines to the file extension you use for your picture
  12.     files.
  13. */
  14. iext = '.PIC'
  15. oext = '.CIP'
  16.  
  17. '@echo off'
  18. parse upper arg lfname
  19. if lfname = '' then do
  20.    Say "Enter the name of the file to be reformatted without the extension."
  21.    pull lfname
  22. end
  23. else
  24.    NOP
  25.  
  26. fname = lfname||iext
  27. outfname = lfname||oext
  28.  
  29. linen.0 = LINES(fname)
  30. if linen.0 = 0 then do
  31.    Say "The file "fname" doesn't exist."
  32.    exit 1
  33. end
  34. else 
  35.    NOP
  36.  
  37. 'ERASE 'outfname
  38.  
  39. /* Create a couple of large starting values for minx and miny */
  40. minx = 100000
  41. miny = 100000
  42.  
  43. /* Now parse each line to find the minx and miny values. */
  44. /* look for put commands first */
  45. i = 0
  46. do while LINES(fname) = 1
  47.    i = i + 1
  48.    linen.i = LINEIN(fname)
  49.    if LEFT(linen.i,4) = '\put' then do
  50.       parse var linen.i '\put('x1','y1')'.
  51.       if x1 < minx then
  52.          minx = x1
  53.       else
  54.          NOP
  55.       if y1 < miny then
  56.          miny = y1
  57.       else
  58.          NOP
  59.    end  /* Do */
  60.    /* now look for emline commands */
  61.    else if LEFT(linen.i,7) = '\emline' then do
  62.       parse var linen.i '\emline{'x1'}{'y1'}{'.'}{'x2'}{'y2'}'.
  63.       if x1 < minx then
  64.          minx = x1
  65.       else if x2 < minx then
  66.          minx = x2
  67.       else
  68.          NOP
  69.       if y1 < miny then
  70.          miny = y1
  71.       else if y2 < miny then
  72.          miny = y2
  73.       else
  74.          NOP
  75.    end  /* Do */
  76.    /* Finally find the bezier commands */
  77.    else if LEFT(linen.i,7) = '\bezier' then do
  78.       parse var linen.i '\bezier{'.'}('x1','y1')('x2','y2')('x3','y3')'.
  79.       if x1 < minx then
  80.          minx = x1
  81.       else if x2 < minx then
  82.          minx = x2
  83.       else if x3 < minx then
  84.          minx = x3
  85.       else
  86.          NOP
  87.       if y1 < miny then
  88.          miny = y1
  89.       else if y2 < miny then
  90.          miny = y2
  91.       else if y3 < miny then
  92.          miny = y3
  93.       else
  94.          NOP
  95.    end  /* Do */
  96. end /* do */
  97. linen.0 = i
  98.  
  99. /* Now that we have the min values, put the lines back together with the new
  100.    x and y values. */
  101. do i = 1 to linen.0
  102.    if LEFT(linen.i,15) = '\begin{picture}' then do
  103.       parse var linen.i '\begin{picture}('x1','y1')'
  104.       linout = '\begin{picture}('x1-minx','y1-miny')'
  105.    end  /* Do */
  106.    else if LEFT(linen.i,4) = '\put' then do
  107.       parse var linen.i '\put('x1','y1')'rest
  108.       linout = '\put('x1-minx','y1-miny')'rest
  109.    end
  110.    else if LEFT(linen.i,7) = '\emline' then do
  111.       parse var linen.i '\emline{'x1'}{'y1'}{'pt1'}{'x2'}{'y2'}'rest
  112.       linout = '\emline{'x1-minx'}{'y1-miny'}{'pt1'}{'x2-minx'}{'y2-miny'}'rest
  113.    end
  114.    else if LEFT(linen.i,7) = '\bezier' then do
  115.       parse var linen.i '\bezier{'num'}('x1','y1')('x2','y2')('x3','y3')'
  116.       linout = '\bezier{'num'}('x1-minx','y1-miny')('x2-minx','y2-miny')('x3-minx','y3-miny')'
  117.    end
  118.    else
  119.       linout = linen.i
  120.  
  121.    call LINEOUT outfname, linout
  122. end
  123.  
  124. exit
  125.