mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-24 11:41:58 +00:00
acme: factor out tag parsing code
This commit is contained in:
parent
3a62e56307
commit
81d992e35f
3 changed files with 28 additions and 21 deletions
|
@ -95,6 +95,7 @@ void flushwarnings(void);
|
||||||
void startplumbing(void);
|
void startplumbing(void);
|
||||||
long nlcount(Text*, long, long, long*);
|
long nlcount(Text*, long, long, long*);
|
||||||
long nlcounttopos(Text*, long, long, long);
|
long nlcounttopos(Text*, long, long, long);
|
||||||
|
Rune* parsetag(Window*, int*);
|
||||||
|
|
||||||
Runestr runestr(Rune*, uint);
|
Runestr runestr(Rune*, uint);
|
||||||
Range range(int, int);
|
Range range(int, int);
|
||||||
|
|
|
@ -477,9 +477,9 @@ includename(Text *t, Rune *r, int n)
|
||||||
Runestr
|
Runestr
|
||||||
dirname(Text *t, Rune *r, int n)
|
dirname(Text *t, Rune *r, int n)
|
||||||
{
|
{
|
||||||
Rune *b, c;
|
Rune *b;
|
||||||
uint m, nt;
|
uint nt;
|
||||||
int slash;
|
int slash, i;
|
||||||
Runestr tmp;
|
Runestr tmp;
|
||||||
|
|
||||||
b = nil;
|
b = nil;
|
||||||
|
@ -490,15 +490,13 @@ dirname(Text *t, Rune *r, int n)
|
||||||
goto Rescue;
|
goto Rescue;
|
||||||
if(n>=1 && r[0]=='/')
|
if(n>=1 && r[0]=='/')
|
||||||
goto Rescue;
|
goto Rescue;
|
||||||
b = runemalloc(nt+n+1);
|
b = parsetag(t->w, &i);
|
||||||
bufread(&t->w->tag.file->b, 0, b, nt);
|
|
||||||
slash = -1;
|
slash = -1;
|
||||||
for(m=0; m<nt; m++){
|
for(i--; i >= 0; i--){
|
||||||
c = b[m];
|
if(b[i] == '/'){
|
||||||
if(c == '/')
|
slash = i;
|
||||||
slash = m;
|
|
||||||
if(c==' ' || c=='\t')
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(slash < 0)
|
if(slash < 0)
|
||||||
goto Rescue;
|
goto Rescue;
|
||||||
|
|
|
@ -440,6 +440,23 @@ wincleartag(Window *w)
|
||||||
textsetselect(&w->tag, w->tag.q0, w->tag.q1);
|
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
|
void
|
||||||
winsettag1(Window *w)
|
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 */
|
/* 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)
|
if(w->tag.ncache!=0 || w->tag.file->mod)
|
||||||
wincommit(w, &w->tag); /* check file name; also guarantees we can modify tag contents */
|
wincommit(w, &w->tag); /* check file name; also guarantees we can modify tag contents */
|
||||||
old = runemalloc(w->tag.file->b.nc+1);
|
old = parsetag(w, &i);
|
||||||
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;
|
|
||||||
if(runeeq(old, i, w->body.file->name, w->body.file->nname) == FALSE){
|
if(runeeq(old, i, w->body.file->name, w->body.file->nname) == FALSE){
|
||||||
textdelete(&w->tag, 0, i, TRUE);
|
textdelete(&w->tag, 0, i, TRUE);
|
||||||
textinsert(&w->tag, 0, w->body.file->name, w->body.file->nname, 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 */
|
textcommit(f->text[i], FALSE); /* no-op for t */
|
||||||
if(t->what == Body)
|
if(t->what == Body)
|
||||||
return;
|
return;
|
||||||
r = runemalloc(w->tag.file->b.nc);
|
r = parsetag(w, &i);
|
||||||
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;
|
|
||||||
if(runeeq(r, i, w->body.file->name, w->body.file->nname) == FALSE){
|
if(runeeq(r, i, w->body.file->name, w->body.file->nname) == FALSE){
|
||||||
seq++;
|
seq++;
|
||||||
filemark(w->body.file);
|
filemark(w->body.file);
|
||||||
|
|
Loading…
Reference in a new issue