Skip to content

Instantly share code, notes, and snippets.

@NicHub
Created August 20, 2019 04:50
Show Gist options
  • Save NicHub/18d6592ae4bda48da0333f37b50a1c1e to your computer and use it in GitHub Desktop.
Save NicHub/18d6592ae4bda48da0333f37b50a1c1e to your computer and use it in GitHub Desktop.
check_char.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Find characters with ASCII code greater than 127.
usage:
cd /DIRECTORY_TO_CHECK/
python /PATH_TO/check_char.py
"""
import glob
import os
def getChars(filename):
try:
# Read input file.
with open(filename, "r") as f:
data = f.read()
# Check characters.
charlist = []
for i, c in enumerate(data):
uDec = ord(c)
if uDec > 127:
charlist.append(c)
if len(charlist) > 0:
print("\n" + filename)
for curchar in charlist:
res = f" {ord(curchar)} {curchar}"
print(res)
except:
print("Error in " + filename)
def main():
path = os.getcwd() + os.sep
print("\nSEARCH IN : " + path + "\n")
files = [f for f in glob.glob(path + "**/*.c", recursive=True)]
files += [f for f in glob.glob(path + "**/*.h", recursive=True)]
for f in files:
getChars(f)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment