tnew - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit b8c9f31785f3243a52432023d4d555d490963769
parent e96129189712a83de71d45cbc852a54c5960d575
Author: rsc 
Date:   Mon, 21 Mar 2005 07:37:34 +0000

new

Diffstat:
  M src/cmd/netfiles/main.c             |      16 +++++++++++++---
  M src/cmd/netfiles/mkfile             |       1 +
  M src/cmd/netfiles/netfileget         |      16 ++++++++--------
  A src/cmd/netfiles/netfilelib.rc      |      21 +++++++++++++++++++++
  M src/cmd/netfiles/netfileput         |      14 ++++++++------
  M src/cmd/netfiles/netfilestat        |      24 +++++++++---------------

6 files changed, 60 insertions(+), 32 deletions(-)
---
diff --git a/src/cmd/netfiles/main.c b/src/cmd/netfiles/main.c
t@@ -173,12 +173,22 @@ isdot(Win *w, uint xq0, uint xq1)
 char*
 expandarg(Win *w, Event *e)
 {
+        uint q0, q1;
+        
         if(e->c2 == 'l')        /* in tag - no choice but to accept acme's expansion */
                 return estrdup(e->text);
-        dprint("expand %d %d %d %d\n", e->oq0, e->oq1, e->q0, e->q1);
-        if(e->oq0 == e->oq1 && e->q0 != e->q1 && !isdot(w, e->q0, e->q1))
+        winaddr(w, ",");
+        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);
-        else
+                q0 = winreadaddr(w, &q1);
+                cprint("\tre-expand to %d-%d\n", q0, q1);        
+        }else
                 winaddr(w, "#%ud,#%ud", e->q0, e->q1);
         return winmread(w, "xdata");
 }
diff --git a/src/cmd/netfiles/mkfile b/src/cmd/netfiles/mkfile
t@@ -15,6 +15,7 @@ XTARG=\
         netfileget\
         netfileput\
         netfilestat\
+        netfilelib.rc\
 
 install:V:
         for i in $XTARG; do
diff --git a/src/cmd/netfiles/netfileget b/src/cmd/netfiles/netfileget
t@@ -11,17 +11,17 @@ if(! ~ $#* 2){
         exit usage
 }
 
-ns=`{namespace}
-if(u test -S $ns/$1)
-        f=$f^9p
-
-t=/tmp/netget.$pid.$USER
-fn sigexit { rm -f $t }
+. netfilelib.rc $1
 
 fn getfile {
         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
+        egrep -v '^Fetching' $t.e >$t.e2
+        if(test -s $t.e2){
+                cat $t.e >[1=2]
                 exit 1
+        }
         cat $t
 }
 
t@@ -31,7 +31,7 @@ fn getfile9p {
 }
 
 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
         cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}'
 }
diff --git a/src/cmd/netfiles/netfilelib.rc b/src/cmd/netfiles/netfilelib.rc
t@@ -0,0 +1,21 @@
+
+ns=`{namespace}
+if([2]/dev/null)
+        f=$f^9p
+
+fn mysftp {
+        if(! [2]/dev/null){
+                echo 'caching sftp' $1 >[1=2]
+                sftpcache -D $1
+        }
+        if(! [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 }
+
diff --git a/src/cmd/netfiles/netfileput b/src/cmd/netfiles/netfileput
t@@ -6,17 +6,18 @@ if(! ~ $#* 2){
 }
 
 f=putfile
-ns=`{namespace}
-if(u test -S $ns/$1)
-        f=$f^9p
 
-t=/tmp/netget.$pid.$USER
-fn sigexit { rm -f $t }
+. netfilelib.rc $1
 
 fn putfile{
         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
+        egrep -v '^Uploading' $t.e >$t.e2
+        if(test -s $t.e2){
+                cat $t.e >[1=2]
+                exit 1
+        }
 }
 fn putfile9p{
         if(! 9p write $1/$2)
t@@ -25,3 +26,4 @@ fn putfile9p{
 
 $f $1 $2
 exit 0
+
diff --git a/src/cmd/netfiles/netfilestat b/src/cmd/netfiles/netfilestat
t@@ -6,33 +6,27 @@ if(! ~ $#* 2){
 }
 
 f=dostat
-ns=`{namespace}
-if(u test -S $ns/$1)
-        f=$f^9p
 
-t=/tmp/netisdir.$pid.$USER
-fn sigexit { rm -f $t }
+. netfilelib.rc $1
 
 fn dostat {
         {
-                echo !echo XXX connected
-                echo cd $2
-                echo !echo XXX directory exists
-        }  | sftp -b /dev/stdin $1 >$t >[2=1]
-        if(9 grep -s XXX.directory.exists $t){
+                9 echo -cd $2
+        }  | mysftp $1 >$t
+        if(9 test -e $t -a ! -s $t){
                 echo directory
                 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
                 exit 0
         }
-        cat $t | sed 's/sftp> //g; /^$/d; /XXX/d; /^cd /d' >[1=2]
-        if(! 9 grep -s XXX.connected $t){
-                echo connect failed
+        if(9 grep -s 'Couldn''t stat remote file|such file' $t){
+                echo nonexistent
                 exit 0
         }
-        echo nonexistent
+        cat $t >[1=2]
+        echo unknown error
         exit 0
 }