Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/grpc/tools/distrib/guard_headers.sh

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/bin/bash
2 # Copyright 2015, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32 set -e
33
34 cd `dirname $0`/../..
35
36 function process_dir {
37 base_dir=$1
38 prefix=$2
39 comment_language=$3
40 (
41 cd $base_dir
42 find . -name "*.h" | while read f ; do
43 guard=${prefix}_`echo ${f#*/} | tr '[:lower:]/.-' '[:upper:]___'`
44 if [ "$comment_language" = "c++" ] ; then
45 comment="// $guard"
46 else
47 comment="/* $guard */"
48 fi
49 awk '
50 BEGIN {
51 guard = "'${guard}'";
52 comment_language = "'${comment_language}'";
53 }
54 prev ~ /^#ifndef/ && !got_first_ifndef {
55 got_first_ifndef = 1;
56 prev = "#ifndef " guard;
57 }
58 prev ~ /^#define/ && !got_first_define {
59 got_first_define = 1;
60 prev = "#define " guard;
61 }
62 NR > 1 { print prev; }
63 { prev = $0; }
64 END {
65 if (prev ~ /^#endif/) {
66 if (comment_language ~ /^c$/) {
67 print "#endif /* " guard " */";
68 } else if (comment_language ~ /^c\+\+$/) {
69 print "#endif // " guard;
70 } else {
71 print "ERROR: unknown comment language: " comment_language;
72 }
73 } else {
74 print "ERROR: file does not end with #endif";
75 }
76 }
77 ' "${f}" > "${f}.rewritten"
78 mv "${f}.rewritten" "${f}"
79 done
80 )
81 }
82
83 process_dir include/grpc GRPC c
84 process_dir include/grpc++ GRPCXX c++
85 process_dir src/core GRPC_INTERNAL_CORE c
86 process_dir src/cpp GRPC_INTERNAL_CPP c++
87 process_dir src/compiler GRPC_INTERNAL_COMPILER c++
88 process_dir test/core GRPC_TEST_CORE c
89 process_dir test/cpp GRPC_TEST_CPP c++
90 process_dir examples GRPC_EXAMPLES c++
OLDNEW
« no previous file with comments | « third_party/grpc/tools/distrib/docker_for_windows.rb ('k') | third_party/grpc/tools/distrib/python/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698