{$O+,F+} UNIT FNameTransform; INTERFACE USES Dos; function GetPath(path:PathStr):DirStr; function TruncatePath(path:PathStr):DirStr; function GetExtension(path:PathStr):ExtStr; function TruncateExtension(path:PathStr):PathStr; function GetName(path:PathStr):NameStr; function ReplSlashToBackSlash(path:PathStr):PathStr; IMPLEMENTATION USES xStrings, StrMode; procedure FindDelimiters; near; {$IfDef Seg16} {Аргументы: es:si->string Возвращает: bx=позиция последнего '\' cx=позиция последнего '.' } assembler; asm mov di,si; SegES lodsb; xor ah,ah; mov cx,ax; mov dx,ax; mov bx,ax; jcxz @End add di,ax; mov al,'\'; std repne scasb jne @Skip inc di; inc cx @Skip: xchg cx,bx; sub cx,bx; inc di mov al,'.'; cld repne scasb jne @Skip2 dec di; inc cx @Skip2: @End: mov ax,dx; sub dx,cx; inc dx; xchg dx,cx; mov dx,es end; {$Else IfDef Seg16} {Аргументы: si->string Возвращает: ebx=позиция последнего '\', если нет '\', то ebx=0 ecx=позиция последнего '.' } assembler; asm mov edi,esi; lodsb; xor eax,eax; mov ecx,eax; mov edx,eax; mov ebx,eax; jecxz @End add edi,eax; mov al,'\'; std repne scasb jne @Skip inc ecx @Skip: xchg ecx,ebx; {EBX:=позиция последнего '\'} sub ecx,ebx; inc di mov edi,esi; add edi,edx mov al,'.' repne scasb jne @Skip2 inc ecx @Skip2: mov eax,edx; sub edx,ecx; inc edx; xchg edx,ecx; @End: end; {$EndIf Def Seg16} procedure Copy; near; assembler; {$IfDef Seg16} asm cmp ax,bx; jbe @Cont xchg ax,bx @Cont: stosb or al,al; jz @End xchg ax,cx call xxMove @End: end; {$Else IfDef Seg16} asm cmp eax,ebx; jbe @Cont xchg eax,ebx @Cont: stosb or al,al; jz @End xchg eax,ecx call xxMove @End: end; {$EndIf Def Seg16} function GetPath(path:PathStr):DirStr; assembler; const StrSize=SizeOf(DirStr)-1; {$IfDef Seg16} asm les si,path call FindDelimiters xchg ax,bx les di,@Result; mov bx,StrSize call Copy end; {$Else IfDef Seg16} asm push ebx; push edi; push esi mov esi,path call FindDelimiters xchg eax,ebx mov edi,@Result; mov ebx,StrSize call Copy pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} function TruncatePath(path:PathStr):DirStr; assembler; const StrSize=SizeOf(DirStr)-1; {$IfDef Seg16} asm les si,path call FindDelimiters add si,bx; sub ax,bx; les di,@Result; mov bx,StrSize call Copy end; {$Else IfDef Seg16} asm push ebx; push edi; push esi mov esi,path call FindDelimiters add esi,ebx; sub eax,ebx; mov edi,@Result; mov ebx,StrSize call Copy pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} function GetExtension(path:PathStr):ExtStr; assembler; const StrSize=SizeOf(ExtStr)-1; {$IfDef Seg16} asm les si,path call FindDelimiters dec cx; sub ax,cx; add si,cx les di,@Result; mov bx,StrSize call Copy end; {$Else IfDef Seg16} asm push ebx; push edi; push esi mov esi,path call FindDelimiters dec ecx; sub eax,ecx; add esi,ecx mov edi,@Result; mov ebx,StrSize call Copy pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} function TruncateExtension(path:PathStr):PathStr; assembler; const StrSize=SizeOf(PathStr)-1; {$IfDef Seg16} asm les si,path call FindDelimiters xchg ax,cx; dec ax les di,@Result; mov bx,StrSize call Copy end; {$Else IfDef Seg16} asm push ebx; push edi; push esi mov esi,path call FindDelimiters xchg eax,ecx; dec eax mov edi,@Result; mov ebx,StrSize call Copy pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} function GetName(path:PathStr):NameStr; assembler; const MaxStrSize=SizeOf(NameStr)-1; {$IfDef Seg16} asm les si,path; call FindDelimiters add si,bx; sub cx,bx; xchg ax,cx; dec ax les di,@Result; mov bx,MaxStrSize call Copy end; {$Else IfDef Seg16} asm push ebx; push edi; push esi mov esi,path; call FindDelimiters add esi,ebx; sub ecx,ebx; xchg eax,ecx; dec eax mov edi,@Result; mov ebx,MaxStrSize call Copy pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} function ReplSlashToBackSlash(path:PathStr):PathStr; assembler; {$IfDef Seg16} asm les si,path push es; push di push word(@Result+2); push word(@Result) SEGES lodsb; xor ah,ah push ax call Move push word(@Result+2); push word(@Result) {$IFOPT G+} push '/'; push '\' {$ELSE} mov ax,'/'; push ax mov ax,'\'; push ax {$ENDIF} call ReplaceChar end; {$Else IfDef Seg16} asm push ebx; push edi; push esi { mov eax,path} mov edx,@Result xor ecx,ecx; mov cl,[edx] call Move mov eax,Result mov edx,dword('/') mov ecx,dword('\') call ReplaceChar pop esi; pop edi; pop ebx end; {$EndIf Def Seg16} END.