	section	Change90,CODE
	IDNT	ALL

**	Change90
**		for makeing changes and alterations to source files semi-automatically
**
**		Copyright ©1990 DigiSoft
**
**	Permission is granted to purchasers of Macro68 to modify this source
**	file.  Permission is further granted to distribute the source code that
**	they have modified subject to the following conditions:
**	1.  That the original, unaltered, source is included with the
**	    distribution.
**	2.  That no charge is made for the distribution, other than the cost of
**	    media.                    (Distribution via Fred Fish is permitted)
**	3.  That my copyright notice remains as part of this and any other
**	    file adapted from this file.
**                                               Paul Coward
**                                                         DigiSoft
**
**	Tabstops : 8
**	Assemble with Macro68


**	20-04-90	** written


**  FUNCTION & USAGE
**
**	Change90 SourceFilename DestinationFilename ScriptFilename
**
**	Reads commands from the script file and alters the source file
**	to reflect those commands.  The result is written to the
**	destination file.
**
**  COMMANDS
**
**	#DELETE		Followed by the number of characters to be deleted.
**
**	#DELETELINE	Followed by the number of lines to be deleted.
**
**	#DOWN		Followed by the number of lines to move down.  Will
**			stop on the first character of the target line.
**
**	#ENDOFLINE	Move to the end of the current line.
**
**	#IFNOTFOUND	Skip given number of commands if the last SEARCH or
**			SEARCHNEXT command failed.
**
**	#INSERT		Insert the following text at the current location.
**
**	#LEFT		Followed by the number of characters to move.
**
**	#LEFTONLINE	Followed by the number of characters to move.  The move
**			will stop at the end of the current line.
**
**	#REMLINE	Given a pattern to search for this will delete
**			the line containing that pattern.
**
**	#REMTEXT	Given a pattern to search for this will delete
**			all of the text from the line found with that
**			pattern.
**
**	#REPLACE	Given a pattern to search for this will replace
**			it with the given string.
**
**	#REPLACENEXT	Given a pattern to search for this will search
**			forward from the current location and replace the
**			first instance of the pattern with the given string.
**
**	#RIGHT		Followed by the number of characters to move.
**
**	#RIGHTONLINE	Followed by the number of characters to move.  The move
**			will stop at the begginning of the current line.
**
**	#SEARCH		Search for a pattern from the start of the file.
**
**	#SEARCHNEXT	Search for a pattern from the current location.
**
**	#STARTOFFILE	Move to the beginning of the file.
**
**	#STARTOFLINE	Move to the start of the current line.
**
**	#UP		Followed by the number of lines to move up.  Will
**			stop on the first character of the target line.
**
**	#;		The rest of the command line is treated as a comment
**
**	##		The rest of the command file is ignored
**
**  MODIFIERS
**
**	-c		makes the search case sensitive
**	-i		causes the user to be prompted before the action is compleated


		OBJFILE		"ram:Change90"
	;	ERRFILE		"ram:Change90.bugs"

	;	PALL
	;	HALL
	;	LFCOND
		EXEOBJ
	;	LIST
	;	LISTSYMS
	;	ADDSYM
	;	LISTFILE	"ram:Change90.lst"
	;	CREFFILE	"ram:Change90.cref"
	;	EQUFILE		"ram:Change90.equ"
	;	REALTIME
		STRICT


	ifnd	EXEC_TYPES_I
_AbsExecBase		equ	4
_LVOAlert		equ	-108	;exec
_LVOCloseLibrary	equ	-414	;exec
_LVOOpenLibrary		equ	-552	;exec
AT_Recovery		equ	$00000000
AG_OpenLib		equ	$00030000
MODE_OLDFILE		equ	1005
MODE_NEWFILE		equ	1006
	endc


_LVOdsAllocCPremember	equ	-30
_LVOdsAllocScratch	equ	-42
_LVOdsClearRemember	equ	-66
_LVOdsDosClose		equ	-414
_LVOdsDosOpen		equ	-408
_LVOdsDosRead		equ	-858
_LVOdsDosWrite		equ	-864
_LVOdsEscapeString	equ	-624
_LVOdsFileSize		equ	-162
_LVOdsFreeScratch	equ	-174
_LVOdsGetDecimal	equ	-180
_LVOdsParse		equ	-216
_LVOdsPrintf		equ	-636
_LVOdsPuts		equ	-648
_LVOdsReadLine		equ	-654
_LVOdsSearch		equ	-240
_LVOdsStrLen		equ	-288


csd_RememberKey		equ	84		;.l
csd_Args		equ	88		;8 bytes
csd_SourceFileStart	equ	96		;.l
csd_SourceFileEnd	equ	100		;.l
csd_SourceBuffEnd	equ	104		;.l
csd_ComandFileStart	equ	108		;.l
csd_ComandFileLoc	equ	112		;.l
csd_ReplacementLen	equ	116		;.l
csd_CommandNumber	equ	120		;.l
csd_SearchBuffer	equ	124		;256 bytes
csd_ReplaceBuffer	equ	380		;256 bytes
csd_CaseFlg		equ	636		;.b
csd_InteractFlg		equ	637		;.b
csd_AnswerBuffer	equ	638		;256 bytes
csd_SourceFileLoc	equ	894		;.l
csd_FoundFlg		equ	898		;.b
csd_SIZEOF		equ	899


	ifnd	AO_DSSLib
	if1
	PRINTX	Resident maclib not in use.
	endc
dsl_SearchCaseFlg	equ	$22+(8*4)+2
AO_DSSLib		equ	$00008099	;alert number id support library can't be opened
Tab			equ	$09
Lf			equ	$0a
Cr			equ	$0d
CSI			equ	$9b
csd_StdErr		equ	72
csd_Output		equ	80
	endc


