Skip to content

Commit

Permalink
Format code with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
tprk77 committed Jun 13, 2018
1 parent 40d4710 commit 9d54764
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Clang-Format configuration file for automatically formatting source code
---
BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
...
40 changes: 40 additions & 0 deletions format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Bash script to automatically format LCM source code (currently C and C++).
# Requires `clang-format` utilily, which is part of the LLVM project. More
# information can be found here: https://clang.llvm.org/docs/ClangFormat.html
#
# To install `clang-format` on Ubuntu do:
#
# $ sudo apt install clang-format
#
# On Windows 10 you are recommended to use the Linux Subsystem. You can install
# the Linux Subsystem by doing the following:
#
# 1. Open PowerShell as Administrator, enter the command:
#
# PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
#
# 2. Restart the computer.
# 3. Go to the Microsoft Store, install the Ubuntu app.
#
# This script does not format Java, Python, or Lua source code. At the moment,
# it only formats C and C++ sources, i.e., *.h, *.c, *.hpp, and *.cpp. It only
# formats code in certain directories, see below for the full list.

LCM_ROOT="$(cd $(dirname "$0") && pwd)"

function format_c_cpp_dir_r {
find "$1" -regex '.*\.\(c\|h\)\(pp\)?' -print0 | xargs -0 clang-format -i
}

#format_c_cpp_dir_r "${LCM_ROOT}/lcm"
#format_c_cpp_dir_r "${LCM_ROOT}/lcmgen"
#format_c_cpp_dir_r "${LCM_ROOT}/lcm-examples"
#format_c_cpp_dir_r "${LCM_ROOT}/lcm-test"
#format_c_cpp_dir_r "${LCM_ROOT}/lcm-logger"
#format_c_cpp_dir_r "${LCM_ROOT}/lcm-python"
#format_c_cpp_dir_r "${LCM_ROOT}/lcm-lua"
#format_c_cpp_dir_r "${LCM_ROOT}/liblcm-test"

exit 0

0 comments on commit 9d54764

Please sign in to comment.