;****************************************************************************
;**		symchg.m:
;**			change to new symbols
;**			4/30/86, T. Revay
;**
;**		This macro reads symbols to be changed from a file, "symchg.txt".
;**		The file format is a list of symbols; symbols on odd numbered lines
;**		(with the first line in the file as line no. 1) are translated into
;**		the symbols on the even numbered line below them, with a period on
;**		the last line of the file.  For example, if symchg.txt contains:
;**
;**		FIRSTSYM
;**		NEWFIRSTSYM
;**		SECONDSYM
;**		NEWSECONDSYM
;**		.
;**
;**		the translation would be:
;**		
;**		(translate FIRSTSYM NEWFIRSTSYM)
;**		(translate SECONDSYM NEWSECONDSYM)
;**
;**		The last line of symchg.txt MUST contain a period as the ONLY
;**		character on the line.  This is the terminating condition for the
;**		macro, so it's real important.
;**
;**		To use this macro, change the "symchg.txt" file to record the search
;**		and translate strings you want.  Then edit the file(s) you want the
;**		symbols changed in.  Press F10, type "symchg", and off you go.  Note
;**		that the "translate" command will prompt you for every change you
;**		make; this can be changed to produce a global change if you're
;**		very brave (remember to press Alt-F10 to recompile the macro if
;**		you've made any changes.
;**
;***************************************************************************

(macro symchg
	(
		(string searchpat
				reppat
				filename
				sjunk
				bufname
		)
		(int	line
		)

		(pause_on_error)
		(inq_names filename sjunk bufname)
		(if (exist "symchg.txt")
			(
			(edit_file "symchg.txt")
			(= line 1)
			(goto_line line)
			(beginning_of_line)
			(sprintf searchpat "%s" (read))
			)
		;else
			(
			(beep)
			(message "The file 'symchg.txt' must exist!  Press a key...")
			(keyboard_flush)
			(while (== (read_char) -1) )
			(sprintf searchpat ".\n")
			)
		)
		(while (!= searchpat ".\n")
			(
			(sprintf searchpat "%s" (substr searchpat 1 (- (strlen searchpat) 1) ) )
			(++ line)
			(goto_line line)
			(beginning_of_line)
			(sprintf reppat "%s" (read))
			(sprintf reppat "%s" (substr reppat 1 (- (strlen reppat) 1) ) )
			(message "Searching for [%s] ..." searchpat)
			(edit_file filename)
			(top_of_buffer)

;**	These two lines following are for debugging; you should redirect output
;** to your printer if you uncomment them.
;**			(printf "Line %d: changing [%s] " line searchpat )
;**			(printf " to [%s]\n" reppat)

;** Here is the call to translate.  The commented one performs a global
;** traslation without prompting -- BE CAREFUL ABOUT USING IT!

			(translate searchpat reppat)			
;**			(translate searchpat reppat 1)

			(edit_file "symchg.txt")
			(++ line)
			(goto_line line)
			(sprintf searchpat "%s" (read))
			)
		)
		(message "Finished" )
		(edit_file filename)
	)
)

