	section	CompareDates,CODE
	IDNT	ALL

	comment	®
CompareDates
	for comparing two (or three) file dates

	This is intended for use in batch files to give the result of a
poor man's make utility.  The code is "pure" so that it can be made resident.
	The program will return WARN if any of the files listed on the command
line have a datestamp later than the first file.  Else it will return OK.

example:

comparedates	sourcefile.asm targetfile headerfile
	if WARN
		macro68 sourcefile.asm -o targetfile
	endif

	Copyright ©1991 DigiSoft
  12 Dinmore St.  Moorooka 4105  Brisbane, QLD  Australia
       Phone  ISD (617) 277-3255  STD (07) 277-3255

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


written	23-08-91

end of comment block ®


Release	equstr	'1.001'

	exeobj
	objfile		ram:CompareDates
;	errorfile	ram:CompareDates.bugs
;	creffile	ram:CompareDates.cref
;	addsym
	realtime
	strict
	newsyntax
;	verboseoptim
;	multipass
	pure
;	verbosefile	"CON:0/0/600/50/Macro68"

***** INCLUDES

	ifnd	EXEC_TYPES_I
	if1
	printx	Resident maclib not in use.
	endc
	incpath	includes:
	macfile	exec/types.i
	macfile	libraries/dos.i
	macfile	libraries/dosextens.i
	endc

***** EQUATES

	ifnd	EXEC_TYPES_I
Lf	equ	$a
CSI	equ	$9b
Tab	equ	9
	endc

_LVOdsAllocScratch	equ	-42
_LVOdsPuts		equ	-648
_LVOdsAllocCPremember	equ	-30
_LVOdsParse		equ	-216
_LVOdsClearRemember	equ	-66
_LVOdsFreeScratch	equ	-174
_LVOdsDosLock		equ	-678
_LVOdsDosUnLock		equ	-684
_LVOdsDosExamine	equ	-696


		setso	84
csd_Args		so.l	2
csd_RememberKey		so.l	1
csd_ArgPointers		so.l	1
csd_baseFileName	so.l	1
csd_testFileNames	so.l	10
csd_FIB			so.b	fib_SIZEOF
csd_SIZEOF	soval



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


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

	; --- do workbench stuff first --- ABORT if from workbench

		movea.l		(ThisTask,a6),a3
		tst.l		(pr_CLI,a3)
		bne.b		.fromCLI		;branch if from CLI
		lea		(pr_MsgPort,a3),A0	;our process base
		jsr		(_LVOWaitPort,a6)	;wait for message from starter
		lea		(pr_MsgPort,a3),A0	;our process base
		jsr		(_LVOGetMsg,a6)
		movea.l		d0,a1			;workbench message
		jsr		(_LVOReplyMsg,a6)
		moveq		#RETURN_FAIL,d0
		rts

	; --- open the support library

.fromCLI:	moveq		#17,d0			;version #
		lea	 	(supportLibName,pc),a1	;point to liberary name
		jsr		(_LVOOpenLibrary,a6)	;exec
		tst.l		d0
		bne.b		.libOpen
		lea		(intuitionLibName,pc),a1
		jsr		(_LVOOldOpenLibrary,a6)
		tst.l		d0
		bne.b		.intuitionAvailable
		movei.l		#AT_Recovery!AG_OpenLib!AO_Intuition,d7
		jsr		(_LVOAlert,a6)
		bra.b		.failStart
.intuitionAvailable:
		movea.l		d0,a6				;intuition base
		lea		(digisoftLibLost_AlertMsg,pc),a0
		moveq		#0,d0
		moveq		#50,d1
		jsr		(_LVODisplayAlert,a6)
		movea.l		a6,a1
		movea.l		(_AbsExecBase).w,a6
		jsr		(_LVOCloseLibrary,a6)
.failStart:	moveq		#RETURN_FAIL,d0
		rts

	; --- initialize the scratch area

.libOpen:	movea.l		d0,a6
		move.l		#csd_SIZEOF,d0
		moveq		#33,d1
		moveq		#0,d2
		jsr		(_LVOdsAllocScratch,a6)
		bne		Exit_To_DOS

	; --- 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,(csd_ArgPointers,a5)
		beq		InsufficientMemory

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

	; --- any filename args ?

configure:	move.l		(csd_baseFileName,a5),d1
		bsr.b		GetFIB
		move.l		(csd_FIB+fib_DateStamp+ds_Days,a5),d4
		move.l		(csd_FIB+fib_DateStamp+ds_Minute,a5),d5
		move.l		(csd_FIB+fib_DateStamp+ds_Tick,a5),d6
		moveq		#0,d7				;assume success

		lea		(csd_testFileNames,a5),a2
.next:		move.l		(a2)+,d1
		beq.b		EXIT
		bsr.b		GetFIB
		cmp.l		(csd_FIB+fib_DateStamp+ds_Days,a5),d4
		bhi.b		.next				;second is earlier
		blo.b		.warn				;first is earlier
		cmp.l		(csd_FIB+fib_DateStamp+ds_Minute,a5),d5
		bhi.b		.next				;second is earlier
		blo.b		.warn				;first is earlier
		cmp.l		(csd_FIB+fib_DateStamp+ds_Tick,a5),d6
		bhi.b		.next				;second is earlier
.warn:		moveq		#RETURN_WARN,d7			;bad luck!

EXIT:		lea		(csd_RememberKey,a5),a0
		jsr		(_LVOdsClearRemember,a6)
Exit_To_DOS:	jsr		(_LVOdsFreeScratch,a6)
		movea.l		a6,a1
		movea.l		(4).w,a6
		jsr		(_LVOCloseLibrary,a6)
		move.l		d7,d0
		rts						;exit to DOS


	; --- error detected during start - exit gracefully

exitWithError:	lea		(InitError_Msg,pc),a1
		bra.b		exit
InsufficientMemory:
		lea		(InsufficientMemory_Msg,pc),a1
		bra.b		exit
examineError:	jsr		(_LVOdsDosUnLock,a6)
		addq.l		#4,sp				;waste return
		lea		(examineError_Msg,pc),a1
		bra.b		exit
fileNotFoundError:
		addq.l		#4,sp				;waste return
		lea		(fileError_Msg,pc),a1
exit:		jsr		(_LVOdsPuts,a6)
		moveq		#RETURN_FAIL,d7
		bra.b		EXIT


	; general subs

GetFIB:		moveq		#ACCESS_READ,d2
		jsr		(_LVOdsDosLock,a6)
		beq.b		fileNotFoundError
		move.l		d0,d1
		lea		(csd_FIB,a5),a0
		move.l		a0,d2
		jsr		(_LVOdsDosExamine,a6)
		beq.b		examineError
		jmp		(_LVOdsDosUnLock,a6)


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


CmdTemplate:
	db	'BASEFILE/A,TESTFILE/A,NEXTFILE1,NEXTFILE2,NEXTFILE3,NEXTFILE4,'
	cstr	'NEXTFILE5,NEXTFILE6,NEXTFILE7,NEXTFILE8,NEXTFILE9'


additionalHelp:
	db	'USAGE:',Lf
	db	'CompareDates BaseFile TestFile [NextFile1...NextFile9]',Lf
	db	Tab,'To compare the datestamp of the base file against the',Lf
	db	Tab,'datestamp of the subsequent files.  WARN will be returned',Lf
	cstr	Tab,'if any of the test files is later than the base file.',Lf,Lf


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


intuitionLibName:
	cstr	'intuition.library'
supportLibName:
	cstr	'digisoftSupport.library'


Title:	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'CompareDates  Release ',Release,' CopyRight ©1991 DIGISOFT',Lf
	cstr	CSI,$30,';',$33,$31,'m'			;reset graphic rendition


	oddok
digisoftLibLost_AlertMsg:
	dw	137
	db	15
	cstr		'digisoftSupport.library ----------- LOST'
	db	-1
	dw	43
	db	35
	cstr		'LEFT = OK'
	db	-1
	dw	640-123
	db	35
	cstr		'RIGHT = OK',0
	odderror


InitError_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'INITIALIZATION ERROR !!!',Lf
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	cstr	Lf


InsufficientMemory_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'ERROR !!!',Lf
	db	Tab,Tab,'Insufficient memory!'
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	cstr	Lf

fileError_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'ERROR !!!',Lf
	db	Tab,Tab,'Can''t find the file!'
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	cstr	Lf


examineError_Msg:
	db	Lf
	db	CSI,$35,';',$33,$33,'m'			;set graphic rendition
	db	'ERROR !!!',Lf
	db	Tab,Tab,'Examine failed!'
	db	CSI,$30,';',$33,$31,'m'			;reset graphic rendition
	cstr	Lf


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

	END
