aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/acme/exec.c41
-rw-r--r--src/cmd/rio/Imakefile27
2 files changed, 38 insertions, 30 deletions
diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c
index 7ad28872..ad818505 100644
--- a/src/cmd/acme/exec.c
+++ b/src/cmd/acme/exec.c
@@ -693,12 +693,44 @@ checksha1(char *name, File *f, Dir *d)
f->qidpath = d->qid.path;
f->mtime = d->mtime;
}
-}
+}
+
+static uint
+trimspaces(Rune *r, uint *np, int eof)
+{
+ uint i, w, nonspace, n;
+ Rune c;
+
+ nonspace = 0;
+ w = 0;
+ n = *np;
+ for(i=0; i<n; i++) {
+ c = r[i];
+ if(c == '\n')
+ w = nonspace;
+ r[w++] = c;
+ if(c != ' ' && c != '\t')
+ nonspace = w;
+ }
+ if(nonspace > 0 && nonspace < w) {
+ // Trailing spaces at end of buffer.
+ // Tell caller to reread them with what follows,
+ // so we can determine whether they need trimming.
+ // Unless the trailing spaces are the entire buffer,
+ // in which case let them through to avoid an infinite loop
+ // if an entire buffer fills with spaces.
+ // At EOF, just consume the spaces.
+ if(!eof)
+ *np = n - (w - nonspace);
+ w = nonspace;
+ }
+ return w;
+}
void
putfile(File *f, int q0, int q1, Rune *namer, int nname)
{
- uint n, m;
+ uint n, nn, m;
Rune *r;
Biobuf *b;
char *s, *name;
@@ -753,7 +785,10 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
if(n > BUFSIZE/UTFmax)
n = BUFSIZE/UTFmax;
bufread(&f->b, q, r, n);
- m = snprint(s, BUFSIZE+1, "%.*S", n, r);
+ nn = n;
+ if(w->autoindent)
+ nn = trimspaces(r, &n, q+n==q1);
+ m = snprint(s, BUFSIZE+1, "%.*S", nn, r);
sha1((uchar*)s, m, nil, h);
if(Bwrite(b, s, m) != m){
warning(nil, "can't write file %s: %r\n", name);
diff --git a/src/cmd/rio/Imakefile b/src/cmd/rio/Imakefile
deleted file mode 100644
index 43a78931..00000000
--- a/src/cmd/rio/Imakefile
+++ /dev/null
@@ -1,27 +0,0 @@
-INCLUDES = -I$(TOP)
-DEPLIBS = $(DEPXLIB)
-LOCAL_LIBRARIES = $(XLIB)
-DEFINES = -DSHAPE # -g3 -DDEBUG -DDEBUG_EV
-SRCS = main.c event.c manage.c menu.c client.c grab.c cursor.c error.c color.c
-OBJS = main.o event.o manage.o menu.o client.o grab.o cursor.o error.o color.o
-HFILES = dat.h fns.h patchlevel.h
-MFILES = README 9wm.man Imakefile Makefile.no-imake
-
-ComplexProgramTarget(rio)
-
-bun:
- bundle $(MFILES) $(SRCS) $(HFILES) >bun
-
-dist:
- bundle $(MFILES) main.c event.c manage.c >bun1
- bundle menu.c client.c grab.c cursor.c error.c $(HFILES) >bun2
-
-trout: 9wm.man
- troff -man 9wm.man >trout
-
-vu: trout
- xditview trout
-
-clean::
- $(RM) bun bun[12] trout core
-