Skip to content

Instantly share code, notes, and snippets.

@Snape3058
Created September 13, 2024 14:55
Show Gist options
  • Select an option

  • Save Snape3058/80b930939c27e65aee04f97d7725dfa6 to your computer and use it in GitHub Desktop.

Select an option

Save Snape3058/80b930939c27e65aee04f97d7725dfa6 to your computer and use it in GitHub Desktop.
A code snippet to pretty print a position in cocci file.
org = open(p[0].file).read().split("\n")[int(p[0].line) - 1]
prt = org.lstrip()
print("%s:%s:%s: cocci: found" % (p[0].file, p[0].line, p[0].column))
print("%s | %s" % (p[0].line, prt))
print(
"%s | %s%s"
% (
" " * len(p[0].line),
" " * (int(p[0].column) - (len(org) - len(prt))),
"^" * (int(p[0].column_end) - int(p[0].column)),
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment