changes from plan 9

This commit is contained in:
rsc 2004-12-27 01:16:26 +00:00
parent 334cb1e91c
commit 6d7fdb243c
6 changed files with 31 additions and 17 deletions

View file

@ -113,6 +113,9 @@ threadmain(int argc, char *argv[])
exits("usage");
}ARGEND
fontnames[0] = estrdup(fontnames[0]);
fontnames[1] = estrdup(fontnames[1]);
quotefmtinstall();
cputype = getenv("cputype");
objtype = getenv("objtype");
@ -218,9 +221,7 @@ threadmain(int argc, char *argv[])
#define WPERCOL 8
disk = diskinit();
if(loadfile)
rowload(&row, loadfile, TRUE);
else{
if(!loadfile || !rowload(&row, loadfile, TRUE)){
rowinit(&row, screen->clipr);
if(ncol < 0){
if(argc == 0)
@ -859,7 +860,7 @@ rfget(int fix, int save, int setfont, char *name)
}
r = emalloc(sizeof(Reffont));
r->f = f;
fontcache = realloc(fontcache, (nfontcache+1)*sizeof(Reffont*));
fontcache = erealloc(fontcache, (nfontcache+1)*sizeof(Reffont*));
fontcache[nfontcache++] = r;
}
Found:
@ -868,8 +869,10 @@ rfget(int fix, int save, int setfont, char *name)
if(reffonts[fix])
rfclose(reffonts[fix]);
reffonts[fix] = r;
free(fontnames[fix]);
fontnames[fix] = name;
if(fontnames[fix] != name){
free(fontnames[fix]);
fontnames[fix] = estrdup(name);
}
}
if(setfont){
reffont.f = r->f;

View file

@ -329,7 +329,7 @@ Text* rowtype(Row*, Rune, Point);
void rowdragcol(Row*, Column*, int but);
int rowclean(Row*);
void rowdump(Row*, char*);
void rowload(Row*, char*, int);
int rowload(Row*, char*, int);
void rowloadfonts(char*);
struct Timer

View file

@ -445,6 +445,7 @@ collecttext(void)
goto Return;
}while(s->r[begline]!='.' || s->r[begline+1]!='\n');
s->r[s->n-2] = '\0';
s->n -= 2;
}else{
okdelim(delim = getch());
getrhs(s, delim, 'a');

View file

@ -476,14 +476,16 @@ rowloadfonts(char *file)
if(l == nil)
goto Return;
l[Blinelen(b)-1] = 0;
if(*l && strcmp(l, fontnames[i])!=0)
if(*l && strcmp(l, fontnames[i])!=0){
free(fontnames[i]);
fontnames[i] = estrdup(l);
}
}
Return:
Bterm(b);
}
void
int
rowload(Row *row, char *file, int initing)
{
int i, j, line, percent, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd;
@ -526,7 +528,7 @@ rowload(Row *row, char *file, int initing)
goto Rescue2;
l[Blinelen(b)-1] = 0;
if(*l && strcmp(l, fontnames[i])!=0)
rfget(i, TRUE, i==0 && initing, estrdup(l));
rfget(i, TRUE, i==0 && initing, l);
}
if(initing && row->ncol==0)
rowinit(row, screen->clipr);
@ -697,11 +699,11 @@ rowload(Row *row, char *file, int initing)
winsettag(w);
}else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
get(&w->body, nil, nil, FALSE, XXX, nil, 0);
free(r);
if(fontr){
fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
free(fontr);
}
free(r);
if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
q0 = q1 = 0;
textshow(&w->body, q0, q1, 1);
@ -709,14 +711,15 @@ rowload(Row *row, char *file, int initing)
}
Bterm(b);
Rescue1:
fbuffree(buf);
return;
return TRUE;
Rescue2:
warning(nil, "bad load file %s:%d\n", file, line);
Bterm(b);
goto Rescue1;
Rescue1:
fbuffree(buf);
return FALSE;
}
void

View file

@ -45,7 +45,7 @@ textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx)
frinit(&t->fr, r, f, b, t->fr.cols);
rr = t->fr.r;
rr.min.x -= Scrollwid; /* back fill to scroll bar */
rr.min.x -= Scrollwid+Scrollgap; /* back fill to scroll bar */
draw(t->fr.b, rr, t->fr.cols[BACK], nil, ZP);
/* use no wider than 3-space tabs in a directory */
maxt = maxtab;
@ -193,6 +193,10 @@ textload(Text *t, uint q0, char *file, int setqid)
if(t->ncache!=0 || t->file->b.nc || t->w==nil || t!=&t->w->body || (t->w->isdir && t->file->nname==0))
error("text.load");
if(t->w->isdir && t->file.nname==0){
warning(nil, "empty directory name");
return 0;
}
fd = open(file, OREAD);
if(fd < 0){
warning(nil, "can't open %s: %r\n", file);
@ -645,7 +649,10 @@ texttype(Text *t, Rune r)
switch(r){
case Kleft:
if(t->q0 > 0){
wincommit(t->w, t);
if(t->w)
wincommit(t->w, t);
else
textcommit(t->w, TRUE);
textshow(t, t->q0-1, t->q0-1, TRUE);
}
return;

View file

@ -83,7 +83,7 @@ errorwin1(Rune *dir, int ndir, Rune **incl, int nincl)
static Rune Lpluserrors[] = { '+', 'E', 'r', 'r', 'o', 'r', 's', 0 };
r = runemalloc(ndir+8);
if(n = ndir){ /* assign = */
if((n = ndir) != 0){
runemove(r, dir, ndir);
r[n++] = L'/';
}