1nl=' 2' 3tab=' ' 4if(~ $#distname 0) 5 distname=plan9 6 7wctl=/dev/null 8if(test -w /dev/wctl) 9 wctl=/dev/wctl 10 11fn log { 12 echo $* >>/srv/log 13} 14 15fn logprog { 16 echo '% '^$"* >>/srv/log 17 $* >[2=1] >>/srv/log 18} 19 20fn sigint { 21 # nothing happens 22} 23 24fn prompt { 25 def=() 26 what=() 27 if(~ $1 -d && ! ~ $#* 1){ 28 def=$2 29 shift 30 shift 31 } 32 33 optstr=() 34 if(~ $1 -w && ! ~ $#* 1){ 35 optstr=$2 36 shift 37 shift 38 } 39 40 pr=$1 41 shift 42 43 opts=($*) 44 if(~ $#opts 0) { 45 suf=' ' 46 } 47 if not if(! ~ $#optstr 0) { 48 if(~ $optstr '') 49 suf=' ' 50 if not { 51 pr=$pr^' ('^$"optstr^')' 52 suf='' 53 } 54 } 55 if not { 56 pr=$pr^' ('^$1 57 shift 58 for(i) 59 pr=$pr^', '^$i 60 pr=$pr^')' 61 suf='' 62 } 63 64 if(~ $#def 1) 65 pr=$pr^$suf^'['^$def^']' 66 if not 67 pr=$pr^$suf^'[no default]' 68 69 pr=$pr^': ' 70 71 72 okay=no 73 while(~ $okay no) { 74 echo -n current >$wctl 75 echo -n top >$wctl 76 echo -n $pr >[1=2] 77 ifs='' {rd=`{read}} 78 if(~ $#rd 0) 79 exit notdone 80 if(~ $rd !*){ 81 ifs='' {rd=`{echo $rd | sed 's/!//'}} 82 echo $rd 83 rc -c $rd 84 echo !$status 85 } 86 if not{ 87 rd=`{echo $rd} 88 if(~ $#rd 0 || ~ $rd '') 89 rd=$def 90 91 switch($#opts){ 92 case 0 93 if(! ~ $rd '') 94 okay=yes 95 case * 96 if(~ $rd $opts) 97 okay=yes 98 } 99 } 100 } 101 echo -n $rd >/env/rd # just in case 102} 103 104fn desc { 105 echo -n ' '^$1^' - ' 106 grep '^# desc: ' $1 | sed 's/# desc: //' 107} 108 109fn prereq { 110 grep '^# prereq:' $1 | sed 's/# prereq://' 111} 112 113fn mustdo { 114 echo You must `{grep '^# mustdo:' $1 | sed 's/# mustdo://'} 115} 116 117# there's no easy way to pass shell variables 118# up from children to parents; the parents have 119# to be coerced into noticing that the environment 120# changed, even when in the same environment group. 121# 122# instead, we explicitly export the variables we want 123# to percolate, and the parent calls coherence to reread 124# the variables. 125# 126# we just append to the vars file, so that later exports 127# override earlier ones; when we call coherence, 128# the duplicates are thrown out. 129 130fn export { 131 null=() 132 nonnull=() 133 for(i in $*){ 134 if(~ $#$i 0) 135 null=($null $i) 136 if not 137 nonnull=($nonnull $i) 138 } 139 if(! ~ $#nonnull 0) 140 whatis $nonnull |grep -v '^\./' >>/tmp/vars >[2]/dev/null 141 for(i in $null) 142 echo $i^'=()' >>/tmp/vars 143} 144 145fn coherence { 146 if(test -f /tmp/vars) { 147 grep '^[a-z]*=' /tmp/vars >/tmp/vars2 148 v=`{sed 's/^([a-z]*)=.*/\1/' /tmp/vars2 | sort -u} 149 . /tmp/vars2 150 rm /tmp/vars2 151 rm /tmp/vars 152 export $v 153 } 154} 155 156# ip device stats 157 158fn isipdevup { 159 grep -s $1 /net/ipifc/*/status >[2]/dev/null 160} 161 162 163