     1                                  ; ****************************************************************************
     2                                  ; pwd8086.s (pwd0.s) - by Erdogan Tan - 05/05/2022
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Retro UNIX 8086 v1 - pwd - print working directory pathname
     5                                  ;
     6                                  ; [ Last Modification: 06/05/2022 ]
     7                                  ;
     8                                  ; Derived from (original) UNIX v5 'pwd.c' source Code
     9                                  ; Ref:
    10                                  ; www.tuhs.org (https://minnie.tuhs.org)
    11                                  ; v5root.tar.gz
    12                                  ; ****************************************************************************
    13                                  ; [ usr/source/s2/pwd.c (archive date: 27-11-1974) ]
    14                                  
    15                                  ; pwd0.s - Retro UNIX 8086 v1 (16 bit version of 'pwd1.s')
    16                                  ; pwd1.s - Retro UNIX 386 v1 (unix v1 inode structure)
    17                                  ; pwd2.s - Retro UNIX 386 v1.1 (16 byte directory entries)
    18                                  ; pwd3.s - Retro UNIX 386 v1.2 (& v2) (modified unix v7 inode)
    19                                  
    20                                  ; UNIX v1 system calls
    21                                  _rele 	equ 0
    22                                  _exit 	equ 1
    23                                  _fork 	equ 2
    24                                  _read 	equ 3
    25                                  _write	equ 4
    26                                  _open	equ 5
    27                                  _close 	equ 6
    28                                  _wait 	equ 7
    29                                  _creat 	equ 8
    30                                  _link 	equ 9
    31                                  _unlink	equ 10
    32                                  _exec	equ 11
    33                                  _chdir	equ 12
    34                                  _time 	equ 13
    35                                  _mkdir 	equ 14
    36                                  _chmod	equ 15
    37                                  _chown	equ 16
    38                                  _break	equ 17
    39                                  _stat	equ 18
    40                                  _seek	equ 19
    41                                  _tell 	equ 20
    42                                  _mount	equ 21
    43                                  _umount	equ 22
    44                                  _setuid	equ 23
    45                                  _getuid	equ 24
    46                                  _stime	equ 25
    47                                  _quit	equ 26	
    48                                  _intr	equ 27
    49                                  _fstat	equ 28
    50                                  _emt 	equ 29
    51                                  _mdate 	equ 30
    52                                  _stty 	equ 31
    53                                  _gtty	equ 32
    54                                  _ilgins	equ 33
    55                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    56                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    57                                  
    58                                  ;;;
    59                                  ESCKey equ 1Bh
    60                                  EnterKey equ 0Dh
    61                                  
    62                                  
    63                                  ;%macro sys 1-4
    64                                  ;   ; 03/09/2015
    65                                  ;   ; 13/04/2015
    66                                  ;   ; Retro UNIX 386 v1 system call.
    67                                  ;   %if %0 >= 2   
    68                                  ;       mov ebx, %2
    69                                  ;       %if %0 >= 3    
    70                                  ;           mov ecx, %3
    71                                  ;           ;%if %0 = 4
    72                                  ;           %if	%0 >= 4 ; 11/03/2022
    73                                  ;		mov edx, %4
    74                                  ;           %endif
    75                                  ;       %endif
    76                                  ;   %endif
    77                                  ;   mov eax, %1
    78                                  ;   int 30h
    79                                  ;%endmacro
    80                                  
    81                                  %macro sys 1-4
    82                                      ; Retro UNIX 8086 v1 system call.
    83                                      %if %0 >= 2   
    84                                          mov bx, %2
    85                                          %if %0 >= 3
    86                                              mov cx, %3
    87                                              %if %0 >= 4
    88                                                 mov dx, %4
    89                                              %endif
    90                                          %endif
    91                                      %endif
    92                                      mov ax, %1
    93                                      int 20h
    94                                  %endmacro
    95                                  
    96                                  ;; Retro UNIX 386 v1 system call format:
    97                                  ;; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    98                                  
    99                                  ;; 11/03/2022
   100                                  ;; Note: Above 'sys' macro has limitation about register positions;
   101                                  ;;	ebx, ecx, edx registers must not be used after their
   102                                  ;;	positions in sys macro.
   103                                  ;; for example:
   104                                  ;;	'sys _write, 1, msg, ecx' is defective, because
   105                                  ;;	 ecx will be used/assigned before edx in 'sys' macro.
   106                                  ;; correct order may be:
   107                                  ;;	'sys _write, 1, msg, eax ; (eax = byte count)
   108                                  
   109                                  ; Retro UNIX 8086 v1 system call format:
   110                                  ; sys systemcall (ax) <arg1 (bx)>, <arg2 (cx)>, <arg3 (dx)>
   111                                  
   112                                  ; ----------------------------------------------------------------------------
   113                                  
   114                                  [BITS 16] ; 16-bit intructions (for 8086/x86 real mode)
   115                                  
   116                                  [ORG 0] 
   117                                  
   118                                  START_CODE:
   119                                  	; 06/05/2022 (16 bit version) -ax,bx,cx,dx-
   120                                  	; 06/05/2022 (32 bit version) -eax,ebx,ecx,edx-
   121                                  	; 05/05/2022
   122                                  
   123                                  ;main() {
   124                                  ;	int n;
   125                                  
   126                                  	;  clear (reset) stack (not necessary)
   127 00000000 59                      	pop	cx ; cx = number of arguments
   128                                  pwd_0:
   129 00000001 58                      	pop	ax ; ax = argument 0 = executable file name
   130 00000002 E2FD                    	loop	pwd_0
   131                                  
   132                                  	;mov	byte [y.zero], 0 ; (not necessary)
   133                                  			; (because Retro UNIX kernel
   134                                  			; clears bss -memory page- while
   135                                  			; assigning it to program)
   136                                  	;mov	word [off], 0
   137                                  
   138                                  	; 06/05/2022
   139 00000004 FF0E[2A03]              	dec	word [off] 
   140                                  
   141                                  ;loop0:
   142                                  ;	stat(dot, &x);
   143                                  ;	if((file = open(dotdot,0)) < 0) prname();
   144                                  
   145                                  loop0:
   146                                  	sys	_stat, dot, _x
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000008 BB[1901]            <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 0000000B B9[2C03]            <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 0000000E B81200              <1>  mov ax, %1
    93 00000011 CD20                <1>  int 20h
   147                                  
   148                                  	sys	_open, dotdot, 0  ; open for read
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000013 BB[1801]            <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 00000016 B90000              <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000019 B80500              <1>  mov ax, %1
    93 0000001C CD20                <1>  int 20h
   149 0000001E 723E                    	jc	short prname
   150                                  
   151                                  ;loop1:
   152                                  ;	if((n = read(file,&y,16)) < 16) prname();
   153                                  ;	if(y.jnum != x.inum)goto loop1;
   154                                  ;	close(file);
   155                                  ;	if(y.jnum == 1) ckroot();
   156                                  ;	cat();
   157                                  ;	chdir(dotdot);
   158                                  ;	goto loop0;
   159                                  ;}
   160                                  
   161 00000020 A3[2803]                	mov	[file], ax
   162                                  loop1:
   163                                  	sys	_read, [file], _y, 10 ; Retro UNIX 386 v1
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000023 8B1E[2803]          <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 00000027 B9[4E03]            <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88 0000002A BA0A00              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 0000002D B80300              <1>  mov ax, %1
    93 00000030 CD20                <1>  int 20h
   164                                  	;sys	_read, [file], _y, 16 ; Retro UNIX 386 v1.1 & v1.2
   165 00000032 722A                    	jc	short prname
   166                                  	;cmp	ax, 10	 ; cmp eax, 16
   167                                  	;jb	short prname	
   168 00000034 09C0                    	or	ax, ax
   169 00000036 7426                    	jz	short prname
   170 00000038 A1[4E03]                	mov	ax, [jnum]	   
   171 0000003B 3B06[2C03]              	cmp	ax, [inum]
   172 0000003F 75E2                    	jne	short loop1
   173                                  	sys	_close, [file]
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000041 8B1E[2803]          <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86                              <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000045 B80600              <1>  mov ax, %1
    93 00000048 CD20                <1>  int 20h
   174                                  	;cmp	word [jnum], 1	; Retro UNIX 386 v1.2
   175 0000004A 833E[4E03]29            	cmp	word [jnum], 41 ; root dir inode number
   176 0000004F 7439                    	je	short ckroot
   177 00000051 E87E00                  	call	cat
   178                                  	sys	_chdir, dotdot
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000054 BB[1801]            <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86                              <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000057 B80C00              <1>  mov ax, %1
    93 0000005A CD20                <1>  int 20h
   179 0000005C EBAA                    	jmp	short loop0
   180                                  
   181                                  ;prname() {
   182                                  ;	name[off] = '\n';
   183                                  ;	write(1,name,off+1);
   184                                  ;	exit();
   185                                  
   186                                  prname:
   187                                  	sys	_write, 1, nextline, 3	; 06/05/2022
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 0000005E BB0100              <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 00000061 B9[1B01]            <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88 00000064 BA0300              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000067 B80400              <1>  mov ax, %1
    93 0000006A CD20                <1>  int 20h
   188                                  
   189 0000006C 8B36[2A03]              	mov	si, [off]
   190                                  	;mov	byte [si+name], 0Dh ; CR
   191 00000070 C784[2801]0D0A          	mov	word [si+name], 0A0Dh  ; CRLF 
   192                                  	;inc	dword [off]
   193 00000076 46                      	inc	si
   194 00000077 46                      	inc	si
   195                                  	;mov	[off], si
   196                                  	;sys	_write, 1, name, [off]
   197                                  	sys	_write, 1, name, si
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 00000078 BB0100              <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 0000007B B9[2801]            <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88 0000007E 89F2                <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000080 B80400              <1>  mov ax, %1
    93 00000083 CD20                <1>  int 20h
   198                                  exit:
   199                                  	sys	_exit
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84                              <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86                              <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 00000085 B80100              <1>  mov ax, %1
    93 00000088 CD20                <1>  int 20h
   200                                  ;hang:
   201                                  ;	nop
   202                                  ;	jmp	short hang
   203                                  
   204                                  ;ckroot() {
   205                                  ;	int i, n;
   206                                  ;
   207                                  ;	if((n = stat(y.name,&x)) < 0) prname();
   208                                  ;	i = x.devn;
   209                                  ;	if((n = chdir(root)) < 0) prname();
   210                                  ;	if((file = open(root,0)) < 0) prname();
   211                                  ;loop:
   212                                  ;	if((n = read(file,&y,16)) < 16) prname();
   213                                  ;	if(y.jnum == 0) goto loop;
   214                                  ;	if((n = stat(y.name,&x)) < 0) prname();
   215                                  ;	if(x.devn != i) goto loop;
   216                                  ;	x.i[0] =& 060000;
   217                                  ;	if(x.i[0] != 040000) goto loop;
   218                                  ;	cat();
   219                                  ;	prname();
   220                                  
   221                                  	; 06/05/2022
   222                                  	; Note: For Retro UNIX 386 v1 & v1.1 & v1.2,
   223                                  	;	mounted device is handled via 'mnti'
   224                                  	;	field which keeps (device 0) mounting
   225                                  	;	directory inode number for mounted
   226                                  	;	device (1). Device number (0 or 1) check
   227                                  	;	(via 'sysstat') is not possible
   228                                  	;	for current Retro UNIX kernel versions
   229                                  	;	because 'sysstat' output does not contain
   230                                  	;	device number.
   231                                  	;	***
   232                                  	;	As a temporary solution (before a next
   233                                  	;	kernel version with new 'sysstat'),
   234                                  	;	root dir entries are checked for a subdir 
   235                                  	;	('usr' & 'mnt' dirs for now) with root dir
   236                                  	;	inode number (41 or 1), if there is..
   237                                  	;	root directory is a real (device 0) root
   238                                  	;	directory; if not, device 1 root directory 
   239                                  	;	is mounted to a sub directory of device 0.
   240                                  	; 	(Also it must be verified after 'chdir /')
   241                                  	;
   242                                  	;	assumptions...
   243                                  	;	a sub dir with root inode number	
   244                                  	;	dotdot / - chdir /
   245                                  	;	   no    -  no ----> root
   246                                  	;	   yes 	 - (yes) --> root, not checked
   247                                  	;	   no    - yes ----> mounted
   248                                  	;	   yes   - (no) ---> root, not checked				  
   249                                  
   250                                  ckroot:
   251                                  	; 06/05/2022
   252                                  	; check 'usr' directory
   253 0000008A BA[1F01]                	mov	dx, usr
   254 0000008D E83000                  	call	statm 
   255 00000090 742C                    	jz	short ckroot_2	; root dir
   256                                  	; check 'mnt' directory
   257 00000092 BA[2301]                	mov	dx, mnt
   258 00000095 E82800                  	call	statm 
   259 00000098 7424                    	jz	short ckroot_2	; root dir
   260                                  
   261                                  	sys	_chdir, root
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 0000009A BB[1D01]            <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86                              <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 0000009D B80C00              <1>  mov ax, %1
    93 000000A0 CD20                <1>  int 20h
   262 000000A2 721A                    	jc	short ckroot_2	; jmp short prname
   263                                  
   264                                  	; check 'usr' directory
   265 000000A4 BA[1F01]                	mov	dx, usr
   266 000000A7 E81600                  	call	statm 
   267 000000AA 7408                    	jz	short ckroot_1	; mounted
   268                                  	; check 'mnt' directory
   269 000000AC BA[2301]                	mov	dx, mnt
   270 000000AF E80E00                  	call	statm 
   271 000000B2 750A                    	jnz	short ckroot_2	; not mounted
   272                                  
   273                                  	; mounted
   274                                  ckroot_1:
   275                                  	; move mounting directory name
   276 000000B4 89D6                    	mov	si, dx
   277 000000B6 BF[5003]                	mov	di, yname
   278 000000B9 A5                      	movsw
   279 000000BA A5                      	movsw
   280                                  	; concatenate (add to head of the path)
   281 000000BB E81400                  	call	cat
   282                                  ckroot_2:
   283 000000BE EB9E                    	jmp	prname
   284                                  
   285                                  statm:
   286                                  	; 06/05/2022
   287                                  	sys	_stat, dx, _x
    82                              <1> 
    83                              <1>  %if %0 >= 2
    84 000000C0 89D3                <1>  mov bx, %2
    85                              <1>  %if %0 >= 3
    86 000000C2 B9[2C03]            <1>  mov cx, %3
    87                              <1>  %if %0 >= 4
    88                              <1>  mov dx, %4
    89                              <1>  %endif
    90                              <1>  %endif
    91                              <1>  %endif
    92 000000C5 B81200              <1>  mov ax, %1
    93 000000C8 CD20                <1>  int 20h
   288 000000CA 7205                    	jc	short statm_1
   289                                  	;cmp	word [inum], 1	; Retro UNIX 386 v1.2
   290 000000CC 833E[2C03]29            	cmp	word [inum], 41 ; root dir inode number
   291                                  statm_1:
   292 000000D1 C3                      	retn
   293                                  
   294                                  ;cat() {
   295                                  ;	int i, j;
   296                                  ;
   297                                  ;	i = -1;
   298                                  ;	while(y.name[++i] != 0);
   299                                  ;	if((off+i+2) > 511) prname();
   300                                  ;	for(j=off+1; j>=0; --j) name[j+i+1] = name[j];
   301                                  ;	off=i+off+1;
   302                                  ;	name[i] = root[0];
   303                                  ;	for(--i; i>=0; --i) name[i] = y.name[i];
   304                                  ;}
   305                                  
   306                                  cat:
   307 000000D2 31DB                    	xor	bx, bx
   308 000000D4 4B                      	dec	bx ; i = -1
   309                                  cat_0:
   310 000000D5 43                      	inc	bx ; ++i
   311 000000D6 80BF[5003]00            	cmp	byte [yname+bx], 0
   312 000000DB 77F8                    	ja	short cat_0
   313 000000DD 89DA                    	mov	dx, bx ; i
   314 000000DF 8B0E[2A03]              	mov	cx, [off]
   315 000000E3 41                      	inc	cx ; j = [off]+1
   316 000000E4 01CA                    	add	dx, cx  ; dx = [off]+i+1
   317 000000E6 81FAFD01                	cmp	dx, 511-2 ; (+ CRLF + 0) 
   318                                  	;ja	short prname
   319 000000EA 77D2                    	ja	short ckroot_2 ; jmp prname
   320 000000EC BE[2801]                	mov	si, name
   321 000000EF 01CE                    	add	si, cx ; name[j]
   322 000000F1 89F7                    	mov	di, si
   323 000000F3 01DF                    	add	di, bx ; name[j+i]
   324 000000F5 47                      	inc	di ; name[j+i+1]	
   325                                  cat_1:
   326                                  	;std
   327                                  	;rep	stosb
   328                                  	;cld
   329 000000F6 49                      	dec	cx
   330 000000F7 7808                    	js	short cat_2
   331 000000F9 4E                      	dec	si
   332 000000FA 8A04                    	mov	al, [si]
   333 000000FC 4F                      	dec	di
   334 000000FD 8805                    	mov	[di], al
   335 000000FF EBF5                    	jmp	short cat_1
   336                                  cat_2:
   337 00000101 8916[2A03]              	mov	[off], dx ; [off] = i+[off]+1
   338 00000105 C687[2801]2F            	mov	byte [name+bx], '/' ; name[i] = root[0]
   339                                  cat_3:
   340 0000010A 4B                      	dec	bx ; --i
   341 0000010B 780A                    	js	short cat_4 ; 0 -> -1
   342                                  		 ; name[i] = yname[i]
   343 0000010D 8A87[5003]              	mov	al, [yname+bx]
   344 00000111 8887[2801]              	mov	[name+bx], al
   345 00000115 EBF3                    	jmp	short cat_3 ; i >= 0
   346                                  cat_4:
   347 00000117 C3                      	retn
   348                                  
   349                                  ;-----------------------------------------------------------------
   350                                  ;  data - initialized data
   351                                  ;-----------------------------------------------------------------
   352                                  
   353                                  ; 05/05/2022
   354                                  
   355 00000118 2E                      dotdot:	db '.'
   356 00000119 2E                      dot:	db '.'
   357 0000011A 00                      	db 0
   358                                  
   359                                  ; 06/05/2022
   360                                  nextline:
   361 0000011B 0D0A                    	db 0Dh, 0Ah
   362 0000011D 2F00                    root:	db '/', 0
   363                                  
   364                                  ; default mounting directories (for current retro unix version)
   365 0000011F 75737200                usr:	db 'usr', 0
   366 00000123 6D6E7400                mnt:	db 'mnt', 0
   367                                  
   368                                  ;-----------------------------------------------------------------
   369                                  ;  bss - uninitialized data
   370                                  ;-----------------------------------------------------------------	
   371                                  
   372 00000127 90                      align 4
   373                                  
   374                                  bss_start:
   375                                  
   376                                  ABSOLUTE bss_start
   377                                  
   378                                  ; 06/05/2022
   379                                  
   380 00000128 <res 200h>              name:	resb 512
   381                                  
   382 00000328 ????                    file:	resw 1
   383 0000032A ????                    off:	resw 1
   384                                  
   385                                  _x:	; stat(us) buffer
   386                                  inum:
   387 0000032C ????                    	resw 1
   388                                  ximode:
   389                                  	;resb 64 ; Retro UNIX 386 v1.2
   390 0000032E <res 20h>               	resb 32 ; Retro UNIX 386 v1 & v1.1
   391                                  _y:	; directory entry buffer
   392 0000034E ????                    jnum:	resw 1
   393                                  yname:	;resb 14 ; Retro UNIX 386 v1.1 & v1.2
   394 00000350 ????????????????        	resb 8 ; Retro UNIX 386 v1 (unix v1)
   395 00000358 ????                    yzero:	resw 1
   396                                  
   397                                  ; 05/05/2022
   398                                  
   399                                  ;-----------------------------------------------------------------
   400                                  ; Original UNIX v5 - /usr/bin/pwd file - c source code (pwd.c)
   401                                  ;-----------------------------------------------------------------
   402                                  ;
   403                                  ;char dot[] ".";
   404                                  ;char dotdot[] "..";
   405                                  ;char root[] "/";
   406                                  ;char name[512];
   407                                  ;int file, off -1;
   408                                  ;struct statb {int devn, inum, i[18];}x;
   409                                  ;struct entry { int jnum; char name[16];}y;
   410                                  ;
   411                                  ;main() {
   412                                  ;	int n;
   413                                  ;
   414                                  ;loop0:
   415                                  ;	stat(dot, &x);
   416                                  ;	if((file = open(dotdot,0)) < 0) prname();
   417                                  ;loop1:
   418                                  ;	if((n = read(file,&y,16)) < 16) prname();
   419                                  ;	if(y.jnum != x.inum)goto loop1;
   420                                  ;	close(file);
   421                                  ;	if(y.jnum == 1) ckroot();
   422                                  ;	cat();
   423                                  ;	chdir(dotdot);
   424                                  ;	goto loop0;
   425                                  ;}
   426                                  ;ckroot() {
   427                                  ;	int i, n;
   428                                  ;
   429                                  ;	if((n = stat(y.name,&x)) < 0) prname();
   430                                  ;	i = x.devn;
   431                                  ;	if((n = chdir(root)) < 0) prname();
   432                                  ;	if((file = open(root,0)) < 0) prname();
   433                                  ;loop:
   434                                  ;	if((n = read(file,&y,16)) < 16) prname();
   435                                  ;	if(y.jnum == 0) goto loop;
   436                                  ;	if((n = stat(y.name,&x)) < 0) prname();
   437                                  ;	if(x.devn != i) goto loop;
   438                                  ;	x.i[0] =& 060000;
   439                                  ;	if(x.i[0] != 040000) goto loop;
   440                                  ;	cat();
   441                                  ;	prname();
   442                                  ;}
   443                                  ;prname() {
   444                                  ;	name[off] = '\n';
   445                                  ;	write(1,name,off+1);
   446                                  ;	exit();
   447                                  ;}
   448                                  ;cat() {
   449                                  ;	int i, j;
   450                                  ;
   451                                  ;	i = -1;
   452                                  ;	while(y.name[++i] != 0);
   453                                  ;	if((off+i+2) > 511) prname();
   454                                  ;	for(j=off+1; j>=0; --j) name[j+i+1] = name[j];
   455                                  ;	off=i+off+1;
   456                                  ;	name[i] = root[0];
   457                                  ;	for(--i; i>=0; --i) name[i] = y.name[i];
   458                                  ;}
