gccgo...
[official-gcc.git] / contrib / uninclude
blob8ba28e5cfb7a25c60253d8b37d6413128e225c3a
1 #! /bin/sh
3 # (C) 1998, 2007 Free Software Foundation
4 # Originally by Alexandre Oliva <oliva@lsd.ic.unicamp.br>
6 # This gawk/shell script is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as published
8 # by the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
11 # Given a preprocessed C/C++ code snippet, this script will replace any
12 # standard header files with an actual #include <...> directive.
14 # Example:
15 # # 1 "test.c"
16 # # 1 "/usr/include/stdio.h" 1 3
17 # <snip>
18 # # 1 "test.c" 2
20 # main() { printf("Hello world!\n"); }
22 # is replaced with
23 # # 1 "test.c"
24 # #include <stdio.h>
25 # main() { printf("Hello world!\n"); }
28 # Header files whose pathnames contain any of the following patterns
29 # are considered as standard headers: usr/include, g++-include,
30 # include/g++, include/c++/<version>, gcc-lib/<anything>/include.
32 gawk ${EXCLUDEPATT+-vexclude="$EXCLUDEPATT"} \
33 ${INCLUDEPATT+-vinclude="$INCLUDEPATT"} '
34 BEGIN {
35 skipping = 0;
36 cppline = "^# [0-9]+ \"[^\"]*/(usr/include|g\\+\\+-include|include/g\\+\\+|include/c\\+\\+/[^/]+|gcc-lib/[^\"]+/include|gcc/include)/([^\"]+)\"( [1-4])*$"
38 !skipping && $0 ~ cppline &&
39 (exclude == "" || $3 !~ exclude) && (include == "" || $3 ~ include) {
40 skipping = 1;
41 printf "%s\n", "#include <" gensub(cppline, "\\2", "", $0) ">"
42 next;
44 skipping && /^# [0-9]+ / && $3 == lastincluded {
45 skipping = 0;
46 next;
48 !skipping && /^# [0-9]+ / {
49 lastincluded = $3;
51 !skipping { print }
52 ' ${1+"$@"}