;dBRIEF Source  - v3.10
;Copyright (c) 1991 - Global Technologies Corporation
;ALL RIGHTS RESERVED
#include "dbrief.h"
(macro _print_source
	(
		(int			print_buffer
						_lines
						line_counter
						page_counter
						temp_counter
						_width
		)
		(string		_file
						_buff
						_txtfile
						_output_file
						_switch
						_graphics
						_indenting
						_print_temp_str
						_printer_setup
						_spool
						previous_tab_setting
		)
		(= previous_tab_setting (use_tab_char "n"))
		(= curr_indent_col 1)
		(inq_names _file NULL _buff)
		(if (! (get_parm 0 _file "File name to print: " NULL _file))
			(return 0)
		)
		(set_msg_level 3)
		(if (exist _file)
			(edit_file _file)
		;else
			(
				(_display_popup_message "%s not found!" (upper _file) 1)
				(return 0)
			)
		)
		(set_msg_level 0)
		(sprintf _print_temp_str "Printing %s - line #'s? [Yn]: " (upper _buff))
		(if (! (get_parm 1 _switch _print_temp_str 1 "Y"))
			(return 0)
		)
		(if (! (get_parm 2 _graphics "Conditional outlining? [yN]: " 1 "N"))
			(return 0)
		)
		(if (! (get_parm 3 _indenting "Reindent? [yN]: " 1 "N"))
			(return 0)
		)
		(= _width dbr_cols_page)
		(if (! (get_parm 4 _width "Report width: " _width))
			(return 0)
		)
		(= _printer_setup dbr_printer_setup)
		(if (! (get_parm 5 _printer_setup "Printer setup string: " 32 _printer_setup))
			(return 0)
		)
		(sprintf _print_temp_str "Print %s to file? [Yn]: " (upper _buff))
		(if (! (get_parm 6 _txtfile _print_temp_str 1 "Y"))
			(return 0)
		)
		(if (== (upper _txtfile) "Y")
			(if (get_parm 7 _output_file "File name: " NULL (+ (substr (upper _file) 1 (- (index _file ".") 1)) ".PRN"))
				(message "")
			;else
				(return 0)
			)
		;else
			(if (! (get_parm 8 _spool "Spool to printer? [Yn]: " 1 "Y"))
				(return 0)
			)
		)
		(save_position)
		(= _switch (upper _switch))
		(= dbr_current_buffer (inq_buffer))
		(if (== (upper _txtfile) "Y")
			(
				(if (exist _output_file)
					(del _output_file)
				)
				(= print_buffer (create_buffer "Print Source" _output_file))
			)
		;else
			(= print_buffer (create_buffer "Print Source" NULL 0))
		)
		(message "Printing, press any key to abort...")
		(set_buffer print_buffer)
		(if (!= (upper _spool) "Y")
			(
				(if (>= (version) 310)
					(execute_macro "db_hide 1")
				)
				(create_window 30 20 74 3 "Printing, please wait...")
				(if (>= (version) 310)
					(execute_macro "db_show 1")
				)
				(attach_buffer print_buffer)
			)
		)
		(set_buffer dbr_current_buffer)
		(end_of_buffer)
		(inq_position _lines NULL)
		(top_of_buffer)
		(= line_counter 0)
		(= temp_counter 0)
		(= page_counter 1)
		(set_buffer print_buffer)
		(_print_line _printer_setup _graphics _indenting _txtfile)
		(_page_break _file page_counter _switch "N" "N" _txtfile _width)
		(set_buffer dbr_current_buffer)
		(while (&& (<= (++ line_counter) _lines)(! (inq_kbd_char)))
			(
				(++ temp_counter)
				(move_abs line_counter 1)
				(= _print_temp_str (read))
				(set_buffer print_buffer)
				(if (== _switch "Y")
					(sprintf _print_temp_str "%-4d- %s" line_counter _print_temp_str)
				)
				(_print_line _print_temp_str _graphics _indenting _txtfile)
				(if (!= (upper _spool) "Y")
					(refresh)
				)
				(if (>= temp_counter dbr_lines_page)
					(
						(_print_line "\n" "N" "N" _txtfile)
						(++ page_counter)
						(_page_break _file page_counter _switch "N" "N" _txtfile _width)
						(= temp_counter 0)
					)
				)
				(set_buffer dbr_current_buffer)
			)
		)
		(keyboard_flush)
		(set_buffer print_buffer)
		(_print_line "\n" "N" "N" _txtfile)
		(if (== (upper _txtfile) "Y")
			(write_buffer)
		)
		(set_buffer dbr_current_buffer)
		(attach_buffer dbr_current_buffer)
		(if (!= (upper _spool) "Y")
			(delete_window)
		)
		(delete_buffer print_buffer)
		(restore_position)
		(if (== (upper _spool) "Y")
			(
				(sprintf _print_temp_str "%s %s >&NUL" dbr_spooler _output_file)
				(dos _print_temp_str)
				(_display_popup_message "%s has been spooled." (upper _file) 0)
			)
		;else
			(_display_popup_message "Printing complete." "" 0)
		)
		(use_tab_char previous_tab_setting)
	)
)
(macro _print_line
	(
		(string		_graphics
						_indenting
						_output
						_print_temp_str
		)
		(get_parm 0 _print_temp_str)
		(get_parm 1 _graphics)
		(get_parm 2 _indenting)
		(get_parm 3 _output)
		(if (|| (== (upper _graphics) "Y")(== (upper _indenting) "Y"))
			(if (== (substr _print_temp_str 5 2) "- ")
				(_insert_graphics (substr _print_temp_str 1 6) (ltrim (trim (substr _print_temp_str 7))) _graphics)
			;else
				(_insert_graphics "" (ltrim (trim _print_temp_str)) _graphics)
			)
		;else
			(insert _print_temp_str)
		)
		(if (== (upper _output) "N")
			(
				(move_rel -1 0)
				(drop_anchor)
				(end_of_line)
				(while (!= 0 (print))
					(
						(raise_anchor)
						(beginning_of_line)
						(drop_anchor)
						(end_of_line)
					)
				)
				(raise_anchor)
				(beginning_of_line)
				(move_rel 1 0)
			)
		)
	)
)
(macro _page_break
	(
		(int			_page
						_width
		)
		(string		_name
						_line
						_graphics
						_indenting
						_output
						_print_temp_str
		)
		(get_parm 0 _name)
		(get_parm 1 _page)
		(get_parm 2 _line)
		(get_parm 3 _graphics)
		(get_parm 4 _indenting)
		(get_parm 5 _output)
		(get_parm 6 _width)
		(sprintf _print_temp_str "Source Print - File: %s %s Page: %d\n" (upper _name) (_replicate " " (- (- _width (strlen _name)) 31)) _page)
		(_print_line _print_temp_str _graphics _indenting _output)
		(_print_line (+ (_replicate "-" _width) "\n") _graphics _indenting _output)
		(if (== _line "Y")
			(
				(_print_line "Line  Source\n" _graphics _indenting _output)
				(_print_line (+ "----- " (+ (_replicate "-" (- _width 6)) "\n")) _graphics _indenting _output)
			)
		;else
			(
				(_print_line "Source\n" _graphics _indenting _output)
				(_print_line (+ (_replicate "-" _width) "\n") _graphics _indenting _output)
			)
		)
	)
)