Release			equ	'1.0 '
VerNo			equ	'0.06'

*************************
*	COLD ENTRY	*
*************************


START:		moveq		#0,d3
		move.l		a0,d6
		move.l		d0,d7
		movea.l		(_AbsExecBase).w,a6	;establish exec for calls

	; --- open the support library

		moveq		#2,d0			;version #
		lea	 	(supportLibName,pc),a1	;point to liberary name
		jsr		(_LVOOpenLibrary,a6)	;exec
		tst.l		d0
		bne.b		1$
		move.l		#AT_Recovery!AG_OpenLib!AO_DSSLib,d7
		jsr		(_LVOAlert,a6)
		bra		EXIT

	; --- initialize the scratch area

1$		movea.l		d0,a6
		move.l		#csd_SIZEOF,d0
		moveq		#33,d1
		moveq		#0,d2
		jsr		(_LVOdsAllocScratch,a6)
		bne		EXIT

	; --- initialize the argument pointers

		movem.l		d6-d7,(csd_Args,a5)	;& a_Length(A0)

	; --- display banner

		lea		(Title,pc),a1
		jsr		(_LVOdsPuts,a6)

	; --- parse args

		lea		(csd_RememberKey,a5),a0
		move.l		#256,d0
		jsr		(_LVOdsAllocCPremember,a6)
		move.l		d0,(ArgPointers).l
		beq		exitWithError

		lea		(csd_Args,a5),a0
		lea		(additionalHelp,pc),a1
		lea		(ArgPointers+4,pc),a2
		lea		(CmdTemplate,pc),a3
		jsr		(_LVOdsParse,a6)
		bpl.b		configure
		movea.l		(ArgPointers,pc),a1
		jsr		(_LVOdsPuts,a6)
		bra		exitWithError

	; --- any source file args ?

configure:	move.l		(sourceFileName,pc),d1
		beq		exitWithError
		move.l		#MODE_OLDFILE,d2
		jsr		(_LVOdsDosOpen,a6)
		beq		exitWithError
		move.l		d0,d1
		jsr		(_LVOdsFileSize,a6)
		move.l		d0,d3			;save file size
		addq.l		#4,d0			;to get 8 extra bytes for nulls
		add.l		d0,d0
		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsAllocCPremember,a6)
		bne.b		1$
		jsr		(_LVOdsDosClose,a6)
		bra		exitWithError

1$		addq.l		#4,d0			;leave nulls at start
		move.l		d0,d2
		jsr		(_LVOdsDosRead,a6)
		sne		d4
		jsr		(_LVOdsDosClose,a6)
		tst.b		d4
		bne		exitWithError

		move.l		d2,(csd_SourceFileStart,a5)	;pointer to the start of the buffer
		movea.l		d2,a0
		lea		(0,a0,d3.l),a0			;pointer to the end of the file
		move.l		a0,(csd_SourceFileEnd,a5)
		lea		(0,a0,d3.l),a0			;pointer to the end of the buffer
		move.l		a0,(csd_SourceBuffEnd,a5)

	; --- any command file args ?

		move.l		(comandFileName,pc),d1
		beq		exitWithError

	; --- see if info is passed on the command line

		movea.l		d1,a0
		cmpi.b		#'#',(a0)
		bne.b		scriptFileGiven
		move.l		d1,(csd_ComandFileStart,a5)	;pointer to the start of the buffer
		move.l		d1,(csd_ComandFileLoc,a5)	;pointer to the current location in the comand file
		bra.b		DoFirstCmd


scriptFileGiven:
		move.l		#MODE_OLDFILE,d2
		jsr		(_LVOdsDosOpen,a6)
		beq		exitWithError
		move.l		d0,d1
		jsr		(_LVOdsFileSize,a6)
		move.l		d0,d3			;save file size
		addq.l		#8,d0
		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsAllocCPremember,a6)
		bne.b		1$
		jsr		(_LVOdsDosClose,a6)
		bra		exitWithError

1$		move.l		d0,d2
		jsr		(_LVOdsDosRead,a6)
		sne		d4
		jsr		(_LVOdsDosClose,a6)
		tst.b		d4
		bne		exitWithError

		move.l		d2,(csd_ComandFileStart,a5)	;pointer to the start of the buffer
		move.l		d2,(csd_ComandFileLoc,a5)	;pointer to the current location in the comand file

		bra.b		DoFirstCmd


	; --- modify the file


SkipCommentLine:
		cmpi.b		#Lf,(a0)+
		bne.b		SkipCommentLine
		move.l		a0,(csd_ComandFileLoc,a5)
		bra.b		DoFirstCmd


DoNextCmd:	clr.w		(csd_CaseFlg,a5)		;also clears csd_InteractFlg

		push.l		(csd_CommandNumber,a5)
		lea		(CommandNumberDone_Msg,pc),a0
		movea.l		sp,a1
		jsr		(_LVOdsPrintf,a6)
		addq.l		#4,sp

DoFirstCmd:	movea.l		(csd_ComandFileLoc,a5),a0
		moveq		#0,d0
.findNextCmd:	move.b		(a0)+,d0
		beq		endOfCommandFile
		cmpi.b		#'#',d0
		bne.b		.findNextCmd
		cmpi.b		#';',(a0)
		beq		SkipCommentLine
		cmpi.b		#'#',(a0)
		beq		endOfCommandFile

		lea		(CaseTable,pc),a1
		lea		(commandTable,pc),a2
.findCmd:	movea.l		a0,a3
		move.w		(a2)+,d1			;offset
		moveq		#0,d2
		move.b		(a2),d2				;string length
		move.l		a2,d5

