-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Swihart
committed
Mar 1, 2016
1 parent
4c062ee
commit b383053
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python | ||
#-*- coding: utf-8 -*- | ||
|
||
import sys | ||
|
||
CONFIG_NAME = ".clang_complete" | ||
|
||
def readConfiguration(): | ||
try: | ||
f = open(CONFIG_NAME, "r") | ||
except IOError: | ||
return [] | ||
|
||
result = [] | ||
for line in f.readlines(): | ||
strippedLine = line.strip() | ||
if strippedLine: | ||
result.append(strippedLine) | ||
f.close() | ||
return result | ||
|
||
def writeConfiguration(lines): | ||
f = open(CONFIG_NAME, "w") | ||
f.writelines(lines) | ||
f.close() | ||
|
||
def parseArguments(arguments): | ||
nextIsInclude = False | ||
nextIsDefine = False | ||
nextIsIncludeFile = False | ||
|
||
includes = [] | ||
defines = [] | ||
include_file = [] | ||
options = [] | ||
|
||
for arg in arguments: | ||
if nextIsInclude: | ||
includes += [arg] | ||
nextIsInclude = False | ||
elif nextIsDefine: | ||
defines += [arg] | ||
nextIsDefine = False | ||
elif nextIsIncludeFile: | ||
include_file += [arg] | ||
nextIsIncludeFile = False | ||
elif arg == "-I": | ||
nextIsInclude = True | ||
elif arg == "-D": | ||
nextIsDefine = True | ||
elif arg[:2] == "-I": | ||
includes += [arg[2:]] | ||
elif arg[:2] == "-D": | ||
defines += [arg[2:]] | ||
elif arg == "-include": | ||
nextIsIncludeFile = True | ||
elif arg.startswith('-std='): | ||
options.append(arg) | ||
elif arg == '-ansi': | ||
options.append(arg) | ||
elif arg.startswith('-pedantic'): | ||
options.append(arg) | ||
elif arg.startswith('-W'): | ||
options.append(arg) | ||
|
||
result = list(map(lambda x: "-I" + x, includes)) | ||
result.extend(map(lambda x: "-D" + x, defines)) | ||
result.extend(map(lambda x: "-include " + x, include_file)) | ||
result.extend(options) | ||
|
||
return result | ||
|
||
def mergeLists(base, new): | ||
result = list(base) | ||
for newLine in new: | ||
if newLine not in result: | ||
result.append(newLine) | ||
return result | ||
|
||
configuration = readConfiguration() | ||
args = parseArguments(sys.argv) | ||
result = mergeLists(configuration, args) | ||
writeConfiguration(map(lambda x: x + "\n", result)) | ||
|
||
|
||
import subprocess | ||
proc = subprocess.Popen(sys.argv[1:]) | ||
ret = proc.wait() | ||
|
||
if ret is None: | ||
sys.exit(1) | ||
sys.exit(ret) | ||
|
||
# vim: set ts=2 sts=2 sw=2 expandtab : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters