X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/3f14b03d36a95255a15cc197a12969bfbcc01624..31cef89cb428866f787983e68246030321893df4:/usr/src/cmd/px/35iosubs.s diff --git a/usr/src/cmd/px/35iosubs.s b/usr/src/cmd/px/35iosubs.s index 476677d52c..3ca6d49544 100644 --- a/usr/src/cmd/px/35iosubs.s +++ b/usr/src/cmd/px/35iosubs.s @@ -1,5 +1,7 @@ # -# 35iosubs.s +# Copyright (c) 1979 Regents of the University of California +# +# char sccsid[] = "@(#)35iosubs.s 4.2 10/16/80"; # # IO SUBROUTINES # @@ -23,7 +25,7 @@ .globl _fwrite .globl _mktemp .globl _rewind - .globl _sscanf + .globl _setbuf .globl _ungetc .globl _unlink # @@ -144,22 +146,23 @@ wtopen: .byte 'w, 0 # is stored in the file variable. # # -_getname: - .word R6|R7|R8|R9|R11 - cvtbl (r10)+, r8 # r8 has file name length - moval 4(ap), r9 # r9 will point to cleared stack - addl2 r8, r9 - blbc r9,l3501 - incl r9 -l3501: - movl ( r9)+, r11 # r11 pts to file variable - tstl ( r11) #check for existing file record +_getname: #(datasze, maxnamlen, name, fileptr) +#int datasze; +#int maxnamlen; +#char *name; +#struct file **fileptr; + + .word R6|R7|R8|R9 + movl 4(ap),r6 #r6 has data size + movl 12(ap), r8 # r8 points to file name + movl 16(ap), r9 # r9 pts to file variable + tstl ( r9) #check for existing file record bneq gotone # # allocate and initialize a new file record # clrl r7 # r7 has status flags - cvtwl (r10)+,r6 #r6 has data size + tstl r6 #check for size bneq l3502 movw $FTEXT, r7 #default to text file movl $1,r6 #default size @@ -167,13 +170,12 @@ l3502: addl3 $recsze,r6,-(sp)#size of record calls $1,_palloc #r0 points to allocated buffer addl2 $recsze,r0 #adjust to base of record -l3503: clrl LCOUNT(r0) #set default line limits movl _llimit,LLIMIT(r0) movw r7,FUNIT(r0) #set flags movl r6,FSIZE(r0) #set size - movl r11,FLEV(r0) #set ptr to file variable - movl r0,( r11) #set file var ptr + movl r9,FLEV(r0) #set ptr to file variable + movl r0,( r9) #set file var ptr # # link the new record into the file chain # @@ -184,42 +186,42 @@ l3504: movl r1,r6 #advance previous movl FCHAIN(r1),r1 #get next l3505: - cmpl FLEV(r1), r11 #check level + cmpl FLEV(r1), r9 #check level blssu l3504 #continue until greater movl r1,FCHAIN(r0) #link in new record movl r0,FCHAIN(r6) - movl r0, r11 # r11 points to file record + movl r0, r9 # r9 points to file record jbr setname # # have a previous buffer, dispose of associated file # gotone: - addl2 $2,r10 #discard data size - movl ( r11), r11 # r11 points to file record - bicw2 $~(FDEF+TEMP+FTEXT),FUNIT( r11) #clear status flags - bbc $fDEF,FUNIT( r11),l3506 #check for predefined file - bicw2 $FDEF,FUNIT( r11) #clear predefined flag + movl ( r9), r9 # r9 points to file record + bicw2 $~(FDEF+TEMP+FTEXT),FUNIT( r9) #clear status flags + bbc $fDEF,FUNIT( r9),l3506 #check for predefined file + bicw2 $FDEF,FUNIT( r9) #clear predefined flag jbr setname l3506: - pushl FBUF( r11) #flush and close previous file + pushl FBUF( r9) #flush and close previous file calls $1,_fclose - movl FBUF( r11),r0 + movl FBUF( r9),r0 bbs $ioERR,FLAG(r0),eclose - bbc $fTEMP,FUNIT( r11),setname #check for temp file + bbc $fTEMP,FUNIT( r9),setname #check for temp file tstl r8 #remove renamed temp files beql setname - pushl PFNAME( r11) + pushl PFNAME( r9) calls $1,_unlink tstl r0 #check for remove error beql setname - movl PFNAME( r11),_file +eunlink: + movl PFNAME( r9),_file movw $EREMOVE,_perrno moval error,PC(fp) #error return ret eclose: - movl PFNAME( r11),_file + movl PFNAME( r9),_file movw $ECLOSE,_perrno moval error,PC(fp) #error return ret @@ -229,45 +231,37 @@ eclose: setname: tstl r8 #check for a given name bneq l3508 #br => has a name - tstb FNAME( r11) #check for no current name + tstb FNAME( r9) #check for no current name bneq l3513 #br => had a previous name so use it # # no name given and no previous name, so generate # a new one of the form tmp.xxxxxx # - bisw2 $TEMP,FUNIT( r11)#set status to temporary + bisw2 $TEMP,FUNIT( r9)#set status to temporary pushal tmpname #get a unique temp name calls $1,_mktemp - movl $13, r8 #max length of temp name - brb l3511 -# -# name is given, strip trailing blanks -# -l3508: - bicw2 $TEMP,FUNIT( r11)#set permanent status - moval 4(ap),r0 #r0 pts to end of file name - addl3 r8,r0,r1 #r1 pts to end of name -l3509: - cmpb -(r1),$blank #delete trailing blanks - bneq l3511 #(note: could use "scanc" with source - clrb (r1) # and table reversed) - sobgtr r8,l3509 + movl r0, r8 #ptr to new temp name + movl $16,r2 #maximum name length + brb l3512 # # put the new name into the structure # -l3511: - cmpl r8,$fnamesze #check for name too long - blss l3512 - movw $ENAMESIZE,_perrno - moval error,PC(fp) #error return - ret +l3508: + bicw2 $TEMP,FUNIT( r9) #set permanent status + locc $blank,8(ap),( r8) #check for trailing blanks + subl3 r0,8(ap),r2 #deduct length of blanks + cmpl r2,$fnamesze #check for name too long + bgeq enamsze l3512: - movc3 r8,(r0),FNAME( r11) #move name into record - clrb FNAME( r11)[ r8] #place null char after name - moval FNAME( r11),PFNAME( r11) #set pointer to name + movc3 r2,( r8),FNAME( r9) #move name into record + clrb (r3) #place zero after name + moval FNAME( r9),PFNAME( r9) #set pointer to name l3513: - movl r9,r1 #return ptr to updated stack - movl r11,r0 #return ptr to file record + movl r9,r0 #return ptr to file record + ret +enamsze: + movw $ENAMESIZE,_perrno + moval error,PC(fp) #error return ret # # unit establishes a new active file @@ -278,13 +272,6 @@ _unit: beql erefinaf bbs $fDEF,FUNIT(r7),erefinaf movl PFNAME(r7),_file - cmpl r7,$stdin #flush stdout if activating stdin - bneq l3523 - cmpw _bufopt,$1 # and stdout is line buffered - bneq l3523 - pushl stdout+FBUF - calls $1,_fflush -l3523: ret erefinaf: movw $EREFINAF,_perrno @@ -365,25 +352,31 @@ l3518: # close all active files down to the specified FLEV # _pclose: - .word R6|R7 - movl _fchain, r7 + .word R6|R9 + movl _fchain, r9 beql l3520 l3519: - cmpl FLEV( r7),4(ap) + cmpl FLEV( r9),4(ap) bgtru l3520 - bbs $fDEF,FUNIT( r7),l3525 - movl FBUF( r7),r6 + bbs $fDEF,FUNIT( r9),l3525 + movl FBUF( r9),r6 + beql l3525 pushl r6 calls $1,_fclose jbs $ioERR,FLAG(r6),eclose + bbc $fTEMP,FUNIT( r9),l3525 + pushl PFNAME( r9) #remove TEMP files + calls $1,_unlink + tstl r0 + jneq eunlink l3525: - subl3 $recsze, r7,-(sp) - movl FCHAIN( r7), r7 + subl3 $recsze, r9,-(sp) + movl FCHAIN( r9), r9 calls $1,_pfree - tstl r7 + tstl r9 bneq l3519 l3520: - movl r7,_fchain + movl r9,_fchain ret # # write out the pxp data