######################################################################## # # # This software is part of the ast package # # Copyright (c) 1994-2011 AT&T Intellectual Property # # and is licensed under the # # Eclipse Public License, Version 1.0 # # by AT&T Intellectual Property # # # # A copy of the License is available at # # http://www.eclipse.org/org/documents/epl-v10.html # # (with md5 checksum b35adb5213ca9657e911e9befb180842) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # Glenn Fowler # # # ######################################################################## : wrapper for .exe challenged win32 systems/commands global command := 'execrate' global bins := ''/bin /usr/bin /usr/sbin'' matchstr $[shell {getopts '[-][123:xyz]' opt --xyz; echo 0$opt}] { 0123 { global ARGV0 := ""-a $command"" global USAGE := "$' [-? @(#)$Id: execrate (AT&T Labs Research) 2002-02-02 $ ] '$USAGE_LICENSE$' [+NAME?execrate - wrapper for .exe challenged commands] [+DESCRIPTION?\bexecrate\b runs \acommand\a after checking the \afile\a operands for standard semantics with respect to \bwin32\b \b.exe\b suffix conventions. This command is only needed on \bwin32\b systems that inconsistently handle \b.exe\b across library and command interfaces. \acommand\a may be one of \bcat\b(1), \bchmod\b(1), \bcmp\b(1), \bcp\b(1), \bln\b(1), \bmv\b(1), or \brm\b(1). Only the 2 argument forms of \bcp\b, \bln\b and \bmv\b are handled. Unsupported commands and commands requiring no change are silently executed.] [+?With no arguments \bexecrate\b exits with status 0 if the current system is \b.exe\b challenged, 1 if the current system is normal.] [n:show?Show the underlying commands but do not execute.] command [ option ... ] file ... [+SEE ALSO?\bwebster\b(1)] "' proc usage { global OPTIND := '0' getopts $ARGV0 $USAGE OPT '-?' exit 2 } global exec := '1' while getopts $ARGV0 "$USAGE" OPT { matchstr $OPT { n { global exec := '0' } * { usage } } } shift $[expr $OPTIND - 1] } * { proc usage { echo "Usage: execrate [ -n ] [ command [ option ... ] file ... ]" > !2 exit 2 } global exec := '1' while : { matchstr $1 { -n { global exec := '0' } -* { usage } * { break } } shift } } } matchstr $Argc { 0 { if test ! -x /bin/cat.exe { exit 1 # normal } if /bin/cat /bin/cat >/dev/null !2 > !1 { exit 1 # normal } exit 0 # challenged } 1 { usage } } matchstr $1 { *cat|*rm { global NUM := '0' } *chgrp|*chmod { global NUM := '1' } *cmp|*cp|*ln|*mv { global NUM := '2' } * { matchstr $exec { 0 { echo @Argv } * { @Argv } } exit } } global CMD := $1 shift matchstr $CMD { */* { } * { for d in [$bins] { if test -x $d/$1 -o -x $d/$1.exe { global CMD := "$d/$1" break } } } } while : { matchstr $1 { -* { global CMD := ""$CMD $1"" } * { break } } shift } matchstr $exec { 0 { global CMD := ""echo $CMD"" } } matchstr $NUM:$Argc { *:0 { } 1:* { global CMD := ""$CMD $1"" global NUM := '0' shift } } matchstr $NUM:$Argc { 0:* { global status := '0'for f in @Argv { if test $f -ef "$f".exe { global f := "$f.exe" } $CMD $f matchstr $Status { 0 { } * { global status := $Status } } } exit $status } 2:2 { global f := $1 matchstr $f { *.exe { } * { if test $f -ef "$f".exe { global f := "$f.exe" } } } matchstr $f { *.exe { if test -d $2 { global t := "$2/$f" } else { global t := $2 } matchstr $t { */* { global b := $[basename $t] } * { global b := $t } } matchstr $b { *.* { $CMD $f $t; exit } * { $CMD $f "$t".exe; exit } } } } } } $CMD @Argv (CommandList children: [ (C {(Lit_Other ":")} {(wrapper)} {(KW_For for)} {(.exe)} {(challenged)} {(win32)} {(systems/commands)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:command) op:Equal rhs:{(execrate)} spids:[72])] spids: [72] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:bins) op: Equal rhs: {(SQ <"/bin /usr/bin /usr/sbin">)} spids: [76] ) ] spids: [76] ) (Case to_match: { (CommandSubPart command_list: (CommandList children: [ (Subshell child: (CommandList children: [ (Sentence child: (C {(getopts)} {(SQ <"[-][123:xyz]">)} {(opt)} {(--xyz)}) terminator: ) (C {(echo)} {(0) ($ VSub_Name "$opt")}) ] ) redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[103])] spids: [85 101] ) ] ) left_token: spids: [84 105] ) } arms: [ (case_arm pat_list: [{(0123)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ARGV0) op: Equal rhs: {(DQ ("-a ") ($ VSub_Name "$command"))} spids: [112] ) ] spids: [112] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:USAGE) op: Equal rhs: { (SQ <"\n"> <"[-?\n"> <"@(#)$Id: execrate (AT&T Labs Research) 2002-02-02 $\n"> <"]\n"> ) ($ VSub_Name "$USAGE_LICENSE") (SQ <"\n"> <"[+NAME?execrate - wrapper for .exe challenged commands]\n"> <"[+DESCRIPTION?"> <" runs "> <" after checking the "> <"\n"> <"\toperands for standard semantics with respect to "> <" "> <.exe> <"\n"> <"\tsuffix conventions. This command is only needed on "> <"\n"> <"\tsystems that inconsistently handle "> <.exe> <" across library and\n"> <"\tcommand interfaces. "> <" may be one of "> <"(1), "> <"(1),\n"> <"\t"> <"(1), "> <"(1), "> <"(1), "> <"(1), or "> <"(1).\n"> <"\tOnly the 2 argument forms of "> <", "> <" and "> <" are handled.\n"> <"\tUnsupported commands and commands requiring no change are\n"> <"\tsilently executed.]\n"> <"[+?With no arguments "> <" exits with status 0 if the current system\n"> <"\tis "> <.exe> <" challenged, 1 if the current system is normal.]\n"> <"[n:show?Show the underlying commands but do not execute.]\n"> <"\n"> <"command [ option ... ] file ...\n"> <"\n"> <"[+SEE ALSO?"> <"(1)]\n"> ) } spids: [119] ) ] spids: [119] ) (FuncDef name: usage body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:OPTIND) op:Equal rhs:{(0)} spids:[241])] spids: [241] ) (C {(getopts)} {($ VSub_Name "$ARGV0")} {(DQ ($ VSub_Name "$USAGE"))} {(OPT)} {(SQ <"-?">)} ) (C {(exit)} {(2)}) ] spids: [238] ) spids: [233 236] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:exec) op:Equal rhs:{(1)} spids:[268])] spids: [268] ) (While cond: [(C {(getopts)} {($ VSub_Name "$ARGV0")} {(DQ ($ VSub_Name "$USAGE"))} {(OPT)})] body: (DoGroup children: [ (Case to_match: {($ VSub_Name "$OPT")} arms: [ (case_arm pat_list: [{(n)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exec) op: Equal rhs: {(0)} spids: [297] ) ] spids: [297] ) ] spids: [294 295 300 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(usage)})] spids: [303 304 308 -1] ) ] spids: [287 291 311] ) ] spids: [285 314] ) ) (C {(shift)} { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Name "$OPTIND")} {(-)} {(1)})] ) left_token: spids: [319 327] ) } ) ] spids: [109 110 330 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (FuncDef name: usage body: (BraceGroup children: [ (SimpleCommand words: [ {(echo)} {(DQ ("Usage: execrate [ -n ] [ command [ option ... ] file ... ]"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[349])] ) (C {(exit)} {(2)}) ] spids: [340] ) spids: [335 338] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:exec) op:Equal rhs:{(1)} spids:[361])] spids: [361] ) (While cond: [(C {(Lit_Other ":")})] body: (DoGroup children: [ (Case to_match: {($ VSub_Number "$1")} arms: [ (case_arm pat_list: [{(-n)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exec) op: Equal rhs: {(0)} spids: [382] ) ] spids: [382] ) ] spids: [379 380 385 -1] ) (case_arm pat_list: [{(-) (Lit_Other "*")}] action: [(C {(usage)})] spids: [388 390 394 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(ControlFlow token:)] spids: [397 398 402 -1] ) ] spids: [372 376 405] ) (C {(shift)}) ] spids: [370 411] ) ) ] spids: [332 333 414 -1] ) ] spids: [82 107 416] ) (Case to_match: {($ VSub_Pound "$#")} arms: [ (case_arm pat_list: [{(0)}] action: [ (If arms: [ (if_arm cond: [(C {(test)} {(KW_Bang "!")} {(-x)} {(/bin/cat.exe)})] action: [(C {(exit)} {(1)})] spids: [-1 438] ) ] spids: [-1 448] ) (If arms: [ (if_arm cond: [ (SimpleCommand words: [{(/bin/cat)} {(/bin/cat)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [457] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [460] ) ] ) ] action: [(C {(exit)} {(1)})] spids: [-1 464] ) ] spids: [-1 474] ) (C {(exit)} {(0)}) ] spids: [424 425 485 -1] ) (case_arm pat_list:[{(1)}] action:[(C {(usage)})] spids:[487488493-1]) ] spids: [418 422 495] ) (Case to_match: {($ VSub_Number "$1")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (cat)} {(Lit_Other "*") (rm)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NUM) op:Equal rhs:{(0)} spids:[511])] spids: [511] ) ] spids: [503 508 515 -1] ) (case_arm pat_list: [{(Lit_Other "*") (chgrp)} {(Lit_Other "*") (chmod)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NUM) op:Equal rhs:{(1)} spids:[525])] spids: [525] ) ] spids: [517 522 529 -1] ) (case_arm pat_list: [ {(Lit_Other "*") (cmp)} {(Lit_Other "*") (cp)} {(Lit_Other "*") (ln)} {(Lit_Other "*") (mv)} ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NUM) op:Equal rhs:{(2)} spids:[545])] spids: [545] ) ] spids: [531 542 549 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Case to_match: {($ VSub_Name "$exec")} arms: [ (case_arm pat_list: [{(0)}] action: [(C {(echo)} {(DQ ($ VSub_At "$@"))})] spids: [561 562 570 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(DQ ($ VSub_At "$@"))})] spids: [573 574 580 -1] ) ] spids: [554 558 583] ) (C {(exit)}) ] spids: [551 552 589 -1] ) ] spids: [497 501 591] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:CMD) op:Equal rhs:{($ VSub_Number "$1")} spids:[593])] spids: [593] ) (C {(shift)}) (Case to_match: {($ VSub_Name "$CMD")} arms: [ (case_arm pat_list:[{(Lit_Other "*") (/) (Lit_Other "*")}] spids:[604607609-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (ForEach iter_name: d iter_words: [{($ VSub_Name "$bins")}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (C {(test)} {(-x)} {($ VSub_Name "$d") (/) ($ VSub_Number "$1")} {(-o)} {(-x)} {($ VSub_Name "$d") (/) ($ VSub_Number "$1") (.exe)} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMD) op: Equal rhs: {($ VSub_Name "$d") (/) ($ VSub_Number "$1")} spids: [647] ) ] spids: [647] ) (ControlFlow token:) ] spids: [-1 645] ) ] spids: [-1 656] ) ] spids: [623 659] ) spids: [619 -1] ) ] spids: [611 612 662 -1] ) ] spids: [598 602 664] ) (While cond: [(C {(Lit_Other ":")})] body: (DoGroup children: [ (Case to_match: {($ VSub_Number "$1")} arms: [ (case_arm pat_list: [{(-) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMD) op: Equal rhs: {(DQ ($ VSub_Name "$CMD") (" ") ($ VSub_Number "$1"))} spids: [683] ) ] spids: [683] ) ] spids: [679 681 690 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(ControlFlow token:)] spids: [693 694 698 -1] ) ] spids: [672 676 701] ) (C {(shift)}) ] spids: [670 706] ) ) (Case to_match: {($ VSub_Name "$exec")} arms: [ (case_arm pat_list: [{(0)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMD) op: Equal rhs: {(DQ ("echo ") ($ VSub_Name "$CMD"))} spids: [717] ) ] spids: [717] ) ] spids: [714 715 723 -1] ) ] spids: [708 712 725] ) (Case to_match: {($ VSub_Name "$NUM") (Lit_Other ":") ($ VSub_Pound "$#")} arms: [ (case_arm pat_list:[{(Lit_Other "*") (Lit_Other ":") (0)}] spids:[735738740-1]) (case_arm pat_list: [{(1) (Lit_Other ":") (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMD) op: Equal rhs: {(DQ ($ VSub_Name "$CMD") (" ") ($ VSub_Number "$1"))} spids: [747] ) ] spids: [747] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NUM) op:Equal rhs:{(0)} spids:[755])] spids: [755] ) (C {(shift)}) ] spids: [742 745 762 -1] ) ] spids: [727 733 764] ) (Case to_match: {($ VSub_Name "$NUM") (Lit_Other ":") ($ VSub_Pound "$#")} arms: [ (case_arm pat_list: [{(0) (Lit_Other ":") (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:status) op:Equal rhs:{(0)} spids:[779])] spids: [779] ) (ForEach iter_name: f do_arg_iter: True body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (C {(test)} {(DQ ($ VSub_Name "$f"))} {(-ef)} {(DQ ($ VSub_Name "$f")) (.exe)} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:f) op: Equal rhs: {($ VSub_Name "$f") (.exe)} spids: [808] ) ] spids: [808] ) ] spids: [-1 806] ) ] spids: [-1 813] ) (C {($ VSub_Name "$CMD")} {(DQ ($ VSub_Name "$f"))}) (Case to_match: {($ VSub_QMark "$?")} arms: [ (case_arm pat_list:[{(0)}] spids:[830831833-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:status) op: Equal rhs: {($ VSub_QMark "$?")} spids: [839] ) ] spids: [839] ) ] spids: [836 837 842 -1] ) ] spids: [823 827 845] ) ] spids: [788 848] ) spids: [-1 -1] ) (C {(exit)} {($ VSub_Name "$status")}) ] spids: [774 777 856 -1] ) (case_arm pat_list: [{(2) (Lit_Other ":") (2)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:f) op: Equal rhs: {($ VSub_Number "$1")} spids: [863] ) ] spids: [863] ) (Case to_match: {($ VSub_Name "$f")} arms: [ (case_arm pat_list:[{(Lit_Other "*") (.exe)}] spids:[874876878-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (If arms: [ (if_arm cond: [ (C {(test)} {(DQ ($ VSub_Name "$f"))} {(-ef)} {(DQ ($ VSub_Name "$f")) (.exe)} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:f) op: Equal rhs: {($ VSub_Name "$f") (.exe)} spids: [902] ) ] spids: [902] ) ] spids: [-1 900] ) ] spids: [-1 907] ) ] spids: [881 882 910 -1] ) ] spids: [867 871 913] ) (Case to_match: {($ VSub_Name "$f")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (.exe)}] action: [ (If arms: [ (if_arm cond: [(C {(test)} {(-d)} {(DQ ($ VSub_Number "$2"))})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:t) op: Equal rhs: {($ VSub_Number "$2") (/) ($ VSub_Name "$f")} spids: [940] ) ] spids: [940] ) ] spids: [-1 938] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:t) op: Equal rhs: {($ VSub_Number "$2")} spids: [948] ) ] spids: [948] ) ] spids: [946 952] ) (Case to_match: {($ VSub_Name "$t")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (/) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:b) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(basename)} {(DQ ($ VSub_Name "$t"))})] ) left_token: spids: [968 974] ) } spids: [967] ) ] spids: [967] ) ] spids: [962 965 976 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:b) op: Equal rhs: {($ VSub_Name "$t")} spids: [982] ) ] spids: [982] ) ] spids: [979 980 985 -1] ) ] spids: [955 959 988] ) (Case to_match: {($ VSub_Name "$b")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (.) (Lit_Other "*")}] action: [ (Sentence child: (C {($ VSub_Name "$CMD")} {(DQ ($ VSub_Name "$f"))} {(DQ ($ VSub_Name "$t"))} ) terminator: ) (C {(exit)}) ] spids: [998 1001 1016 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Sentence child: (C {($ VSub_Name "$CMD")} {(DQ ($ VSub_Name "$f"))} {(DQ ($ VSub_Name "$t")) (.exe)} ) terminator: ) (C {(exit)}) ] spids: [1019 1020 1036 -1] ) ] spids: [991 995 1039] ) ] spids: [923 925 1042 -1] ) ] spids: [916 920 1045] ) ] spids: [858 861 1048 -1] ) ] spids: [766 772 1050] ) (C {($ VSub_Name "$CMD")} {(DQ ($ VSub_At "$@"))}) ] )