1$		addq.l		#1,a2
		move.b		(a3)+,d0
		move.b		(0,a1,d0.w),d0
		cmp.b		(a2),d0
		bne.b		2$
		subq.b		#1,d2
		bne.b		1$
		cmpi.b		#' ',(a3)+
		bgt.b		2$
		movea.l		a3,a0
.skipWhitespace:
		cmpi.b		#' ',(a0)+
		bls.b		.skipWhitespace
		subq.l		#1,a0
		move.l		a0,(csd_ComandFileLoc,a5)
		addq.l		#1,(csd_CommandNumber,a5)
		jmp		(commandTable,pc,d1.w)

2$		movea.l		d5,a2
		moveq		#0,d5
		move.b		(a2)+,d5
		add.l		a2,d5
		addq.l		#1,d5
		andi.w		#$fffe,d5
		movea.l		d5,a2
		cmpi.l		#-1,(a2)
		bne		.findCmd
		addq.l		#1,(csd_CommandNumber,a5)
		bra		unknownCommandERROR

commandTable:
	sw	DeleteCharacters-commandTable
	pstr	'delete'
	even
	sw	DeleteLine-commandTable
	pstr	'deleteline'
	even
	sw	DownXlines-commandTable
	pstr	'down'
	even
	sw	ToEndOfLine-commandTable
	pstr	'endofline'
	even
	sw	IfNotFound-commandTable
	pstr	'ifnotfound'
	even
	sw	InsertString-commandTable
	pstr	'insert'
	even
	sw	LeftXcharacters-commandTable
	pstr	'left'
	even
	sw	LeftOnLine-commandTable
	pstr	'leftonline'
	even
	sw	RemoveLine-commandTable
	pstr	'remline'
	even
	sw	RemoveText-commandTable
	pstr	'remtext'
	even
	sw	SearchAndReplace-commandTable
	pstr	'replace'
	even
	sw	ReplaceNext-commandTable
	pstr	'replacenext'
	even
	sw	RightXcharacters-commandTable
	pstr	'right'
	even
	sw	RightOnLine-commandTable
	pstr	'rightonline'
	even
	sw	SearchForString-commandTable
	pstr	'search'
	even
	sw	SearchForNextString-commandTable
	pstr	'searchnext'
	even
	sw	ToStartOfFile-commandTable
	pstr	'startoffile'
	even
	sw	ToStartOfLine-commandTable
	pstr	'startofline'
	even
	sw	UpXlines-commandTable
	pstr	'up'
	even
	dl	-1


*****************************
*****************************
*****************************

	; --- command is DELETE

DeleteCharacters:
		jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		movea.l		(csd_SourceFileLoc,a5),a1
		lea		(0,a1,d0.l),a0
		cmpa.l		(csd_SourceFileEnd,a5),a0
		bls.b		.concatinate
		movea.l		(csd_SourceFileEnd,a5),a0
.concatinate:	move.b		(a0)+,(a1)+
		bne.b		.concatinate
		sub.l		d0,(csd_SourceFileEnd,a5)
		bra		DoNextCmd


*****************************

	; --- command is DELETELINE

DeleteLine:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		movea.l		(csd_SourceFileLoc,a5),a0
		move.w		d0,d1
.findStartOfLine:
		cmpa.l		(csd_SourceFileStart,a5),a0
		beq.b		1$
		cmpi.b		#Lf,-(a0)
		bne.b		.findStartOfLine
		addq.l		#1,a0
1$		move.l		a0,d0
		move.l		a0,(csd_SourceFileLoc,a5)
		bra.b		2$
.findEndOfLine:	move.b		(a0),d5
		beq.b		2$
		addq.l		#1,a0
		cmpi.b		#Lf,d5
		bne.b		.findEndOfLine
2$		dbra		d1,.findEndOfLine

		move.l		a0,d1
		sub.l		d0,d1				;length of line to be deleted
		movea.l		d0,a1				;start of line to be deleted

		tst.b		(csd_InteractFlg,a5)
		beq.b		.concatinate
		pushm.l		d0-d4/a0-a1
		move.l		a1,d2
		move.l		d1,d3
		move.l		(csd_Output,a5),d1
		jsr		(_LVOdsDosWrite,a6)
		lea		(QueryRemline_Msg,pc),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		a0,d2
		jsr		(_LVOdsDosWrite,a6)
		lea		(csd_AnswerBuffer,a5),a0
		moveq		#127,d0
		neg.b		d0
		jsr		(_LVOdsReadLine,a6)
		sne		d4
		move.l		#Cr_Msg,d2
		moveq		#crMsgSize,d3
		jsr		(_LVOdsDosWrite,a6)
		tst.b		d4
		beq.b		.concatinateOk			;accept if not interactive input
		cmpi.b		#'y',(a0)
		beq.b		.concatinateOk
		cmpi.b		#'Y',(a0)
		beq.b		.concatinateOk
		popm.l		d0-d4/a0-a1
		addq.l		#1,a0				;don't find the same again
		bra		DoNextCmd
.concatinateOk:	popm.l		d0-d4/a0-a1
.concatinate:	move.b		(a0)+,(a1)+
		bne.b		.concatinate
		sub.l		d1,(csd_SourceFileEnd,a5)
		movea.l		d0,a0
		bra		DoNextCmd


*****************************

	; --- command is DOWN

DownXlines:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
1$		movea.l		(csd_SourceFileLoc,a5),a0
2$		move.b		(a0)+,d1
		beq.b		3$
		cmpi.b		#Lf,d1
		bne.b		2$
		subq.l		#1,d0
		bne.b		1$
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd
3$		movea.l		(csd_SourceFileEnd,a5),a0
		subq.l		#1,a0
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is ENDOFLINE

ToEndOfLine:	movea.l		(csd_SourceFileLoc,a5),a0
1$		move.b		(a0)+,d1
		beq.b		2$
		cmpi.b		#Lf,d1
		bne.b		1$
