home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / lib / getoptcvt < prev    next >
Encoding:
Text File  |  1990-12-08  |  2.0 KB  |  105 lines

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