summaryrefslogtreecommitdiff
path: root/mcon/U/Tr.U
blob: 64fefbe79bbe5d8f2c762cae6cc08a76b3969791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
?RCS: $Id: Tr.U 1 2006-08-24 12:32:52Z rmanfredi $
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic Licence,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: Tr.U,v $
?RCS: Revision 3.0.1.2  1994/10/29  18:00:54  ram
?RCS: patch43: forgot to quote $@ to protect against "evil" characters
?RCS:
?RCS: Revision 3.0.1.1  1994/10/29  15:58:35  ram
?RCS: patch36: created
?RCS:
?X: 
?X: This unit produces a bit of shell code that must be dotted in in order
?X: to do a character translation. It catches translations to uppercase or
?X: to lowercase, and then invokes the real tr to perform the job.
?X:
?X: This unit is necessary on HP machines (HP strikes again!) with non-ascii
?X: ROMAN8-charset, where normal letters are not arranged in a row, so a-z
?X: covers not the whole alphabet but lots of special chars. This was reported
?X: by Andreas Sahlbach <a.sahlbach@tu-bs.de>.
?X:
?X: Units performing a tr '[A-Z]' '[a-z]' or the other way round should include
?X: us in their dependency and use ./tr instead.
?X:
?MAKE:Tr: startsh tr eunicefix
?MAKE:	-pick add $@ %<
?F:./tr
?T:up low LC_ALL
: see whether [:lower:] and [:upper:] are supported character classes
echo " "
case "`echo AbyZ | LC_ALL=C $tr '[:lower:]' '[:upper:]' 2>/dev/null`" in
ABYZ)
	echo "Good, your tr supports [:lower:] and [:upper:] to convert case." >&4
	up='[:upper:]'
	low='[:lower:]'
	;;
*)	# There is a discontinuity in EBCDIC between 'I' and 'J'
        # (0xc9 and 0xd1), therefore that is a nice testing point.
        if test "X$up" = X -o "X$low" = X; then
	    case "`echo IJ | LC_ALL=C $tr '[I-J]' '[i-j]' 2>/dev/null`" in
	    ij) up='[A-Z]'
	        low='[a-z]'
		;;
	    esac
        fi
	if test "X$up" = X -o "X$low" = X; then
	    case "`echo IJ | LC_ALL=C $tr I-J i-j 2>/dev/null`" in
	    ij) up='A-Z'
		low='a-z'
		;;
	    esac
        fi
	if test "X$up" = X -o "X$low" = X; then
	    case "`echo IJ | od -x 2>/dev/null`" in
	    *C9D1*|*c9d1*)
		echo "Hey, this might be EBCDIC." >&4
		if test "X$up" = X -o "X$low" = X; then
		    case "`echo IJ | \
				LC_ALL=C $tr '[A-IJ-RS-Z]' '[a-ij-rs-z]' 2>/dev/null`" in
		    ij) up='[A-IJ-RS-Z]'
		        low='[a-ij-rs-z]'
			;;
		    esac
		fi
		if test "X$up" = X -o "X$low" = X; then
		    case "`echo IJ | LC_ALL=C $tr A-IJ-RS-Z a-ij-rs-z 2>/dev/null`" in
		    ij) up='A-IJ-RS-Z'
		        low='a-ij-rs-z'
			;;
		    esac
		fi
		;;
	    esac
	fi
esac
case "`echo IJ | LC_ALL=C $tr \"$up\" \"$low\" 2>/dev/null`" in
ij)
    echo "Using $up and $low to convert case." >&4
    ;;
*)
    echo "I don't know how to translate letters from upper to lower case." >&4
    echo "Your tr is not acting any way I know of." >&4
    exit 1
    ;;
esac
: set up the translation script tr, must be called with ./tr of course
cat >tr <<EOSC
$startsh
case "\$1\$2" in
'[A-Z][a-z]') LC_ALL=C exec $tr '$up' '$low';;
'[a-z][A-Z]') LC_ALL=C exec $tr '$low' '$up';;
esac
LC_ALL=C exec $tr "\$@"
EOSC
chmod +x tr
$eunicefix tr