aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-01-13 20:00:51 -0500
committerRuss Cox <rsc@swtch.com>2020-01-13 21:43:54 -0500
commit81d992e35f12d53e6799d20c744ffb4e6a49787d (patch)
tree3b82a7de122d983cb024b0eeac858adbdc230e99 /src
parent3a62e5630748d788166a50ed34b7f0dc6d43a5ee (diff)
downloadplan9port-81d992e35f12d53e6799d20c744ffb4e6a49787d.tar.gz
plan9port-81d992e35f12d53e6799d20c744ffb4e6a49787d.tar.bz2
plan9port-81d992e35f12d53e6799d20c744ffb4e6a49787d.zip
acme: factor out tag parsing code
Diffstat (limited to 'src')
-rw-r--r--src/cmd/acme/fns.h1
-rw-r--r--src/cmd/acme/look.c18
-rw-r--r--src/cmd/acme/wind.c30
3 files changed, 28 insertions, 21 deletions
diff --git a/src/cmd/acme/fns.h b/src/cmd/acme/fns.h
index 8dc02378..fece1dbd 100644
--- a/src/cmd/acme/fns.h
+++ b/src/cmd/acme/fns.h
@@ -95,6 +95,7 @@ void flushwarnings(void);
void startplumbing(void);
long nlcount(Text*, long, long, long*);
long nlcounttopos(Text*, long, long, long);
+Rune* parsetag(Window*, int*);
Runestr runestr(Rune*, uint);
Range range(int, int);
diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c
index 44e23cca..7b70e242 100644
--- a/src/cmd/acme/look.c
+++ b/src/cmd/acme/look.c
@@ -477,9 +477,9 @@ includename(Text *t, Rune *r, int n)
Runestr
dirname(Text *t, Rune *r, int n)
{
- Rune *b, c;
- uint m, nt;
- int slash;
+ Rune *b;
+ uint nt;
+ int slash, i;
Runestr tmp;
b = nil;
@@ -490,15 +490,13 @@ dirname(Text *t, Rune *r, int n)
goto Rescue;
if(n>=1 && r[0]=='/')
goto Rescue;
- b = runemalloc(nt+n+1);
- bufread(&t->w->tag.file->b, 0, b, nt);
+ b = parsetag(t->w, &i);
slash = -1;
- for(m=0; m<nt; m++){
- c = b[m];
- if(c == '/')
- slash = m;
- if(c==' ' || c=='\t')
+ for(i--; i >= 0; i--){
+ if(b[i] == '/'){
+ slash = i;
break;
+ }
}
if(slash < 0)
goto Rescue;
diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c
index 820955b0..5950ef0e 100644
--- a/src/cmd/acme/wind.c
+++ b/src/cmd/acme/wind.c
@@ -440,6 +440,23 @@ wincleartag(Window *w)
textsetselect(&w->tag, w->tag.q0, w->tag.q1);
}
+Rune*
+parsetag(Window *w, int *len)
+{
+ int i;
+ Rune *r;
+
+ r = runemalloc(w->tag.file->b.nc+1);
+ bufread(&w->tag.file->b, 0, r, w->tag.file->b.nc);
+ r[w->tag.file->b.nc] = '\0';
+
+ for(i=0; i<w->tag.file->b.nc; i++)
+ if(r[i]==' ' || r[i]=='\t')
+ break;
+ *len = i;
+ return r;
+}
+
void
winsettag1(Window *w)
{
@@ -458,12 +475,7 @@ winsettag1(Window *w)
/* there are races that get us here with stuff in the tag cache, so we take extra care to sync it */
if(w->tag.ncache!=0 || w->tag.file->mod)
wincommit(w, &w->tag); /* check file name; also guarantees we can modify tag contents */
- old = runemalloc(w->tag.file->b.nc+1);
- bufread(&w->tag.file->b, 0, old, w->tag.file->b.nc);
- old[w->tag.file->b.nc] = '\0';
- for(i=0; i<w->tag.file->b.nc; i++)
- if(old[i]==' ' || old[i]=='\t')
- break;
+ old = parsetag(w, &i);
if(runeeq(old, i, w->body.file->name, w->body.file->nname) == FALSE){
textdelete(&w->tag, 0, i, TRUE);
textinsert(&w->tag, 0, w->body.file->name, w->body.file->nname, TRUE);
@@ -584,11 +596,7 @@ wincommit(Window *w, Text *t)
textcommit(f->text[i], FALSE); /* no-op for t */
if(t->what == Body)
return;
- r = runemalloc(w->tag.file->b.nc);
- bufread(&w->tag.file->b, 0, r, w->tag.file->b.nc);
- for(i=0; i<w->tag.file->b.nc; i++)
- if(r[i]==' ' || r[i]=='\t')
- break;
+ r = parsetag(w, &i);
if(runeeq(r, i, w->body.file->name, w->body.file->nname) == FALSE){
seq++;
filemark(w->body.file);