2$		subq.l		#1,a0
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is IFNOTFOUND

IfNotFound:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR		;NOTE: use any number larger than the number of command lines to abort entirely
		tst.l		d0
		beq		showFormatERROR		;NOTE: 0 will fail
		move.l		a0,(csd_ComandFileLoc,a5)
		tst.b		(csd_FoundFlg,a5)
		bne		DoNextCmd

		bsr.b		.skipCommentLine	;go to the end of the line
.findNextCmd:	move.b		(a0)+,d1		;first find the start of the next command
		beq		endOfCommandFile
		cmpi.b		#'#',d1
		bne.b		.findNextCmd
		cmpi.b		#'#',(a0)		;end of commands in file ?
		beq		endOfCommandFile	;yes
		cmpi.b		#';',(a0)		;this a comment ?
		bne.b		.skipXcommands		;no
		bsr.b		.skipCommentLine
		bra.b		.findNextCmd

.skipXcommands:	bsr.b		.skipCommentLine
		addq.l		#1,(csd_CommandNumber,a5)
		subq.l		#1,d0
		bne.b		.findNextCmd
		subq.l		#1,(csd_CommandNumber,a5)
		move.l		a0,(csd_ComandFileLoc,a5)
		bra		DoNextCmd

.skipCommentLine:
		move.b		(a0)+,d1
		beq		endOfCommandFile
		cmpi.b		#Lf,d1
		bne.b		.skipCommentLine
		rts


*****************************

	; --- command is INSERT

InsertString:	cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_ReplaceBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)
		lea		(csd_ReplaceBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)
;*;		subq.l		#1,d0

		move.l		d0,d1				;expansion required
		movea.l		(csd_SourceFileEnd,a5),a0
		add.l		d1,(csd_SourceFileEnd,a5)
		lea		(0,a0,d1.l),a1
		cmpa.l		(csd_SourceBuffEnd,a5),a1
		bhi		bufferSizeExceededERROR
		movea.l		(csd_SourceFileLoc,a5),a2
		move.b		(a2),d0
		clr.b		(a2)				;give it a null to find
		clr.b		(a1)				;ensure that null termination remains
3$		move.b		-(a0),-(a1)
		bne.b		3$
		move.b		d0,(a1)

		movea.l		a2,a0				;so search dosn't keep finding the same thing
		lea		(csd_ReplaceBuffer,a5),a1
4$		move.b		(a1)+,d0
		beq		DoNextCmd
		move.b		d0,(a0)+
		bra.b		4$


*****************************

	; --- command is LEFT

LeftXcharacters:
		jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		move.l		(csd_SourceFileLoc,a5),d1
		sub.l		d0,d1
		cmp.l		(csd_SourceFileStart,a5),d1
		bhs.b		1$
		move.l		(csd_SourceFileStart,a5),d1
1$		move.l		d1,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is LEFTONLINE

LeftOnLine:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		subq.w		#1,d0
		movea.l		(csd_SourceFileLoc,a5),a0
1$		move.b		-(a0),d1
		beq.b		2$
		cmpi.b		#Lf,d1
		dbeq		d0,1$
		bne.b		3$
2$		addq.l		#1,a0
3$		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is REMLINE

RemoveLine:	bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)
		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)

		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)
.lookForMore:	lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.findStartOfLine
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.findStartOfLine:
		suba.l		d0,a0
1$		cmpa.l		(csd_SourceFileStart,a5),a0
		beq.b		2$
		cmpi.b		#Lf,-(a0)
		bne.b		1$
		addq.l		#1,a0
2$		move.l		a0,d0
.findEndOfLine:	cmpi.b		#Lf,(a0)+
		bne.b		.findEndOfLine

		move.l		a0,d1
		sub.l		d0,d1				;length of line to be deleted
		movea.l		d0,a1				;start of line to be deleted

		tst.b		(csd_InteractFlg,a5)
		beq.b		.concatinate
		pushm.l		d0-d4/a0-a1
		move.l		a1,d2
		move.l		d1,d3
		move.l		(csd_Output,a5),d1
		jsr		(_LVOdsDosWrite,a6)
		lea		(QueryRemline_Msg,pc),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		a0,d2
		jsr		(_LVOdsDosWrite,a6)
		lea		(csd_AnswerBuffer,a5),a0
		moveq		#127,d0
		neg.b		d0
		jsr		(_LVOdsReadLine,a6)
		sne		d4
		move.l		#Cr_Msg,d2
		moveq		#crMsgSize,d3
		jsr		(_LVOdsDosWrite,a6)
		tst.b		d4
		beq.b		.concatinateOk			;accept if not interactive input
		cmpi.b		#'y',(a0)
		beq.b		.concatinateOk
		cmpi.b		#'Y',(a0)
		beq.b		.concatinateOk
		popm.l		d0-d4/a0-a1
		addq.l		#1,a0				;don't find the same again
		bra		.lookForMore
.concatinateOk:	popm.l		d0-d4/a0-a1
.concatinate:	move.b		(a0)+,(a1)+
		bne.b		.concatinate
		sub.l		d1,(csd_SourceFileEnd,a5)
		movea.l		d0,a0
		bra		.lookForMore


*****************************


	; --- command is REPLACE

SearchAndReplace:
		bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate

skipWhitespace:	cmpi.b		#' ',(a0)+
		bls.b		skipWhitespace
		subq.l		#1,a0

		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_ReplaceBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)

		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)
		lea		(csd_ReplaceBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,(csd_ReplacementLen,a5)

		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)
