home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / EPRINT.EX < prev    next >
Text File  |  1993-06-24  |  4KB  |  181 lines

  1.         ------------------------------
  2.         -- Print a Euphoria program --
  3.         ------------------------------
  4. -- This works with HP PCL printers.
  5. -- You can change control codes (bold, italics etc) for other printers.
  6. -- If you have a color printer you can choose colors,
  7. -- otherwise you will simply get keywords in bold, comments in italics.
  8.  
  9. constant TRUE = 1, FALSE = 0
  10.  
  11. --- some parameters you can adjust for your printer ----------------
  12. constant NCOLUMNS = 2              -- 1 or 2
  13. constant CONDENSED = TRUE          -- TRUE or FALSE
  14. constant PAGE_LENGTH = 59*NCOLUMNS -- (upper bound) 118 for condensed
  15. constant COLOR_PRINTER = FALSE      -- TRUE (HP550C) or FALSE
  16. constant SYNTAX = TRUE              -- TRUE to highlight syntax
  17.                     -- FALSE to print other kinds of text files
  18. --------------------------------------------------------------------
  19.  
  20. constant ESC = 27
  21.  
  22. constant hp550c = {"2", "8", "1", "4", "10", "12", "1", "1"}
  23.  
  24. integer printer
  25.  
  26. procedure bold_on()
  27.     puts(printer, ESC & "(s3B")
  28. end procedure
  29.  
  30. procedure bold_off()
  31.     puts(printer, ESC & "(s0B")
  32. end procedure
  33.  
  34. procedure italics_on()
  35.     puts(printer, ESC & "(s1S")
  36. end procedure
  37.  
  38. procedure italics_off()
  39.     puts(printer, ESC & "(s0S")
  40. end procedure
  41.  
  42. procedure second_column()
  43.     puts(printer, ESC & "&a80C")
  44. end procedure
  45.  
  46. procedure form_feed()
  47.     puts(printer, 12)
  48. end procedure
  49.  
  50. procedure reset()
  51.     puts(printer, ESC & 'E')   -- reset
  52. end procedure
  53.  
  54. procedure color()
  55.     puts(printer, ESC & "*r-4U")  -- CYMK
  56. end procedure
  57.  
  58. procedure small()
  59.     puts(printer, ESC & "(s20H")    -- Print Pitch (width)
  60.     puts(printer, ESC & "(s8V")     -- Point Size (height)
  61.     puts(printer, ESC & "&l4C")     -- vertical motion
  62. end procedure
  63.  
  64. -- symbols needed by syncolor.e:
  65. global integer SCREEN
  66. global constant BLANK_LINE = ""
  67. global constant NORMAL_COLOR = 8,
  68.         COMMENT_COLOR = 4,
  69.         KEYWORD_COLOR = 1,
  70.         BUILTIN_COLOR = 5,
  71.         STRING_COLOR = 6
  72. global constant bracket_color = {NORMAL_COLOR}
  73.  
  74. global procedure text_color(integer color)
  75. -- this overrides the graphics.e procedure for screen color
  76. -- that is used by syncolor.e
  77.     sequence color_code
  78.  
  79.     if not SYNTAX then
  80.     return
  81.     end if
  82.  
  83.     if COLOR_PRINTER then
  84.     color_code = hp550c[color]
  85.     puts(printer, ESC & "*v" & color_code & "S")
  86.     else
  87.     -- normal mono printer
  88.     if color = KEYWORD_COLOR then
  89.         italics_off()
  90.         bold_on()
  91.     elsif color = COMMENT_COLOR then
  92.         bold_off()
  93.         italics_on()
  94.     else
  95.         italics_off()
  96.         bold_off()
  97.     end if
  98.     end if
  99. end procedure
  100.  
  101. include syncolor.e
  102.  
  103. procedure try_colors()
  104. -- display colors on hp550c
  105.     for i = '0' to '6' do
  106.     for j = '0' to '9' do
  107.         puts(printer, ESC & "*v" & i & j & "S")
  108.         printf(printer, "%s:", {i&j})
  109.         puts(printer, "Testing Colors ...\n")
  110.     end for
  111.     end for
  112. end procedure
  113.  
  114. procedure eprint()
  115.     integer efile
  116.     sequence command
  117.     object line
  118.     sequence buffer
  119.     integer base_line
  120.  
  121.     command = command_line()
  122.     if length(command) != 3 then
  123.     puts(1, "usage: eprint filename.e\n")
  124.     return
  125.     end if
  126.     efile = open(command[3], "r")
  127.     if efile = -1 then
  128.     puts(1, "couldn't open " & command[3] & '\n')
  129.     return
  130.     end if
  131.     printer = open("PRN", "w")
  132.     if printer = -1 then
  133.     puts(1, "Can't open printer\n")
  134.     return
  135.     end if
  136.     SCREEN = printer -- SCREEN is needed by syncolor
  137.     init_class()
  138.     reset()
  139.     if COLOR_PRINTER then
  140.     color()
  141.     end if
  142.     if CONDENSED then
  143.     small()
  144.     end if
  145.     -- try_colors()
  146.     -- return
  147.  
  148.     -- read in whole file
  149.     buffer = {}
  150.     while 1 do
  151.     line = gets(efile)
  152.     if atom(line) then
  153.         exit
  154.     end if
  155.     if line[length(line)] = '\n' then
  156.         line = line[1..length(line)-1]
  157.     end if
  158.     buffer = append(buffer, line)
  159.     end while
  160.     base_line = 1
  161.     while base_line <= length(buffer) do
  162.     for i = base_line to base_line + PAGE_LENGTH - 1 do
  163.         if i <= length(buffer) then
  164.         DisplayColorLine(buffer[i], TRUE)
  165.         if NCOLUMNS = 2 and i + PAGE_LENGTH <= length(buffer) then
  166.             second_column()
  167.             DisplayColorLine(buffer[i + PAGE_LENGTH], TRUE)
  168.         end if
  169.         puts(printer, '\n')
  170.         end if
  171.     end for
  172.     base_line = base_line + PAGE_LENGTH * NCOLUMNS
  173.     form_feed()
  174.     end while
  175.     close(efile)
  176.     close(printer)
  177. end procedure
  178.  
  179. eprint()
  180.  
  181.