.index"
	br	3f
2:
	movb	j.index+8.,f.recs+6
	bisb	$60,f.recs+6
3:
	jsr	r5,putindex		/to ensure that current index
					/is written with job record
	sys	open; f.recs; 1
	mov	r0,wr
	mov	j.index+10.,0f
	sys	seek; 0:..; 0
	mov	$60.,0f
	sys	write; j.record; 0:..	/write control info &
					/fixed-length fields
	clr	r1			/r1 used to count non-null cases
	mov	flengths,0f
	beq	1f
	mov	wr,r0
	sys	write; j.title; 0:..
1:
	mov	wr,r0
	sys	write; orchar; 1
	mov	flengths+2,0f
	beq	1f
	mov	wr,r0
	sys	write; j.case1; 0:..
	inc	r1
	mov	wr,r0
	sys	write; slchar; 1
1:
	mov	flengths+4,0f
	beq	1f
	mov	wr,r0
	sys	write; j.case2; 0:..
	br	0f
1:
	tst	r1
	beq	0f
	mov	wr,r0
	sys	seek; -1; 1
0:
	mov	wr,r0
	sys	write; orchar; 1
	clr	r1			/reinitialize r1 to count
					/non-null authors
	mov	flengths+6,0f
	beq	1f
	mov	wr,r0
	sys	write; j.auth1; 0:..
	inc	r1
	mov	wr,r0
	sys	write; slchar; 1
1:
	mov	flengths+8.,0f
	beq	1f
	mov	wr,r0
	sys	write; j.auth2; 0:..
	inc	r1
	mov	wr,r0
	sys	write; slchar; 1
1:
	mov	flengths+10.,0f
	beq	1f
	mov	wr,r0
	sys	write; j.auth3; 0:..
	inc	r1
	mov	wr,r0
	sys	write; slchar; 1
1:
	mov	flengths+12.,0f
	beq	1f
	mov	wr,r0
	sys	write; j.auth4; 0:..
	br	0f
1:
	tst	r1
	beq	0f
	mov	wr,r0
	sys	seek; -1; 1
0:
	mov	wr,r0
	sys	write; orchar; 2	/write 1 "|" to delimit authors
					/another to delimit spare v field
	mov	$"nu,bline
	movb	$'\n,bline+2
	movb	$1,lflag
	clrb	eflag
	jsr	r5,interpreter		/write "saved" message
	jsr	r5,mesg
	< saved\n\0>
	.even
	mov	wr,r0
	sys	close
	clrb	cflag			/reset core changed flag
	bic	$100000,j.number	/reset lock bit
	jsr	r5,putindex		/write updated index 
	br	9f
8:
	movb	$1,eflag		/set error indicator
9:
	mov	(sp)+,r1		/restore r1
	rts	r5			/return



	.even
/"allocate" allocates space in job records files
/inputs:
/   address of job record length passed as argument after call
/outputs:
/   (1)  r0 = 0 if out of space
/        r0 = ptr to free space if space available
/   (2)  "f.recs" contains file name where space exists
/   (3)  first word of records file where space exists is
/        incremented over space allocated.
allocate:
	mov	r1,-(sp)		/save regs
	mov	r2,-(sp)
	mov	*(r5)+,r2		/retrieve argument
	clr	r1			/r1 keeps track of record file no
0:
	inc	r1
	cmp	r1,$4
	ble	1f
	jsr	r5,ioerror
	<22>				/record files are full
	br	8f
1:
	movb	r1,f.recs+6
	bisb	$60,f.recs+6		/change to ASCII digit
	sys	open; f.recs; 1		/open a job record file for wr
	mov	r0,wr
	sys	open; f.recs; 0		/open a job record file for read
	mov	r0,rr
	sys	read; temp; 2
	mov	temp,temp+2		/"temp+2" contains allocation ptr
	add	r2,temp
	bcc	1f			/branch if not over file edge
	mov	rr,r0
	sys	close
	mov	wr,r0
	sys	close
	br	0b
1:
	mov	wr,r0
	sys	seek; 0; 0
	sys	write; temp; 2		/update next available slot ptr
	mov	rr,r0
	sys	close
	mov	wr,r0
	sys	close
	mov	temp+2,r0
	br	9f
8:					/error leg
	clr	r0			/return r0=0
	movb	$1,eflag		/set error indicator
9:
	mov	(sp)+,r2		/restore regs
	mov	(sp)+,r1
	rts	r5			/return



/"fndlengths" computes length of variable length fields
fndlengths:
	mov	r1,-(sp)		/save r1
	mov	$j.title,r0
	mov	$j.title+128.,r1
0:
	tstb	(r0)+			/compute length of title
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.title,r0
	dec	r0
	mov	r0,flengths
	mov	$j.case1,r0
	mov	$j.case1+10.,r1