.lookForMore:	lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.doReplacement
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.doReplacement:	movea.l		a0,a2				;save the end of match
		suba.l		d0,a0				;point to the start of the match

		tst.b		(csd_InteractFlg,a5)
		beq.b		.replace
		pushm.l		d0-d4/a0-a1
		addq.l		#1,a0
6$		cmpa.l		(csd_SourceFileStart,a5),a0
		beq.b		7$
		cmpi.b		#Lf,-(a0)
		bne.b		6$
		addq.l		#1,a0
7$		move.l		a0,d2
0$		cmpi.b		#Lf,(a0)+			;find remainder of line
		bne.b		0$
		move.l		a0,d3
		sub.l		d2,d3
		move.l		(csd_Output,a5),d1
		jsr		(_LVOdsDosWrite,a6)
		lea		(QueryReplace_Msg,pc),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		a0,d2
		jsr		(_LVOdsDosWrite,a6)
		lea		(csd_AnswerBuffer,a5),a0
		moveq		#127,d0
		neg.b		d0
		jsr		(_LVOdsReadLine,a6)
		sne		d4
		move.l		#Cr_Msg,d2
		moveq		#crMsgSize,d3
		jsr		(_LVOdsDosWrite,a6)
		tst.b		d4
		beq.b		.replaceOk			;accept if not interactive input
		cmpi.b		#'y',(a0)
		beq.b		.replaceOk
		cmpi.b		#'Y',(a0)
		beq.b		.replaceOk
		popm.l		d0-d4/a0-a1
		addq.l		#1,a0				;don't find the same again
		bra		.lookForMore
.replaceOk:	popm.l		d0-d4/a0-a1

.replace:	cmp.l		(csd_ReplacementLen,a5),d0
		blo.b		.makeMoreRoom

		; --- insert the replacement string

		lea		(csd_ReplaceBuffer,a5),a1
1$		move.b		(a1)+,d1
		beq.b		2$
		move.b		d1,(a0)+
		bra.b		1$

2$		sub.l		(csd_ReplacementLen,a5),d0
		bls		.lookForMore


		; --- contract the file

.tooMuchRoom:	push.l		a0
5$		move.b		(a2)+,(a0)+
		bne.b		5$
		sub.l		d0,(csd_SourceFileEnd,a5)
		pop.l		a0
		bra		.lookForMore



		; --- expand the area to fit the replacement string

.makeMoreRoom:	movea.l		a0,a2
		move.l		(csd_ReplacementLen,a5),d1
		sub.l		d0,d1				;expansion required
		movea.l		(csd_SourceFileEnd,a5),a0
		add.l		d1,(csd_SourceFileEnd,a5)
		lea		(0,a0,d1.l),a1
		cmpa.l		(csd_SourceBuffEnd,a5),a1
		bhi		bufferSizeExceededERROR
		clr.b		(a2)				;give it a null to find
		clr.b		(a1)				;ensure that null termination remains
3$		move.b		-(a0),-(a1)
		bne.b		3$

		movea.l		a2,a0				;so search dosn't keep finding the same thing
		lea		(csd_ReplaceBuffer,a5),a1
4$		move.b		(a1)+,d0
		beq		.lookForMore
		move.b		d0,(a0)+
		bra.b		4$


*****************************


	; --- command is REPLACE

ReplaceNext:	bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate

.skipWhitespace:
		cmpi.b		#' ',(a0)+
		bls.b		.skipWhitespace
		subq.l		#1,a0

		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_ReplaceBuffer,a5),a2
.copyStr:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyStr
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)

		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)
		lea		(csd_ReplaceBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,(csd_ReplacementLen,a5)

		movea.l		(csd_SourceFileLoc,a5),a0
		lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.doReplacement
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.doReplacement:	movea.l		a0,a2				;save the end of match
		suba.l		d0,a0				;point to the start of the match

		tst.b		(csd_InteractFlg,a5)
		beq.b		.replace
		pushm.l		d0-d4/a0-a1
		addq.l		#1,a0
6$		cmpa.l		(csd_SourceFileStart,a5),a0
		beq.b		7$
		cmpi.b		#Lf,-(a0)
		bne.b		6$
		addq.l		#1,a0
7$		move.l		a0,d2
0$		cmpi.b		#Lf,(a0)+			;find remainder of line
		bne.b		0$
		move.l		a0,d3
		sub.l		d2,d3
		move.l		(csd_Output,a5),d1
		jsr		(_LVOdsDosWrite,a6)
		lea		(QueryReplace_Msg,pc),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		a0,d2
		jsr		(_LVOdsDosWrite,a6)
		lea		(csd_AnswerBuffer,a5),a0
		moveq		#127,d0
		neg.b		d0
		jsr		(_LVOdsReadLine,a6)
		sne		d4
		move.l		#Cr_Msg,d2
		moveq		#crMsgSize,d3
		jsr		(_LVOdsDosWrite,a6)
		tst.b		d4
		beq.b		.replaceOk			;accept if not interactive input
		cmpi.b		#'y',(a0)
		beq.b		.replaceOk
		cmpi.b		#'Y',(a0)
		beq.b		.replaceOk
		popm.l		d0-d4/a0-a1
		addq.l		#1,a0				;don't find the same again
		bra		DoNextCmd
.replaceOk:	popm.l		d0-d4/a0-a1

.replace:	cmp.l		(csd_ReplacementLen,a5),d0
		blo.b		.makeMoreRoom

		; --- insert the replacement string

		lea		(csd_ReplaceBuffer,a5),a1
1$		move.b		(a1)+,d1
		beq.b		2$
		move.b		d1,(a0)+
		bra.b		1$

2$		sub.l		(csd_ReplacementLen,a5),d0
		bls		DoNextCmd


		; --- contract the file

.tooMuchRoom:	push.l		a0
5$		move.b		(a2)+,(a0)+
		bne.b		5$
		sub.l		d0,(csd_SourceFileEnd,a5)
		pop.l		a0
		bra		DoNextCmd



		; --- expand the area to fit the replacement string

.makeMoreRoom:	movea.l		a0,a2
		move.l		(csd_ReplacementLen,a5),d1
		sub.l		d0,d1				;expansion required
		movea.l		(csd_SourceFileEnd,a5),a0
		add.l		d1,(csd_SourceFileEnd,a5)
		lea		(0,a0,d1.l),a1
		cmpa.l		(csd_SourceBuffEnd,a5),a1
		bhi		bufferSizeExceededERROR
		clr.b		(a2)				;give it a null to find
		clr.b		(a1)				;ensure that null termination remains
3$		move.b		-(a0),-(a1)
		bne.b		3$

		movea.l		a2,a0				;so search dosn't keep finding the same thing
		lea		(csd_ReplaceBuffer,a5),a1
4$		move.b		(a1)+,d0
		beq		DoNextCmd
		move.b		d0,(a0)+
		bra.b		4$


*****************************


	; --- command is REMTEXT

RemoveText:	bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)
		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)

		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)
