1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBFILETYPE_COMMON
38 #include"drd64_libfiletype.h"
40 #define DRD64_SRC_LIBFILETYPE_COMMON_SRCID 0x01
42 #define LOCATION(n) DRD64_ERR_LOCATION( \
43 DRD64_ERROR_MODULE_LIBFILETYPE, DRD64_ERROR_ARCH_NODEPEND, \
44 DRD64_SRC_LIBFILETYPE_COMMON_SRCID, (n))
47 /*----------------------------------------------------------------------
48 ----------------------------------------------------------------------*/
49 #define FUNCID_LibFileType_Common_GetFileNamePosition 0x01
51 LibFileType_Common_GetFileNamePosition(
58 assert( NULL != pstr_filepath );
60 i_maxlen = (int)strnlen( pstr_filepath, DRD64_MAX_PATH );
61 pstr_now = pstr_filepath + i_maxlen;
62 for( i_len = i_maxlen; i_len > 0; i_len-- ) {
63 if( '/' == *pstr_now-- ) { break; }
66 if( 1 > i_len ) { pstr_now = pstr_filepath + i_maxlen; }
67 else { pstr_now += 2; }
73 /*----------------------------------------------------------------------
74 ----------------------------------------------------------------------*/
75 #define FUNCID_LibFileType_Common_GetFileExtPosition 0x02
77 LibFileType_Common_GetFileExtPosition(
84 assert( NULL != pstr_filepath );
86 i_maxlen = (int)strnlen( pstr_filepath, DRD64_MAX_PATH );
87 pstr_now = pstr_filepath + i_maxlen;
88 for( i_len = i_maxlen; i_len > 0; i_len-- ) {
89 if( '.' == *pstr_now-- ) { break; }
92 if( 1 > i_len ) { pstr_now = pstr_filepath + i_maxlen; }
93 else { pstr_now += 2; }
99 /***********************************************************************
100 ***********************************************************************/
101 #define FUNCID_LibFileType_Common_GetFileType_fromFileName 0x04
104 LibFileType_GetFileType_fromFileName(
105 LibFileType_FileType *p_filetype,
106 char *pstr_filepath )
112 /* Search from Ext. DB --- */
113 pstr_ext = LibFileType_Common_GetFileExtPosition( pstr_filepath );
116 if( !strncmp( pstr_ext, fexttypedb[i_cnt].str_ext, DRD64_MAX_PATH ) )
118 p_filetype->b_type = fexttypedb[i_cnt].b_type;
119 p_filetype->w_subtype = fexttypedb[i_cnt].w_subtype;
120 goto goto_LibFileType_Common_GetFileType_fromFileName_post;
122 }while( (Byte)0xff != fexttypedb[++i_cnt].b_type );
124 /* Judge of Special File-Name */
125 pstr_name = LibFileType_Common_GetFileNamePosition( pstr_filepath );
128 if( !strncmp( pstr_name, fnametypedb[i_cnt].str_filename, DRD64_MAX_PATH ) )
130 p_filetype->b_type = fnametypedb[i_cnt].b_type;
131 p_filetype->w_subtype = fnametypedb[i_cnt].w_subtype;
132 goto goto_LibFileType_Common_GetFileType_fromFileName_post;
134 }while( (Byte)0xff != fnametypedb[++i_cnt].b_type );
136 p_filetype->b_type = DRD64_LIBFILETYPE_BINARY;
137 p_filetype->w_subtype = DRD64_LIBFILETYPE_SUB_BINARY;
139 goto_LibFileType_Common_GetFileType_fromFileName_post:
144 /* EOF of drd64_.c ----------------------------------- */