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: mov r0,-(sp) 97: jsr pc,_close 98: tst (sp)+ 99: tst r0 100: bmi 9f 101: bit $TEMP,FUNIT(r1) 102: beq 1f 103: tst r3 104: beq 1f 105: mov r0,-(sp) 106: mov r1,-(sp) 107: jsr pc,cleanup 108: mov (sp)+,r1 109: mov (sp)+,r0 110: 1: 111: bic $![TEMP+FTEXT],FUNIT(r1) 112: mov FBUF(r1),r0 113: clr (r0)+ / clear the getc/putc buffer 114: clr (r0)+ 115: clr (r0)+ 116: mov r1,r0 117: / 118: / get the filename to the 119: / buffer (not necess. easy) 120: / 121: 2: 122: tst r3 123: bne 2f 124: / 125: / no name given 126: / 127: tst FNAME(r0) 128: beq 1f 129: / 130: / no name given and had 131: / a prev name so use it 132: / again 133: / 134: mov newsp,sp 135: jmp *reta 136: 9: 137: mov $ECLOSE,_perrno 138: error ECLOSE 139: / 140: / no name given and no 141: / prev name so generate 142: / a new one of the form 143: / "tmp.x" 144: / 145: 1: 146: bis $TEMP,FUNIT(r0) 147: inc nextu 148: movb nextu,tnam+4 149: mov $tnam,r2 150: mov $6.,-(sp) 151: br alname 152: / 153: / name given 154: / strip trailing blanks 155: / 156: 2: 157: bic $TEMP,FUNIT(r0) 158: add r3,r2 159: clrb (r2) 160: 1: 161: cmpb -1(r2),$' 162: bne 1f 163: clrb -(r2) 164: dec r3 165: bne 1b 166: 1: 167: sub r3,r2 168: inc r3 169: mov r3,-(sp) 170: / 171: / save the new name 172: / in dynamic space 173: / 174: alname: 175: mov r0,r3 176: jsr pc,_alloc 177: mov r0,r1 178: 1: 179: movb (r2)+,(r0)+ 180: bne 1b 181: mov r1,r2 182: / 183: / free previous file name 184: / (if any) 185: / 186: mov FNAME(r3),r0 187: beq 1f 188: mov r0,-(sp) 189: jsr pc,_free 190: tst (sp)+ 191: / 192: / put the new name 193: / into the structure 194: / 195: 1: 196: mov r2,FNAME(r3) 197: mov r2,PFNAME(r3) 198: mov r3,r0 199: mov newsp,sp 200: jmp *reta 201: .bss 202: reta: .=.+2 203: newsp: .=.+2 204: .text 205: .globl cleanup 206: cleanup: 207: mov r2,-(sp) 208: mov 4(sp),r2 209: mov PFNAME(r2),-(sp) 210: jsr pc,_unlink 211: tst (sp)+ 212: tst r0 213: bpl 1f 214: mov PFNAME(r2),_file 215: mov $EREMOVE,_perrno 216: error EREMOVE 217: 1: 218: mov PFNAME(r2),-(sp) 219: jsr pc,_free 220: tst (sp)+ 221: mov (sp)+,r2 222: rts pc