;dBRIEF Header - v3.10
;Copyright (c) 1991 - Global Technologies Corporation
;ALL RIGHTS RESERVED
#include "dbrief.h"
(macro head
	(
		(string			header_type
		)
		(if (get_parm 0 header_type "Program, Function or proCedure? [Pfc]: " 1 "P")
			(
				(switch (upper header_type)
					"P"
						(_pro_header "proghead.cfg" 0)
					"C"
						(_pro_header "prochead.cfg" dbr_hdr_inclusion)
					"F"
						(_pro_header "funchead.cfg" dbr_hdr_inclusion)
				)
			)
		)
	)
)
(macro _pro_header
	(
		(int		year
					month
					day
					hours
					minutes
					x_
					y_
					line_
					col_
					hdr_inclusion
		)
		(string  buffer_name
					cfg_file
		)
		(get_parm 0 cfg_file)
		(get_parm 1 hdr_inclusion)
		(message "Creating header...")
		(inq_position x_ y_)
		(inq_names NULL NULL buffer_name)
		(if (== cfg_file "proghead.cfg")
			(top_of_buffer)
		)
		(if (exist cfg_file)
			(read_file cfg_file)
		;else
			(read_file (search_path  (inq_environment "BPATH") cfg_file))
		)
		(save_position)
		(if (== cfg_file "proghead.cfg")
			(
				(translate (+ "[dir]" (_replicate " " (- (strlen (_get_directory)) 5))) (upper (_get_directory)) 1 0 0 0 0)
				(translate "[dir]" (upper (_get_directory)) 1 0 0 0 0)
				(translate (+ "[drv]" (_replicate " " (- (strlen (substr (_get_directory) 1 2)) 5))) (+ (upper (substr (_get_directory) 1 2)) "	 ") 1 0 0 0 0)
				(translate "[drv]" (+ (upper (substr (_get_directory) 1 2)) "	 ") 1 0 0 0 0)
				(translate (+ "[file]" (_replicate " " (- (strlen buffer_name) 6))) (upper buffer_name) 1 0 0 0 0)
				(translate "[file]" (upper buffer_name) 1 0 0 0 0)
				(translate (+ "[copy]" (_replicate " " (- (strlen dbr_copyright) 6))) dbr_copyright 1 0 0 0 0)
				(translate "[copy]" dbr_copyright 1 0 0 0 0)
				(translate (+ "[defx]" (_replicate " " (- (strlen (+ (_get_dialect_info dbr_dialect 3) "	 ")) 6))) (+ (_get_dialect_info dbr_dialect 3) "	") 1 0 0 0 0)
				(translate "[defx]" (_get_dialect_info dbr_dialect 3) 1 0 0 0 0)
			)
		)
		(translate (+ "[auth]" (_replicate " " (- (strlen dbr_author) 6))) dbr_author 1 0 0 0 0)
		(translate "[auth]" dbr_author 1 0 0 0 0)
		(translate (+ "[mdyr]" (_replicate " " (- (strlen (_date_time 5)) 6))) (_date_time 5) 1 0 0 0 0)
		(translate "[mdyr]" (_date_time 5) 1 0 0 0 0)
		(translate (+ "[date]" (_replicate " " (- (strlen (_date_time 1)) 6))) (_date_time 1) 1 0 0 0 0)
		(translate "[date]" (_date_time 1) 1 0 0 0 0)
		(translate (+ "[year]" (_replicate " " (- (strlen (_date_time 2)) 6))) (+ (_date_time 2) "  ") 1 0 0 0 0)
		(translate "[year]" (_date_time 2) 1 0 0 0 0)
		(translate (+ "[time]" (_replicate " " (- (strlen (_date_time 3)) 6))) (_date_time 3) 1 0 0 0 0)
		(translate "[time]" (_date_time 3) 1 0 0 0 0)
		(translate (+ "[ampm]" (_replicate " " (- (strlen (_date_time 4)) 6))) (_date_time 4) 1 0 0 0 0)
		(translate "[ampm]" (_date_time 4) 1 0 0 0 0)
		(translate (+ "[dial]" (_replicate " " (- (strlen (_get_dialect_info dbr_dialect 1)) 6))) (_get_dialect_info dbr_dialect 1) 1 0 0 0 0)
		(translate "[dial]" (_get_dialect_info dbr_dialect 1) 1 0 0 0 0)
		(translate (+ "[libr]" (_replicate " " (- (strlen dbr_library) 6))) dbr_library 1 0 0 0 0)
		(translate "[libr]" dbr_library 1 0 0 0 0)
		(translate "<~" (_comment_character 3) 1 1 0 0 0)
		(message "")
		(restore_position)
	)
)
(macro _procedure_header
	(
		(int				year
							month
							day
							hours
							minutes
							line_
							col_
		)
		(string			begin_command
							end_command
							buffer_name
							date_str
							time_str
							header_file
		)
		(get_parm 0 begin_command)
		(get_parm 1 end_command)
		(get_parm 2 header_file)
		(inq_names NULL NULL buffer_name)
		(if (< (atoi (substr begin_command 1 1) 0) 97)
			(
				(_case_insert (+ begin_command "\n\n") 0 4 1)
				(_case_insert end_command 0 0 1)
			)
		;else
			(
				(_case_insert (+ begin_command "\n\n") 0 4 0)
				(_case_insert end_command 0 0 0)
			)
		)
		(move_rel -2 0)
		(end_of_line)
		(drop_bookmark 9 "y")
		(beginning_of_line)
		(move_rel dbr_hdr_inclusion)
		(if dbr_auto_header
			(_pro_header header_file dbr_hdr_inclusion)
		)
		(goto_bookmark 9)
	)
)
(macro revi
	(
		(int			p_col
						p_row
		)
		(string		date_time
						cmd_parm1
						cmd_parm2
		)
		(save_position)
		(end_of_buffer)
		(if (search_back (+ (_comment_character 3) " Revision:") 0 0)
			(
				(move_abs 0 12)
				(= temp_str (ltrim (trim (read 5))))
				(sprintf temp_str "Revision number [Previous: %s]: " temp_str)
			)
		;else
			(sprintf temp_str "Revision number: " temp_str)
		)
		(restore_position)
		(save_position)
		(if (get_parm 0 cmd_parm1 temp_str)
			(if (get_parm 1 cmd_parm2 "Description: ")
				(
					(end_of_buffer)
					(if (search_back (+ (+ "<" (_comment_character 3)) (_replicate "." 77)) 1 0)
						(
							(beginning_of_line)
							(move_rel 1 0)
							(= date_time (+ (_date_time 1) " at "))
							(= date_time (+ date_time (_date_time 3)))
							(= temp_str (+ cmd_parm1 " Last Revised: "))
							(= temp_str (+ temp_str date_time))
							(sprintf temp_str (+ (_comment_character 3) " Revision: %s\n") temp_str)
							(insert temp_str)
							(sprintf temp_str (+ (_comment_character 3) " Description: %s\n") cmd_parm2)
							(insert temp_str)
							(insert (+ (_comment_character 3) (+ (_replicate "." 77) "\n")))
						)
					;else
						(_display_popup_message "No comment header found!" "" 1)
					)
					(restore_position)
					(move_rel 3 0)
				)
			)
		)
	)
)
