Sophie

Sophie

distrib > Altlinux > 4.1 > i586 > media > core-src > by-pkgid > 32ca40091ab539ab6443fcc05c86b593 > files > 7

thunderbird-2.0.0.21-alt0.M41.1.src.rpm

#!/bin/sh -euf

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
prefix - ??

Examle:
$PROG '/usr/include' '/usr/src/RPM/BUILD/firefox-1.5/dist/include' 'firefox'

EOF
    [ -n "$1" ] && exit "$1" || exit
}

msg() {
    printf %s\\n "$@"
}

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 3 ] || usage 1
include_dir="$1" && shift
indir="$1" && shift
my_place="$1" && shift

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")" || msg "Error: $h: '$ih'"
	if [ -z "$eh" ]; then
	    if ! eh="$(find_header "${h%/*}" "$ih")"; then
		eh="$(find "$indir/" -name "$ih_name")" || msg "Error: $h: '$ih'"
		[ "$(printf %s\\n "$eh" |wc -l)" = "1" ] || { msg "Error: $h: '$(msg "$eh" |tr \\n \ )'"; continue; }
	    fi
	    [ -n "$eh" ] || { echo "Error: not found: $h: '$ih'"; continue; }
	    subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$my_place/${eh#$indir/}>%" -- "$h" ||
		msg "Error: $h"
	    continue
	fi
	nh="${eh#$include_dir/}"
	
	# check nss/nspr
	nh="${nh#*nspr/}"
	nh="${nh#*nss/}"

	subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%" -- "$h" ||
	    echo "Error: $h: 's%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%'"
    done
done