Skip to content

Commit

Permalink
Fix dis, add cc_args
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Swihart committed Mar 1, 2016
1 parent 4c062ee commit b383053
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
94 changes: 94 additions & 0 deletions bin/cc_args
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 :
9 changes: 7 additions & 2 deletions bin/dis
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import capstone
import click
import os
import re
import sys

Expand All @@ -14,12 +15,16 @@ def get_matching(name):


@click.command()
@click.argument('code')
@click.argument('codestr')
@click.option('-a', '--arch', default='x86', type=click.Choice(get_matching('ARCH')))
@click.option('-m', '--mode', default='64', type=click.Choice(get_matching('MODE')))
@click.option('-d', '--show-addrs', is_flag=True, help='Show addresses in printout')
def dis(code, arch, mode, show_addrs):
def dis(codestr, arch, mode, show_addrs):
""" Disassemble the provided code """
code = codestr
if os.path.isfile(codestr):
with open(codestr, 'rb') as f:
code = f.read()
cs_arch = None
cs_mode = None
# Check the architecture
Expand Down
1 change: 1 addition & 0 deletions freshrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fresh tarjoilija/zgen '_zgen' --file=~/.zsh/_zgen
fresh chronoslynx/dotfiles 'bin/dis' --bin=~/.local/bin/dis
fresh chronoslynx/dotfiles 'bin/edit' --bin=~/.local/bin/edit
fresh chronoslynx/dotfiles 'bin/udacity-tagger' --bin=~/.local/bin/udacity-tagger
fresh chronoslynx/dotfiles 'bin/cc_args' --bin=~/.local/bin/cc_args
fresh wwalker/ssh-find-agent 'ssh-find-agent.sh' --bin=~/.ssh-find-agent.sh

## terminal colors
Expand Down

0 comments on commit b383053

Please sign in to comment.