I know that this may seem like a lot of work but you will be surprised.
The python (standard libraries) re library can be used to extract the content of strings, and optionally comments.
There is also an installable python library for python called pyenchant which is a spell checker, (for various human languages), which can be quickly run on the extracted text to spot, (and optionally make correction suggestions for), miss-spelt words. To install pyenchant simply invoke pip install pyenchant
while connected to the internet.
Between the two it is simple, (once you get your head round regular expressions), to write a python script that will, on being invoked with a C/CPP/etc file, or list of files, as a parameter will extract and spell check all of the strings in those files.
This could be invoked from the makefile, (optionally returning non-zero to abort the make if any are found), or given that VS has some python integration added lately possibly even from within VS.
- Price: Free
- Licence: Open Source
- Make Integration: Easy I, and a lot of others, python use python as a part of our make process all of the time as there are a lot of other things that can be done such as getting information from a VCS such as git/mercurial/svn to automatically insert version information or to stop release builds on un-checked in code.
Maybe something like, (the following is a rough & ready example for strings in quotes - note that it could be improved in numerous ways):
import enchant
import re
CHECKER = enchant.Dict() # Create the dictionary in the default language
def get_bad_words(textlist):
""" Get the words in the list of strings """
words = set()
for line in textlist:
#print(line)
for word in line.split():
word = word.strip(r'\x0a\x0d\\:;.,!?*() ')
if len(word) and not word.startswith('%') and not CHECKER.check(word):
words.add(word)
return words
def check_file(filename):
""" Check a single file """
content = open(filename).read()
strings = re.findall(r'"(.*)"', content) # Use re to find strings
suspects = get_bad_words(strings)
if len(suspects):
print(filename, "contains the following suspect words")
print(repr(', '.join(list(suspects))))
if __name__ == "__main__": # Guard against execution when imported
import sys
if len(sys.argv) < 2:
print("Usage:\n\tpython CSpellCheck.py FILENAME [....]
else:
for FNAME in sys.argv[1:]:
check_file(FNAME)