xref: /titanic_50/usr/src/cmd/getopt/getoptcvt.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24#	  All Rights Reserved
25
26
27#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
28# This program changes all occurences of the SVR2 getopt invocation line
29# to use the SVR3 version of getopt.
30# Sedfunc is used to handle arguments with single quotes.
31# If -b option is given, getoptcvt will create script that will usually work
32# in releases previous to 3.0.
33bflag=
34while getopts b c
35do
36	case $c in
37	b)  bflag=1;;
38	\?) echo "getoptcvt [-b] file"
39	    exit 2;;
40	esac
41done
42shift `expr $OPTIND - 1`
43if [ "$bflag" = 1 ]
44then
45	ed <<'!' - $1
461,$s/set[ 	][ 	]*--[ 	][ 	]*`getopt[ 	][ 	]*\(.*\)[ 	][ 	]*.*`/{\
47if [ "$OPTIND" != 1 ]\
48then\
49	set -- `getopt \1 $*`\
50else\
51sedfunc() \
52{\
53echo "$1" | sed "s\/'\/'\\\\\\\\''\/g"\
54}\
55exitcode_=0\
56while getopts \1 c_\
57do\
58	case $c_ in\
59	\\?)\
60		exitcode_=1\
61		break;;\
62	*)	if [ "$OPTARG" ]\
63		then\
64			optarg_=`sedfunc "$OPTARG"`\
65			arg_="$arg_ '-$c_' '$optarg_'"\
66		else\
67			arg_="$arg_ '-$c_'"\
68		fi;;\
69	esac\
70done\
71shift `expr $OPTIND - 1`\
72arg_="$arg_ '--'"\
73for i_ in "$@"\
74do\
75	optarg_=`sedfunc "$i_"`\
76	arg_="$arg_ '$optarg_'"\
77done\
78eval set -- "$arg_"\
79test  $exitcode_ = 0\
80fi ;}/
811,$p
82Q
83!
84else
85	ed <<'!' - $1
861,$s/set[ 	][ 	]*--[ 	][ 	]*`getopt[ 	][ 	]*\(.*\)[ 	][ 	]*.*`/{\
87sedfunc()\
88{\
89echo "$1" | sed "s\/'\/'\\\\\\\\''\/g"\
90}\
91exitcode_=0\
92while getopts \1 c_\
93do\
94	case $c_ in\
95	\\?)\
96		exitcode_=1\
97		break;;\
98	*)	if [ "$OPTARG" ]\
99		then\
100			optarg_=`sedfunc "$OPTARG"`\
101			arg_="$arg_ -$c_ '$optarg_'"\
102		else\
103			arg_="$arg_ -$c_"\
104		fi;;\
105	esac\
106done\
107shift `expr $OPTIND - 1`\
108arg_="$arg_ --"\
109for i_ in "$@"\
110do\
111	optarg_=`sedfunc "$i_"`\
112	arg_="$arg_ '$optarg_'"\
113done\
114eval set -- "$arg_"\
115test  $exitcode_ = 0 ;}/
1161,$p
117Q
118!
119fi
120