common-functions.sh.in
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:12k
源码类别:
传真(Fax)编程
开发平台:
C/C++
- #! @SCRIPT_SH@
- # $Id: common-functions.sh.in,v 1.36 2009/09/08 03:18:43 faxguy Exp $
- #
- # This holds various functions that are common to the
- # various bin scripts.
- #
- #
- # Produce mailable encoding for binary files.
- #
- encode()
- {
- if [ ! -f "$1" ]; then
- return # encode what?
- fi
- if [ -x "$MIMENCODE" ]; then
- $MIMENCODE < $1 2>$ERRORSTO
- elif [ -x "$UUENCODE" ]; then
- if [ "$ENCODING" = "base64" ]; then
- $UUENCODE -m $1 ==== | $GREP -v "====$" 2>$ERRORSTO
- else
- $UUENCODE $1 $1 2>$ERRORSTO
- fi
- else
- # Do not use "-x" for backward compatibility; even if it fails
- # this is last chance to encode data, so there's nothing to lose.
- $MIMENCODE < $1 2>$ERRORSTO
- fi
- }
- #
- # For getting all of the "faxinfo" items to line up. As the CallID tags
- # can be customized we must take unmodified faxinfo output into account.
- #
- setInfoSize()
- {
- INFOSIZE=`$INFO -n $1 | $SED 's/:.*//g' | $SED q | wc -L`
- for ITEM in DICTSENDER DICTPAGES DICTQUALITY DICTSIZE DICTRECEIVED
- DICTTIMETORECV DICTSIGNALRATE DICTDATAFORMAT DICTERRCORRECT
- DICTCALLID1 DICTCALLID2 DICTCALLID3 DICTCALLID4 DICTCALLID
- DICTCALLID6 DICTCALLID7 DICTRECEIVEDON DICTCOMMID; do
- THISLEN="`eval echo \""$"$ITEM\" | wc -L | $SED 's/ //g'`"
- if [ $THISLEN -gt $INFOSIZE ]; then INFOSIZE=$THISLEN; fi
- done
- }
- #
- # For getting all of the notify job items to line up.
- #
- setItemSize()
- {
- ITEMSIZE=0
- for ITEM in DICTDESTINATION DICTJOBID DICTGROUPID DICTSENDER DICTMAILADDR
- DICTCOMMID DICTMODEM DICTSUBMITTEDFROM DICTPAGEWIDTH
- DICTPAGELENGTH DICTRES DICTSTATUS DICTDIALOGS DICTDIALS
- DICTCALLS DICTPAGES DICTATTEMPTS DICTDIRNUM DICTRECEIVER DICTQUALITY
- DICTPAGEWIDTH DICTPAGELENGTH DICTDATAFORMAT DICTREMOTEEQUIPMENT
- DICTREMOTESTATION DICTSIGNALRATE; do
- THISLEN="`eval echo \""$"$ITEM\" | wc -L | $SED 's/ //g'`"
- if [ $THISLEN -gt $ITEMSIZE ]; then ITEMSIZE=$THISLEN; fi
- done
- }
- faxInfo()
- {
- $INFO -n $1 | $SED -e 's/^ *//g'
- -e "s/^ *Sender:/$DICTSENDER:/"
- -e "s/^Pages:/$DICTPAGES:/"
- -e "s/^Quality:/$DICTQUALITY:/"
- -e "s/^Page:/$DICTSIZE:/"
- -e "s/^Received:/$DICTRECEIVED:/"
- -e "s/^TimeToRecv:/$DICTTIMETORECV:/"
- -e "s/^SignalRate:/$DICTSIGNALRATE:/"
- -e "s/^DataFormat:/$DICTDATAFORMAT:/"
- -e "s/^ErrCorrect:/$DICTERRCORRECT:/"
- -e "s/^CallID1:/$DICTCALLID1:/"
- -e "s/^CallID2:/$DICTCALLID2:/"
- -e "s/^CallID3:/$DICTCALLID3:/"
- -e "s/^CallID4:/$DICTCALLID4:/"
- -e "s/^CallID5:/$DICTCALLID5:/"
- -e "s/^CallID6:/$DICTCALLID6:/"
- -e "s/^CallID7:/$DICTCALLID7:/"
- -e "s/ Yes$/ $DICTYES/"
- -e "s/ No$/ $DICTNO/"
- -e "s/ Normal$/ $DICTNORMAL/"
- -e "s/ Fine$/ $DICTFINE/"
- -e 's/:/|/' |
- printFormatted $INFOSIZE
- }
- printFormatted()
- {
- $AWK -F| -v s=$1 'BEGIN { size = s; } { ("echo ""$1"" | wc -L") | getline ilen; close("echo ""$1"" | wc -L"); printf "%"size-ilen"s%s:%sn", "",$1,$2 }'
- }
- #
- # Export qfile content to environment
- # parseQfile(prefix, filename)
- # Both parameters can be omitted. Defaults to no prefix and $QFILE.
- #
- parseQfile()
- {
- # In shell scripts, there are no special characters in hard-quoted
- # strings (quoted with (')). Single-quotes can't even be escaped
- # inside such strings and must be put outside of them. We thus replace
- # (') with (''') which terminates the current string, adds a single
- # quote and starts a new string.
- #
- # We no longer escape newlines, because we don't eval
- #
- # print out variable name and value so we can eval it in the shell
- #
- VAR_PREFIX="$1"
- if [ -n "$2" ] ; then
- FILENAME=$2;
- else
- FILENAME=$QFILE;
- fi
- if [ ! -f "$FILENAME" ] ; then
- return # cannot do much more without a file
- fi
- $AWK -F: '
- function p(varname,val)
- {
- gsub(/ 47/, "