Created
October 21, 2010 20:05
-
-
Save ViktorStiskala/639215 to your computer and use it in GitHub Desktop.
cclean.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Transliterate and clean C code using iconv and GNU Indent | |
# Created: 2010-10-21 | |
# Author: Viktor Stískala, viktor@stiskala.cz | |
# | |
filename="$1" | |
encoding="$2" | |
# check whether file exists | |
if [ -z "$filename" ] | |
then | |
echo "Please specify the file to convert" 1>2 | |
exit 1 | |
fi | |
# default encoding | |
if [ -z "$2" ] | |
then | |
encoding="ISO8859-2" | |
fi | |
# line endings conversion | |
convert="dos2unix" | |
if [ -z `which dos2unix` ] | |
then | |
convert="fromdos" | |
elif [ -z `which fromdos` ] | |
then | |
convert="" | |
echo "Cannot convert line endings, conversion program not found" 1>2 | |
fi | |
if [ -n "$convert" ] | |
then | |
$convert "$filename" | |
fi | |
# transliterate using iconv | |
iconv -f "$encoding" -t ASCII//TRANSLIT -o "$1" "$1" | |
# change indent style | |
indent -npro --no-blank-lines-after-declarations --blank-lines-after-procedures \ | |
--no-blank-lines-after-commas -nbbo --braces-after-if-line --brace-indent 0 \ | |
--braces-after-struct-decl-line --no-comment-delimiters-on-blank-lines \ | |
--dont-cuddle-else --else-endif-column 1 --space-after-cast \ | |
--declaration-indentation 4 --dont-left-justify-declarations \ | |
--honour-newlines --braces-after-func-def-line \ | |
--indent-level 4 --parameter-indentation 4 --continue-at-parentheses \ | |
--space-after-procedure-calls --continuation-indentation 4 \ | |
--no-space-after-parentheses --dont-break-procedure-type --space-after-for \ | |
--space-after-if --space-after-while --dont-star-comments \ | |
--swallow-optional-blank-lines --line-length 80 --comment-line-length 80 \ | |
--continue-at-parentheses --cuddle-do-while --use-tabs --tab-size 4 $filename | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment