| version 1.29, 2002/07/04 14:29:28 |
version 1.30, 2002/07/04 20:07:35 |
| Line 24 TMP_FILE=`tempfile -p sms. -s .html \ |
|
| Line 24 TMP_FILE=`tempfile -p sms. -s .html \ |
|
| || mktemp /tmp/sms.XXXXXX \ |
|| mktemp /tmp/sms.XXXXXX \ |
| || echo /tmp/sms.$$.html` |
|| echo /tmp/sms.$$.html` |
| |
|
| if [ $# -lt 1 ]; then |
usage() |
| echo -e "Usage:\n $0 <number-or-alias>\n"; |
{ |
| echo -n "Message is taken from standart input." |
# calculate number of spaces used in aligment of usage message |
| echo " Use special characters with care."; |
S=`echo $0 | sed 's/./ /g;'` |
| echo "Spaces are handled properly."; |
cat <<EOF |
| |
Usage: |
| |
$0 [--alias-file <alias-file> ] |
| |
$S [--config-file <config-file> ] |
| |
$S [--tmp-file <tmp-file> ] |
| |
$S [--username <username> ] |
| |
$S [--number] <number-or-alias> |
| |
|
| |
Message is taken from standart input. |
| |
Use special characters with care. |
| |
Spaces are handled properly. |
| |
|
| |
If --alias-file and/or --config-file isn't |
| |
specified, default values are used. |
| |
|
| |
EOF |
| exit 1; |
exit 1; |
| |
} |
| |
|
| |
if [ $# -lt 1 ]; then |
| |
usage |
| fi |
fi |
| |
|
| number=`echo "$1" | grep '^[0-9]\+$'`; |
# Cmdline parsing {{{ |
| |
for option |
| |
do |
| |
# If the previous option needs an argument, assign it. |
| |
if test -n "$prev"; then |
| |
eval "$prev=\$option" |
| |
prev= |
| |
continue |
| |
fi |
| |
|
| |
case "$option" in |
| |
-*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; |
| |
*) optarg= ;; |
| |
esac |
| |
|
| |
case "$option" in |
| |
|
| |
--number | --numbe | --numb | --num | --nu | --n | \ |
| |
-number | -numbe | -numb | -num | -nu | -n) |
| |
prev=prev_number ;; |
| |
--number=* | --numbe=* | --numb=* | --num=* | --nu=* | --n=* | \ |
| |
-number=* | -numbe=* | -numb=* | -num=* | -nu=* | -n=*) |
| |
prev_number="$optarg" ;; |
| |
|
| |
--alias-file | --alias-fil | --alias-fi | --alias-f | --alias | --alia | \ |
| |
--ali | --al | --a | \ |
| |
-alias-file | -alias-fil | -alias-fi | -alias-f | -alias | -alia | \ |
| |
-ali | -al | -a) |
| |
prev=ALIAS_FILE ;; |
| |
--alias-file=* | --alias-fil=* | --alias-fi=* | --alias-f=* | --alia=* | \ |
| |
--ali=* | --al=* | --a=* | \ |
| |
-alias-file=* | -alias-fil=* | -alias-fi=* | -alias-f=* | -alia=* | \ |
| |
-ali=* | -al=* | -a=*) |
| |
ALIAS_FILE="$optarg" ;; |
| |
|
| |
--config-file | --config-fil | --config-fi | --config-f | --config | \ |
| |
--confi | --conf | --con | --co | --c | \ |
| |
-config-file | -config-fil | -config-fi | -config-f | -config | \ |
| |
-confi | -conf | -con | -co | -c) |
| |
prev=CONFIG_FILE ;; |
| |
--config-file=* | --config-fil=* | --config-fi=* | --config-f=* | --config=* | \ |
| |
--confi=* | --conf=* | --con=* | --co=* | --c=* | \ |
| |
-config-file=* | -config-fil=* | -config-fi=* | -config-f=* | -config=* | \ |
| |
-confi=* | -conf=* | -con=* | -co=* | -c=*) |
| |
CONFIG_FILE="$optarg" ;; |
| |
|
| |
--tmp-file | --tmp-fil | --tmp-fi | --tmp-f | \ |
| |
--tmp | --tm | --t | \ |
| |
-tmp-file | -tmp-fil | -tmp-fi | -tmp-f | \ |
| |
-tmp | -tm | -t) |
| |
prev=TMP_FILE ;; |
| |
--tmp-file=* | --tmp-fil=* | --tmp-fi=* | --tmp-f=* | \ |
| |
--tmp=* | --tm=* | --t=* | \ |
| |
-tmp-file=* | -tmp-fil=* | -tmp-fi=* | -tmp-f=* | \ |
| |
-tmp=* | -tm=* | -t=*) |
| |
# first remove already created $TMP_FILE and create new empty |
| |
rm -f $TMP_FILE; |
| |
TMP_FILE="$optarg"; touch $TMP_FILE ;; |
| |
|
| |
--username | --usernam | --userna | --usern | --user | \ |
| |
--use | --us | --u | \ |
| |
-username | -usernam | -userna | -usern | -user | \ |
| |
-use | -us | -u) |
| |
prev=NAME ;; |
| |
--username=* | --usernam=* | --userna=* | --usern=* | --user=* | \ |
| |
--use=* | --us=* | --u=* | \ |
| |
-username=* | -usernam=* | -userna=* | -usern=* | -user=* | \ |
| |
-use=* | -us=* | -u=*) |
| |
NAME="$optarg" ;; |
| |
|
| |
|
| |
--help | --hel | --he | --h | -help | -hel | -he | -h) |
| |
usage; |
| |
;; |
| |
|
| |
-*) { echo "error: $option: invalid option; use --help to show usage" 1>&2; |
| |
exit 1; } |
| |
;; |
| |
|
| |
*) prev_number="$option" ;; |
| |
|
| |
esac |
| |
done |
| |
# Cmdline parsing }}} |
| |
|
| |
#number=`echo "$1" | grep '^[0-9]\+$'`; |
| |
number=`echo "$prev_number" | grep '^[0-9]\+$'`; |
| |
|
| # check for alias {{{ |
# check for alias {{{ |
| if [ -z "$number" ]; then |
if [ -z "$number" ]; then |
| echo "Parameter '$1' treated as an alias."; |
echo "Parameter '$prev_number' treated as an alias."; |
| echo -n "Looking for alias file '$ALIAS_FILE'... "; |
echo -n "Looking for alias file '$ALIAS_FILE'... "; |
| if [ -f "$ALIAS_FILE" ]; then |
if [ -f "$ALIAS_FILE" ]; then |
| echo "found."; |
echo "found."; |
| echo -n "Looking for alias '$1'... "; |
echo -n "Looking for alias '$prev_number'... "; |
| number=`awk "BEGIN { alias=tolower(\"$1\"); } \ |
number=`awk "BEGIN { alias=tolower(\"$prev_number\"); } \ |
| /^#/ { next; } \ |
/^#/ { next; } \ |
| // { \\$0 = tolower(\\$0); } \ |
// { \\$0 = tolower(\\$0); } \ |
| \\$0 ~ alias { if (NF > 2) { print \\$3; } \ |
\\$0 ~ alias { if (NF > 2) { print \\$3; } \ |
|
|
| echo -n "Looking for config file '$CONFIG_FILE'... "; |
echo -n "Looking for config file '$CONFIG_FILE'... "; |
| if [ -f "$CONFIG_FILE" ]; then |
if [ -f "$CONFIG_FILE" ]; then |
| echo "found."; |
echo "found."; |
| echo -n "Looking for username... "; |
if [ -z "$NAME" ]; then # username was not specified on cmdline |
| NAME=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
echo -n "Looking for username... "; |
| /^user/ { if (NF > 2) { print $3; exit; } \ |
NAME=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
| else { print $2; } exit; }' "$CONFIG_FILE"`; |
/^user/ { if (NF > 2) { print $3; exit; } \ |
| if [ -z "$NAME" ]; then |
else { print $2; } exit; }' "$CONFIG_FILE"`; |
| echo "not found."; |
if [ -z "$NAME" ]; then |
| else |
echo "not found."; |
| echo "'$NAME'"; |
else |
| |
echo "'$NAME'"; |
| |
fi |
| fi |
fi |
| |
|
| echo -n "Looking for password... "; |
echo -n "Looking for password... "; |