.lookForMore:	lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.findStartOfLine
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.findStartOfLine:
		suba.l		d0,a0
1$		cmpi.b		#Lf,-(a0)
		bne.b		1$
		addq.l		#1,a0
		move.l		a0,d0
.findEndOfLine:	cmpi.b		#Lf,(a0)+
		bne.b		.findEndOfLine
		subq.l		#1,a0				;leave the Lf

		move.l		a0,d1
		sub.l		d0,d1				;length of line to be deleted
		movea.l		d0,a1				;start of line to be deleted

		tst.b		(csd_InteractFlg,a5)
		beq.b		.concatinate
		pushm.l		d0-d4/a0-a1
		move.l		a1,d2
		move.l		d1,d3
		move.l		(csd_Output,a5),d1
		jsr		(_LVOdsDosWrite,a6)
		lea		(QueryRemtext_Msg,pc),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		a0,d2
		jsr		(_LVOdsDosWrite,a6)
		lea		(csd_AnswerBuffer,a5),a0
		moveq		#127,d0
		neg.b		d0
		jsr		(_LVOdsReadLine,a6)
		sne		d4
		move.l		#Cr_Msg,d2
		moveq		#crMsgSize,d3
		jsr		(_LVOdsDosWrite,a6)
		tst.b		d4
		beq.b		.concatinateOk			;accept if not interactive input
		cmpi.b		#'y',(a0)
		beq.b		.concatinateOk
		cmpi.b		#'Y',(a0)
		beq.b		.concatinateOk
		popm.l		d0-d4/a0-a1
		addq.l		#1,a0				;don't find the same again
		bra		.lookForMore
.concatinateOk:	popm.l		d0-d4/a0-a1
.concatinate:	move.b		(a0)+,(a1)+
		bne.b		.concatinate
		sub.l		d1,(csd_SourceFileEnd,a5)
		movea.l		d0,a0
		bra		.lookForMore


*****************************

	; --- command is RIGHT

RightXcharacters:
		jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		move.l		(csd_SourceFileLoc,a5),d1
		add.l		d0,d1
		cmp.l		(csd_SourceFileEnd,a5),d1
		blo.b		1$
		move.l		(csd_SourceFileEnd,a5),d1
		subq.l		#1,d1
1$		move.l		d1,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is RIGHTONLINE

RightOnLine:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		subq.w		#1,d0
		movea.l		(csd_SourceFileLoc,a5),a0
1$		move.b		(a0)+,d1
		beq.b		2$
		cmpi.b		#Lf,d1
		dbeq		d0,1$
		bne.b		3$
2$		subq.l		#1,a0
3$		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is SEARCH

SearchForString:
		clr.b		(csd_FoundFlg,a5)
		bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)
		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)

		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)
.lookForMore:	lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.recordLocation
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.recordLocation:
		st		(csd_FoundFlg,a5)
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is SEARCHNEXT

SearchForNextString:
		clr.b		(csd_FoundFlg,a5)
		bsr		CheckSwitches
		cmpi.b		#'"',(a0)+
		bne		showFormatERROR

		lea		(csd_SearchBuffer,a5),a2
.copyString:	move.b		(a0)+,d0
		move.b		d0,(a2)+
		cmpi.b		#Lf,d0
		beq		showFormatERROR
		cmpi.b		#'"',d0
		bne.b		.copyString
		clr.b		-(a2)				;null terminate
		move.l		a0,(csd_ComandFileLoc,a5)
		lea		(csd_SearchBuffer,a5),a0
		jsr		(_LVOdsEscapeString,a6)

		movea.l		(csd_SourceFileLoc,a5),a0
		lea		(csd_SearchBuffer,a5),a1
		bsr		ParseSearchString
		bne.b		.wildcardSearch
		bsr		NormalSearch
		bne.b		.recordLocation
		beq		DoNextCmd

.wildcardSearch:
		move.b		(csd_CaseFlg,a5),(dsl_SearchCaseFlg,a6)	;0 to ignore case in compare / -1 to preserve case in compare
		jsr		(_LVOdsSearch,a6)
		beq		DoNextCmd

.recordLocation:
		st		(csd_FoundFlg,a5)
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is STARTOFFILE

ToStartOfFile:	move.l		(csd_SourceFileStart,a5),(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************

	; --- command is UP

UpXlines:	jsr		(_LVOdsGetDecimal,a6)
		beq		showFormatERROR
		move.l		a0,(csd_ComandFileLoc,a5)
		movea.l		(csd_SourceFileLoc,a5),a0
1$		move.b		-(a0),d1
		beq.b		2$
		cmpi.b		#Lf,d1
		bne.b		1$
		subq.l		#1,d0
		bne.b		1$
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd
2$		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)

		;**** FALL THROUGH

