From da91a1145440ac06787552d844b947f436782453 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Thu, 24 Oct 2019 16:22:16 -0500 Subject: [PATCH] added clang-format file and make pretty. Removed previous indent tools. --- .astylerc | 9 --- .clang-format | 10 +++ .indent.pro | 1 - Makefile | 5 ++ doc/indent/README.md | 46 ++++++++++++ fixup.bat | 31 -------- fixup.sh | 170 ------------------------------------------- indent-all.bat | 41 ----------- indent.bat | 30 -------- indent.sh | 43 ----------- 10 files changed, 61 insertions(+), 325 deletions(-) delete mode 100644 .astylerc create mode 100644 .clang-format delete mode 100644 .indent.pro create mode 100644 doc/indent/README.md delete mode 100644 fixup.bat delete mode 100755 fixup.sh delete mode 100644 indent-all.bat delete mode 100644 indent.bat delete mode 100755 indent.sh diff --git a/.astylerc b/.astylerc deleted file mode 100644 index d2b510f3..00000000 --- a/.astylerc +++ /dev/null @@ -1,9 +0,0 @@ -#--indent-cases ---indent-classes ---indent-switches ---indent=spaces=4 -#--max-instatement-indent=4 -#--min-conditional-indent=0 ---brackets=linux ---convert-tabs ---mode=c diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..2e98edb4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +--- +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +BreakBeforeBraces: Linux +IndentWidth: 4 +SortIncludes: false +... diff --git a/.indent.pro b/.indent.pro deleted file mode 100644 index 22a1b031..00000000 --- a/.indent.pro +++ /dev/null @@ -1 +0,0 @@ --kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl diff --git a/Makefile b/Makefile index 6df22b52..a1b9e9d2 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,11 @@ mstpsnap: ports/linux/mstpsnap.mak bdk-atxx4-mstp: ports/bdk-atxx4-mstp/Makefile $(MAKE) -s -C ports/bdk-atxx4-mstp clean all +pretty: + find ./src -iname *.h -o -iname *.c -exec clang-format -i -style=file -fallback-style=none {} \; + find ./include -iname *.h -o -iname *.c -exec clang-format -i -style=file -fallback-style=none {} \; + find ./demo -iname *.h -o -iname *.c -exec clang-format -i -style=file -fallback-style=none {} \; + clean: $(MAKE) -s -C lib clean $(MAKE) -s -C demo clean diff --git a/doc/indent/README.md b/doc/indent/README.md new file mode 100644 index 00000000..5fd76fe3 --- /dev/null +++ b/doc/indent/README.md @@ -0,0 +1,46 @@ +# How to configure clang‐format + +## Overview +clang-format is an utility to format source code in several languages +according to predefined settings. Settings for auto-formatting of C source +files are summarized below, and should be saved in .clang-format file in root +folder. These settings are chosen to closely match the formatting style used. + +## Configuring Editors +### Visual Studio Code +Install the C/C++ extension and customize settings.json to include: + + "C_Cpp.clang_format_path": "/path/to/", + "C_Cpp.clang_format_style": "file", + "C_Cpp.clang_format_fallbackStyle": "none" + +### Emacs +Add the line + + (load "/path/to/clang-format.el") + +to `~/.emacs.d/init.el`. Format a source file with `M-x clang-format-region`. + +### CLion +* Add the .clang-format file to the Kratos root directory as + explained aboveGo to File->Settings->Tools->External Tools + and click on the plus sign. A window should pop up. + Choose a name, for example "clang-format" +* For the Tool settings tab I'm using this configuration: + - Program: clang-format (you should use the name of your executable here) + - Parameters: --style=file -i $FileName$ + - Working directory: $FileDir$ +Now, with your file open, you can go to Tools->External tools and run the config above. It basically calls clang-format and does inplace formatting using the style define in the first .clang-format file found in a parent directory. + +### .clang-format file + + --- + BasedOnStyle: Google + AllowShortFunctionsOnASingleLine: None + AllowShortIfStatementsOnASingleLine: false + AllowShortLoopsOnASingleLine: false + AlwaysBreakAfterReturnType: None + BreakBeforeBraces: Linux + IndentWidth: 4 + SortIncludes: false + ... diff --git a/fixup.bat b/fixup.bat deleted file mode 100644 index 4f68dbb0..00000000 --- a/fixup.bat +++ /dev/null @@ -1,31 +0,0 @@ -@echo off -rem fix DOS/Unix names and Subversion EOL-Style -rem unix2dos.exe from MSYS: mingw.sourceforge.net -rem svn.exe from Subversion Tools -call :treeProcess -goto :eof - -:treeProcess -rem fix all the specific files of this subdirectory: -for %%f in (*.c) do ( - unix2dos.exe "%%f" - svn.exe propset svn:eol-style native "%%f" - svn.exe propset svn:mime-type text/plain "%%f" -) -for %%f in (*.h) do ( - unix2dos.exe "%%f" - svn.exe propset svn:eol-style native "%%f" - svn.exe propset svn:mime-type text/plain "%%f" -) -for %%f in (*.bat) do ( - unix2dos.exe "%%f" - svn.exe propset svn:eol-style native "%%f" - svn.exe propset svn:mime-type text/plain "%%f" -) -rem loop over all directories and sub directories -for /D %%d in (*) do ( - cd %%d - call :treeProcess - cd .. -) -exit /b diff --git a/fixup.sh b/fixup.sh deleted file mode 100755 index f9058658..00000000 --- a/fixup.sh +++ /dev/null @@ -1,170 +0,0 @@ -#!/bin/sh -# fix DOS/Unix names and Subversion EOL-Style, and remove backup files - -#DOS2UNIX=/usr/bin/dos2unix -DOS2UNIX=/usr/bin/fromdos - -# exit silently if utility is not installed -[ -x ${DOS2UNIX} ] || exit 0 -[ -x /usr/bin/svn ] || exit 0 - -directory=${1-`pwd`} -for filename in $( find ${directory} -name '*.c' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.h' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.bat' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.pl' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/x-script.perl ${filename} -done - -for filename in $( find ${directory} -name '*.eww' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/xml ${filename} -done - -for filename in $( find ${directory} -name '*.ewp' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/xml ${filename} -done - -for filename in $( find ${directory} -name '*.cbp' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/xml ${filename} -done - -for filename in $( find ${directory} -name '*.icf' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.htm' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/html ${filename} -done - -for filename in $( find ${directory} -name '*.txt' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.lua' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/plain ${filename} -done - -for filename in $( find ${directory} -name '*.sh' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/x-script.sh ${filename} -done - -for filename in $( find ${directory} -name '*.b32' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/x-makefile ${filename} -done - -for filename in $( find ${directory} -name '*.mak' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/x-makefile ${filename} -done - -for filename in $( find ${directory} -name 'Makefile' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propset svn:eol-style native ${filename} - /usr/bin/svn propset svn:mime-type text/x-makefile ${filename} -done - -for filename in $( find ${directory} -name '*.xls' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propdel svn:eol-style ${filename} - /usr/bin/svn propset svn:mime-type application/excel ${filename} -done - -for filename in $( find ${directory} -name '*.ods' ) -do - echo Fixing DOS/Unix ${filename} - ${DOS2UNIX} ${filename} - echo Setting Subversion EOL Style for ${filename} - /usr/bin/svn propdel svn:eol-style ${filename} - /usr/bin/svn propset svn:mime-type application/vnd.oasis.opendocument.spreadsheet ${filename} -done - -for filename in $( find ${directory} -name '*~' ) -do - echo Removing backup ${filename} - rm ${filename} -done - diff --git a/indent-all.bat b/indent-all.bat deleted file mode 100644 index e8c284bd..00000000 --- a/indent-all.bat +++ /dev/null @@ -1,41 +0,0 @@ -rem Indent the C and H files with specific coding standard -rem requires 'indent.exe' from MSYS (MinGW). -rem See http://www.gnu.org/software/indent/manual/indent.pdf -set OPTIONS=-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl -rem -kr The Kernighan & Ritchie style, corresponds to the following options: -rem -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -rem -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -rem -nprs -npsl -saf -sai -saw -nsc -nsob -nss -rem -nut Use spaces instead of tabs. -rem -nlp Do not line up parentheses. -rem -ip4 Indent parameter types in old-style function definitions by n spaces. -rem -cli4 Case label indent of n spaces. -rem -bfda Break the line before all arguments in a declaration. -rem -nbc Do not force newlines after commas in declarations. -rem -nbbo Do not prefer to break long lines before boolean operators. -rem -c0 Put comments to the right of code in column n. -rem -cd0 Put comments to the right of the declarations in column n. -rem -cp0 Put comments to the right of #else and #endif statements in column n. -rem -di0 Put variables in column n. -rem -l79 Set maximum line length for non-comment lines to n. -rem -nhnl Do not prefer to break long lines at the position of newlines in the input. - -call :treeProcess -goto :eof - -:treeProcess -rem perform the indent on all the files of this subdirectory: -for %%f in (*.c) do ( - indent.exe "%%f" -o "%%f" %OPTIONS% -) -for %%f in (*.h) do ( - indent.exe "%%f" -o "%%f" %OPTIONS% -) -rem loop over all directories and sub directories -for /D %%d in (*) do ( - cd %%d - call :treeProcess - cd .. -) -exit /b - diff --git a/indent.bat b/indent.bat deleted file mode 100644 index 5d143530..00000000 --- a/indent.bat +++ /dev/null @@ -1,30 +0,0 @@ -@echo off -rem Indent the C and H files with specific coding standard -rem requires 'indent.exe' from MSYS (MinGW). -rem See http://www.gnu.org/software/indent/manual/indent.pdf -rem -kr The Kernighan & Ritchie style, corresponds to the following options: -rem -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -rem -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -rem -nprs -npsl -saf -sai -saw -nsc -nsob -nss -rem -nut Use spaces instead of tabs. -rem -nlp Do not line up parentheses. -rem -ip4 Indent parameter types in old-style function definitions by n spaces. -rem -cli4 Case label indent of n spaces. -rem -bfda Break the line before all arguments in a declaration. -rem -nbc Do not force newlines after commas in declarations. -rem -nbbo Do not prefer to break long lines before boolean operators. -rem -c0 Put comments to the right of code in column n. -rem -cd0 Put comments to the right of the declarations in column n. -rem -cp0 Put comments to the right of #else and #endif statements in column n. -rem -di0 Put variables in column n. -rem -l79 Set maximum line length for non-comment lines to n. -rem -nhnl Do not prefer to break long lines at the position of newlines in the input. - -echo Fixing Unix/DOS line endings for "%1" -unix2dos.exe "%1" -echo Setting Subversion EOL Style for "%1" -svn.exe propset svn:eol-style native "%1" -svn.exe propset svn:mime-type text/plain "%1" -echo Indenting "%1" -set OPTIONS=-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl -indent.exe "%1" -o "%1" %OPTIONS% diff --git a/indent.sh b/indent.sh deleted file mode 100755 index f13f9708..00000000 --- a/indent.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# indent uses a local indent.pro file if it exists -# File must be in consistent unix format before indenting - -#DOS2UNIX=/usr/bin/dos2unix -DOS2UNIX=/usr/bin/fromdos -INDENT=/usr/bin/indent -REMOVE=/bin/rm - -# exit silently if utility is not installed -[ -x ${INDENT} ] || exit 0 -[ -x ${DOS2UNIX} ] || exit 0 - -INDENTRC=".indent.pro" -if [ ! -e ${INDENTRC} ] -then - echo No ${INDENTRC} file found. Creating ${INDENTRC} file. - echo "-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl" > ${INDENTRC} -fi - -directory=${1-`pwd`} -for filename in $( find $directory -name '*.c' ) -do - echo Fixing DOS/Unix $filename - ${DOS2UNIX} $filename - echo Indenting $filename - ${INDENT} $filename -done - -for filename in $( find $directory -name '*.h' ) -do - echo Fixing DOS/Unix $filename - ${DOS2UNIX} $filename - echo Indenting $filename - ${INDENT} $filename -done - -for filename in $( find $directory -name '*~' ) -do - echo Removing backup $filename - ${REMOVE} $filename -done -