;File name:	RENAME.S			Revision date:	1992.04.27
;Created by:	Ulf Ronald Andersson		Creation date:	1992.02.18
;Copyright:	(C)1992 Ulf Ronald Andersson
;
	output	.TTP
;
	include	URAn_SYS.S
	include	URAn_DOS.S
;
;
	text
;
	opt	a+
	opt	o+
	opt	p+
;	
;
must_args	= 2
;
;
printi	macro	string
	bra.s	.skip\@
.string\@:	dc.b	\1,NUL
	even
.skip\@:
	lea	.string\@(pc),a0
	bsr	printsb
	endm	;printi
;
;
prints	macro	string
	lea	\1,a0
	bsr	printsb
	endm	;prints
;
;
printd	macro	string
	move.l	\1,a0
	bsr	printsb
	endm	;printd
;
;
idprint	macro	string
	bra.s	.skip\@
.string\@:	dc.b	\1,NUL
	even
.skip\@:
	lea	.string\@(pc),a0
	bsr	idprintsb
	endm	;idprint
;
;
_startup:
	move.l	4(sp),a5		;a5->BP
	move.l	bp_bss_beg_p(a5),a0
	add.l	bp_bss_len(a5),a0
	move.l	a0,sp			;sp->bss_beg + bss_len
	sub.l	a5,a0			;a0 = total size of program
	gemdos	Mshrink,!,(a5),a0	;returns RAM to OS
	lea	static,a4
	clr	_argc-static(a4)
	lea	_argv(pc),a2
	lea	_argcopy(pc),a1
	lea	_prog_id(pc),a0
	move.l	a0,(a2)+
	lea	bp_argstring(a5),a3
	move.b	bp_arglen(a5),d7
	and	#$7F,d7
	clr	d6
	subq	#1,d7
	bmi.s	.gotargs
.getarg_lp_1:
	cmpi.b	#' ',(a3)+
	dbgt	d7,.getarg_lp_1
	ble.s	.gotargs
	subq	#1,a3
	addq	#1,d6			;_argc += 1
	move.l	a1,(a2)+		;_argv[d6] = a1
.getarg_lp_2:
	move.b	(a3)+,(a1)+
	cmpi.b	#' ',(a3)
	dble	d7,.getarg_lp_2
	bgt.s	.gotargs
	clr.b	(a1)+
	bra.s	.getarg_lp_1
;
.gotargs:
	move	d6,_argc-static(a4)
	bsr	main
	move.w	d0,-(sp)
	beq.s	.do_exit
	move.l	a0,a3
	beq.s	.do_exit
	printi	<CR,LF>
	move.l	a3,a0
	bsr.s	idprintsb
	printi	<CR,LF,' usage:	RENAME.TTP oldpath newpath',CR,LF>
.do_exit:
	gemdos	Pterm,()
;
;
printsb:
	gemdos	Cconws,(a0)
	rts
;
;
idprintsb:
	pea	(a0)
	prints	erase_s(pc)
	printd	_argv(pc)
	printi	<':	'>
	printd	(sp)+
	rts
;
;
	data
;
_argc:		ds.w	1
_argv:		ds.l	65
_argcopy:	dcb.b	128,0
crlf_s:		dc.b	CR,LF,NUL
erase_s:	dc.b	CR,ESC,'K',NUL
	even
;
static:
;
_prog_id:	dc.b	'RENAME',NUL
;
argc_err_s:	dc.b	'Specify 2 unique arguments !',NUL
failed_s:	dc.b	'Renaming did not work !',NUL
		even
;
;
	bss
;
;
	ds.l	$100	;allow 256 longwords on minimum stack
;
;
	text
;
;
main:						;main(argc,argv)
	idprint	<'Counting arguments.'>
	lea	argc_err_s(pc),a0
	moveq	#-1,d0
	cmp	#2,_argc-static(a4)
	bne.s	main_exit
	idprint	<'Arguments accepted.'>
	gemdos	Frename|_ind,!,_argv+4(pc),_argv+8(pc)
	lea	failed_s(pc),a0
	tst	d0
	bne.s	main_exit
	prints	erase_s(pc)
	clr.l	d0
main_exit:
	rts
;
;
	end	;of file:	COPY.S