*****************************

	; --- command is STARTOFLINE

ToStartOfLine:	movea.l		(csd_SourceFileLoc,a5),a0
1$		move.b		-(a0),d1
		beq.b		2$
		cmpi.b		#Lf,d1
		bne.b		1$
		addq.l		#1,a0
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd
2$		movea.l		(csd_SourceFileStart,a5),a0
		move.l		a0,(csd_SourceFileLoc,a5)
		bra		DoNextCmd


*****************************


unknownCommandERROR:
		push.l		(csd_CommandNumber,a5)
		lea		(UnknownCommandError_Msg,pc),a0
		movea.l		sp,a1
		jsr		(_LVOdsPrintf,a6)
		addq.l		#4,sp
		bra		EXIT



showFormatERROR:
		push.l		(csd_CommandNumber,a5)
		lea		(CommandFormatError_Msg,pc),a0
		movea.l		sp,a1
		jsr		(_LVOdsPrintf,a6)
		addq.l		#4,sp
		bra		DoNextCmd


*****************************

	; --- write the result back out


endOfCommandFile:
		move.l		(targetFileName,pc),d1
		beq		exitWithError
		move.l		#MODE_NEWFILE,d2
		jsr		(_LVOdsDosOpen,a6)
		beq		exitWithError
		move.l		d0,d1

		movea.l		(csd_SourceFileStart,a5),a0
		jsr		(_LVOdsStrLen,a6)
		move.l		d0,d3
		move.l		(csd_SourceFileStart,a5),d2
		jsr		(_LVOdsDosWrite,a6)
		sne		d4
		jsr		(_LVOdsDosClose,a6)
		tst.b		d4
		bne		exitWithError

EXIT:		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsClearRemember,a6)

		clr.b		(dsl_SearchCaseFlg,a6)
		jsr		(_LVOdsFreeScratch,a6)
		movea.l		a6,a1
		movea.l		(4).w,a6
		jsr		(_LVOCloseLibrary,a6)
		moveq		#0,d0
		rts					;exit to DOS


***************************************

;	Return NE if wildcards used, EQ if not

ParseSearchString:
		movea.l		a1,a2
		lea		(WildcardTable,pc),a3
		moveq		#0,d0
1$		move.b		(a2)+,d0
		beq.b		2$
		tst.b		(0,a3,d0.w)
		beq.b		1$
2$		rts





NormalSearch:	lea.l		(CaseTable,pc),a2
		push.l		a0
		push.l		a1
		moveq		#0,d0
		moveq		#0,d1

.continueCompare:
		move.b		(a1)+,d0
		tst.b		(csd_CaseFlg,a5)
		bne.b		.findFirstCharCaseSensitive

		move.b		(0,a2,d0.w),d0	;force lower case
.findFirstChar:	move.b		(a0)+,d1
		beq.b		.searchFailed
		cmp.b		(0,a2,d1.w),d0	;compare lower case chars
		bne.b		.findFirstChar
		bra.b		0$

.findFirstCharCaseSensitive:
		move.b		(a0)+,d1
		beq.b		.searchFailed
		cmp.b		d1,d0		;compare chars case sensitive
		bne.b		.findFirstCharCaseSensitive

0$		move.l		a0,d2
.compareNext:	move.b		(a1)+,d0
		beq.b		.searchSuccessful
		tst.b		(csd_CaseFlg,a5)
		bne.b		1$
		move.b		(0,a2,d0.w),d0	;force lower case

1$		move.b		(a0)+,d1
		beq.b		.searchFailed
		tst.b		(csd_CaseFlg,a5)
		bne.b		2$
		move.b		(0,a2,d1.w),d1	;force lower case

2$		cmp.b		d0,d1
		beq.b		.compareNext

		movea.l		d2,a0
		movea.l		(sp),a1		;get start of search string
		bra.b		.continueCompare

.searchSuccessful:
		pop.l		a1
		move.l		a0,d0
		subq.l		#1,d2
		sub.l		d2,d0		;string length
		addq.l		#4,sp
		moveq		#-1,d1
		rts

.searchFailed:	pop.l		a1
		pop.l		a0
		moveq		#0,d0
noSwitch:	rts





CheckSwitches:	cmpi.b		#'-',(a0)
		bne.b		noSwitch
		addq.l		#1,a0
		move.b		(a0)+,d0
		move.b		(0,a1,d0.w),d0
		subi.b		#'a',d0
		bmi		showFormatERROR
		cmpi.b		#'z'-'a',d0
		bhi		showFormatERROR
		add.w		d0,d0
		move.w		(switchLookupTable,pc,d0.w),d0
		jmp		(switchLookupTable,pc,d0.w)


switchLookupTable:
	dw	showFormatERROR-switchLookupTable		;a
	dw	showFormatERROR-switchLookupTable		;b
	dw	setCaseSwitch-switchLookupTable			;c
	dw	showFormatERROR-switchLookupTable		;d
	dw	showFormatERROR-switchLookupTable		;e
	dw	showFormatERROR-switchLookupTable		;f
	dw	showFormatERROR-switchLookupTable		;g
	dw	showFormatERROR-switchLookupTable		;h
	dw	setInteractiveSwitch-switchLookupTable		;i
	dw	showFormatERROR-switchLookupTable		;j
	dw	showFormatERROR-switchLookupTable		;k
	dw	showFormatERROR-switchLookupTable		;l
	dw	showFormatERROR-switchLookupTable		;m
	dw	showFormatERROR-switchLookupTable		;n
	dw	showFormatERROR-switchLookupTable		;o
	dw	showFormatERROR-switchLookupTable		;p
	dw	showFormatERROR-switchLookupTable		;q
	dw	showFormatERROR-switchLookupTable		;r
	dw	showFormatERROR-switchLookupTable		;s
	dw	showFormatERROR-switchLookupTable		;t
	dw	showFormatERROR-switchLookupTable		;u
	dw	showFormatERROR-switchLookupTable		;v
	dw	showFormatERROR-switchLookupTable		;w
	dw	showFormatERROR-switchLookupTable		;x
	dw	showFormatERROR-switchLookupTable		;y
	dw	showFormatERROR-switchLookupTable		;z