0:					/compute length of 1st case
	tstb	(r0)+
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.case1,r0
	dec	r0
	mov	r0,flengths+2
	mov	$j.case2,r0
	mov	$j.case2+10.,r1
0:					/compute length of 2nd case
	tstb	(r0)+
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.case2,r0
	dec	r0
	mov	r0,flengths+4
	mov	$j.auth1,r0
	mov	$j.auth1+30.,r1
0:
	tstb	(r0)+			/compute length of 1st author
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.auth1,r0
	dec	r0
	mov	r0,flengths+6
	mov	$j.auth2,r0
	mov	$j.auth2+30.,r1
0:
	tstb	(r0)+			/compute length of 2nd author
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.auth2,r0
	dec	r0
	mov	r0,flengths+8.
	mov	$j.auth3,r0
	mov	$j.auth3+30.,r1
0:
	tstb	(r0)+			/compute length of 3rd author
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.auth3,r0
	dec	r0
	mov	r0,flengths+10.
	mov	$j.auth4,r0
	mov	$j.auth4+30.,r1
0:
	tstb	(r0)+			/compute length of 4th author
	beq	1f
	cmp	r0,r1
	blo	0b
	inc	r0
1:
	sub	$j.auth4,r0
	dec	r0
	mov	r0,flengths+12.
	mov	(sp)+,r1		/restore r1
	rts	r5			/return
	.=b.overlay+1100.
e.overlay:				/end overlay area
	sys	open; jobsub; 0
	mov	r0,rj
	sys	open; savesub; 0
	mov	r0,rs
	sys	intr; 0			/disable DEL's
	sys	open; f.index; 0	/open "jobindex" for reading
	mov	r0,ri
	sys	open; f.index; 1	/open "jobindex" for writing
	mov	r0,wi
	mov	sp,savesp		/save stack pointer at command
					/level
	sys	intr; level0		/intercept DEL's
	mov	$"jo,bline		/set up to read dummy record
	mov	$"b/,bline+2
	mov	$"0-,bline+4
	mov	$"S\n,bline+6
	clrb	cflag
	clrb	eflag
	movb	$1,lflag
	jsr	r5,interpreter
level0:
	mov	savesp,sp		/pop stack to command level
	clrb	intflag			/reset flag that indicates
					/DEL interrupt occurred
	sys	intr; 0			/disable DEL's
1:
	clrb	eflag			/reset error indicator
	mov	$1,r0
	sys	write; prompt; 3	/write prompt char
	jsr	r5,interpreter		/call interpreter
	br	1b
done:					/exit
	tstb	cflag			/current record changed?
	beq	1f			/branch if no
	jsr	r5,mesg
	<3RESPOND "SAVE" OR "NOSAVE"4\n\0>
	.even
	br	level0
1:
	mov	ri,r0
	sys	close
	mov	wi,r0
	sys	close
	sys	exit
savesp:
	.=.+2
token2:
	.=.+2
token3:
	.=.+2
token4:
	.=.+2
j.record:
j.index:
j.length:
	.=.+4
j.number:
	.=.+8.
j.loc:
	.=.+2
j.odate:
	.=.+2
j.ddate:
	.=.+2
j.dcode:
	.=.+4
j.cdate:
	.=.+2
j.attny:
	.=.+6
j.super:
	.=.+6
j.dir:
	.=.+6
j.orig1:
	.=.+2
j.orig2:
	.=.+2
j.orig3:
	.=.+2
j.orig4:
	.=.+2
	.=.+10.				/reserved for future use
j.title:
	.=.+128.
j.case1:
	.=.+10.
j.case2:
	.=.+10.
j.auth1:
	.=.+30.
j.auth2:
	.=.+30.
j.auth3:
	.=.+30.
j.auth4:
	.=.+30.
	.=.+8.				/This is buffer area in case
					/all variable fields are max
	.even
ri:
	.=.+2
wi:
	.=.+2
rj:
	.=.+2				/read id for "jobsub"
rs:
	.=.+2				/read id for "savesub"
rr:
	.=.+2
wr:
	.=.+2
whatsin:				/"whatsin" = "1" if "job" in over
	1				/lay; = "2" if "save" in overlay
temp:
	.=.+54.
bline:
	.=.+221.
eline:
	.=.+1
blanks:
	<         >
prompt:
	<\n! >
cflag:
	.=.+1				/"core record changed" flag
eflag:
	.=.+1				/"error indicator"
lflag:
	.=.+1				/"in line buffer" flag
f.index:
	<f.index\0>
f.recs:
	<f.recs \0>
f.cases:
	<f.cases\0>
f.attnys:
	<f.attnys\0>
jobsub:
	<jobsub\0>
savesub:
	<savesub\0>
nl:
	<\n>
