83 lines
2.0 KiB
Bash
83 lines
2.0 KiB
Bash
|
#!/bin/sh -euf
|
||
|
# -*- mode: Ksh; tab-width: 8; fill-column: 70; -*-
|
||
|
# $Id: fix_headers.sh,v 0.0.1 2006/04/05 15:39:57 legion Exp $
|
||
|
|
||
|
PROG="${0##*/}"
|
||
|
|
||
|
usage() {
|
||
|
[ "$1" = 0 ] || exec >&2
|
||
|
cat <<EOF
|
||
|
|
||
|
Program to correct headers at mozilla-based projects.
|
||
|
|
||
|
Usage: $PROG <include_dir> <project_include_dir> <prefix>
|
||
|
|
||
|
include_dir - system includes location
|
||
|
project_include_dir - project includes
|
||
|
|
||
|
Examle:
|
||
|
$PROG '/usr/include' '/var/tmp/firefox-buildroot/usr/include/firefox'
|
||
|
|
||
|
EOF
|
||
|
[ -n "$1" ] && exit "$1" || exit
|
||
|
}
|
||
|
|
||
|
msg() {
|
||
|
printf %s\\n "$@"
|
||
|
}
|
||
|
|
||
|
err() {
|
||
|
msg "Error: $@" >&2
|
||
|
}
|
||
|
|
||
|
find_header() {
|
||
|
local path="$1" && shift
|
||
|
local fn="$1" && shift
|
||
|
while [ -n "$path" ]; do
|
||
|
[ -f "$path/$fn" ] && break
|
||
|
path="${path%/*}"
|
||
|
done
|
||
|
[ -f "$path/$fn" ] && msg "$path/$fn" || return 1
|
||
|
}
|
||
|
|
||
|
[ "$#" -eq 2 ] || usage 1
|
||
|
include_dir="$(readlink -ve "$1")" && shift
|
||
|
indir="$(readlink -ve "$1")" && shift
|
||
|
|
||
|
exclude_list=
|
||
|
indir="$indir/"
|
||
|
for p in nss nspr mozldap; do
|
||
|
[ "$indir" != "${indir#*/$p/}" ] || exclude_list="$exclude_list $p"
|
||
|
done
|
||
|
indir="${indir%/}"
|
||
|
|
||
|
find "$indir/" -name '*.h' |
|
||
|
while read h; do
|
||
|
sed -ne 's|^[[:space:]]*#[[:space:]]*include[[:space:]]\+"\([^"]\+\)".*$|\1|p' -- "$h" | sort -u |
|
||
|
while read ih; do
|
||
|
ih_name="${ih##*/}"
|
||
|
eh="$(find "$include_dir" -name "$ih_name")" || err "$h: '$ih'"
|
||
|
if [ -z "$eh" ]; then
|
||
|
if ! eh="$(find_header "${h%/*}" "$ih")"; then
|
||
|
eh="$(find "$indir/" -name "$ih_name")" || err "$h: '$ih'"
|
||
|
[ "$(printf %s\\n "$eh" |wc -l)" = "1" ] || { err "$h: '$(msg "$eh" |tr \\n \ )'"; continue; }
|
||
|
fi
|
||
|
if [ -z "$eh" ]; then
|
||
|
err "not found: $h: '$ih'"
|
||
|
continue
|
||
|
fi
|
||
|
subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <${eh#*$include_dir/}>%" -- "$h" ||
|
||
|
err "$h"
|
||
|
continue
|
||
|
fi
|
||
|
nh="${eh#$include_dir/}"
|
||
|
|
||
|
for p in $exclude_list; do
|
||
|
nh="${nh#*$p/}"
|
||
|
done
|
||
|
|
||
|
subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%" -- "$h" ||
|
||
|
err "$h: 's%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%'"
|
||
|
done
|
||
|
done
|