星期二, 4月 22, 2008

[tips] poorman's uudecode

For those who cursed by ash and awk, welcome to 80's !

now you can send everything in ASCII -- hooray!!

#!/bin/sh
#
# uudecode.sh
#
# Author: Ximian, Inc.
#
# Modified: by timchen119 at http://timchen119.blogspot.com from Ximian go-gnome's GPL code
#
# Usage: uudecode.sh encodedfile > decodefile
#
# License: GPL
#
# Download: http://kalug.linux.org.tw/~tim/gpl/uudecode.sh
#
# Ref: http://ftp.cesnet.cz/pub/ximian-gnome/installers/go-gnome
#
# The Ximian Desktop Pre-Installer
#
# Comments to:
# distribution@ximian.com
#
# Copyright 2000-2001, Ximian, Inc.
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
# USA.
#
#
# This script and its embedded programs are distributed with
# absolutely, positively NO WARRANTY WHATSOEVER, without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. The author and Ximian, Inc. take no responsibility for
# the consequences of running this script.
#
#

CACHEDIR=/tmp
_awk="awk"

# poor man's uudecode
_awkprog="$CACHEDIR/uudecode.awk"
# encoded file
_uudecode_in=$1

#awk-script
cat > ${_awkprog} <<EOF
function x(l, p) {
n="!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_";
return index(n,substr(l,p+1,1));
}
/^begin/ {}
/^[^be]/ {
len = x(\$0, 0);
for (i=1;len>0;i+=4) {
a=x(\$0,i);b=x(\$0,i+1);c=x(\$0,i+2);d=x(\$0,i+3);
printf("%c",a*4+b/16);
if (len>1) {
printf("%c",b*16+c/4);
if (len>2) {
printf("%c",c*64+d);
}
}
len-=3;
}
}
EOF
${_awk} -f ${_awkprog} < ${_uudecode_in}
rm -f ${_awkprog}


get uudecode.sh at here.

沒有留言: