; PS:<KERMIT>UPDATE.MAC.3,  7-Jul-83 19:25:10, Frank
;  Use .FBWRT, not .FBCRE for date criterion.

	Title update

	search monsym,macsym,cmd
	.require sys:macrel,mac:cmd

$ver=1
$edit=^d2

; Symbols & macros.

e=<d=<c=<b=<a=1>+1>+1>+1>+1	; Temporary ACs.
p=17				; Stack pointer
pdlsiz==100			; Stack size.

; Macro definitions.

; %jserr - JSYS error handler
;
define %jserr (label) <		;; Use this immediately following a JSYS.
	erjmp [	jserr		;; Give most recent JSYS error msg,
ifb <label>,<	HALTF%		;; then if no label was specified, halt,
		jrst .+1	;; continuably,
>;ifb
ifnb <label>,<	jrst label>	;; or if there was, go there.
	      ]
>;%jserr
	
	subttl Data

CMDSTG				; CMD allocates some storage for itself...
	0
pdl:	block pdlsiz		; Stack.
injfn:	0			; Wild JFN to step thru.
outjfn:	0			; JFN for command file to build.
fildat:	0			; Date to compare against.
temp:	block 10		; Temporary storage.
destln==50			; String for
dest:	block destln		;  destination of COPY command.


entvec:	jrst start		; Start address
	jrst start		; Reenter address
ver:	byte(3)0(9)$ver(6)0(18)$edit ; Version
evlen= .-entvec

; Initialization

start:	RESET%
	move p, [pdlsiz,,pdl]

; Get JFN of input file & open it, using TTY: as source of file name

	tmsg <
UPDATE produces a list of files modified since the given date in a form
that can be used as a command file for the EXEC or NFT.

>
	call cmdini
ifile:	prompt <Files to Copy: >
	move a, sbk+.cmbfp
	movem a, temp
	movei a, cjfnbk		; Set up defaults in CMD's JFN block.
	movx b, gj%old!gj%flg!gj%ifg ; Old file, allow wildcards.
	movem b, (a)		; Generation 0, these flags
	setzm .gjdev(a)		; Connected device
	setzm .gjdir(a)		;  and directory.
	hrroi b, [asciz/*/]	; All files...
	movem b, .gjnam(a)
	movem b, .gjext(a)
	movei a, [flddb. .cmfil,,,<Input filespec, possibly wild>]
	call cfield
	movem b, injfn		; Save input jfn for later

; Same deal for the output file

ofile:	call cmdini
	hrroi a, [asciz/Name of Command File to Produce: /]
	move e, a
	call dpromp
	movem e, sbk+.cmrty
	move a, temp
	movem a, sbk+.cmbfp
	movei a, cjfnbk
	movx b, gj%new!gj%fou	; New file.
	movem b, (a)		; Generation 0, these flags
	setzm .gjdev(a)		; Connected device
	setzm .gjdir(a)		;  and directory.
	hrroi b, [asciz/UPDATE/] ; File name UPDATE,
	movem b, .gjnam(a)
	hrroi b, [asciz/CMD/]	; File type .CMD.
	movem b, .gjext(a)
	movei a, [flddb. .cmfil,,,<Name of command file to build>]
	call cfield
	movem b, outjfn		; Save the output jfn
	move a, b
	move b, [fld(^d7,of%bsz)!of%wr] ; 7 bit bytes, write access
	OPENF%			; Open it
	 %jserr ofile		; Try again if error

prefix:	prompt <Target Prefix (network node, device, directory): >
	movei a, [flddb. .cmtxt]
	call cfield
	move a, [point 7, atmbuf]
	move b, [point 7, dest]
pref2:	ildb c, a
	idpb c, b
	jumpn c, pref2

date:	prompt <Include only files modified since: >
	movei a, [flddb. .cmtad,,<cm%ida+cm%itm>]
	call cfield
	movem b, fildat

; Main processing loop

dir:	setz e,			; File counter.
	movei a, .priou
	move b, injfn		; Start off with JFN of initial file
	setzb c, d		;  and a little message
	JFNS
	tmsg <...>
	move a, b

dloop:	hrrzs a			; GTFDB doesn't like flags in LH.
	skipa b, .+1		; Get write date.
	 1,,.fbwrt
	movei c, d
	GTFDB
	 %jserr next
	camg d, fildat		; New file?
	 jrst next		;  No, get next one.
	aos e			; Yes, count it.
	move a, outjfn		; And write a COPY command for it.
	hrroi b, [asciz/copy /]
	setzb c, d
	SOUT
	hrrz b, injfn		; Again, no flags.
	setzb c, d
	JFNS
	hrroi b, [asciz/ (to) /]
	SOUT
	hrroi b, dest
	SOUT
	hrroi b, [asciz/
/]
	SOUT
next:	move a, injfn		; Get back the original JFN.
	GNJFN			; Get the Next JFN that matches.
	 skipa			;  If none, then all done.
	jrst dloop		; Loop for all files.

; Come here when no more files match the given specification.
 
done:	RLJFN	
	tmsg <
Done, >
	movei a, .priou
	move b, e
	movei c, ^d10
	NOUT%
	 nop
	tmsg < files found>
	jumpn e, [tmsg <
Commands are in >
		movei a, .priou
		move b, outjfn
		setzb c, d
		JFNS
		jrst .+1 ]
	move a, outjfn
	skipg e
	 txo a, cz%abt		; If none, don't create the file.
	CLOSF
	 %jserr
	HALTF
	jrst start

	end <evlen,,entvec>