setInteractiveSwitch:
		st		(csd_InteractFlg,a5)
.skipWhitespace:
		cmpi.b		#' ',(a0)+
		bls.b		.skipWhitespace
		subq.l		#1,a0
		rts


setCaseSwitch:	st		(csd_CaseFlg,a5)
.skipWhitespace:
		cmpi.b		#' ',(a0)+
		bls.b		.skipWhitespace
		subq.l		#1,a0
		rts


*******************************************************************************


bufferSizeExceededERROR:
		lea		(BufferError_Msg,pc),a1
		jsr		(_LVOdsPuts,a6)
		bra		EXIT


exitWithError:	lea		(InitError_Msg,pc),a1
		jsr		(_LVOdsPuts,a6)
		bra		EXIT

***************************************
***************************************
***************************************


ArgPointers:	dl	0
sourceFileName:	dl	0		;pointer to filename
targetFileName:	dl	0		;pointer to filename
comandFileName:	dl	0		;pointer to filename

CmdTemplate:
	db	'SOURCEFILE/A,TARGETFILE/A,COMANDFILE/A',0


additionalHelp:
	db	'USAGE:',Lf
	db	'Change90 SourceFile.asm TargetFile.asm CommandFile.c90',Lf,Lf,0


***************************************
***************************************
***************************************


supportLibName:
	db	'digisoftSupport.library',0
	cnop	0,2


	oddok
Title:	db	CSI,'5;33m'			;set graphic rendition
	db	'Change90  '
	db	'Release '
	dl	Release
	db	' Vers '
	dl	VerNo
	db	' CopyRight ©1990 DIGISOFT',Lf
	db	CSI,'0;31m'			;reset graphic rendition
	db	'  12 Dinmore St.  Moorooka 4105  Brisbane, QLD  Australia',Lf
	db	'       Phone  ISD (617) 277-3255  STD (07) 277-3255'
	db	0
	odderror


InitError_Msg:
	db	Lf
	db	CSI,'5;33m'			;set graphic rendition
	db	'INITIALIZATION ERROR !!!',Lf
	db	Tab,Tab,'Bad command line OR Insufficient memory!'
	db	CSI,'0;31m'			;reset graphic rendition
	db	Lf,0


BufferError_Msg:
	db	Lf
	db	CSI,'5;33m'			;set graphic rendition
	db	'BUFFER SIZE LIMITS EXCEEDED !!!',Lf
	db	Tab,Tab,'Try fewer "REPLACE" commands !'
	db	CSI,'0;31m'			;reset graphic rendition
	db	Lf,0


UnknownCommandError_Msg:
	db	Lf
	db	CSI,'5;33m'			;set graphic rendition
	db	'Unknown command error in command # %ld *** ABORTING ! ***'
	db	CSI,'0;31m'			;reset graphic rendition
	db	Lf,0


CommandFormatError_Msg:
	db	Lf
	db	CSI,'5;33m'			;set graphic rendition
	db	'Command format error in command # %ld *** bypassing command !'
	db	CSI,'0;31m'			;reset graphic rendition
	db	Lf,0


CommandNumberDone_Msg:
	db	'Command # %ld compleated.'
Lf_Msg:	db	Lf,0


QueryRemline_Msg:
	db	CSI,'5;33m','Remove this line (Y/N)?  ',CSI,'0;31m',0

QueryRemtext_Msg:
	db	CSI,'5;33m','Remove this text (Y/N)?  ',CSI,'0;31m',0

QueryReplace_Msg:
	db	CSI,'5;33m','Replace this (Y/N)?  ',CSI,'0;31m',0

Cr_Msg:	db	Cr,CSI,'1k',0
crMsgSize	equ	*-Cr_Msg

strMsg:	db	'%s',0


*******************************************************************************


CaseTable:
	db	0,1,2,3,4,5,6,7,8,9,$a,$b,$c,$d,$e,$f
	db	$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f
	db	' !"#$%&',$27,'()*+,-./'
	db	'0123456789:;<=>?'
	db	'@abcdefghijklmno'
	db	'pqrstuvwxyz[\]^_'
	db	'`abcdefghijklmno'
	db	'pqrstuvwxyz{|}~',$7f
	db	$80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8a,$8b,$8c,$8d,$8e,$8f
	db	$90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9a,$9b,$9c,$9d,$9e,$9f
	db	$a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$aa,$ab,$ac,$ad,$ae,$af
	db	$b0,$b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8,$b9,$ba,$bb,$bc,$bd,$be,$bf
	db	$e0,$e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef
	db	$f0,$f1,$f2,$f3,$f4,$f5,$f6,$d7,$f8,$f9,$fa,$fb,$fc,$fd,$fe,$df
	db	$e0,$e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef
	db	$f0,$f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$fa,$fb,$fc,$fd,$fe,$ff


WildcardTable:
	dcb.b	$20+1,0
	db	-1		;!
	db	0
	db	-1		;#
	db	0
	db	-1		;%
	db	0
	dcb.b	3,-1		;'()
	dcb.b	($3e-$2a)+1,0
	db	-1		;?
	dcb.b	($ff-$40)+1,0


*******************************************************************************

	END
