home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / XL2PS.CMD / XL2PS.CMD
OS/2 REXX Batch file  |  1992-11-26  |  10KB  |  265 lines

  1. /* XL2PS.CMD 2.0 30-Aug-1992
  2.  *
  3.  * Convert Excelerator screen interface file to a postscript
  4.  * image, suitable for using in VAX Document
  5.  * 
  6.  * The image produced is appropriate for the Software.Reference
  7.  * doctype, with a figure height of 15 for an informal figure.
  8.  *
  9.  * V2.0 920830 JJM - Change to accept PC line drawing characters
  10.  *                   and convert them to graphical lines so that
  11.  *                   VAX Document ASCII encoding doesn't mess it up.
  12.  */
  13.  
  14. ARG FileArg
  15.  
  16. /* Name of the output file, for now, force to stdout */
  17. Outfile =FileArg || '.PS'
  18. /* Name of the input file, again, fixed for now */
  19. Infile = FileArg || '.SCI'
  20. Y1 = 0
  21. Y2 = 0
  22. Blanks = '                                                                              '
  23.  
  24. /*  Output the stuff that belongs at the beginning of the Postscript */
  25. Nn = LINEOUT( Outfile, '%!PS_Adobe 2.0')
  26. Nn = LINEOUT( Outfile, '%%Title: ' || Infile )
  27. Nn = LINEOUT( Outfile, '%%Creator: XL2PS.Cmd 2.0')
  28. Nn = LINEOUT( Outfile, '%%CreationDate: '||DATE('N') TIME('C'))
  29. Nn = LINEOUT( Outfile, '%%DocumentProcSets: XLSCR')
  30. Nn = LINEOUT( Outfile, '%%DocumentSuppliedProcSets: XLSCR')
  31. Nn = LINEOUT( Outfile, '%%EndComments')
  32. Nn = LINEOUT( Outfile, '%%BeginProcSet: XLSCR')
  33.  
  34. /* Set up a buncha macros that simply allow us to have a slightly
  35.  * shorter PostScript output */
  36. Nn = LINEOUT( Outfile, '/B {bind def} bind def')
  37. Nn = LINEOUT( Outfile, '/m { moveto } B /l { lineto } B /t { show } B')
  38. Nn = LINEOUT( Outfile, '/w { setlinewidth } B /n { newpath } B /s { stroke } B')
  39. Nn = LINEOUT( Outfile, '/c { findfont 30 scalefont setfont } B')
  40. Nn = LINEOUT( Outfile, '/g { setgray } B /f { fill } B /sm {setmatrix} B')
  41. Nn = LINEOUT( Outfile, '/mx {matrix} B /cm {currentmatrix} B')
  42. Nn = LINEOUT( Outfile, '/md mx cm def /setmx {md sm concat} B')
  43. Nn = LINEOUT( Outfile, '%%EndProcSet')
  44. Nn = LINEOUT( Outfile, '%%EndProlog')
  45.  
  46. /* Now do the stuff that scales the image */
  47. Nn = LINEOUT( Outfile, 'gsave')
  48.  
  49. Nn = LINEOUT( Outfile, 'initgraphics')
  50.  
  51. /* The following line is omitted only for inclusion in Document */
  52. /* Uncomment the line if you want to print the result directly  */
  53. /* Comment the line for inclusion in Document or other text processors */
  54. Nn = LINEOUT( Outfile, '100 300 translate')
  55.  
  56. Nn = LINEOUT( Outfile, '.24 .24 scale')
  57.  
  58. Nn = LINEOUT( Outfile, '1.0 w')
  59.  
  60. /* The first two lines of the Excelerator interface file
  61.  * aren't real interesting for now. */
  62. HeaderLine = LINEIN( Infile )
  63. TitleLine = LINEIN( Infile )
  64.  
  65. /* Begin reading the real stuff, continue until out of file */
  66. Line1 = 'xxx'
  67. DO UNTIL Line1 = ''
  68.     Line1 = ''
  69.     Line1 = LINEIN(InFile)
  70.     IF Line1 == '' THEN LEAVE
  71.  
  72.     /* The first line of all fields describes the field */
  73.     Y1 = SUBSTR(Line1,1,2)  /* Column of field */
  74.     X1 = SUBSTR(Line1,3,3)  /* Row of field */
  75.     FieldType = SUBSTR(Line1,6,1) /* Type of field */
  76.  
  77.     /* OK, We'll go do all field types */
  78.     if FieldType \= '?' THEN DO
  79.     /* Get the default contents, strip trailing blanks */
  80.     RawCont = STRIP(LINEIN(InFile),'T',' ')
  81.     FldCont = RawCont;
  82.     /* Search for line-drawing characters in the string */
  83.     LineDraws = 0
  84.     /* Now replace line drawing characters in the field with
  85.          * blanks and make another vector containing only the
  86.          * line drawing characters */
  87.     LineStr = SUBSTR(Blanks,1,LENGTH(RawCont))
  88.     DO I=1 TO LENGTH(RawCont)
  89.         IF SUBSTR(RawCont,I,1) > D2C(127) THEN DO
  90.         LineDraws = 1
  91.         FldCont = OVERLAY(' ',FldCont,I)
  92.         LineStr = OVERLAY(SUBSTR(RawCont,I,1),LineStr,I)
  93.         END
  94.     END
  95.  
  96.     /* If it's an input field, there's 3 extra lines 
  97.      * we really don't care about for now. */
  98.     IF FieldType = 'I' THEN DO
  99.         Dummy=LINEIN(InFile)
  100.         Dummy=LINEIN(InFile)
  101.         Dummy=LINEIN(InFile)
  102.     END
  103.     IF FieldType = 'O' THEN DO
  104.         Dummy=LINEIN(InFile)
  105.     END
  106.  
  107.     /* Calculate where on the page this field starts */
  108.     Y2 = (25-Y1) * 30 - 10
  109.         X2 = TRUNC(X1 * 18 + .5 )
  110.  
  111.     /* Use Courier, unless it's bright, then use bold */
  112.     charset = '/Courier'
  113.     /* If column 12 is a Y, the field is bold */
  114.     if ( SUBSTR(Line1,12,1) ) = 'Y' THEN
  115.         charset = '/Courier-Bold'
  116.  
  117.     /* If it's a reverse-video, we have work to do */
  118.     /* If column 13 is a Y, the field is reverse */
  119.     if ( SUBSTR(Line1,13,1) ) = 'Y' THEN DO
  120.         /* Non-bold really aren-t visible */
  121.         charset = '/Courier-Bold'
  122.         /* Calculate the boundaries of the box */
  123.         Left = X2-2
  124.         Right = X2 + LENGTH(FldCont) * 18 + 2
  125.         Top = Y2 + 23
  126.         Bottom = Y2 - 7
  127.         /* Now draw a black box where the letters belong */
  128.         Outline1 = '0 g n'  Left   Bottom 'm' Right Bottom 'l'
  129.         Outline1 = Outline1 Right Top 'l' Left Top 'l'
  130.         Outline1 = Outline1 Left Bottom 'l'
  131.         Nn = LINEOUT(Outfile, Outline1 )
  132.         /* Fill the box and set the character color to white */
  133.         Nn = LINEOUT(Outfile, 'fill 1 g')
  134.         /* Output the characters */
  135.         OutLine = charset 'c' X2 Y2 'm ('|| FldCont||') t'
  136.             Nn = LINEOUT( Outfile, OutLine )
  137.         /* Set the character color back to black */
  138.         Nn= LINEOUT( Outfile, '0 g' )
  139.         END
  140.     ELSE DO
  141.         /* Not reverse video, output the sharacters */
  142.         OutLine1 = charset 'c' X2 Y2 'm ('|| FldCont||') t'
  143.         Nn = LINEOUT( Outfile, OutLine1 )
  144.         END
  145.     /* Process underlined fields by drawing a line */
  146.     /* If column 15 is a Y, the field is underlined */
  147.     if ( SUBSTR(Line1,15,1) ) = 'Y' THEN DO
  148.         Left = X2-4
  149.         Right = X2 + LENGTH(FldCont) * 18 + 4
  150.         Bottom = Y2 - 7
  151.         Outline1 = '1.0 w n' Left Bottom 'm' Right Bottom 'l s'
  152.         Nn = LINEOUT( Outfile, OutLine1 )
  153.         END
  154.     END
  155.     /* Now it gets really gross -- for each line drawing character
  156.      * (actually, only the single-line ones are handled) we actually
  157.      * *DRAW* the character using vectors.  This is necessary since
  158.      * DEC screws up the character encoding vectors in VAX Document
  159.      * so the the normal line-drawing characters aren't available */
  160.     IF LineDraws = 1 THEN DO
  161.     DO I=1 TO LENGTH(LineSTR)
  162.         X2 = TRUNC((X1+I-1) * 18 + .5 )
  163.         SELECT
  164.         WHEN SUBSTR(LineStr,I,1) = '─' THEN DO
  165.             OutLine1 = X2||' '||Y2+15||' m '
  166.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  167.             OutLine1 = OutLine1 || ' l s'
  168.             Nn = LINEOUT( Outfile, OutLine1 )
  169.         END
  170.         WHEN SUBSTR(LineStr,I,1) = '│' THEN DO
  171.             OutLine1 = X2+9||' '||Y2+30||' m '
  172.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2
  173.             OutLine1 = OutLine1 || ' l s'
  174.             Nn = LINEOUT( Outfile, OutLine1 )
  175.         END
  176.         WHEN SUBSTR(LineStr,I,1) = '┌' THEN DO
  177.             OutLine1 = X2+9||' '||Y2||' m '
  178.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' l '
  179.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  180.             OutLine1 = OutLine1 || ' l s'
  181.             Nn = LINEOUT( Outfile, OutLine1 )
  182.         END
  183.         WHEN SUBSTR(LineStr,I,1) = '┐' THEN DO
  184.             OutLine1 = X2+9||' '||Y2||' m '
  185.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' l '
  186.             OutLine1 = OutLine1 || X2 || ' ' || Y2+15
  187.             OutLine1 = OutLine1 || ' l s'
  188.             Nn = LINEOUT( Outfile, OutLine1 )
  189.         END
  190.         WHEN SUBSTR(LineStr,I,1) = '└' THEN DO
  191.             OutLine1 = X2+9||' '||Y2+30||' m '
  192.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' l '
  193.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  194.             OutLine1 = OutLine1 || ' l s'
  195.             Nn = LINEOUT( Outfile, OutLine1 )
  196.         END
  197.         WHEN SUBSTR(LineStr,I,1) = '┘' THEN DO
  198.             OutLine1 = X2||' '||Y2+15||' m '
  199.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' l '
  200.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2+30
  201.             OutLine1 = OutLine1 || ' l s'
  202.             Nn = LINEOUT( Outfile, OutLine1 )
  203.         END
  204.         WHEN SUBSTR(LineStr,I,1) = '├' THEN DO
  205.             OutLine1 = X2+9||' '||Y2+30||' m '
  206.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2
  207.             OutLine1 = OutLine1 || ' l s '
  208.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' m '
  209.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  210.             OutLine1 = OutLine1 || ' l s'
  211.             Nn = LINEOUT( Outfile, OutLine1 )
  212.             Nn = LINEOUT( Outfile, OutLine1 )
  213.         END
  214.         WHEN SUBSTR(LineStr,I,1) = '┤' THEN DO
  215.             OutLine1 = X2+9||' '||Y2+30||' m '
  216.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2
  217.             OutLine1 = OutLine1 || ' l s '
  218.             OutLine1 = OutLine1 || X2||' '||Y2+15||' m '
  219.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2+15
  220.             OutLine1 = OutLine1 || ' l s'
  221.             Nn = LINEOUT( Outfile, OutLine1 )
  222.             Nn = LINEOUT( Outfile, OutLine1 )
  223.         END
  224.         WHEN SUBSTR(LineStr,I,1) = '┬' THEN DO
  225.             OutLine1 = X2||' '||Y2+15||' m '
  226.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  227.             OutLine1 = OutLine1 || ' l s '
  228.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' m '
  229.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2
  230.             OutLine1 = OutLine1 || ' l s'
  231.             Nn = LINEOUT( Outfile, OutLine1 )
  232.         END
  233.         WHEN SUBSTR(LineStr,I,1) = '┴' THEN DO
  234.             OutLine1 = X2||' '||Y2+15||' m '
  235.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  236.             OutLine1 = OutLine1 || ' l s '
  237.             OutLine1 = OutLine1 || X2+9||' '||Y2+15||' m '
  238.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2+30
  239.             OutLine1 = OutLine1 || ' l s'
  240.             Nn = LINEOUT( Outfile, OutLine1 )
  241.         END
  242.         WHEN SUBSTR(LineStr,I,1) = '┼' THEN DO
  243.             OutLine1 = X2||' '||Y2+15||' m '
  244.             OutLine1 = OutLine1 || X2+18 || ' ' || Y2+15
  245.             OutLine1 = OutLine1 || ' l s '
  246.             OutLine1 = OutLine1 || X2+9||' '||Y2+30||' m '
  247.             OutLine1 = OutLine1 || X2+9 || ' ' || Y2
  248.             OutLine1 = OutLine1 || ' l s'
  249.             Nn = LINEOUT( Outfile, OutLine1 )
  250.         END
  251.         OTHERWISE
  252.             ; /* It's a character we don't recognize */
  253.         END
  254.     END
  255.     END
  256. END
  257.  
  258. /* Draw a box around the screen area */
  259. Nn = LINEOUT( Outfile, '3.0 w n')
  260. Nn = LINEOUT( Outfile, '0 0 m 0 750 l 1466 750 l 1466 0 l 0 0 l s')
  261. /* Finally, tell the printer we really would like to see this */
  262. Nn = LINEOUT( Outfile, 'grestore')
  263. Nn = LINEOUT( Outfile, 'showpage')
  264. Nn = LINEOUT( Outfile, '%!')
  265.