| | #! /bin/sh |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| |
|
| | |
| | |
| | func_usage () |
| | { |
| | echo "\ |
| | Usage: declared.sh [OPTION]... < SOURCE.h |
| | |
| | Extracts the declared global symbols of a C header file. |
| | |
| | Options: |
| | --help print this help and exit |
| | --version print version information and exit |
| | |
| | Send patches and bug reports to <bug-gnulib@gnu.org>." |
| | } |
| |
|
| | |
| | |
| | func_version () |
| | { |
| | echo "declared.sh (GNU gnulib)" |
| | echo "Copyright (C) 2025 Free Software Foundation, Inc. |
| | License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> |
| | This is free software: you are free to change and redistribute it. |
| | There is NO WARRANTY, to the extent permitted by law." |
| | echo |
| | printf 'Written by %s.\n' "Bruno Haible" |
| | } |
| |
|
| | |
| | |
| | func_fatal_error () |
| | { |
| | echo "declared.sh: *** $1" 1>&2 |
| | echo "declared.sh: *** Stop." 1>&2 |
| | exit 1 |
| | } |
| |
|
| | |
| | while test $# -gt 0; do |
| | case "$1" in |
| | --help | --hel | --he | --h ) |
| | func_usage |
| | exit 0 ;; |
| | --version | --versio | --versi | --vers | --ver | --ve | --v ) |
| | func_version |
| | exit 0 ;; |
| | -- ) |
| | shift; break ;; |
| | -* ) |
| | func_fatal_error "unrecognized option: $1" |
| | ;; |
| | * ) |
| | break ;; |
| | esac |
| | done |
| |
|
| | if test $# -gt 0; then |
| | func_fatal_error "too many arguments" |
| | fi |
| |
|
| | |
| | sed_remove_comments=" |
| | /[/][/*]/{ |
| | ta |
| | :a |
| | s,^\\(\\([^\"'/]\\|\"\\([^\\\"]\\|[\\].\\)*\"\\|'\\([^\\']\\|[\\].\\)*'\\|[/][^\"'/*]\\|[/]\"\\([^\\\"]\\|[\\].\\)*\"\\|[/]'\\([^\\']\\|[\\].\\)*'\\)*\\)//.*,\\1, |
| | te |
| | s,^\\(\\([^\"'/]\\|\"\\([^\\\"]\\|[\\].\\)*\"\\|'\\([^\\']\\|[\\].\\)*'\\|[/][^\"'/*]\\|[/]\"\\([^\\\"]\\|[\\].\\)*\"\\|[/]'\\([^\\']\\|[\\].\\)*'\\)*\\)/[*]\\([^*]\\|[*][^/*]\\)*[*][*]*/,\\1 , |
| | ta |
| | /^\\([^\"'/]\\|\"\\([^\\\"]\\|[\\].\\)*\"\\|'\\([^\\']\\|[\\].\\)*'\\|[/][^\"'/*]\\|[/]\"\\([^\\\"]\\|[\\].\\)*\"\\|[/]'\\([^\\']\\|[\\].\\)*'\\)*[/][*]/{ |
| | s,^\\(\\([^\"'/]\\|\"\\([^\\\"]\\|[\\].\\)*\"\\|'\\([^\\']\\|[\\].\\)*'\\|[/][^\"'/*]\\|[/]\"\\([^\\\"]\\|[\\].\\)*\"\\|[/]'\\([^\\']\\|[\\].\\)*'\\)*\\)/[*].*,\\1 , |
| | tu |
| | :u |
| | n |
| | s,^\\([^*]\\|[*][^/*]\\)*[*][*]*/,, |
| | tv |
| | s,^.*\$,, |
| | bu |
| | :v |
| | } |
| | :e |
| | }" |
| |
|
| | |
| | |
| | |
| | sed_test='s,^\(\(a\|X\)*\)//.*,\1,' |
| | sed_result=`echo 'aaa//bcd' | sed -e "$sed_test"` |
| | test "$sed_result" = 'aaa' \ |
| | || func_fatal_error "The 'sed' program is not GNU sed. Try installing GNU sed." |
| |
|
| | |
| | |
| | sed_join_multiline_externs=' |
| | /^extern [^;"]*$/{ |
| | :a |
| | N |
| | s/\n/ /g |
| | /^extern [^;"]*$/{ |
| | ba |
| | } |
| | }' |
| |
|
| | |
| | sed_extract_extern_declared='s/^extern [^()]*[ *]\([A-Za-z_][A-Za-z0-9_]*\) *[;(].*$/\1/p' |
| |
|
| | sed -e "$sed_remove_comments" \ |
| | | sed -e "$sed_join_multiline_externs" \ |
| | | sed -n -e "$sed_extract_extern_declared" |
| |
|