Rizin
unix-like reverse engineering framework and cli tools
clang-format Namespace Reference

Functions

def should_scan (filename)
 
def skip (filename)
 
def get_matching_files ()
 
def get_edited_files (args)
 
def build_command (check, filenames, verbose)
 
def format_files (args, files)
 
def get_file (args)
 
def get_files (args)
 
def process (args)
 
def parse ()
 
def main ()
 

Variables

list dirlist
 
list skiplist
 
list patterns = ["*.c", "*.cpp", "*.h", "*.hpp", "*.inc"]
 

Function Documentation

◆ build_command()

def clang-format.build_command (   check,
  filenames,
  verbose 
)

Definition at line 73 of file clang-format.py.

73 def build_command(check, filenames, verbose):
74  cmd = ["clang-format", "--style=file"]
75  if verbose:
76  cmd += ["--verbose"]
77  if check:
78  cmd += ["--Werror", "--dry-run"]
79  else:
80  cmd += ["-i"]
81  return cmd + filenames
82 
83 
def build_command(check, filenames, verbose)
Definition: clang-format.py:73

Referenced by format_files().

◆ format_files()

def clang-format.format_files (   args,
  files 
)

Definition at line 84 of file clang-format.py.

84 def format_files(args, files):
85  if len(files) == 0:
86  print("No C files to format.")
87  sys.exit(0)
88  cmd = build_command(args.check, files, args.verbose)
89  r = subprocess.run(cmd, check=False)
90  sys.exit(r.returncode)
91 
92 
size_t len
Definition: 6502dis.c:15
def format_files(args, files)
Definition: clang-format.py:84

References build_command(), and len.

Referenced by process().

◆ get_edited_files()

def clang-format.get_edited_files (   args)

Definition at line 64 of file clang-format.py.

64 def get_edited_files(args):
65  repo = Repo()
66 
67  for diff in repo.index.diff(args.diff):
68  filename = diff.a_path
69  if should_scan(filename) and not skip(filename):
70  yield filename
71 
72 
void skip(file *in, unsigned n)
Definition: gzappend.c:202
def should_scan(filename)
Definition: clang-format.py:47
def get_edited_files(args)
Definition: clang-format.py:64

References should_scan(), and skip().

Referenced by get_files().

◆ get_file()

def clang-format.get_file (   args)

Definition at line 93 of file clang-format.py.

93 def get_file(args):
94  filename = args.file
95  if should_scan(filename) and not skip(filename):
96  return [filename]
97 
98  return []
99 
100 
def get_file(args)
Definition: clang-format.py:93

References should_scan(), and skip().

Referenced by get_files().

◆ get_files()

def clang-format.get_files (   args)

Definition at line 101 of file clang-format.py.

101 def get_files(args):
102  if args.diff:
103  return get_edited_files(args)
104 
105  if args.file:
106  return get_file(args)
107 
108  return get_matching_files()
109 
110 
def get_matching_files()
Definition: clang-format.py:57
def get_files(args)

References get_edited_files(), get_file(), and get_matching_files().

Referenced by process().

◆ get_matching_files()

def clang-format.get_matching_files ( )

Definition at line 57 of file clang-format.py.

57 def get_matching_files():
58  for directory, pattern in itertools.product(dirlist, patterns):
59  for filename in glob.iglob(directory + "/**/" + pattern, recursive=True):
60  if not skip(filename):
61  yield filename
62 
63 

References skip().

Referenced by get_files().

◆ main()

def clang-format.main ( void  )

Definition at line 135 of file clang-format.py.

135 def main():
136  args = parse()
137  process(args)
138 
139 
def process(args)
Definition: regcomp.c:57

References process().

◆ parse()

def clang-format.parse ( )

Definition at line 116 of file clang-format.py.

116 def parse():
117  parser = argparse.ArgumentParser(description="Clang format the rizin project")
118  parser.add_argument(
119  "-c", "--check", action="store_true", help="enable the check mode"
120  )
121  parser.add_argument(
122  "-v", "--verbose", action="store_true", help="use verbose output"
123  )
124  parser.add_argument("-f", "--file", help="formats (or checks) only the given file")
125  parser.add_argument(
126  "-d",
127  "--diff",
128  type=str,
129  default=None,
130  help="format all modified file related to branch",
131  )
132  return parser.parse_args()
133 
134 

◆ process()

def clang-format.process (   args)

Definition at line 111 of file clang-format.py.

111 def process(args):
112  files = get_files(args)
113  format_files(args, list(files))
114 
115 
static void list(RzEgg *egg)
Definition: rz-gg.c:52

References format_files(), get_files(), and list().

Referenced by main().

◆ should_scan()

def clang-format.should_scan (   filename)

Definition at line 47 of file clang-format.py.

47 def should_scan(filename):
48  return any(directory in filename for directory in dirlist) and any(
49  pattern[1:] in filename for pattern in patterns
50  )
51 
52 

Referenced by get_edited_files(), and get_file().

◆ skip()

def clang-format.skip (   filename)

Definition at line 53 of file clang-format.py.

53 def skip(filename):
54  return any(skipfile in filename for skipfile in skiplist)
55 
56 

Referenced by get_edited_files(), get_file(), and get_matching_files().

Variable Documentation

◆ dirlist

list clang-format.dirlist
Initial value:
1 = [
2  "binrz",
3  "librz",
4  "subprojects/rzar",
5  "subprojects/rzbochs",
6  "subprojects/rzgdb",
7  "subprojects/ptrace-wrap",
8  "subprojects/rzqnx",
9  "subprojects/rzw32dbg_wrap",
10  "subprojects/rzwinkd",
11  "test/unit",
12 ]

Definition at line 14 of file clang-format.py.

◆ patterns

list clang-format.patterns = ["*.c", "*.cpp", "*.h", "*.hpp", "*.inc"]

Definition at line 44 of file clang-format.py.

Referenced by rz_asm_tokenize_asm_regex().

◆ skiplist

list clang-format.skiplist
Initial value:
1 = [
2  "/gnu/",
3  "librz/asm/arch/vax/",
4  "librz/asm/arch/riscv/",
5  "librz/asm/arch/sh/gnu/",
6  "librz/asm/arch/i8080/",
7  "librz/asm/arch/z80/",
8  "librz/asm/arch/avr/",
9  "librz/asm/arch/arm/aarch64/",
10  "librz/hash/xxhash/",
11  "librz/bin/mangling/cxx/",
12  "librz/bin/d/jni.h",
13  "librz/util/bdiff.c",
14  "librz/asm/arch/tms320/c55x/table.h",
15  "librz/include/sflib/",
16 ]

Definition at line 27 of file clang-format.py.