1: /
   2: / getname
   3: /
   4: / takes the width of a string in r3
   5: / returns a pointer to a file structure in r0
   6: /
   7: / there should be a string on the stack
   8: / of length the contents of r3 on top of
   9: / a pointer to the file variable
  10: /
  11: / a new file structure is allocated if needed
  12: / temporary names are generated, and given
  13: / names are blank trimmed
  14: /
  15: / if a new file buffer is allocated, the address
  16: / is stored throught the file variable pointer
  17: /
  18: /
  19: getname:
  20:         mov     (sp)+,reta
  21:         mov     sp,r2
  22:         mov     r3,r1
  23:         inc     r1
  24:         bic     $1,r1
  25:         add     sp,r1
  26:         mov     (r1)+,r0
  27:         mov     r1,newsp
  28:         tst     (r0)
  29:         bne     gotone
  30: /
  31: / dont have a file struct
  32: / so alloc a new one
  33: /
  34:         mov     r0,-(sp)
  35:         mov     (lc),r0
  36:         bne     1f
  37:         mov     $1,r0
  38: 1:
  39:         add     $518.+14.,r0
  40:         mov     r0,-(sp)
  41:         jsr     pc,_alloc
  42:         tst     (sp)+
  43:         mov     r0,518.(r0)
  44:         add     $518.+12.,r0
  45:         mov     (lc)+,(r0)+
  46:         bne     1f
  47:         bis     $FTEXT,FUNIT(r0)
  48:         mov     $1,FSIZE(r0)
  49: 1:
  50:         mov     (sp),FLEV(r0)
  51:         mov     $fchain-FCHAIN,-(sp)    / get head of file chain
  52:         mov     fchain,r1               / contents of head of file chain
  53: 1:
  54:         bne     2f                      / end of the chain?
  55:         mov     (sp)+,r1                / get last chain entry
  56:         mov     r0,FCHAIN(r1)           / and stuff the current file in
  57:         clr     FCHAIN(r0)              / last entry
  58:         br      3f
  59: 2:
  60:         cmp     FLEV(r1),2(sp)          / are we past it yet?
  61:         beq     3f
  62:         bhi     2f
  63:         mov     r1,(sp)                 / advance the chain
  64:         mov     FCHAIN(r1),r1
  65:         br      1b
  66: 2:
  67:         mov     r1,FCHAIN(r0)
  68:         mov     (sp)+,r1                / address of last entry
  69:         mov     r0,FCHAIN(r1)           / stuff in the current entry
  70: 3:
  71:         mov     r0,*(sp)+
  72:         br      2f
  73: /
  74: / have a previous buffer
  75: / close the associated file
  76: /
  77: gotone:
  78:         tst     (lc)+
  79:         mov     (r0),r1
  80:         mov     FUNIT(r1),r0
  81:         bgt     3f              / from name from prog hedr
  82:         bic     $100000,FUNIT(r1)
  83:         br      1f
  84: 3:
  85:         bit     $FWRITE,FUNIT(r1)
  86:         beq     6f
  87:         mov     r0,-(sp)
  88:         mov     r1,-(sp)
  89:         mov     FBUF(r1),-(sp)
  90:         jsr     pc,_fflush
  91:         tst     (sp)+
  92:         mov     (sp)+,r1
  93:         mov     (sp)+,r0
  94: 6:
  95:         bic     $!17,r0
  96:         sys     close
  97:         bes     9f
  98:         bit     $TEMP,FUNIT(r1)
  99:         beq     1f
 100:         tst     r3
 101:         beq     1f
 102:         mov     r0,-(sp)
 103:         mov     r1,-(sp)
 104:         jsr     pc,cleanup
 105:         mov     (sp)+,r1
 106:         mov     (sp)+,r0
 107: 1:
 108:         bic     $![TEMP+FTEXT],FUNIT(r1)
 109:         mov     FBUF(r1),r0
 110:         clr     (r0)+           / clear the getc/putc buffer
 111:         clr     (r0)+
 112:         clr     (r0)+
 113:         mov     r1,r0
 114: /
 115: / get the filename to the
 116: / buffer (not necess. easy)
 117: /
 118: 2:
 119:         tst     r3
 120:         bne     2f
 121: /
 122: / no name given
 123: /
 124:         tst     FNAME(r0)
 125:         beq     1f
 126: /
 127: / no name given and had
 128: / a prev name so use it
 129: / again
 130: /
 131:         mov     newsp,sp
 132:         jmp     *reta
 133: 9:
 134:         mov     $ECLOSE,_perrno
 135:         error   ECLOSE
 136: /
 137: / no name given and no
 138: / prev name so generate
 139: / a new one of the form
 140: / "tmp.x"
 141: /
 142: 1:
 143:         bis     $TEMP,FUNIT(r0)
 144:         inc     nextu
 145:         movb    nextu,tnam+4
 146:         mov     $tnam,r2
 147:         mov     $6.,-(sp)
 148:         br      alname
 149: /
 150: / name given
 151: / strip trailing blanks
 152: /
 153: 2:
 154:         bic     $TEMP,FUNIT(r0)
 155:         add     r3,r2
 156:         clrb    (r2)
 157: 1:
 158:         cmpb    -1(r2),$'
 159:         bne     1f
 160:         clrb    -(r2)
 161:         dec     r3
 162:         bne     1b
 163: 1:
 164:         sub     r3,r2
 165:         inc     r3
 166:         mov     r3,-(sp)
 167: /
 168: / save the new name
 169: / in dynamic space
 170: /
 171: alname:
 172:         mov     r0,r3
 173:         jsr     pc,_alloc
 174:         mov     r0,r1
 175: 1:
 176:         movb    (r2)+,(r0)+
 177:         bne     1b
 178:         mov     r1,r2
 179: /
 180: / free previous file name
 181: / (if any)
 182: /
 183:         mov     FNAME(r3),r0
 184:         beq     1f
 185:         mov     r0,-(sp)
 186:         jsr     pc,_free
 187:         tst     (sp)+
 188: /
 189: / put the new name
 190: / into the structure
 191: /
 192: 1:
 193:         mov     r2,FNAME(r3)
 194:         mov     r2,PFNAME(r3)
 195:         mov     r3,r0
 196:         mov     newsp,sp
 197:         jmp     *reta
 198: .bss
 199: reta:   .=.+2
 200: newsp:  .=.+2
 201: .text
 202:         .globl  cleanup
 203: cleanup:
 204:         mov     r2,-(sp)
 205:         mov     4(sp),r2
 206:         mov     PFNAME(r2),0f
 207:         sys     indir;8f
 208: .data
 209: 8:      sys     unlink;0: ..
 210: .text
 211:         bec     1f
 212:         mov     PFNAME(r2),_file
 213:         mov     $EREMOVE,_perrno
 214:         error   EREMOVE
 215: 1:
 216:         mov     PFNAME(r2),-(sp)
 217:         jsr     pc,_free
 218:         tst     (sp)+
 219:         mov     (sp)+,r2
 220:         rts     pc

Defined functions

alname defined in line 171; used 1 times
cleanup declared in line 202; defined in line 203; used 2 times
getname defined in line 19; never used
gotone defined in line 77; used 1 times
  • in line 29

Defined variables

newsp defined in line 200; used 3 times
reta defined in line 199; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 678
Valid CSS Valid XHTML 1.0 Strict