This commit is contained in:
rsc 2005-03-21 07:37:34 +00:00
parent e961291897
commit b8c9f31785
6 changed files with 60 additions and 32 deletions

View file

@ -173,12 +173,22 @@ isdot(Win *w, uint xq0, uint xq1)
char* char*
expandarg(Win *w, Event *e) expandarg(Win *w, Event *e)
{ {
uint q0, q1;
if(e->c2 == 'l') /* in tag - no choice but to accept acme's expansion */ if(e->c2 == 'l') /* in tag - no choice but to accept acme's expansion */
return estrdup(e->text); return estrdup(e->text);
dprint("expand %d %d %d %d\n", e->oq0, e->oq1, e->q0, e->q1); winaddr(w, ",");
if(e->oq0 == e->oq1 && e->q0 != e->q1 && !isdot(w, e->q0, e->q1)) winctl(w, "addr=dot");
q0 = winreadaddr(w, &q1);
cprint("acme expanded %d-%d into %d-%d (dot %d-%d)\n",
e->oq0, e->oq1, e->q0, e->q1, q0, q1);
if(e->oq0 == e->oq1 && e->q0 != e->q1 && !isdot(w, e->q0, e->q1)){
winaddr(w, "#%ud+#1-/[^ \t\\n]*/,#%ud-#1+/[^ \t\\n]*/", e->q0, e->q1); winaddr(w, "#%ud+#1-/[^ \t\\n]*/,#%ud-#1+/[^ \t\\n]*/", e->q0, e->q1);
else q0 = winreadaddr(w, &q1);
cprint("\tre-expand to %d-%d\n", q0, q1);
}else
winaddr(w, "#%ud,#%ud", e->q0, e->q1); winaddr(w, "#%ud,#%ud", e->q0, e->q1);
return winmread(w, "xdata"); return winmread(w, "xdata");
} }

View file

@ -15,6 +15,7 @@ XTARG=\
netfileget\ netfileget\
netfileput\ netfileput\
netfilestat\ netfilestat\
netfilelib.rc\
install:V: install:V:
for i in $XTARG; do for i in $XTARG; do

View file

@ -11,17 +11,17 @@ if(! ~ $#* 2){
exit usage exit usage
} }
ns=`{namespace} . netfilelib.rc $1
if(u test -S $ns/$1)
f=$f^9p
t=/tmp/netget.$pid.$USER
fn sigexit { rm -f $t }
fn getfile { fn getfile {
rm -f $t rm -f $t
if(! echo get $2 $t | sftp -b /dev/stdin $1 >/dev/null) if(! 9 echo -get $2 $t | mysftp $1 >$t.e >[2=1])
exit 1 exit 1
egrep -v '^Fetching' $t.e >$t.e2
if(test -s $t.e2){
cat $t.e >[1=2]
exit 1
}
cat $t cat $t
} }
@ -31,7 +31,7 @@ fn getfile9p {
} }
fn getdir { fn getdir {
if(! {echo cd $2; echo ls -l} | sftp -b /dev/stdin $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t) if(! {echo cd $2; echo ls -l} | mysftp $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t)
exit 1 exit 1
cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}' cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}'
} }

View file

@ -0,0 +1,21 @@
ns=`{namespace}
if(</dev/null dial 'unix!'^$ns/$1 >[2]/dev/null)
f=$f^9p
fn mysftp {
if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
echo 'caching sftp' $1 >[1=2]
sftpcache -D $1
}
if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
sftp -b /dev/stdin $1
}
if not{
{cat; echo DONE} | dial -e 'unix!'^$ns/$1.sftp
}
}
t=/tmp/netfilexxx.$pid.$USER
fn sigexit { rm -f $t $t.e $t.e2 }

View file

@ -6,17 +6,18 @@ if(! ~ $#* 2){
} }
f=putfile f=putfile
ns=`{namespace}
if(u test -S $ns/$1)
f=$f^9p
t=/tmp/netget.$pid.$USER . netfilelib.rc $1
fn sigexit { rm -f $t }
fn putfile{ fn putfile{
cat >$t cat >$t
if(! echo put $t $2 | sftp -b /dev/stdin $1 >/dev/null) if(! 9 echo -put $t $2 | mysftp $1 >$t.e >[2=1])
exit 1 exit 1
egrep -v '^Uploading' $t.e >$t.e2
if(test -s $t.e2){
cat $t.e >[1=2]
exit 1
}
} }
fn putfile9p{ fn putfile9p{
if(! 9p write $1/$2) if(! 9p write $1/$2)
@ -25,3 +26,4 @@ fn putfile9p{
$f $1 $2 $f $1 $2
exit 0 exit 0

View file

@ -6,33 +6,27 @@ if(! ~ $#* 2){
} }
f=dostat f=dostat
ns=`{namespace}
if(u test -S $ns/$1)
f=$f^9p
t=/tmp/netisdir.$pid.$USER . netfilelib.rc $1
fn sigexit { rm -f $t }
fn dostat { fn dostat {
{ {
echo !echo XXX connected 9 echo -cd $2
echo cd $2 } | mysftp $1 >$t
echo !echo XXX directory exists if(9 test -e $t -a ! -s $t){
} | sftp -b /dev/stdin $1 >$t >[2=1]
if(9 grep -s XXX.directory.exists $t){
echo directory echo directory
exit 0 exit 0
} }
if(9 grep -s 'is not a directory' $t){ if(9 grep -s 'Can''t change directory|is not a directory' $t){
echo file echo file
exit 0 exit 0
} }
cat $t | sed 's/sftp> //g; /^$/d; /XXX/d; /^cd /d' >[1=2] if(9 grep -s 'Couldn''t stat remote file|such file' $t){
if(! 9 grep -s XXX.connected $t){ echo nonexistent
echo connect failed
exit 0 exit 0
} }
echo nonexistent cat $t >[1=2]
echo unknown error
exit 0 exit 0
} }