~thomas-voss/location-service/generalize-glue-code-for-agps-operation

« back to all changes in this revision

Viewing changes to tools/formatcode.in

  • Committer: thomas-voss
  • Date: 2015-02-02 15:05:32 UTC
  • mto: This revision was merged to the branch mainline in revision 196.
  • Revision ID: thomas.voss@canonical.com-20150202150532-9jm6l7ctsey92zka
Add documentation for debugging, hacking and debugging the location service.
Pull manual testing instructions over from the wiki.
Add tools for formatting the source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Copyright (C) 2013 Canonical Ltd
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
# Authored by: Michi Henning <michi.henning@canonical.com>
 
18
 
 
19
# Simple script to format files with astyle, followed by clang-format (which
 
20
# undoes some damage that's done by astyle, without wiping out astyle edits we want
 
21
# to happen).
 
22
#
 
23
# usage: formatcode [FILE]...
 
24
#
 
25
# If no arguments are provided, we format stdin and write to stdout.
 
26
 
 
27
astyle="@ASTYLE_COMMAND@"
 
28
format="@CLANG_FORMAT_COMMAND@"
 
29
dos2unix="@DOS2UNIX_COMMAND@"
 
30
style="@CMAKE_SOURCE_DIR@/_clang-format"
 
31
 
 
32
# Check that the format commands were found.
 
33
[ "$astyle" = "ASTYLE_COMMAND-NOTFOUND" -o \
 
34
  "$dos2unix" = "DOS2UNIX_COMMAND-NOTFOUND" -o \
 
35
  "$format" = "CLANG_FORMAT_COMMAND-NOTFOUND" ] && {
 
36
    echo "formatcode: cmake did not find all formatting tools" >&2
 
37
    exit 1
 
38
}
 
39
 
 
40
# If no arguments were provided, read stdin and write stdout.
 
41
# Recent versions of astyle can't read stdin: http://sourceforge.net/p/astyle/bugs/63/
 
42
# astyle 2.03 writes DOS line endings: https://sourceforge.net/p/astyle/bugs/268/
 
43
[ $# -eq 0 ] && {
 
44
    tmpdir=`mktemp -d`
 
45
    tmp=`mktemp -p $tmpdir`
 
46
    cp "$style" $tmpdir
 
47
    cat >$tmp
 
48
    cd $tmpdir
 
49
    "$astyle" -q --options=@CMAKE_SOURCE_DIR@/astyle-config -n $tmp
 
50
    "$dos2unix" -q $tmp
 
51
    "$format" -i -style=file $tmp
 
52
    cat $tmp
 
53
    rm -fr $tmpdir
 
54
    exit $?
 
55
}
 
56
 
 
57
# Format files in place.
 
58
"$astyle" --options=@CMAKE_SOURCE_DIR@/astyle-config -n "$@"
 
59
[ $? -ne 0 ] && exit $?
 
60
 
 
61
"$dos2unix" -q "$@"
 
62
 
 
63
"$format" -i -style=file $files "$@"
 
64
exit $?