1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import sys
import string
 
 
def Extract_RightSide_From_FileLines( FileLines ) :
    RightSideList = []
    for eachline in FileLines :
        if( IsExistOnlyOneEqual( eachline ) == True ) :
            RightSideValue = RightSideOfEqual( eachline )
            RightSideList.append( RightSideValue )
    return RightSideList
 
 
def Extract_LeftSide_From_FileLines( FileLines ) :
    LeftSideList = []
    for eachline in FileLines :
        if( IsExistOnlyOneEqual( eachline ) == True ) :
            LeftSideValue = LeftSideOfEqual( eachline )
            LeftSideList.append( LeftSideValue )
    return LeftSideList
 
 
def IsExistOnlyOneEqual( strLine ) :
    strLine = RemoveLuaComment( strLine )
     
    find_pos = strLine.find( '=', 0 )
    if( find_pos == -1 ) :
        return False
         
    find_pos = strLine.find( '=', find_pos + 1 )
    if( find_pos == -1 ) :
        return True
         
    return False
 
 
def RemoveLuaComment( strLine ) :
    find_pos = strLine.find( '--', 0 )
    if( find_pos != -1 ) :
        return strLine[0 : find_pos].strip()
    return strLine.strip()
 
 
def LeftSideOfEqual( strLine ) :
    strLine = RemoveLuaComment( strLine )
    find_pos = strLine.find( '=', 0 )
    if( find_pos != -1 ) :
        return strLine[0 : find_pos].strip()
    return strLine.strip()
 
 
def RightSideOfEqual( strLine ) :
    strLine = RemoveLuaComment( strLine )
    find_pos = strLine.find( '=', 0 )
    if( find_pos != -1 ) :
        return strLine[find_pos + 1 : len(strLine)].strip()
    return strLine.strip()
 
 
def Extract_Alparbet_Number_UnderBar( strLine ) :
    strAlparbet_Number_UnderBar = string.letters + string.digits + '_'
    strList = []
    for OneWord in strLine :
        if( OneWord in strAlparbet_Number_UnderBar ) :
            strList.append( OneWord )
    strTemp = ''.join( strList )
    return strTemp
 
 
def RefTypeMaching( strStartKeyword, nLineNumber, strSourceLine, strRefTypeList ) :
    strSourceTempList = strSourceLine.split()
    for eachSource in strSourceTempList :
        strExtractedSource = Extract_Alparbet_Number_UnderBar( eachSource )
         
        if( strExtractedSource.startswith( strStartKeyword ) == True ) :
            if( strExtractedSource not in strRefTypeList ) :
                print 'RefType Mismatch. LineNumber : ' + str( nLineNumber ) + ', Source String : ' + strExtractedSource
 
 
 
 
def main(argv) :
    Reference_file = argv[1]
    Programed_file = argv[2]
     
    # Reference File Loading(RefTypeList)
    Ref_fstream = open( Reference_file, 'r' )
    RefFileList = Ref_fstream.xreadlines()
    RefTypeList = Extract_LeftSide_From_FileLines( RefFileList )
    Ref_fstream.close()
     
    # Programed File Loading(ProgramFileList)
    Programed_fstream = open( Programed_file, 'r' )
    ProgramFileList = Programed_fstream.readlines()
    Programed_fstream.close()
     
    # Print Type Check 
    print '---------------------------------------------------------'
    print 'Start Type Check. File Name : ' + str( argv[2] )
    print '---------------------------------------------------------'
    for i, eachProgramLine in enumerate( ProgramFileList ) :
        strRemovedComment = RemoveLuaComment( eachProgramLine )
        RefTypeMaching( 'Item_', i + 1, strRemovedComment, RefTypeList )
    print '---------------------------------------------------------'
 
 
 
if __name__ == "__main__"
    main(argv=sys.argv)
2010/02/11 16:56 2010/02/11 16:56

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요