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