WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
Pages (2) [1] 2   ( Go to first unread post )

GetFileExtension - Get the Extension of a filename, it reads the extension of a filename including the dot separator, only condition to use the procedure is to avoid NULL pointers.

Vortex
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 140
Member No.: 8
Joined: 13-May 04


Here is a GetFileExtension procedure. It reads the extension of a filename including the dot separator. The only condition to use the procedure is to avoid NULL pointers.

CODE
.386
.model flat,stdcall
option casemap:none

.data

GFEtable db 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.code

GetFileExtension PROC uses esi _file:DWORD


mov esi,_file
mov edx,OFFSET GFEtable
xor ecx,ecx
l0:
mov eax,esi  ; The procedure returns the address of the filename
@@:    ; if there is no extension
add esi,1
mov cl,BYTE PTR [esi]
cmp BYTE PTR [edx+ecx],0
je @b
cmp cl,'.'
je l0
ret

GetFileExtension ENDP

END


Attached File ( Number of downloads: 39 )
 Login or Register to download

PMEmail PosterUsers Website
Top
SeaFarer
Quote Post


Extremely Active Member
******

Group: Members
Posts: 1753
Member No.: 1464
Joined: 2-September 05


At 597 bytes, what a gem! Great example!

Hutch's site is right...

Caution! Hi-speed software! biggrin.gif

Thanks for sharing. wink.gif
PM
Top
Vortex
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 140
Member No.: 8
Joined: 13-May 04


SeaFarer,

Probably, the algo is oversized but the lookup table there is intended to speed up the search engine. Maybe, it could be possibe to recode the procedure with MMX instructions to get a shorter version.
PMEmail PosterUsers Website
Top
Slider
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 287
Member No.: 5004
Joined: 11-May 07


Thanks Vortex.

What are some ways that it could be used for ?

PMEmail Poster
Top
Vortex
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 140
Member No.: 8
Joined: 13-May 04


Hi Slider,

There are some cases where you would like to extract the extensions from full qualified paths. A typical example is determining if the user is typing a file name with the correct extension.
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (2) [1] 2  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google