Use os.path.splitext to split out file extension

Python's standard library provides a function to split out file
extensions, and it also handles dot files correctly.

Use that instead of just retrieving the last two characters of
the file name.

This should help with issue #27.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
This commit is contained in:
Chen-Yu Tsai 2018-04-10 07:44:25 +00:00
parent 25f5533882
commit 883281e446
2 changed files with 3 additions and 3 deletions

View file

@ -63,7 +63,7 @@ def query (cmd, *args):
elif cmd == 'file':
version = args[0]
path = args[1]
ext = path[-2:]
ext = os.path.splitext(path)[1]
if ext == '.c' or ext == '.h':
tokens = scriptLines ('tokenize-file', version, path)

View file

@ -74,7 +74,7 @@ def updateDefinitions (blobs):
hash = db.hash.get (blob)
filename = db.file.get (blob)
ext = filename[-2:]
ext = os.path.splitext(filename)[1]
if not (ext == '.c' or ext == '.h'): continue
lines = scriptLines ('parse-defs', hash, filename)
@ -97,7 +97,7 @@ def updateReferences (blobs):
hash = db.hash.get (blob)
filename = db.file.get (blob)
ext = filename[-2:]
ext = os.path.splitext(filename)[1]
if not (ext == '.c' or ext == '.h'): continue
tokens = scriptLines ('tokenize-file', '-b', hash)