home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / lib / getoptcvt < prev    next >
Encoding:
Text File  |  1988-06-26  |  1.8 KB  |  102 lines

  1. :
  2. #    Copyright (c) 1984, 1986, 1987, 1988 AT&T
  3. #      All Rights Reserved
  4.  
  5. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  6. #    The copyright notice above does not evidence any
  7. #    actual or intended publication of such source code.
  8.  
  9. #ident    "@(#)getopt:getoptcvt.sh    1.4"
  10. # This program changes all occurences of the SVR2 getopt invocation line
  11. # to use the SVR3 version of getopt.
  12. # Sedfunc is used to handle arguments with single quotes.
  13. # If -b option is given, getoptcvt will create script that will usually work
  14. # in releases previous to 3.0.
  15. bflag=
  16. while getopts b c
  17. do
  18.     case $c in
  19.     b)  bflag=1;;
  20.     \?) echo "getoptcvt [-b] file"
  21.         exit 2;;
  22.     esac
  23. done
  24. shift `expr $OPTIND - 1`
  25. if [ "$bflag" = 1 ]
  26. then
  27.     ed <<'!' - $1
  28. 1,$s/set[     ][     ]*--[     ][     ]*`getopt[     ][     ]*\(.*\)[     ][     ]*.*`/{\
  29. if [ "$OPTIND" != 1 ]\
  30. then\
  31.     set -- `getopt \1 $*`\
  32. else\
  33. sedfunc() \
  34. {\
  35. echo "$1" | sed "s\/'\/'\\\\\\\\''\/g"\
  36. }\
  37. exitcode_=0\
  38. while getopts \1 c_\
  39. do\
  40.     case $c_ in\
  41.     \\?)\
  42.         exitcode_=1\
  43.         break;;\
  44.     *)    if [ "$OPTARG" ]\
  45.         then\
  46.             optarg_=`sedfunc "$OPTARG"`\
  47.             arg_="$arg_ '-$c_' '$optarg_'"\
  48.         else\
  49.             arg_="$arg_ '-$c_'"\
  50.         fi;;\
  51.     esac\
  52. done\
  53. shift `expr $OPTIND - 1`\
  54. arg_="$arg_ '--'"\
  55. for i_ in "$@"\
  56. do\
  57.     optarg_=`sedfunc "$i_"`\
  58.     arg_="$arg_ '$optarg_'"\
  59. done\
  60. eval set -- "$arg_"\
  61. test  $exitcode_ = 0\
  62. fi ;}/
  63. 1,$p
  64. Q
  65. !
  66. else
  67.     ed <<'!' - $1
  68. 1,$s/set[     ][     ]*--[     ][     ]*`getopt[     ][     ]*\(.*\)[     ][     ]*.*`/{\
  69. sedfunc()\
  70. {\
  71. echo "$1" | sed "s\/'\/'\\\\\\\\''\/g"\
  72. }\
  73. exitcode_=0\
  74. while getopts \1 c_\
  75. do\
  76.     case $c_ in\
  77.     \\?)\
  78.         exitcode_=1\
  79.         break;;\
  80.     *)    if [ "$OPTARG" ]\
  81.         then\
  82.             optarg_=`sedfunc "$OPTARG"`\
  83.             arg_="$arg_ -$c_ '$optarg_'"\
  84.         else\
  85.             arg_="$arg_ -$c_"\
  86.         fi;;\
  87.     esac\
  88. done\
  89. shift `expr $OPTIND - 1`\
  90. arg_="$arg_ --"\
  91. for i_ in "$@"\
  92. do\
  93.     optarg_=`sedfunc "$i_"`\
  94.     arg_="$arg_ '$optarg_'"\
  95. done\
  96. eval set -- "$arg_"\
  97. test  $exitcode_ = 0 ;}/
  98. 1,$p
  99. Q
  100. !
  101. fi
  102.