#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-list-files
|
|
# Copyright (C) 2007 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
# This script returns a list of locations in SDEROOT relative form
|
|
#
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. $SDEROOT/lib/libsde.in
|
|
|
|
list_usage() {
|
|
local progname=${0##*/}
|
|
cat <<EOT
|
|
Usage: $progname [--absolute] [--roots] [FILES...]
|
|
EOT
|
|
}
|
|
|
|
shortopts='a'
|
|
longopts='roots,absolute'
|
|
options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
|
|
if [ $? -ne 0 ]; then
|
|
list_usage
|
|
exit -1
|
|
fi
|
|
|
|
# load new arguments list
|
|
eval set -- "$options"
|
|
|
|
show_roots=
|
|
show_absolute_path=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--roots) show_roots=1 ;;
|
|
-a|--absolute) show_absolute_path=1 ;;
|
|
|
|
--) shift; break ;;
|
|
*) echo_abort 1 "Unknown argument '$1', aborting."
|
|
esac
|
|
shift
|
|
done
|
|
|
|
print_error() { echo "$@" >&2; }
|
|
|
|
print_file() {
|
|
local file="$1" root="$2"
|
|
|
|
if [ -z "$root" ]; then
|
|
# only filename
|
|
[ -n "$show_absolute_path" ] || file="${file#$SDEROOT/}"
|
|
elif [ "$root" == "." ]; then
|
|
# $SDEROOT is the root
|
|
|
|
[ -z "$show_absolute_path" ] || root="$SDEROOT"
|
|
else
|
|
[ -z "$show_absolute_path" ] || root="$SDEROOT/$root"
|
|
fi
|
|
|
|
if [ -n "$root" ]; then
|
|
echo "$root ${file#$SDEROOT/}"
|
|
else
|
|
echo "$file"
|
|
fi
|
|
}
|
|
|
|
for x; do
|
|
y=
|
|
if [ -e "$x" ]; then
|
|
if [ "${x:0:1}" == "/" ]; then
|
|
# absolute
|
|
y="$x"
|
|
else
|
|
# $PWD relative
|
|
y="$PWD/$x"
|
|
fi
|
|
elif [ -e "$SDEROOT/$x" ]; then
|
|
# $SDEROOT relative
|
|
y="$SDEROOT/$x"
|
|
fi
|
|
|
|
# canonicalize
|
|
[ -z "$y" ] || y=$( readlink -f "$y" )
|
|
|
|
# analyse
|
|
if [ -z "$y" ]; then
|
|
# missing
|
|
print_error "$x: not found."
|
|
elif [ "$y" == "$SDEROOT" ]; then
|
|
# uh, the root itself
|
|
print_file "." "."
|
|
elif ! expr "$y" : "$SDEROOT/*" > /dev/null; then
|
|
# missing
|
|
print_error "$x: outside the tree."
|
|
elif [ -n "$show_roots" ]; then
|
|
# detect the right VCS roots and split the output accordingly
|
|
print_file "$y" "."
|
|
else
|
|
# just output the list
|
|
print_file "$y"
|
|
fi
|
|
done
|