#! /bin/sh
|
#! /bin/sh
|
|
|
# (C) 1998, 2007 Free Software Foundation
|
# (C) 1998, 2007 Free Software Foundation
|
# Originally by Alexandre Oliva
|
# Originally by Alexandre Oliva
|
|
|
# This gawk/shell script is free software; you can redistribute it and/or
|
# This gawk/shell script is free software; you can redistribute it and/or
|
# modify it under the terms of the GNU General Public License as published
|
# modify it under the terms of the GNU General Public License as published
|
# by the Free Software Foundation; either version 3, or (at your option)
|
# by the Free Software Foundation; either version 3, or (at your option)
|
# any later version.
|
# any later version.
|
|
|
# Given a preprocessed C/C++ code snippet, this script will replace any
|
# Given a preprocessed C/C++ code snippet, this script will replace any
|
# standard header files with an actual #include <...> directive.
|
# standard header files with an actual #include <...> directive.
|
|
|
# Example:
|
# Example:
|
# # 1 "test.c"
|
# # 1 "test.c"
|
# # 1 "/usr/include/stdio.h" 1 3
|
# # 1 "/usr/include/stdio.h" 1 3
|
#
|
#
|
# # 1 "test.c" 2
|
# # 1 "test.c" 2
|
#
|
#
|
# main() { printf("Hello world!\n"); }
|
# main() { printf("Hello world!\n"); }
|
|
|
# is replaced with
|
# is replaced with
|
# # 1 "test.c"
|
# # 1 "test.c"
|
# #include
|
# #include
|
# main() { printf("Hello world!\n"); }
|
# main() { printf("Hello world!\n"); }
|
|
|
|
|
# Header files whose pathnames contain any of the following patterns
|
# Header files whose pathnames contain any of the following patterns
|
# are considered as standard headers: usr/include, g++-include,
|
# are considered as standard headers: usr/include, g++-include,
|
# include/g++, include/c++/, gcc-lib//include.
|
# include/g++, include/c++/, gcc-lib//include.
|
|
|
gawk ${EXCLUDEPATT+-vexclude="$EXCLUDEPATT"} \
|
gawk ${EXCLUDEPATT+-vexclude="$EXCLUDEPATT"} \
|
${INCLUDEPATT+-vinclude="$INCLUDEPATT"} '
|
${INCLUDEPATT+-vinclude="$INCLUDEPATT"} '
|
BEGIN {
|
BEGIN {
|
skipping = 0;
|
skipping = 0;
|
cppline = "^# [0-9]+ \"[^\"]*/(usr/include|g\\+\\+-include|include/g\\+\\+|include/c\\+\\+/[^/]+|gcc-lib/[^\"]+/include|gcc/include)/([^\"]+)\"( [1-4])*$"
|
cppline = "^# [0-9]+ \"[^\"]*/(usr/include|g\\+\\+-include|include/g\\+\\+|include/c\\+\\+/[^/]+|gcc-lib/[^\"]+/include|gcc/include)/([^\"]+)\"( [1-4])*$"
|
}
|
}
|
!skipping && $0 ~ cppline &&
|
!skipping && $0 ~ cppline &&
|
(exclude == "" || $3 !~ exclude) && (include == "" || $3 ~ include) {
|
(exclude == "" || $3 !~ exclude) && (include == "" || $3 ~ include) {
|
skipping = 1;
|
skipping = 1;
|
printf "%s\n", "#include <" gensub(cppline, "\\2", "", $0) ">"
|
printf "%s\n", "#include <" gensub(cppline, "\\2", "", $0) ">"
|
next;
|
next;
|
}
|
}
|
skipping && /^# [0-9]+ / && $3 == lastincluded {
|
skipping && /^# [0-9]+ / && $3 == lastincluded {
|
skipping = 0;
|
skipping = 0;
|
next;
|
next;
|
}
|
}
|
!skipping && /^# [0-9]+ / {
|
!skipping && /^# [0-9]+ / {
|
lastincluded = $3;
|
lastincluded = $3;
|
}
|
}
|
!skipping { print }
|
!skipping { print }
|
' ${1+"$@"}
|
' ${1+"$@"}
|
|
|