add gitignore, clang-format, build script; merge src's patch for spaces in filenames

This commit is contained in:
Iris Lightshard 2021-06-12 23:54:54 -06:00
parent cf57dbe235
commit 5540d37849
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
38 changed files with 15300 additions and 15770 deletions

23
.clang-format Normal file
View file

@ -0,0 +1,23 @@
TabWidth: 2
IndentWidth: 2
ContinuationIndentWidth: 2
UseTab: Never
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
PenaltyReturnTypeOnItsOwnLine: 255
IndentCaseLabels: true
SpaceBeforeParens: ControlStatements
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false
BinPackArguments: false
PointerAlignment: Left
BreakBeforeBraces: Attach
SortIncludes: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignEscapedNewlines: Left

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
**/*.o **/*.o
**/o.* **/o.*
acme

295
acme.c
View file

@ -37,11 +37,9 @@ enum{
}; };
Rune snarfrune[NSnarf + 1]; Rune snarfrune[NSnarf + 1];
char *fontnames[2] = char* fontnames[2] = {
{
"/lib/font/bit/lucsans/typeunicode.7.font", "/lib/font/bit/lucsans/typeunicode.7.font",
"/lib/font/bit/lucm/unicode.9.font" "/lib/font/bit/lucm/unicode.9.font"};
};
Command* command; Command* command;
@ -50,16 +48,12 @@ void acmeerrorinit(void);
void readfile(Column*, char*); void readfile(Column*, char*);
static int shutdown(void*, char*); static int shutdown(void*, char*);
void void derror(Display* d, char* errorstr) {
derror(Display *d, char *errorstr)
{
USED(d); USED(d);
error(errorstr); error(errorstr);
} }
void void threadmain(int argc, char* argv[]) {
threadmain(int argc, char *argv[])
{
int i; int i;
char *p, *loadfile; char *p, *loadfile;
Column* c; Column* c;
@ -72,11 +66,10 @@ threadmain(int argc, char *argv[])
loadfile = nil; loadfile = nil;
ARGBEGIN { ARGBEGIN {
case 'D': case 'D': {
{extern int _threaddebuglevel; extern int _threaddebuglevel;
_threaddebuglevel = ~0; _threaddebuglevel = ~0;
} } break;
break;
case 'a': case 'a':
globalindent[AUTOINDENT] = TRUE; globalindent[AUTOINDENT] = TRUE;
break; break;
@ -124,9 +117,13 @@ threadmain(int argc, char *argv[])
break; break;
default: default:
Usage: Usage:
fprint(2, "usage: acme -aib -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); fprint(
2,
"usage: acme -aib -c ncol -f fontname -F fixedwidthfontname -l "
"loadfile -W winsize\n");
threadexitsall("usage"); threadexitsall("usage");
}ARGEND }
ARGEND
fontnames[0] = estrdup(fontnames[0]); fontnames[0] = estrdup(fontnames[0]);
fontnames[1] = estrdup(fontnames[1]); fontnames[1] = estrdup(fontnames[1]);
@ -197,7 +194,9 @@ threadmain(int argc, char *argv[])
cedit = chancreate(sizeof(int), 0); cedit = chancreate(sizeof(int), 0);
cexit = chancreate(sizeof(int), 0); cexit = chancreate(sizeof(int), 0);
cwarn = chancreate(sizeof(void*), 1); cwarn = chancreate(sizeof(void*), 1);
if(cwait==nil || ccommand==nil || ckill==nil || cxfidalloc==nil || cxfidfree==nil || cerr==nil || cexit==nil || cwarn==nil){ if (
cwait == nil || ccommand == nil || ckill == nil || cxfidalloc == nil ||
cxfidfree == nil || cerr == nil || cexit == nil || cwarn == nil) {
fprint(2, "acme: can't create initial channels: %r\n"); fprint(2, "acme: can't create initial channels: %r\n");
threadexitsall("channels"); threadexitsall("channels");
} }
@ -284,9 +283,7 @@ threadmain(int argc, char *argv[])
threadexitsall(nil); threadexitsall(nil);
} }
void void readfile(Column* c, char* s) {
readfile(Column *c, char *s)
{
Window* w; Window* w;
Rune rb[256]; Rune rb[256];
int nr; int nr;
@ -310,27 +307,14 @@ readfile(Column *c, char *s)
xfidlog(w, "new"); xfidlog(w, "new");
} }
char *ignotes[] = { char* ignotes[] =
"sys: write on closed pipe", {"sys: write on closed pipe", "sys: ttin", "sys: ttou", "sys: tstp", nil};
"sys: ttin",
"sys: ttou",
"sys: tstp",
nil
};
char *oknotes[] ={ char* oknotes[] = {"delete", "hangup", "kill", "exit", nil};
"delete",
"hangup",
"kill",
"exit",
nil
};
int dumping; int dumping;
static int static int shutdown(void* v, char* msg) {
shutdown(void *v, char *msg)
{
int i; int i;
USED(v); USED(v);
@ -340,7 +324,9 @@ shutdown(void *v, char *msg)
return 1; return 1;
killprocs(); killprocs();
if(!dumping && strcmp(msg, "kill")!=0 && strcmp(msg, "exit")!=0 && getpid()==mainpid){ if (
!dumping && strcmp(msg, "kill") != 0 && strcmp(msg, "exit") != 0 &&
getpid() == mainpid) {
dumping = TRUE; dumping = TRUE;
rowdump(&row, nil); rowdump(&row, nil);
} }
@ -367,9 +353,7 @@ shutdownthread(void *v)
} }
*/ */
void void killprocs(void) {
killprocs(void)
{
Command* c; Command* c;
fsysclose(); fsysclose();
@ -383,9 +367,7 @@ killprocs(void)
static int errorfd; static int errorfd;
int erroutfd; int erroutfd;
void void acmeerrorproc(void* v) {
acmeerrorproc(void *v)
{
char *buf, *s; char *buf, *s;
int n; int n;
@ -401,9 +383,7 @@ acmeerrorproc(void *v)
free(buf); free(buf);
} }
void void acmeerrorinit(void) {
acmeerrorinit(void)
{
int pfd[2]; int pfd[2];
if (pipe(pfd) < 0) if (pipe(pfd) < 0)
@ -450,9 +430,7 @@ plumbproc(void *v)
} }
*/ */
void void keyboardthread(void* v) {
keyboardthread(void *v)
{
Rune r; Rune r;
Timer* timer; Timer* timer;
Text* t; Text* t;
@ -489,7 +467,10 @@ keyboardthread(void *v)
casekeyboard: casekeyboard:
typetext = rowtype(&row, r, mouse->xy); typetext = rowtype(&row, r, mouse->xy);
t = typetext; t = typetext;
if(t!=nil && t->col!=nil && !(r==Kdown || r==Kleft || r==Kright)) /* scrolling doesn't change activecol */ if (
t != nil && t->col != nil &&
!(r == Kdown || r == Kleft ||
r == Kright)) /* scrolling doesn't change activecol */
activecol = t->col; activecol = t->col;
if (t != nil && t->w != nil) if (t != nil && t->w != nil)
t->w->body.file->curtext = &t->w->body; t->w->body.file->curtext = &t->w->body;
@ -512,9 +493,7 @@ keyboardthread(void *v)
} }
} }
void void mousethread(void* v) {
mousethread(void *v)
{
Text *t, *argt; Text *t, *argt;
int but; int but;
uint q0, q1; uint q0, q1;
@ -552,7 +531,12 @@ mousethread(void *v)
case MResize: case MResize:
if (getwindow(display, Refnone) < 0) if (getwindow(display, Refnone) < 0)
error("attach to window"); error("attach to window");
draw(screen, screen->r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
screen->r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
iconinit(); iconinit();
scrlresize(); scrlresize();
rowresize(&row, screen->clipr); rowresize(&row, screen->clipr);
@ -579,8 +563,10 @@ mousethread(void *v)
qlock(&row.lk); qlock(&row.lk);
t = rowwhich(&row, m.xy); t = rowwhich(&row, m.xy);
if((t!=mousetext && t!=nil && t->w!=nil) && if (
(mousetext==nil || mousetext->w==nil || t->w->id!=mousetext->w->id)) { (t != mousetext && t != nil && t->w != nil) &&
(mousetext == nil || mousetext->w == nil ||
t->w->id != mousetext->w->id)) {
xfidlog(t->w, "focus"); xfidlog(t->w, "focus");
} }
@ -682,20 +668,18 @@ mousethread(void *v)
} }
/* /*
* There is a race between process exiting and our finding out it was ever created. * There is a race between process exiting and our finding out it was ever
* This structure keeps a list of processes that have exited we haven't heard of. * created. This structure keeps a list of processes that have exited we haven't
* heard of.
*/ */
typedef struct Pid Pid; typedef struct Pid Pid;
struct Pid struct Pid {
{
int pid; int pid;
char msg[ERRMAX]; char msg[ERRMAX];
Pid* next; Pid* next;
}; };
void void waitthread(void* v) {
waitthread(void *v)
{
Waitmsg* w; Waitmsg* w;
Command *c, *lc; Command *c, *lc;
uint pid; uint pid;
@ -825,9 +809,7 @@ waitthread(void *v)
} }
} }
void void xfidallocthread(void* v) {
xfidallocthread(void *v)
{
Xfid *xfree, *x; Xfid *xfree, *x;
enum { Alloc, Free, N }; enum { Alloc, Free, N };
static Alt alts[N + 1]; static Alt alts[N + 1];
@ -866,10 +848,9 @@ xfidallocthread(void *v)
} }
} }
/* this thread, in the main proc, allows fsysproc to get a window made without doing graphics */ /* this thread, in the main proc, allows fsysproc to get a window made without
void * doing graphics */
newwindowthread(void *v) void newwindowthread(void* v) {
{
Window* w; Window* w;
USED(v); USED(v);
@ -885,9 +866,7 @@ newwindowthread(void *v)
} }
} }
Reffont* Reffont* rfget(int fix, int save, int setfont, char* name) {
rfget(int fix, int save, int setfont, char *name)
{
Reffont* r; Reffont* r;
Font* f; Font* f;
int i; int i;
@ -937,9 +916,7 @@ rfget(int fix, int save, int setfont, char *name)
return r; return r;
} }
void void rfclose(Reffont* r) {
rfclose(Reffont *r)
{
int i; int i;
if (decref(&r->ref) == 0) { if (decref(&r->ref) == 0) {
@ -950,7 +927,10 @@ rfclose(Reffont *r)
warning(nil, "internal error: can't find font in cache\n"); warning(nil, "internal error: can't find font in cache\n");
else { else {
nfontcache--; nfontcache--;
memmove(fontcache+i, fontcache+i+1, (nfontcache-i)*sizeof(Reffont*)); memmove(
fontcache + i,
fontcache + i + 1,
(nfontcache - i) * sizeof(Reffont*));
} }
freefont(r->f); freefont(r->f);
free(r); free(r);
@ -959,103 +939,61 @@ rfclose(Reffont *r)
Cursor boxcursor = { Cursor boxcursor = {
{-7, -7}, {-7, -7},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8,
0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F,
0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x70, 0x0E, 0x70,
{0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00}};
0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00}
};
Cursor2 boxcursor2 = { Cursor2 boxcursor2 = {
{-15, -15}, {-15, -15},
{0xFF, 0xFF, 0xFF, 0xFF, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0,
0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
0xFF, 0xC0, 0x03, 0xFF, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F,
0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF,
0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00,
0xFF, 0xC0, 0x03, 0xFF, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC,
0xFF, 0xC0, 0x03, 0xFF, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F,
0xFF, 0xC0, 0x03, 0xFF, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00,
0xFF, 0xC0, 0x03, 0xFF, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00,
0xFF, 0xC0, 0x03, 0xFF, 0xFC, 0x3F, 0x00, 0x00, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC,
0xFF, 0xC0, 0x03, 0xFF, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F,
0xFF, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
0xFF, 0xC0, 0x03, 0xFF,
0xFF, 0xC0, 0x03, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF},
{0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0x00, 0x00, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xFC,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00}
};
void void iconinit(void) {
iconinit(void)
{
Rectangle r; Rectangle r;
Image* tmp; Image* tmp;
if (tagcols[BACK] == nil) { if (tagcols[BACK] == nil) {
/* Black */ /* Black */
tagcols[BACK] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlack); tagcols[BACK] =
tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x1F9B92FF); allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlack);
tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x797979FF); tagcols[HIGH] =
tagcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x797979FF); allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x1F9B92FF);
tagcols[BORD] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x797979FF);
tagcols[TEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x797979FF);
tagcols[HTEXT] = display->black; tagcols[HTEXT] = display->black;
/* Blue */ /* Blue */
textcols[BACK] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x000F19FF); textcols[BACK] =
textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x1F9B92FF); allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x000F19FF);
textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x93A1A1FF); textcols[HIGH] =
textcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x93A1A1FF); allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x1F9B92FF);
textcols[BORD] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x93A1A1FF);
textcols[TEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x93A1A1FF);
textcols[HTEXT] = display->black; textcols[HTEXT] = display->black;
} }
@ -1101,9 +1039,7 @@ iconinit(void)
#define MAXSNARF 100 * 1024 #define MAXSNARF 100 * 1024
void void acmeputsnarf(void) {
acmeputsnarf(void)
{
int i, n; int i, n;
Fmt f; Fmt f;
char* s; char* s;
@ -1128,9 +1064,7 @@ acmeputsnarf(void)
free(s); free(s);
} }
void void acmegetsnarf(void) {
acmegetsnarf(void)
{
char* s; char* s;
int nb, nr, nulls, len; int nb, nr, nulls, len;
Rune* r; Rune* r;
@ -1150,9 +1084,7 @@ acmegetsnarf(void)
free(s); free(s);
} }
int int ismtpt(char* file) {
ismtpt(char *file)
{
int n; int n;
if (mtpt == nil) if (mtpt == nil)
@ -1160,16 +1092,21 @@ ismtpt(char *file)
/* This is not foolproof, but it will stop a lot of them. */ /* This is not foolproof, but it will stop a lot of them. */
n = strlen(mtpt); n = strlen(mtpt);
return strncmp(file, mtpt, n) == 0 && ((n > 0 && mtpt[n-1] == '/') || file[n] == '/' || file[n] == 0); return strncmp(file, mtpt, n) == 0 &&
((n > 0 && mtpt[n - 1] == '/') || file[n] == '/' || file[n] == 0);
} }
int int timefmt(Fmt* f) {
timefmt(Fmt *f)
{
Tm* tm; Tm* tm;
tm = localtime(va_arg(f->args, ulong)); tm = localtime(va_arg(f->args, ulong));
return fmtprint(f, "%04d/%02d/%02d %02d:%02d:%02d", return fmtprint(
tm->year+1900, tm->mon+1, tm->mday, tm->hour, tm->min, tm->sec); f,
"%04d/%02d/%02d %02d:%02d:%02d",
tm->year + 1900,
tm->mon + 1,
tm->mday,
tm->hour,
tm->min,
tm->sec);
} }

62
addr.c
View file

@ -12,34 +12,22 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
enum enum { None = 0, Fore = '+', Back = '-' };
{
None = 0,
Fore = '+',
Back = '-'
};
enum enum { Char, Line };
{
Char,
Line
};
int int isaddrc(int r) {
isaddrc(int r)
{
if (r && utfrune("0123456789+-/$.#,;?", r) != nil) if (r && utfrune("0123456789+-/$.#,;?", r) != nil)
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
/* /*
* quite hard: could be almost anything but white space, but we are a little conservative, * quite hard: could be almost anything but white space, but we are a little
* aiming for regular expressions of alphanumerics and no white space * conservative, aiming for regular expressions of alphanumerics and no white
* space
*/ */
int int isregexc(int r) {
isregexc(int r)
{
if (r == 0) if (r == 0)
return FALSE; return FALSE;
if (isalnum(r)) if (isalnum(r))
@ -54,9 +42,7 @@ isregexc(int r)
// and then nr chars, being careful not to walk past // and then nr chars, being careful not to walk past
// the end of the current line. // the end of the current line.
// It returns the final position. // It returns the final position.
long long nlcounttopos(Text* t, long q0, long nl, long nr) {
nlcounttopos(Text *t, long q0, long nl, long nr)
{
while (nl > 0 && q0 < t->file->b.nc) { while (nl > 0 && q0 < t->file->b.nc) {
if (textreadc(t, q0++) == '\n') if (textreadc(t, q0++) == '\n')
nl--; nl--;
@ -70,9 +56,8 @@ nlcounttopos(Text *t, long q0, long nl, long nr)
return q0; return q0;
} }
Range Range number(
number(uint showerr, Text *t, Range r, int line, int dir, int size, int *evalp) uint showerr, Text* t, Range r, int line, int dir, int size, int* evalp) {
{
uint q0, q1; uint q0, q1;
if (size == Char) { if (size == Char) {
@ -138,10 +123,8 @@ number(uint showerr, Text *t, Range r, int line, int dir, int size, int *evalp)
return r; return r;
} }
Range regexp(
Range uint showerr, Text* t, Range lim, Range r, Rune* pat, int dir, int* foundp) {
regexp(uint showerr, Text *t, Range lim, Range r, Rune *pat, int dir, int *foundp)
{
int found; int found;
Rangeset sel; Rangeset sel;
int q; int q;
@ -171,9 +154,9 @@ regexp(uint showerr, Text *t, Range lim, Range r, Rune *pat, int dir, int *found
return sel.r[0]; return sel.r[0];
} }
Range Range address(
address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, int (*getc)(void*, uint), int *evalp, uint *qp) uint showerr, Text* t, Range lim, Range ar, void* a, uint q0, uint q1,
{ int (*getc)(void*, uint), int* evalp, uint* qp) {
int dir, size, npat; int dir, size, npat;
int prevc, c, nc, n; int prevc, c, nc, n;
uint q; uint q;
@ -210,7 +193,8 @@ address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, i
case '-': case '-':
if (*evalp && (prevc == '+' || prevc == '-')) if (*evalp && (prevc == '+' || prevc == '-'))
if ((nc = (*getc)(a, q)) != '#' && nc != '/' && nc != '?') if ((nc = (*getc)(a, q)) != '#' && nc != '/' && nc != '?')
r = number(showerr, t, r, 1, prevc, Line, evalp); /* do previous one */ r = number(showerr, t, r, 1, prevc, Line, evalp); /* do previous one
*/
dir = c; dir = c;
break; break;
case '.': case '.':
@ -236,8 +220,16 @@ address(uint showerr, Text *t, Range lim, Range ar, void *a, uint q0, uint q1, i
} }
size = Char; size = Char;
/* fall through */ /* fall through */
case '0': case '1': case '2': case '3': case '4': case '0':
case '5': case '6': case '7': case '8': case '9': case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = c - '0'; n = c - '0';
while (q < q1) { while (q < q1) {
nc = (*getc)(a, q++); nc = (*getc)(a, q++);

62
buff.c
View file

@ -12,25 +12,18 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
enum enum {
{
Slop = 100 /* room to grow with reallocation */ Slop = 100 /* room to grow with reallocation */
}; };
static static void sizecache(Buffer* b, uint n) {
void
sizecache(Buffer *b, uint n)
{
if (n <= b->cmax) if (n <= b->cmax)
return; return;
b->cmax = n + Slop; b->cmax = n + Slop;
b->c = runerealloc(b->c, b->cmax); b->c = runerealloc(b->c, b->cmax);
} }
static static void addblock(Buffer* b, uint i, uint n) {
void
addblock(Buffer *b, uint i, uint n)
{
if (i > b->nbl) if (i > b->nbl)
error("internal error: addblock"); error("internal error: addblock");
@ -41,10 +34,7 @@ addblock(Buffer *b, uint i, uint n)
b->nbl++; b->nbl++;
} }
static static void delblock(Buffer* b, uint i) {
void
delblock(Buffer *b, uint i)
{
if (i >= b->nbl) if (i >= b->nbl)
error("internal error: delblock"); error("internal error: delblock");
@ -60,10 +50,7 @@ delblock(Buffer *b, uint i)
* If at very end, q0 will fall on end of cache block. * If at very end, q0 will fall on end of cache block.
*/ */
static static void flush(Buffer* b) {
void
flush(Buffer *b)
{
if (b->cdirty || b->cnc == 0) { if (b->cdirty || b->cnc == 0) {
if (b->cnc == 0) if (b->cnc == 0)
delblock(b, b->cbi); delblock(b, b->cbi);
@ -73,10 +60,7 @@ flush(Buffer *b)
} }
} }
static static void setcache(Buffer* b, uint q0) {
void
setcache(Buffer *b, uint q0)
{
Block **blp, *bl; Block **blp, *bl;
uint i, q; uint i, q;
@ -119,9 +103,7 @@ setcache(Buffer *b, uint q0)
diskread(disk, bl, b->c, b->cnc); diskread(disk, bl, b->c, b->cnc);
} }
void void bufinsert(Buffer* b, uint q0, Rune* s, uint n) {
bufinsert(Buffer *b, uint q0, Rune *s, uint n)
{
uint i, m, t, off; uint i, m, t, off;
if (q0 > b->nc) if (q0 > b->nc)
@ -200,9 +182,7 @@ bufinsert(Buffer *b, uint q0, Rune *s, uint n)
} }
} }
void void bufdelete(Buffer* b, uint q0, uint q1) {
bufdelete(Buffer *b, uint q0, uint q1)
{
uint m, n, off; uint m, n, off;
if (!(q0 <= q1 && q0 <= b->nc && q1 <= b->nc)) if (!(q0 <= q1 && q0 <= b->nc && q1 <= b->nc))
@ -224,16 +204,14 @@ bufdelete(Buffer *b, uint q0, uint q1)
} }
} }
static int static int bufloader(void* v, uint q0, Rune* r, int nr) {
bufloader(void *v, uint q0, Rune *r, int nr)
{
bufinsert(v, q0, r, nr); bufinsert(v, q0, r, nr);
return nr; return nr;
} }
uint uint loadfile(
loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *arg, DigestState *h) int fd, uint q0, int* nulls, int (*f)(void*, uint, Rune*, int), void* arg,
{ DigestState* h) {
char* p; char* p;
Rune* r; Rune* r;
int l, m, n, nb, nr; int l, m, n, nb, nr;
@ -271,17 +249,13 @@ loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *ar
return q1 - q0; return q1 - q0;
} }
uint uint bufload(Buffer* b, uint q0, int fd, int* nulls, DigestState* h) {
bufload(Buffer *b, uint q0, int fd, int *nulls, DigestState *h)
{
if (q0 > b->nc) if (q0 > b->nc)
error("internal error: bufload"); error("internal error: bufload");
return loadfile(fd, q0, nulls, bufloader, b, h); return loadfile(fd, q0, nulls, bufloader, b, h);
} }
void void bufread(Buffer* b, uint q0, Rune* s, uint n) {
bufread(Buffer *b, uint q0, Rune *s, uint n)
{
uint m; uint m;
if (!(q0 <= b->nc && q0 + n <= b->nc)) if (!(q0 <= b->nc && q0 + n <= b->nc))
@ -297,9 +271,7 @@ bufread(Buffer *b, uint q0, Rune *s, uint n)
} }
} }
void void bufreset(Buffer* b) {
bufreset(Buffer *b)
{
int i; int i;
b->nc = 0; b->nc = 0;
@ -312,9 +284,7 @@ bufreset(Buffer *b)
delblock(b, i); delblock(b, i);
} }
void void bufclose(Buffer* b) {
bufclose(Buffer *b)
{
bufreset(b); bufreset(b);
free(b->c); free(b->c);
b->c = nil; b->c = nil;

8
build.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
clang-format -i ./*.c
clang-format -i ./mail/*.c
mk
mv o.acme acme

153
cols.c
View file

@ -12,24 +12,21 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
static Rune Lheader[] = { static Rune Lheader[] = {'N', 'e', 'w', ' ', 'C', 'u', 't', ' ', 'P', 'a',
'N', 'e', 'w', ' ', 's', 't', 'e', ' ', 'S', 'n', 'a', 'r', 'f', ' ',
'C', 'u', 't', ' ', 'S', 'o', 'r', 't', ' ', 'Z', 'e', 'r', 'o', 'x',
'P', 'a', 's', 't', 'e', ' ', ' ', 'D', 'e', 'l', 'c', 'o', 'l', ' ', 0};
'S', 'n', 'a', 'r', 'f', ' ',
'S', 'o', 'r', 't', ' ',
'Z', 'e', 'r', 'o', 'x', ' ',
'D', 'e', 'l', 'c', 'o', 'l', ' ',
0
};
void void colinit(Column* c, Rectangle r) {
colinit(Column *c, Rectangle r)
{
Rectangle r1; Rectangle r1;
Text* t; Text* t;
draw(screen, r, allocimage(display,Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
c->r = r; c->r = r;
c->w = nil; c->w = nil;
c->nw = 0; c->nw = 0;
@ -42,16 +39,19 @@ colinit(Column *c, Rectangle r)
t->what = Columntag; t->what = Columntag;
r1.min.y = r1.max.y; r1.min.y = r1.max.y;
r1.max.y += Border; r1.max.y += Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
textinsert(t, 0, Lheader, 38, TRUE); textinsert(t, 0, Lheader, 38, TRUE);
textsetselect(t, t->file->b.nc, t->file->b.nc); textsetselect(t, t->file->b.nc, t->file->b.nc);
draw(screen, t->scrollr, colbutton, nil, colbutton->r.min); draw(screen, t->scrollr, colbutton, nil, colbutton->r.min);
c->safe = TRUE; c->safe = TRUE;
} }
Window* Window* coladd(Column* c, Window* w, Window* clone, int y) {
coladd(Column *c, Window *w, Window *clone, int y)
{
Rectangle r, r1; Rectangle r, r1;
Window* v; Window* v;
int i, j, minht, ymax, buggered; int i, j, minht, ymax, buggered;
@ -113,11 +113,20 @@ coladd(Column *c, Window *w, Window *clone, int y)
r.max.y = ymax; r.max.y = ymax;
draw(screen, r, textcols[BACK], nil, ZP); draw(screen, r, textcols[BACK], nil, ZP);
r1 = r; r1 = r;
y = min(y, ymax-(v->tag.fr.font->height*v->taglines+v->body.fr.font->height+Border+1)); y = min(
r1.max.y = min(y, v->body.fr.r.min.y+v->body.fr.nlines*v->body.fr.font->height); y,
ymax - (v->tag.fr.font->height * v->taglines + v->body.fr.font->height +
Border + 1));
r1.max.y =
min(y, v->body.fr.r.min.y + v->body.fr.nlines * v->body.fr.font->height);
r1.min.y = winresize(v, r1, FALSE, FALSE); r1.min.y = winresize(v, r1, FALSE, FALSE);
r1.max.y = r1.min.y + Border; r1.max.y = r1.min.y + Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
/* /*
* leave r with w's coordinates * leave r with w's coordinates
@ -154,9 +163,7 @@ coladd(Column *c, Window *w, Window *clone, int y)
return w; return w;
} }
void void colclose(Column* c, Window* w, int dofree) {
colclose(Column *c, Window *w, int dofree)
{
Rectangle r; Rectangle r;
int i, didmouse, up; int i, didmouse, up;
@ -181,7 +188,12 @@ colclose(Column *c, Window *w, int dofree)
memmove(c->w + i, c->w + i + 1, (c->nw - i) * sizeof(Window*)); memmove(c->w + i, c->w + i + 1, (c->nw - i) * sizeof(Window*));
c->w = realloc(c->w, c->nw * sizeof(Window*)); c->w = realloc(c->w, c->nw * sizeof(Window*));
if (c->nw == 0) { if (c->nw == 0) {
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
return; return;
} }
up = 0; up = 0;
@ -204,9 +216,7 @@ colclose(Column *c, Window *w, int dofree)
} }
} }
void void colcloseall(Column* c) {
colcloseall(Column *c)
{
int i; int i;
Window* w; Window* w;
@ -223,15 +233,11 @@ colcloseall(Column *c)
clearmouse(); clearmouse();
} }
void void colmousebut(Column* c) {
colmousebut(Column *c)
{
moveto(mousectl, divpt(addpt(c->tag.scrollr.min, c->tag.scrollr.max), 2)); moveto(mousectl, divpt(addpt(c->tag.scrollr.min, c->tag.scrollr.max), 2));
} }
void void colresize(Column* c, Rectangle r) {
colresize(Column *c, Rectangle r)
{
int i; int i;
Rectangle r1, r2; Rectangle r1, r2;
Window* w; Window* w;
@ -243,7 +249,12 @@ colresize(Column *c, Rectangle r)
draw(screen, c->tag.scrollr, colbutton, nil, colbutton->r.min); draw(screen, c->tag.scrollr, colbutton, nil, colbutton->r.min);
r1.min.y = r1.max.y; r1.min.y = r1.max.y;
r1.max.y += Border; r1.max.y += Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r1.max.y = r.max.y; r1.max.y = r.max.y;
for (i = 0; i < c->nw; i++) { for (i = 0; i < c->nw; i++) {
w = c->w[i]; w = c->w[i];
@ -259,17 +270,19 @@ colresize(Column *c, Rectangle r)
r1.max.y = max(r1.max.y, r1.min.y + Border + font->height); r1.max.y = max(r1.max.y, r1.min.y + Border + font->height);
r2 = r1; r2 = r1;
r2.max.y = r2.min.y + Border; r2.max.y = r2.min.y + Border;
draw(screen, r2, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r2,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r1.min.y = r2.max.y; r1.min.y = r2.max.y;
r1.min.y = winresize(w, r1, FALSE, i == c->nw - 1); r1.min.y = winresize(w, r1, FALSE, i == c->nw - 1);
} }
c->r = r; c->r = r;
} }
static static int colcmp(const void* a, const void* b) {
int
colcmp(const void *a, const void *b)
{
Rune *r1, *r2; Rune *r1, *r2;
int i, nr1, nr2; int i, nr1, nr2;
@ -286,9 +299,7 @@ colcmp(const void *a, const void *b)
return nr1 - nr2; return nr1 - nr2;
} }
void void colsort(Column* c) {
colsort(Column *c)
{
int i, y; int i, y;
Rectangle r, r1, *rp; Rectangle r, r1, *rp;
Window **wp, *w; Window **wp, *w;
@ -315,7 +326,12 @@ colsort(Column *c)
r.max.y = r.min.y + Dy(w->r) + Border; r.max.y = r.min.y + Dy(w->r) + Border;
r1 = r; r1 = r;
r1.max.y = r1.min.y + Border; r1.max.y = r1.min.y + Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.min.y = r1.max.y; r.min.y = r1.max.y;
y = winresize(w, r, FALSE, i == c->nw - 1); y = winresize(w, r, FALSE, i == c->nw - 1);
} }
@ -324,9 +340,7 @@ colsort(Column *c)
c->w = wp; c->w = wp;
} }
void void colgrow(Column* c, Window* w, int but) {
colgrow(Column *c, Window *w, int but)
{
Rectangle r, cr; Rectangle r, cr;
int i, j, k, l, y1, y2, *nl, *ny, tot, nnl, onl, dnl, h; int i, j, k, l, y1, y2, *nl, *ny, tot, nnl, onl, dnl, h;
Window* v; Window* v;
@ -413,7 +427,12 @@ colgrow(Column *c, Window *w, int but)
r.max.y += 1 + nl[j] * v->body.fr.font->height; r.max.y += 1 + nl[j] * v->body.fr.font->height;
r.min.y = winresize(v, r, c->safe, FALSE); r.min.y = winresize(v, r, c->safe, FALSE);
r.max.y += Border; r.max.y += Border;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
y1 = r.max.y; y1 = r.max.y;
} }
/* scan to see new size of everyone below */ /* scan to see new size of everyone below */
@ -440,7 +459,12 @@ colgrow(Column *c, Window *w, int but)
if (i < c->nw - 1) { if (i < c->nw - 1) {
r.min.y = r.max.y; r.min.y = r.max.y;
r.max.y += Border; r.max.y += Border;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
for (j = i + 1; j < c->nw; j++) for (j = i + 1; j < c->nw; j++)
ny[j] -= (y2 - r.max.y); ny[j] -= (y2 - r.max.y);
} }
@ -457,7 +481,12 @@ colgrow(Column *c, Window *w, int but)
if (j < c->nw - 1) { /* no border on last window */ if (j < c->nw - 1) { /* no border on last window */
r.min.y = y1; r.min.y = y1;
r.max.y += Border; r.max.y += Border;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
y1 = r.max.y; y1 = r.max.y;
} }
} }
@ -467,9 +496,7 @@ colgrow(Column *c, Window *w, int but)
winmousebut(w); winmousebut(w);
} }
void void coldragwin(Column* c, Window* w, int but) {
coldragwin(Column *c, Window *w, int but)
{
Rectangle r; Rectangle r;
int i, b; int i, b;
Point p, op; Point p, op;
@ -515,8 +542,9 @@ coldragwin(Column *c, Window *w, int but)
} }
if (i == 0 && c->nw == 1) if (i == 0 && c->nw == 1)
return; /* can't do it */ return; /* can't do it */
if((i>0 && p.y<c->w[i-1]->r.min.y) || (i<c->nw-1 && p.y>w->r.max.y) if (
|| (i==0 && p.y>w->r.max.y)){ (i > 0 && p.y < c->w[i - 1]->r.min.y) ||
(i < c->nw - 1 && p.y > w->r.max.y) || (i == 0 && p.y > w->r.max.y)) {
/* shuffle */ /* shuffle */
colclose(c, w, FALSE); colclose(c, w, FALSE);
coladd(c, w, nil, p.y); coladd(c, w, nil, p.y);
@ -539,7 +567,12 @@ coldragwin(Column *c, Window *w, int but)
} }
r.min.y = winresize(v, r, c->safe, FALSE); r.min.y = winresize(v, r, c->safe, FALSE);
r.max.y = r.min.y + Border; r.max.y = r.min.y + Border;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.min.y = r.max.y; r.min.y = r.max.y;
if (i == c->nw - 1) if (i == c->nw - 1)
r.max.y = c->r.max.y; r.max.y = c->r.max.y;
@ -550,9 +583,7 @@ coldragwin(Column *c, Window *w, int but)
winmousebut(w); winmousebut(w);
} }
Text* Text* colwhich(Column* c, Point p) {
colwhich(Column *c, Point p)
{
int i; int i;
Window* w; Window* w;
@ -574,9 +605,7 @@ colwhich(Column *c, Point p)
return nil; return nil;
} }
int int colclean(Column* c) {
colclean(Column *c)
{
int i, clean; int i, clean;
clean = TRUE; clean = TRUE;

29
disk.c
View file

@ -14,9 +14,7 @@
static Block* blist; static Block* blist;
int int tempfile(void) {
tempfile(void)
{
char buf[128]; char buf[128];
int i, fd; int i, fd;
@ -32,9 +30,7 @@ tempfile(void)
return -1; return -1;
} }
Disk* Disk* diskinit() {
diskinit()
{
Disk* d; Disk* d;
d = emalloc(sizeof(Disk)); d = emalloc(sizeof(Disk));
@ -46,10 +42,7 @@ diskinit()
return d; return d;
} }
static static uint ntosize(uint n, uint* ip) {
uint
ntosize(uint n, uint *ip)
{
uint size; uint size;
if (n > Maxblock) if (n > Maxblock)
@ -63,9 +56,7 @@ ntosize(uint n, uint *ip)
return size * sizeof(Rune); return size * sizeof(Rune);
} }
Block* Block* disknewblock(Disk* d, uint n) {
disknewblock(Disk *d, uint n)
{
uint i, j, size; uint i, j, size;
Block* b; Block* b;
@ -92,9 +83,7 @@ disknewblock(Disk *d, uint n)
return b; return b;
} }
void void diskrelease(Disk* d, Block* b) {
diskrelease(Disk *d, Block *b)
{
uint i; uint i;
ntosize(b->u.n, &i); ntosize(b->u.n, &i);
@ -102,9 +91,7 @@ diskrelease(Disk *d, Block *b)
d->free[i] = b; d->free[i] = b;
} }
void void diskwrite(Disk* d, Block** bp, Rune* r, uint n) {
diskwrite(Disk *d, Block **bp, Rune *r, uint n)
{
int size, nsize; int size, nsize;
Block* b; Block* b;
@ -121,9 +108,7 @@ diskwrite(Disk *d, Block **bp, Rune *r, uint n)
b->u.n = n; b->u.n = n;
} }
void void diskread(Disk* d, Block* b, Rune* r, uint n) {
diskread(Disk *d, Block *b, Rune *r, uint n)
{
if (n > b->u.n) if (n > b->u.n)
error("internal error: diskread"); error("internal error: diskread");

268
ecmd.c
View file

@ -36,32 +36,24 @@ File *tofile(String*);
Rune* cmdname(File* f, String* s, int); Rune* cmdname(File* f, String* s, int);
void runpipe(Text*, int, Rune*, int, int); void runpipe(Text*, int, Rune*, int, int);
void void clearcollection(void) {
clearcollection(void)
{
free(collection); free(collection);
collection = nil; collection = nil;
ncollection = 0; ncollection = 0;
} }
void void resetxec(void) {
resetxec(void)
{
Glooping = nest = 0; Glooping = nest = 0;
clearcollection(); clearcollection();
} }
void void mkaddr(Address* a, File* f) {
mkaddr(Address *a, File *f)
{
a->r.q0 = f->curtext->q0; a->r.q0 = f->curtext->q0;
a->r.q1 = f->curtext->q1; a->r.q1 = f->curtext->q1;
a->f = f; a->f = f;
} }
int int cmdexec(Text* t, Cmd* cp) {
cmdexec(Text *t, Cmd *cp)
{
int i; int i;
Addr* ap; Addr* ap;
File* f; File* f;
@ -72,9 +64,9 @@ cmdexec(Text *t, Cmd *cp)
w = nil; w = nil;
else else
w = t->w; w = t->w;
if(w==nil && (cp->addr==0 || cp->addr->type!='"') && if (
!utfrune("bBnqUXY!", cp->cmdc) && w == nil && (cp->addr == 0 || cp->addr->type != '"') &&
!(cp->cmdc=='D' && cp->u.text)) !utfrune("bBnqUXY!", cp->cmdc) && !(cp->cmdc == 'D' && cp->u.text))
editerror("no current window"); editerror("no current window");
i = cmdlookup(cp->cmdc); /* will be -1 for '{' */ i = cmdlookup(cp->cmdc); /* will be -1 for '{' */
f = nil; f = nil;
@ -128,9 +120,7 @@ cmdexec(Text *t, Cmd *cp)
return 1; return 1;
} }
char* char* edittext(Window* w, int q, Rune* r, int nr) {
edittext(Window *w, int q, Rune *r, int nr)
{
File* f; File* f;
f = w->body.file; f = w->body.file;
@ -152,9 +142,7 @@ edittext(Window *w, int q, Rune *r, int nr)
} }
/* string is known to be NUL-terminated */ /* string is known to be NUL-terminated */
Rune* Rune* filelist(Text* t, Rune* r, int nr) {
filelist(Text *t, Rune *r, int nr)
{
if (nr == 0) if (nr == 0)
return nil; return nil;
r = skipbl(r, nr, &nr); r = skipbl(r, nr, &nr);
@ -166,15 +154,9 @@ filelist(Text *t, Rune *r, int nr)
return collection; return collection;
} }
int int a_cmd(Text* t, Cmd* cp) { return append(t->file, cp, addr.r.q1); }
a_cmd(Text *t, Cmd *cp)
{
return append(t->file, cp, addr.r.q1);
}
int int b_cmd(Text* t, Cmd* cp) {
b_cmd(Text *t, Cmd *cp)
{
File* f; File* f;
USED(t); USED(t);
@ -185,9 +167,7 @@ b_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int B_cmd(Text* t, Cmd* cp) {
B_cmd(Text *t, Cmd *cp)
{
Rune *list, *r, *s; Rune *list, *r, *s;
int nr; int nr;
@ -199,7 +179,8 @@ B_cmd(Text *t, Cmd *cp)
r = skipbl(r, nr, &nr); r = skipbl(r, nr, &nr);
if (nr == 0) if (nr == 0)
new (t, t, nil, 0, 0, r, 0); new (t, t, nil, 0, 0, r, 0);
else while(nr > 0){ else
while (nr > 0) {
s = findbl(r, nr, &nr); s = findbl(r, nr, &nr);
*s = '\0'; *s = '\0';
new (t, t, nil, 0, 0, r, runestrlen(r)); new (t, t, nil, 0, 0, r, runestrlen(r));
@ -210,18 +191,14 @@ B_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int c_cmd(Text* t, Cmd* cp) {
c_cmd(Text *t, Cmd *cp)
{
elogreplace(t->file, addr.r.q0, addr.r.q1, cp->u.text->r, cp->u.text->n); elogreplace(t->file, addr.r.q0, addr.r.q1, cp->u.text->r, cp->u.text->n);
t->q0 = addr.r.q0; t->q0 = addr.r.q0;
t->q1 = addr.r.q1; t->q1 = addr.r.q1;
return TRUE; return TRUE;
} }
int int d_cmd(Text* t, Cmd* cp) {
d_cmd(Text *t, Cmd *cp)
{
USED(cp); USED(cp);
if (addr.r.q1 > addr.r.q0) if (addr.r.q1 > addr.r.q0)
elogdelete(t->file, addr.r.q0, addr.r.q1); elogdelete(t->file, addr.r.q0, addr.r.q1);
@ -230,16 +207,12 @@ d_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
void void D1(Text* t) {
D1(Text *t)
{
if (t->w->body.file->ntext > 1 || winclean(t->w, FALSE)) if (t->w->body.file->ntext > 1 || winclean(t->w, FALSE))
colclose(t->col, t->w, TRUE); colclose(t->col, t->w, TRUE);
} }
int int D_cmd(Text* t, Cmd* cp) {
D_cmd(Text *t, Cmd *cp)
{
Rune *list, *r, *s, *n; Rune *list, *r, *s, *n;
int nr, nn; int nr, nn;
Window* w; Window* w;
@ -258,7 +231,8 @@ D_cmd(Text *t, Cmd *cp)
do { do {
s = findbl(r, nr, &nr); s = findbl(r, nr, &nr);
*s = '\0'; *s = '\0';
/* first time through, could be empty string, meaning delete file empty name */ /* first time through, could be empty string, meaning delete file empty name
*/
nn = runestrlen(r); nn = runestrlen(r);
if (r[0] == '/' || nn == 0 || dir.nr == 0) { if (r[0] == '/' || nn == 0 || dir.nr == 0) {
rs.r = runestrdup(r); rs.r = runestrdup(r);
@ -286,17 +260,13 @@ D_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
static int static int readloader(void* v, uint q0, Rune* r, int nr) {
readloader(void *v, uint q0, Rune *r, int nr)
{
if (nr > 0) if (nr > 0)
eloginsert(v, q0, r, nr); eloginsert(v, q0, r, nr);
return 0; return 0;
} }
int int e_cmd(Text* t, Cmd* cp) {
e_cmd(Text *t, Cmd *cp)
{
Rune* name; Rune* name;
File* f; File* f;
int i, isdir, q0, q1, fd, nulls, samename, allreplaced; int i, isdir, q0, q1, fd, nulls, samename, allreplaced;
@ -348,9 +318,7 @@ e_cmd(Text *t, Cmd *cp)
} }
static Rune Lempty[] = {0}; static Rune Lempty[] = {0};
int int f_cmd(Text* t, Cmd* cp) {
f_cmd(Text *t, Cmd *cp)
{
Rune* name; Rune* name;
String* str; String* str;
String empty; String empty;
@ -367,9 +335,7 @@ f_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int g_cmd(Text* t, Cmd* cp) {
g_cmd(Text *t, Cmd *cp)
{
if (t->file != addr.f) { if (t->file != addr.f) {
warning(nil, "internal error: g_cmd f!=addr.f\n"); warning(nil, "internal error: g_cmd f!=addr.f\n");
return FALSE; return FALSE;
@ -384,15 +350,9 @@ g_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int i_cmd(Text* t, Cmd* cp) { return append(t->file, cp, addr.r.q0); }
i_cmd(Text *t, Cmd *cp)
{
return append(t->file, cp, addr.r.q0);
}
void void copy(File* f, Address addr2) {
copy(File *f, Address addr2)
{
long p; long p;
int ni; int ni;
Rune* buf; Rune* buf;
@ -408,9 +368,7 @@ copy(File *f, Address addr2)
fbuffree(buf); fbuffree(buf);
} }
void void move(File* f, Address addr2) {
move(File *f, Address addr2)
{
if (addr.f != addr2.f || addr.r.q1 <= addr2.r.q0) { if (addr.f != addr2.f || addr.r.q1 <= addr2.r.q0) {
elogdelete(f, addr.r.q0, addr.r.q1); elogdelete(f, addr.r.q0, addr.r.q1);
copy(f, addr2); copy(f, addr2);
@ -423,9 +381,7 @@ move(File *f, Address addr2)
editerror("move overlaps itself"); editerror("move overlaps itself");
} }
int int m_cmd(Text* t, Cmd* cp) {
m_cmd(Text *t, Cmd *cp)
{
Address dot, addr2; Address dot, addr2;
mkaddr(&dot, t->file); mkaddr(&dot, t->file);
@ -437,16 +393,12 @@ m_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int p_cmd(Text* t, Cmd* cp) {
p_cmd(Text *t, Cmd *cp)
{
USED(cp); USED(cp);
return pdisplay(t->file); return pdisplay(t->file);
} }
int int s_cmd(Text* t, Cmd* cp) {
s_cmd(Text *t, Cmd *cp)
{
int i, j, k, c, m, n, nrp, didsub; int i, j, k, c, m, n, nrp, didsub;
long p1, op, delta; long p1, op, delta;
String* buf; String* buf;
@ -462,7 +414,8 @@ s_cmd(Text *t, Cmd *cp)
rp = nil; rp = nil;
delta = 0; delta = 0;
didsub = FALSE; didsub = FALSE;
for(p1 = addr.r.q0; p1<=addr.r.q1 && rxexecute(t, nil, p1, addr.r.q1, &sel); ){ for (p1 = addr.r.q0;
p1 <= addr.r.q1 && rxexecute(t, nil, p1, addr.r.q1, &sel);) {
if (sel.r[0].q0 == sel.r[0].q1) { /* empty match? */ if (sel.r[0].q0 == sel.r[0].q1) { /* empty match? */
if (sel.r[0].q0 == op) { if (sel.r[0].q0 == op) {
p1++; p1++;
@ -533,9 +486,7 @@ Err:
return FALSE; return FALSE;
} }
int int u_cmd(Text* t, Cmd* cp) {
u_cmd(Text *t, Cmd *cp)
{
int n, oseq, flag; int n, oseq, flag;
n = cp->num; n = cp->num;
@ -552,9 +503,7 @@ u_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int w_cmd(Text* t, Cmd* cp) {
w_cmd(Text *t, Cmd *cp)
{
Rune* r; Rune* r;
File* f; File* f;
@ -569,9 +518,7 @@ w_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int x_cmd(Text* t, Cmd* cp) {
x_cmd(Text *t, Cmd *cp)
{
if (cp->re) if (cp->re)
looper(t->file, cp, cp->cmdc == 'x'); looper(t->file, cp, cp->cmdc == 'x');
else else
@ -579,18 +526,14 @@ x_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int X_cmd(Text* t, Cmd* cp) {
X_cmd(Text *t, Cmd *cp)
{
USED(t); USED(t);
filelooper(cp, cp->cmdc == 'X'); filelooper(cp, cp->cmdc == 'X');
return TRUE; return TRUE;
} }
void void runpipe(Text* t, int cmd, Rune* cr, int ncr, int state) {
runpipe(Text *t, int cmd, Rune *cr, int ncr, int state)
{
Rune *r, *s; Rune *r, *s;
int n; int n;
Runestr dir; Runestr dir;
@ -653,16 +596,12 @@ runpipe(Text *t, int cmd, Rune *cr, int ncr, int state)
winlock(t->w, 'M'); winlock(t->w, 'M');
} }
int int pipe_cmd(Text* t, Cmd* cp) {
pipe_cmd(Text *t, Cmd *cp)
{
runpipe(t, cp->cmdc, cp->u.text->r, cp->u.text->n, Inserting); runpipe(t, cp->cmdc, cp->u.text->r, cp->u.text->n, Inserting);
return TRUE; return TRUE;
} }
long long nlcount(Text* t, long q0, long q1, long* pnr) {
nlcount(Text *t, long q0, long q1, long *pnr)
{
long nl, start; long nl, start;
Rune* buf; Rune* buf;
int i, nbuf; int i, nbuf;
@ -697,9 +636,7 @@ enum {
PosnLineChars = 2, PosnLineChars = 2,
}; };
void void printposn(Text* t, int mode) {
printposn(Text *t, int mode)
{
long l1, l2, r1, r2; long l1, l2, r1, r2;
if (t != nil && t->file != nil && t->file->name != nil) if (t != nil && t->file != nil && t->file->name != nil)
@ -718,7 +655,9 @@ printposn(Text *t, int mode)
l1 = 1 + nlcount(t, 0, addr.r.q0, nil); l1 = 1 + nlcount(t, 0, addr.r.q0, nil);
l2 = l1 + nlcount(t, addr.r.q0, addr.r.q1, nil); l2 = l1 + nlcount(t, addr.r.q0, addr.r.q1, nil);
/* check if addr ends with '\n' */ /* check if addr ends with '\n' */
if(addr.r.q1>0 && addr.r.q1>addr.r.q0 && textreadc(t, addr.r.q1-1)=='\n') if (
addr.r.q1 > 0 && addr.r.q1 > addr.r.q0 &&
textreadc(t, addr.r.q1 - 1) == '\n')
--l2; --l2;
warning(nil, "%lud", l1); warning(nil, "%lud", l1);
if (l2 != l1) if (l2 != l1)
@ -739,9 +678,7 @@ printposn(Text *t, int mode)
} }
} }
int int eq_cmd(Text* t, Cmd* cp) {
eq_cmd(Text *t, Cmd *cp)
{
int mode; int mode;
switch (cp->u.text->n) { switch (cp->u.text->n) {
@ -765,9 +702,7 @@ eq_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int nl_cmd(Text* t, Cmd* cp) {
nl_cmd(Text *t, Cmd *cp)
{
Address a; Address a;
File* f; File* f;
@ -787,9 +722,7 @@ nl_cmd(Text *t, Cmd *cp)
return TRUE; return TRUE;
} }
int int append(File* f, Cmd* cp, long p) {
append(File *f, Cmd *cp, long p)
{
if (cp->u.text->n > 0) if (cp->u.text->n > 0)
eloginsert(f, p, cp->u.text->r, cp->u.text->n); eloginsert(f, p, cp->u.text->r, cp->u.text->n);
f->curtext->q0 = p; f->curtext->q0 = p;
@ -797,9 +730,7 @@ append(File *f, Cmd *cp, long p)
return TRUE; return TRUE;
} }
int int pdisplay(File* f) {
pdisplay(File *f)
{
long p1, p2; long p1, p2;
int np; int np;
Rune* buf; Rune* buf;
@ -824,22 +755,24 @@ pdisplay(File *f)
return TRUE; return TRUE;
} }
void void pfilename(File* f) {
pfilename(File *f)
{
int dirty; int dirty;
Window* w; Window* w;
w = f->curtext->w; w = f->curtext->w;
/* same check for dirty as in settag, but we know ncache==0 */ /* same check for dirty as in settag, but we know ncache==0 */
dirty = !w->isdir && !w->isscratch && f->mod; dirty = !w->isdir && !w->isscratch && f->mod;
warning(nil, "%c%c%c %.*S\n", " '"[dirty], warning(
'+', " ."[curtext!=nil && curtext->file==f], f->nname, f->name); nil,
"%c%c%c %.*S\n",
" '"[dirty],
'+',
" ."[curtext != nil && curtext->file == f],
f -> nname,
f -> name);
} }
void void loopcmd(File* f, Cmd* cp, Range* rp, long nrp) {
loopcmd(File *f, Cmd *cp, Range *rp, long nrp)
{
long i; long i;
for (i = 0; i < nrp; i++) { for (i = 0; i < nrp; i++) {
@ -849,9 +782,7 @@ loopcmd(File *f, Cmd *cp, Range *rp, long nrp)
} }
} }
void void looper(File* f, Cmd* cp, int xy) {
looper(File *f, Cmd *cp, int xy)
{
long p, op, nrp; long p, op, nrp;
Range r, tr; Range r, tr;
Range* rp; Range* rp;
@ -864,7 +795,8 @@ looper(File *f, Cmd *cp, int xy)
nrp = 0; nrp = 0;
rp = nil; rp = nil;
for (p = r.q0; p <= r.q1;) { for (p = r.q0; p <= r.q1;) {
if(!rxexecute(f->curtext, nil, p, r.q1, &sel)){ /* no match, but y should still run */ if (!rxexecute(f->curtext, nil, p, r.q1, &sel)) { /* no match, but y should
still run */
if (xy || op > r.q1) if (xy || op > r.q1)
break; break;
tr.q0 = op, tr.q1 = r.q1; tr.q0 = op, tr.q1 = r.q1;
@ -893,9 +825,7 @@ looper(File *f, Cmd *cp, int xy)
--nest; --nest;
} }
void void linelooper(File* f, Cmd* cp) {
linelooper(File *f, Cmd *cp)
{
long nrp, p; long nrp, p;
Range r, linesel; Range r, linesel;
Address a, a3; Address a, a3;
@ -934,17 +864,14 @@ linelooper(File *f, Cmd *cp)
--nest; --nest;
} }
struct Looper struct Looper {
{
Cmd* cp; Cmd* cp;
int XY; int XY;
Window** w; Window** w;
int nw; int nw;
} loopstruct; /* only one; X and Y can't nest */ } loopstruct; /* only one; X and Y can't nest */
void void alllooper(Window* w, void* v) {
alllooper(Window *w, void *v)
{
Text* t; Text* t;
struct Looper* lp; struct Looper* lp;
Cmd* cp; Cmd* cp;
@ -968,18 +895,14 @@ alllooper(Window *w, void *v)
} }
} }
void void alllocker(Window* w, void* v) {
alllocker(Window *w, void *v)
{
if (v) if (v)
incref(&w->ref); incref(&w->ref);
else else
winclose(w); winclose(w);
} }
void void filelooper(Cmd* cp, int XY) {
filelooper(Cmd *cp, int XY)
{
int i; int i;
if (Glooping++) if (Glooping++)
@ -1012,9 +935,7 @@ filelooper(Cmd *cp, int XY)
--nest; --nest;
} }
void void nextmatch(File* f, String* r, long p, int sign) {
nextmatch(File *f, String *r, long p, int sign)
{
if (rxcompile(r->r) == FALSE) if (rxcompile(r->r) == FALSE)
editerror("bad regexp in command address"); editerror("bad regexp in command address");
if (sign >= 0) { if (sign >= 0) {
@ -1042,9 +963,7 @@ File *matchfile(String*);
Address charaddr(long, Address, int); Address charaddr(long, Address, int);
Address lineaddr(long, Address, int); Address lineaddr(long, Address, int);
Address Address cmdaddress(Addr* ap, Address a, int sign) {
cmdaddress(Addr *ap, Address a, int sign)
{
File* f = a.f; File* f = a.f;
Address a1, a2; Address a1, a2;
@ -1131,9 +1050,7 @@ struct Tofile{
String* r; String* r;
}; };
void void alltofile(Window* w, void* v) {
alltofile(Window *w, void *v)
{
Text* t; Text* t;
struct Tofile* tp; struct Tofile* tp;
@ -1152,9 +1069,7 @@ alltofile(Window *w, void *v)
tp->f = t->file; tp->f = t->file;
} }
File* File* tofile(String* r) {
tofile(String *r)
{
struct Tofile t; struct Tofile t;
String rr; String rr;
@ -1167,9 +1082,7 @@ tofile(String *r)
return t.f; return t.f;
} }
void void allmatchfile(Window* w, void* v) {
allmatchfile(Window *w, void *v)
{
struct Tofile* tp; struct Tofile* tp;
Text* t; Text* t;
@ -1189,9 +1102,7 @@ allmatchfile(Window *w, void *v)
} }
} }
File* File* matchfile(String* r) {
matchfile(String *r)
{
struct Tofile tf; struct Tofile tf;
tf.f = nil; tf.f = nil;
@ -1203,9 +1114,7 @@ matchfile(String *r)
return tf.f; return tf.f;
} }
int int filematch(File* f, String* r) {
filematch(File *f, String *r)
{
char* buf; char* buf;
Rune* rbuf; Rune* rbuf;
Window* w; Window* w;
@ -1219,8 +1128,15 @@ filematch(File *f, String *r)
w = f->curtext->w; w = f->curtext->w;
/* same check for dirty as in settag, but we know ncache==0 */ /* same check for dirty as in settag, but we know ncache==0 */
dirty = !w->isdir && !w->isscratch && f->mod; dirty = !w->isdir && !w->isscratch && f->mod;
snprint(buf, BUFSIZE, "%c%c%c %.*S\n", " '"[dirty], snprint(
'+', " ."[curtext!=nil && curtext->file==f], f->nname, f->name); buf,
BUFSIZE,
"%c%c%c %.*S\n",
" '"[dirty],
'+',
" ."[curtext != nil && curtext->file == f],
f -> nname,
f -> name);
rbuf = bytetorune(buf, &i); rbuf = bytetorune(buf, &i);
fbuffree(buf); fbuffree(buf);
match = rxexecute(nil, rbuf, 0, i, &s); match = rxexecute(nil, rbuf, 0, i, &s);
@ -1228,9 +1144,7 @@ filematch(File *f, String *r)
return match; return match;
} }
Address Address charaddr(long l, Address addr, int sign) {
charaddr(long l, Address addr, int sign)
{
if (sign == 0) if (sign == 0)
addr.r.q0 = addr.r.q1 = l; addr.r.q0 = addr.r.q1 = l;
else if (sign < 0) else if (sign < 0)
@ -1242,9 +1156,7 @@ charaddr(long l, Address addr, int sign)
return addr; return addr;
} }
Address Address lineaddr(long l, Address addr, int sign) {
lineaddr(long l, Address addr, int sign)
{
int n; int n;
int c; int c;
File* f = addr.f; File* f = addr.f;
@ -1298,23 +1210,21 @@ lineaddr(long l, Address addr, int sign)
if (p > 0) if (p > 0)
p--; p--;
} }
while(p > 0 && textreadc(f->curtext, p-1)!='\n') /* lines start after a newline */ while (p > 0 && textreadc(f->curtext, p - 1) !=
'\n') /* lines start after a newline */
p--; p--;
a.r.q0 = p; a.r.q0 = p;
} }
return a; return a;
} }
struct Filecheck struct Filecheck {
{
File* f; File* f;
Rune* r; Rune* r;
int nr; int nr;
}; };
void void allfilecheck(Window* w, void* v) {
allfilecheck(Window *w, void *v)
{
struct Filecheck* fp; struct Filecheck* fp;
File* f; File* f;
@ -1326,9 +1236,7 @@ allfilecheck(Window *w, void *v)
warning(nil, "warning: duplicate file name \"%.*S\"\n", fp->nr, fp->r); warning(nil, "warning: duplicate file name \"%.*S\"\n", fp->nr, fp->r);
} }
Rune* Rune* cmdname(File* f, String* str, int set) {
cmdname(File *f, String *str, int set)
{
Rune *r, *s; Rune *r, *s;
int n; int n;
struct Filecheck fc; struct Filecheck fc;

432
edit.c
View file

@ -17,41 +17,263 @@ static char linex[]="\n";
static char wordx[] = " \t\n"; static char wordx[] = " \t\n";
struct cmdtab cmdtab[] = { struct cmdtab cmdtab[] = {
/* cmdc text regexp addr defcmd defaddr count token fn */ /* cmdc text regexp addr defcmd defaddr count token fn */
'\n', 0, 0, 0, 0, aDot, 0, 0, nl_cmd, '\n',
'a', 1, 0, 0, 0, aDot, 0, 0, a_cmd, 0,
'b', 0, 0, 0, 0, aNo, 0, linex, b_cmd, 0,
'c', 1, 0, 0, 0, aDot, 0, 0, c_cmd, 0,
'd', 0, 0, 0, 0, aDot, 0, 0, d_cmd, 0,
'e', 0, 0, 0, 0, aNo, 0, wordx, e_cmd, aDot,
'f', 0, 0, 0, 0, aNo, 0, wordx, f_cmd, 0,
'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, 0,
'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd, nl_cmd,
'm', 0, 0, 1, 0, aDot, 0, 0, m_cmd, 'a',
'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd, 1,
'r', 0, 0, 0, 0, aDot, 0, wordx, e_cmd, 0,
's', 0, 1, 0, 0, aDot, 1, 0, s_cmd, 0,
't', 0, 0, 1, 0, aDot, 0, 0, m_cmd, 0,
'u', 0, 0, 0, 0, aNo, 2, 0, u_cmd, aDot,
'v', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, 0,
'w', 0, 0, 0, 0, aAll, 0, wordx, w_cmd, 0,
'x', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, a_cmd,
'y', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, 'b',
'=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd, 0,
'B', 0, 0, 0, 0, aNo, 0, linex, B_cmd, 0,
'D', 0, 0, 0, 0, aNo, 0, linex, D_cmd, 0,
'X', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, 0,
'Y', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, aNo,
'<', 0, 0, 0, 0, aDot, 0, linex, pipe_cmd, 0,
'|', 0, 0, 0, 0, aDot, 0, linex, pipe_cmd, linex,
'>', 0, 0, 0, 0, aDot, 0, linex, pipe_cmd, b_cmd,
'c',
1,
0,
0,
0,
aDot,
0,
0,
c_cmd,
'd',
0,
0,
0,
0,
aDot,
0,
0,
d_cmd,
'e',
0,
0,
0,
0,
aNo,
0,
wordx,
e_cmd,
'f',
0,
0,
0,
0,
aNo,
0,
wordx,
f_cmd,
'g',
0,
1,
0,
'p',
aDot,
0,
0,
g_cmd,
'i',
1,
0,
0,
0,
aDot,
0,
0,
i_cmd,
'm',
0,
0,
1,
0,
aDot,
0,
0,
m_cmd,
'p',
0,
0,
0,
0,
aDot,
0,
0,
p_cmd,
'r',
0,
0,
0,
0,
aDot,
0,
wordx,
e_cmd,
's',
0,
1,
0,
0,
aDot,
1,
0,
s_cmd,
't',
0,
0,
1,
0,
aDot,
0,
0,
m_cmd,
'u',
0,
0,
0,
0,
aNo,
2,
0,
u_cmd,
'v',
0,
1,
0,
'p',
aDot,
0,
0,
g_cmd,
'w',
0,
0,
0,
0,
aAll,
0,
wordx,
w_cmd,
'x',
0,
1,
0,
'p',
aDot,
0,
0,
x_cmd,
'y',
0,
1,
0,
'p',
aDot,
0,
0,
x_cmd,
'=',
0,
0,
0,
0,
aDot,
0,
linex,
eq_cmd,
'B',
0,
0,
0,
0,
aNo,
0,
linex,
B_cmd,
'D',
0,
0,
0,
0,
aNo,
0,
linex,
D_cmd,
'X',
0,
1,
0,
'f',
aNo,
0,
0,
X_cmd,
'Y',
0,
1,
0,
'f',
aNo,
0,
0,
X_cmd,
'<',
0,
0,
0,
0,
aDot,
0,
linex,
pipe_cmd,
'|',
0,
0,
0,
0,
aDot,
0,
linex,
pipe_cmd,
'>',
0,
0,
0,
0,
aDot,
0,
linex,
pipe_cmd,
/* deliberately unimplemented: /* deliberately unimplemented:
'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd, 'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd,
'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd, 'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd,
'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd, 'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd,
'!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd, '!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd,
*/ */
0, 0, 0, 0, 0, 0, 0, 0 0,
}; 0,
0,
0,
0,
0,
0,
0};
Cmd* parsecmd(int); Cmd* parsecmd(int);
Addr* compoundaddr(void); Addr* compoundaddr(void);
@ -75,9 +297,7 @@ int editing = Inactive;
String* newstring(int); String* newstring(int);
void void editthread(void* v) {
editthread(void *v)
{
Cmd* cmdp; Cmd* cmdp;
USED(v); USED(v);
@ -90,25 +310,19 @@ editthread(void *v)
sendp(editerrc, nil); sendp(editerrc, nil);
} }
void void allelogterm(Window* w, void* x) {
allelogterm(Window *w, void *x)
{
USED(x); USED(x);
elogterm(w->body.file); elogterm(w->body.file);
} }
void void alleditinit(Window* w, void* x) {
alleditinit(Window *w, void *x)
{
USED(x); USED(x);
textcommit(&w->tag, TRUE); textcommit(&w->tag, TRUE);
textcommit(&w->body, TRUE); textcommit(&w->body, TRUE);
w->body.file->editclean = FALSE; w->body.file->editclean = FALSE;
} }
void void allupdate(Window* w, void* x) {
allupdate(Window *w, void *x)
{
Text* t; Text* t;
int i; int i;
File* f; File* f;
@ -133,9 +347,7 @@ allupdate(Window *w, void *x)
winsettag(w); winsettag(w);
} }
void void editerror(char* fmt, ...) {
editerror(char *fmt, ...)
{
va_list arg; va_list arg;
char* s; char* s;
@ -148,9 +360,7 @@ editerror(char *fmt, ...)
threadexits(nil); threadexits(nil);
} }
void void editcmd(Text* ct, Rune* r, uint n) {
editcmd(Text *ct, Rune *r, uint n)
{
char* err; char* err;
if (n == 0) if (n == 0)
@ -193,32 +403,24 @@ editcmd(Text *ct, Rune *r, uint n)
allwindows(allupdate, nil); allwindows(allupdate, nil);
} }
int int getch(void) {
getch(void)
{
if (cmdp == cmdendp) if (cmdp == cmdendp)
return -1; return -1;
return *cmdp++; return *cmdp++;
} }
int int nextc(void) {
nextc(void)
{
if (cmdp == cmdendp) if (cmdp == cmdendp)
return -1; return -1;
return *cmdp; return *cmdp;
} }
void void ungetch(void) {
ungetch(void)
{
if (--cmdp < cmdstartp) if (--cmdp < cmdstartp)
error("ungetch"); error("ungetch");
} }
long long getnum(int signok) {
getnum(int signok)
{
long n; long n;
int c, sign; int c, sign;
@ -236,9 +438,7 @@ getnum(int signok)
return sign * n; return sign * n;
} }
int int cmdskipbl(void) {
cmdskipbl(void)
{
int c; int c;
do do
c = getch(); c = getch();
@ -251,9 +451,7 @@ cmdskipbl(void)
/* /*
* Check that list has room for one more element. * Check that list has room for one more element.
*/ */
void void growlist(List* l) {
growlist(List *l)
{
if (l->u.listptr == 0 || l->nalloc == 0) { if (l->u.listptr == 0 || l->nalloc == 0) {
l->nalloc = INCR; l->nalloc = INCR;
l->u.listptr = emalloc(INCR * sizeof(void*)); l->u.listptr = emalloc(INCR * sizeof(void*));
@ -268,9 +466,7 @@ growlist(List *l)
/* /*
* Remove the ith element from the list * Remove the ith element from the list
*/ */
void void dellist(List* l, int i) {
dellist(List *l, int i)
{
memmove(&l->u.ptr[i], &l->u.ptr[i + 1], (l->nused - (i + 1)) * sizeof(void*)); memmove(&l->u.ptr[i], &l->u.ptr[i + 1], (l->nused - (i + 1)) * sizeof(void*));
l->nused--; l->nused--;
} }
@ -278,25 +474,19 @@ dellist(List *l, int i)
/* /*
* Add a new element, whose position is i, to the list * Add a new element, whose position is i, to the list
*/ */
void void inslist(List* l, int i, void* v) {
inslist(List *l, int i, void *v)
{
growlist(l); growlist(l);
memmove(&l->u.ptr[i + 1], &l->u.ptr[i], (l->nused - i) * sizeof(void*)); memmove(&l->u.ptr[i + 1], &l->u.ptr[i], (l->nused - i) * sizeof(void*));
l->u.ptr[i] = v; l->u.ptr[i] = v;
l->nused++; l->nused++;
} }
void void listfree(List* l) {
listfree(List *l)
{
free(l->u.listptr); free(l->u.listptr);
free(l); free(l);
} }
String* String* allocstring(int n) {
allocstring(int n)
{
String* s; String* s;
s = emalloc(sizeof(String)); s = emalloc(sizeof(String));
@ -307,15 +497,12 @@ allocstring(int n)
return s; return s;
} }
void void freestring(String* s) {
freestring(String *s)
{
free(s->r); free(s->r);
free(s); free(s);
} }
Cmd* Cmd* newcmd(void) {
newcmd(void){
Cmd* p; Cmd* p;
p = emalloc(sizeof(Cmd)); p = emalloc(sizeof(Cmd));
@ -323,9 +510,7 @@ newcmd(void){
return p; return p;
} }
String* String* newstring(int n) {
newstring(int n)
{
String* p; String* p;
p = allocstring(n); p = allocstring(n);
@ -333,9 +518,7 @@ newstring(int n)
return p; return p;
} }
Addr* Addr* newaddr(void) {
newaddr(void)
{
Addr* p; Addr* p;
p = emalloc(sizeof(Addr)); p = emalloc(sizeof(Addr));
@ -343,9 +526,7 @@ newaddr(void)
return p; return p;
} }
void void freecmd(void) {
freecmd(void)
{
int i; int i;
while (cmdlist.nused > 0) while (cmdlist.nused > 0)
@ -358,17 +539,14 @@ freecmd(void)
} }
} }
void void okdelim(int c) {
okdelim(int c) if (
{ c == '\\' || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
if(c=='\\' || ('a'<=c && c<='z') ('0' <= c && c <= '9'))
|| ('A'<=c && c<='Z') || ('0'<=c && c<='9'))
editerror("bad delimiter %c\n", c); editerror("bad delimiter %c\n", c);
} }
void void atnl(void) {
atnl(void)
{
int c; int c;
cmdskipbl(); cmdskipbl();
@ -377,9 +555,7 @@ atnl(void)
editerror("newline expected (saw %C)", c); editerror("newline expected (saw %C)", c);
} }
void void Straddc(String* s, int c) {
Straddc(String *s, int c)
{
if (s->n + 1 >= s->nalloc) { if (s->n + 1 >= s->nalloc) {
s->nalloc += 10; s->nalloc += 10;
s->r = erealloc(s->r, s->nalloc * sizeof(Rune)); s->r = erealloc(s->r, s->nalloc * sizeof(Rune));
@ -388,9 +564,7 @@ Straddc(String *s, int c)
s->r[s->n] = '\0'; s->r[s->n] = '\0';
} }
void void getrhs(String* s, int delim, int cmd) {
getrhs(String *s, int delim, int cmd)
{
int c; int c;
while ((c = getch()) > 0 && c != delim && c != '\n') { while ((c = getch()) > 0 && c != delim && c != '\n') {
@ -410,9 +584,7 @@ getrhs(String *s, int delim, int cmd)
ungetch(); /* let client read whether delimiter, '\n' or whatever */ ungetch(); /* let client read whether delimiter, '\n' or whatever */
} }
String * String* collecttoken(char* end) {
collecttoken(char *end)
{
String* s = newstring(0); String* s = newstring(0);
int c; int c;
@ -425,9 +597,7 @@ collecttoken(char *end)
return s; return s;
} }
String * String* collecttext(void) {
collecttext(void)
{
String* s; String* s;
int begline, i, c, delim; int begline, i, c, delim;
@ -456,9 +626,7 @@ collecttext(void)
return s; return s;
} }
int int cmdlookup(int c) {
cmdlookup(int c)
{
int i; int i;
for (i = 0; cmdtab[i].cmdc; i++) for (i = 0; cmdtab[i].cmdc; i++)
@ -467,9 +635,7 @@ cmdlookup(int c)
return -1; return -1;
} }
Cmd* Cmd* parsecmd(int nest) {
parsecmd(int nest)
{
int i, c; int i, c;
struct cmdtab* ct; struct cmdtab* ct;
Cmd *cp, *ncp; Cmd *cp, *ncp;
@ -500,7 +666,8 @@ parsecmd(int nest)
if (ct->regexp) { if (ct->regexp) {
/* x without pattern -> .*\n, indicated by cmd.re==0 */ /* x without pattern -> .*\n, indicated by cmd.re==0 */
/* X without pattern is all files */ /* X without pattern is all files */
if((ct->cmdc!='x' && ct->cmdc!='X') || if (
(ct->cmdc != 'x' && ct->cmdc != 'X') ||
((c = nextc()) != ' ' && c != '\t' && c != '\n')) { ((c = nextc()) != ' ' && c != '\t' && c != '\n')) {
cmdskipbl(); cmdskipbl();
if ((c = getch()) == '\n' || c < 0) if ((c = getch()) == '\n' || c < 0)
@ -515,7 +682,6 @@ parsecmd(int nest)
if (nextc() == 'g') if (nextc() == 'g')
cmd.flag = getch(); cmd.flag = getch();
} }
} }
} }
} }
@ -562,9 +728,7 @@ parsecmd(int nest)
return cp; return cp;
} }
String* String* getregexp(int delim) {
getregexp(int delim)
{
String *buf, *r; String *buf, *r;
int i, c; int i, c;
@ -598,9 +762,7 @@ getregexp(int delim)
return r; return r;
} }
Addr * Addr* simpleaddr(void) {
simpleaddr(void)
{
Addr addr; Addr addr;
Addr *ap, *nap; Addr *ap, *nap;
@ -612,12 +774,22 @@ simpleaddr(void)
addr.type = getch(); addr.type = getch();
addr.num = getnum(1); addr.num = getnum(1);
break; break;
case '0': case '1': case '2': case '3': case '4': case '0':
case '5': case '6': case '7': case '8': case '9': case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
addr.num = getnum(1); addr.num = getnum(1);
addr.type = 'l'; addr.type = 'l';
break; break;
case '/': case '?': case '"': case '/':
case '?':
case '"':
addr.u.re = getregexp(addr.type = getch()); addr.u.re = getregexp(addr.type = getch());
break; break;
case '.': case '.':
@ -665,9 +837,7 @@ simpleaddr(void)
return ap; return ap;
} }
Addr * Addr* compoundaddr(void) {
compoundaddr(void)
{
Addr addr; Addr addr;
Addr *ap, *next; Addr *ap, *next;

87
elog.c
View file

@ -27,32 +27,25 @@ static int warned = FALSE;
*/ */
typedef struct Buflog Buflog; typedef struct Buflog Buflog;
struct Buflog struct Buflog {
{
short type; /* Replace, Filename */ short type; /* Replace, Filename */
uint q0; /* location of change (unused in f) */ uint q0; /* location of change (unused in f) */
uint nd; /* # runes to delete */ uint nd; /* # runes to delete */
uint nr; /* # runes in string or file name */ uint nr; /* # runes in string or file name */
}; };
enum enum { Buflogsize = sizeof(Buflog) / sizeof(Rune) };
{
Buflogsize = sizeof(Buflog)/sizeof(Rune)
};
/* /*
* Minstring shouldn't be very big or we will do lots of I/O for small changes. * Minstring shouldn't be very big or we will do lots of I/O for small changes.
* Maxstring is RBUFSIZE so we can fbufalloc() once and not realloc elog.r. * Maxstring is RBUFSIZE so we can fbufalloc() once and not realloc elog.r.
*/ */
enum enum {
{
Minstring = 16, /* distance beneath which we merge changes */ Minstring = 16, /* distance beneath which we merge changes */
Maxstring = RBUFSIZE /* maximum length of change we will merge into one */ Maxstring = RBUFSIZE /* maximum length of change we will merge into one */
}; };
void void eloginit(File* f) {
eloginit(File *f)
{
if (f->elog.type != Empty) if (f->elog.type != Empty)
return; return;
f->elog.type = Null; f->elog.type = Null;
@ -63,9 +56,7 @@ eloginit(File *f)
bufreset(f->elogbuf); bufreset(f->elogbuf);
} }
void void elogclose(File* f) {
elogclose(File *f)
{
if (f->elogbuf) { if (f->elogbuf) {
bufclose(f->elogbuf); bufclose(f->elogbuf);
free(f->elogbuf); free(f->elogbuf);
@ -73,17 +64,13 @@ elogclose(File *f)
} }
} }
void void elogreset(File* f) {
elogreset(File *f)
{
f->elog.type = Null; f->elog.type = Null;
f->elog.nd = 0; f->elog.nd = 0;
f->elog.nr = 0; f->elog.nr = 0;
} }
void void elogterm(File* f) {
elogterm(File *f)
{
elogreset(f); elogreset(f);
if (f->elogbuf) if (f->elogbuf)
bufreset(f->elogbuf); bufreset(f->elogbuf);
@ -93,9 +80,7 @@ elogterm(File *f)
warned = FALSE; warned = FALSE;
} }
void void elogflush(File* f) {
elogflush(File *f)
{
Buflog b; Buflog b;
b.type = f->elog.type; b.type = f->elog.type;
@ -120,9 +105,7 @@ elogflush(File *f)
elogreset(f); elogreset(f);
} }
void void elogreplace(File* f, int q0, int q1, Rune* r, int nr) {
elogreplace(File *f, int q0, int q1, Rune *r, int nr)
{
uint gap; uint gap;
if (q0 == q1 && nr == 0) if (q0 == q1 && nr == 0)
@ -157,9 +140,7 @@ elogreplace(File *f, int q0, int q1, Rune *r, int nr)
runemove(f->elog.r, r, nr); runemove(f->elog.r, r, nr);
} }
void void eloginsert(File* f, int q0, Rune* r, int nr) {
eloginsert(File *f, int q0, Rune *r, int nr)
{
int n; int n;
if (nr == 0) if (nr == 0)
@ -171,7 +152,8 @@ eloginsert(File *f, int q0, Rune *r, int nr)
elogflush(f); elogflush(f);
} }
/* try to merge with previous */ /* try to merge with previous */
if(f->elog.type==Insert && q0==f->elog.q0 && f->elog.nr+nr<Maxstring){ if (
f->elog.type == Insert && q0 == f->elog.q0 && f->elog.nr + nr < Maxstring) {
runemove(f->elog.r + f->elog.nr, r, nr); runemove(f->elog.r + f->elog.nr, r, nr);
f->elog.nr += nr; f->elog.nr += nr;
return; return;
@ -190,9 +172,7 @@ eloginsert(File *f, int q0, Rune *r, int nr)
} }
} }
void void elogdelete(File* f, int q0, int q1) {
elogdelete(File *f, int q0, int q1)
{
if (q0 == q1) if (q0 == q1)
return; return;
eloginit(f); eloginit(f);
@ -213,9 +193,7 @@ elogdelete(File *f, int q0, int q1)
} }
#define tracelog 0 #define tracelog 0
void void elogapply(File* f) {
elogapply(File *f)
{
Buflog b; Buflog b;
Rune* buf; Rune* buf;
uint i, n, up, mod; uint i, n, up, mod;
@ -240,11 +218,11 @@ elogapply(File *f)
/* /*
* The edit commands have already updated the selection in t->q0, t->q1, * The edit commands have already updated the selection in t->q0, t->q1,
* but using coordinates relative to the unmodified buffer. As we apply the log, * but using coordinates relative to the unmodified buffer. As we apply the
* we have to update the coordinates to be relative to the modified buffer. * log, we have to update the coordinates to be relative to the modified
* Textinsert and textdelete will do this for us; our only work is to apply the * buffer. Textinsert and textdelete will do this for us; our only work is to
* convention that an insertion at t->q0==t->q1 is intended to select the * apply the convention that an insertion at t->q0==t->q1 is intended to
* inserted text. * select the inserted text.
*/ */
/* /*
@ -265,8 +243,13 @@ elogapply(File *f)
case Replace: case Replace:
if (tracelog) if (tracelog)
warning(nil, "elog replace %d %d (%d %d)\n", warning(
b.q0, b.q0+b.nd, t->q0, t->q1); nil,
"elog replace %d %d (%d %d)\n",
b.q0,
b.q0 + b.nd,
t->q0,
t->q1);
if (!mod) { if (!mod) {
mod = TRUE; mod = TRUE;
filemark(f); filemark(f);
@ -287,8 +270,13 @@ elogapply(File *f)
case Delete: case Delete:
if (tracelog) if (tracelog)
warning(nil, "elog delete %d %d (%d %d)\n", warning(
b.q0, b.q0+b.nd, t->q0, t->q1); nil,
"elog delete %d %d (%d %d)\n",
b.q0,
b.q0 + b.nd,
t->q0,
t->q1);
if (!mod) { if (!mod) {
mod = TRUE; mod = TRUE;
filemark(f); filemark(f);
@ -299,8 +287,13 @@ elogapply(File *f)
case Insert: case Insert:
if (tracelog) if (tracelog)
warning(nil, "elog insert %d %d (%d %d)\n", warning(
b.q0, b.q0+b.nr, t->q0, t->q1); nil,
"elog insert %d %d (%d %d)\n",
b.q0,
b.q0 + b.nr,
t->q0,
t->q1);
if (!mod) { if (!mod) {
mod = TRUE; mod = TRUE;
filemark(f); filemark(f);

232
exec.c
View file

@ -57,8 +57,7 @@ void tab(Text*, Text*, Text*, int, int, Rune*, int);
void zeroxx(Text*, Text*, Text*, int, int, Rune*, int); void zeroxx(Text*, Text*, Text*, int, int, Rune*, int);
typedef struct Exectab Exectab; typedef struct Exectab Exectab;
struct Exectab struct Exectab {
{
Rune* name; Rune* name;
void (*fn)(Text*, Text*, Text*, int, int, Rune*, int); void (*fn)(Text*, Text*, Text*, int, int, Rune*, int);
int mark; int mark;
@ -98,7 +97,13 @@ static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 };
static Rune LZerox[] = {'Z', 'e', 'r', 'o', 'x', 0}; static Rune LZerox[] = {'Z', 'e', 'r', 'o', 'x', 0};
Exectab exectab[] = { Exectab exectab[] = {
{ LAbort, doabort, FALSE, XXX, XXX, }, {
LAbort,
doabort,
FALSE,
XXX,
XXX,
},
{LCut, cut, TRUE, TRUE, TRUE}, {LCut, cut, TRUE, TRUE, TRUE},
{LDel, del, FALSE, FALSE, XXX}, {LDel, del, FALSE, FALSE, XXX},
{LDelcol, delcol, FALSE, XXX, XXX}, {LDelcol, delcol, FALSE, XXX, XXX},
@ -128,12 +133,9 @@ Exectab exectab[] = {
{LTab, tab, FALSE, XXX, XXX}, {LTab, tab, FALSE, XXX, XXX},
{LUndo, undo, FALSE, TRUE, XXX}, {LUndo, undo, FALSE, TRUE, XXX},
{LZerox, zeroxx, FALSE, XXX, XXX}, {LZerox, zeroxx, FALSE, XXX, XXX},
{ nil, 0, 0, 0, 0 } {nil, 0, 0, 0, 0}};
};
Exectab* Exectab* lookup(Rune* r, int n) {
lookup(Rune *r, int n)
{
Exectab* e; Exectab* e;
int nr; int nr;
@ -148,17 +150,13 @@ lookup(Rune *r, int n)
return nil; return nil;
} }
int int isexecc(int c) {
isexecc(int c)
{
if (isfilec(c)) if (isfilec(c))
return 1; return 1;
return c == '<' || c == '|' || c == '>'; return c == '<' || c == '|' || c == '>';
} }
void void execute(Text* t, uint aq0, uint aq1, int external, Text* argt) {
execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
{
uint q0, q1; uint q0, q1;
Rune *r, *s; Rune *r, *s;
char *b, *a, *aa; char *b, *a, *aa;
@ -260,9 +258,7 @@ execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
run(t->w, b, dir.r, dir.nr, TRUE, aa, a, FALSE); run(t->w, b, dir.r, dir.nr, TRUE, aa, a, FALSE);
} }
char* char* printarg(Text* argt, uint q0, uint q1) {
printarg(Text *argt, uint q0, uint q1)
{
char* buf; char* buf;
if (argt->what != Body || argt->file->name == nil) if (argt->what != Body || argt->file->name == nil)
@ -275,9 +271,7 @@ printarg(Text *argt, uint q0, uint q1)
return buf; return buf;
} }
char* char* getarg(Text* argt, int doaddr, int dofile, Rune** rp, int* nrp) {
getarg(Text *argt, int doaddr, int dofile, Rune **rp, int *nrp)
{
int n; int n;
Expand e; Expand e;
char* a; char* a;
@ -312,9 +306,7 @@ getarg(Text *argt, int doaddr, int dofile, Rune **rp, int *nrp)
return a; return a;
} }
char* char* getbytearg(Text* argt, int doaddr, int dofile, char** bp) {
getbytearg(Text *argt, int doaddr, int dofile, char **bp)
{
Rune* r; Rune* r;
int n; int n;
char* aa; char* aa;
@ -328,9 +320,7 @@ getbytearg(Text *argt, int doaddr, int dofile, char **bp)
return aa; return aa;
} }
void void doabort(Text* __0, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
doabort(Text *__0, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
static int n; static int n;
USED(__0); USED(__0);
@ -347,9 +337,7 @@ doabort(Text *__0, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
abort(); abort();
} }
void void newcol(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
newcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
Column* c; Column* c;
Window* w; Window* w;
@ -368,9 +356,7 @@ newcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
} }
} }
void void delcol(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
delcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
int i; int i;
Column* c; Column* c;
Window* w; Window* w;
@ -387,17 +373,22 @@ delcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
return; return;
for (i = 0; i < c->nw; i++) { for (i = 0; i < c->nw; i++) {
w = c->w[i]; w = c->w[i];
if(w->nopen[QWevent]+w->nopen[QWaddr]+w->nopen[QWdata]+w->nopen[QWxdata] > 0){ if (
warning(nil, "can't delete column; %.*S is running an external command\n", w->body.file->nname, w->body.file->name); w->nopen[QWevent] + w->nopen[QWaddr] + w->nopen[QWdata] +
w->nopen[QWxdata] >
0) {
warning(
nil,
"can't delete column; %.*S is running an external command\n",
w->body.file->nname,
w->body.file->name);
return; return;
} }
} }
rowclose(et->col->row, et->col, TRUE); rowclose(et->col->row, et->col, TRUE);
} }
void void del(Text* et, Text* _0, Text* _1, int flag1, int _2, Rune* _3, int _4) {
del(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
{
USED(_0); USED(_0);
USED(_1); USED(_1);
USED(_2); USED(_2);
@ -410,9 +401,7 @@ del(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
colclose(et->col, et->w, TRUE); colclose(et->col, et->w, TRUE);
} }
void void sort(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
sort(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
USED(_0); USED(_0);
USED(_1); USED(_1);
USED(_2); USED(_2);
@ -424,9 +413,7 @@ sort(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
colsort(et->col); colsort(et->col);
} }
uint uint seqof(Window* w, int isundo) {
seqof(Window *w, int isundo)
{
/* if it's undo, see who changed with us */ /* if it's undo, see who changed with us */
if (isundo) if (isundo)
return w->body.file->seq; return w->body.file->seq;
@ -434,9 +421,7 @@ seqof(Window *w, int isundo)
return fileredoseq(w->body.file); return fileredoseq(w->body.file);
} }
void void undo(Text* et, Text* _0, Text* _1, int flag1, int _2, Rune* _3, int _4) {
undo(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
{
int i, j; int i, j;
Column* c; Column* c;
Window* w; Window* w;
@ -457,8 +442,8 @@ undo(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
} }
/* /*
* Undo the executing window first. Its display will update. other windows * Undo the executing window first. Its display will update. other windows
* in the same file will not call show() and jump to a different location in the file. * in the same file will not call show() and jump to a different location in
* Simultaneous changes to other files will be chaotic, however. * the file. Simultaneous changes to other files will be chaotic, however.
*/ */
winundo(et->w, flag1); winundo(et->w, flag1);
for (i = 0; i < row.ncol; i++) { for (i = 0; i < row.ncol; i++) {
@ -473,9 +458,7 @@ undo(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
} }
} }
char* char* getname(Text* t, Text* argt, Rune* arg, int narg, int isput) {
getname(Text *t, Text *argt, Rune *arg, int narg, int isput)
{
char* s; char* s;
Rune* r; Rune* r;
int i, n, promote; int i, n, promote;
@ -539,9 +522,7 @@ getname(Text *t, Text *argt, Rune *arg, int narg, int isput)
return s; return s;
} }
void void zeroxx(Text* et, Text* t, Text* _1, int _2, int _3, Rune* _4, int _5) {
zeroxx(Text *et, Text *t, Text *_1, int _2, int _3, Rune *_4, int _5)
{
Window* nw; Window* nw;
int c, locked; int c, locked;
@ -565,7 +546,11 @@ zeroxx(Text *et, Text *t, Text *_1, int _2, int _3, Rune *_4, int _5)
return; return;
t = &t->w->body; t = &t->w->body;
if (t->w->isdir) if (t->w->isdir)
warning(nil, "%.*S is a directory; Zerox illegal\n", t->file->nname, t->file->name); warning(
nil,
"%.*S is a directory; Zerox illegal\n",
t->file->nname,
t->file->name);
else { else {
nw = coladd(t->w->col, nil, t->w, -1); nw = coladd(t->w->col, nil, t->w, -1);
/* ugly: fix locks so w->unlock works */ /* ugly: fix locks so w->unlock works */
@ -586,9 +571,8 @@ struct TextAddr {
long rq1; long rq1;
}; };
void void get(
get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg) Text* et, Text* t, Text* argt, int flag1, int _0, Rune* arg, int narg) {
{
char* name; char* name;
Rune* r; Rune* r;
int i, n, dirty, samename, isdir; int i, n, dirty, samename, isdir;
@ -617,7 +601,10 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
isdir = (d != nil && (d->qid.type & QTDIR)); isdir = (d != nil && (d->qid.type & QTDIR));
free(d); free(d);
if (isdir) { if (isdir) {
warning(nil, "%s is a directory; can't read with multiple windows on it\n", name); warning(
nil,
"%s is a directory; can't read with multiple windows on it\n",
name);
return; return;
} }
} }
@ -656,7 +643,8 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc); textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc);
if (samename) { if (samename) {
a = &addr[i]; a = &addr[i];
// warning(nil, "%d %d %d %d %d %d\n", a->lorigin, a->rorigin, a->lq0, a->rq0, a->lq1, a->rq1); // warning(nil, "%d %d %d %d %d %d\n", a->lorigin, a->rorigin, a->lq0,
// a->rq0, a->lq1, a->rq1);
q0 = nlcounttopos(u, 0, a->lq0, a->rq0); q0 = nlcounttopos(u, 0, a->lq0, a->rq0);
q1 = nlcounttopos(u, q0, a->lq1, a->rq1); q1 = nlcounttopos(u, q0, a->lq1, a->rq1);
textsetselect(u, q0, q1); textsetselect(u, q0, q1);
@ -669,9 +657,7 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
xfidlog(w, "get"); xfidlog(w, "get");
} }
static void static void checksha1(char* name, File* f, Dir* d) {
checksha1(char *name, File *f, Dir *d)
{
int fd, n; int fd, n;
DigestState* h; DigestState* h;
uchar out[20]; uchar out[20];
@ -694,9 +680,7 @@ checksha1(char *name, File *f, Dir *d)
} }
} }
void void putfile(File* f, int q0, int q1, Rune* namer, int nname) {
putfile(File *f, int q0, int q1, Rune *namer, int nname)
{
uint n, m; uint n, m;
Rune* r; Rune* r;
Biobuf* b; Biobuf* b;
@ -717,7 +701,14 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
if (f->unread) if (f->unread)
warning(nil, "%s not written; file already exists\n", name); warning(nil, "%s not written; file already exists\n", name);
else else
warning(nil, "%s modified%s%s since last read\n\twas %t; now %t\n", name, d->muid[0]?" by ":"", d->muid, f->mtime, d->mtime); warning(
nil,
"%s modified%s%s since last read\n\twas %t; now %t\n",
name,
d->muid[0] ? " by " : "",
d->muid,
f->mtime,
d->mtime);
f->dev = d->dev; f->dev = d->dev;
f->qidpath = d->qid.path; f->qidpath = d->qid.path;
f->mtime = d->mtime; f->mtime = d->mtime;
@ -832,9 +823,7 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
free(name); free(name);
} }
static void static void trimspaces(Text* et) {
trimspaces(Text *et)
{
File* f; File* f;
Rune* r; Rune* r;
Text* t; Text* t;
@ -855,7 +844,8 @@ trimspaces(Text *et)
r = fbufalloc(); r = fbufalloc();
q0 = f->b.nc; q0 = f->b.nc;
delstart = q0; /* end of current space run, or 0 if no active run; = q0 to delete spaces before EOF */ delstart = q0; /* end of current space run, or 0 if no active run; = q0 to
delete spaces before EOF */
while (q0 > 0) { while (q0 > 0) {
n = RBUFSIZE; n = RBUFSIZE;
if (n > q0) if (n > q0)
@ -891,9 +881,7 @@ trimspaces(Text *et)
winunlock(t->w); winunlock(t->w);
} }
void void put(Text* et, Text* _0, Text* argt, int _1, int _2, Rune* arg, int narg) {
put(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
{
int nname; int nname;
Rune* namer; Rune* namer;
Window* w; Window* w;
@ -921,9 +909,8 @@ put(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
free(name); free(name);
} }
void void dump(
dump(Text *_0, Text *_1, Text *argt, int isdump, int _2, Rune *arg, int narg) Text* _0, Text* _1, Text* argt, int isdump, int _2, Rune* arg, int narg) {
{
char* name; char* name;
USED(_0); USED(_0);
@ -941,9 +928,8 @@ dump(Text *_0, Text *_1, Text *argt, int isdump, int _2, Rune *arg, int narg)
free(name); free(name);
} }
void void cut(
cut(Text *et, Text *t, Text *_0, int dosnarf, int docut, Rune *_2, int _3) Text* et, Text* t, Text* _0, int dosnarf, int docut, Rune* _2, int _3) {
{
uint q0, q1, n, locked, c; uint q0, q1, n, locked, c;
Rune* r; Rune* r;
@ -1012,9 +998,8 @@ cut(Text *et, Text *t, Text *_0, int dosnarf, int docut, Rune *_2, int _3)
winunlock(t->w); winunlock(t->w);
} }
void void paste(
paste(Text *et, Text *t, Text *_0, int selectall, int tobody, Rune *_1, int _2) Text* et, Text* t, Text* _0, int selectall, int tobody, Rune* _1, int _2) {
{
int c; int c;
uint q, q0, q1, n; uint q, q0, q1, n;
Rune* r; Rune* r;
@ -1069,9 +1054,7 @@ paste(Text *et, Text *t, Text *_0, int selectall, int tobody, Rune *_1, int _2)
winunlock(t->w); winunlock(t->w);
} }
void void look(Text* et, Text* t, Text* argt, int _0, int _1, Rune* arg, int narg) {
look(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
{
Rune* r; Rune* r;
int n; int n;
@ -1097,9 +1080,7 @@ look(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
static Rune Lnl[] = {'\n', 0}; static Rune Lnl[] = {'\n', 0};
void void sendx(Text* et, Text* t, Text* _0, int _1, int _2, Rune* _3, int _4) {
sendx(Text *et, Text *t, Text *_0, int _1, int _2, Rune *_3, int _4)
{
USED(_0); USED(_0);
USED(_1); USED(_1);
USED(_2); USED(_2);
@ -1121,9 +1102,7 @@ sendx(Text *et, Text *t, Text *_0, int _1, int _2, Rune *_3, int _4)
textshow(t, t->q1, t->q1, 1); textshow(t, t->q1, t->q1, 1);
} }
void void edit(Text* et, Text* _0, Text* argt, int _1, int _2, Rune* arg, int narg) {
edit(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
{
Rune* r; Rune* r;
int len; int len;
@ -1142,9 +1121,7 @@ edit(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
editcmd(et, arg, narg); editcmd(et, arg, narg);
} }
void void xexit(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
xexit(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
USED(et); USED(et);
USED(_0); USED(_0);
USED(_1); USED(_1);
@ -1159,9 +1136,7 @@ xexit(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
} }
} }
void void putall(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
putall(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
int i, j, e; int i, j, e;
Window* w; Window* w;
Column* c; Column* c;
@ -1197,10 +1172,7 @@ putall(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
} }
} }
void id(Text* et, Text* _0, Text* _1, int _2, int _3, Rune* _4, int _5) {
void
id(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
{
USED(_0); USED(_0);
USED(_1); USED(_1);
USED(_2); USED(_2);
@ -1212,9 +1184,8 @@ id(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
warning(nil, "/mnt/acme/%d/\n", et->w->id); warning(nil, "/mnt/acme/%d/\n", et->w->id);
} }
void void local(
local(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) Text* et, Text* _0, Text* argt, int _1, int _2, Rune* arg, int narg) {
{
char *a, *aa; char *a, *aa;
Runestr dir; Runestr dir;
@ -1233,9 +1204,8 @@ local(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
run(nil, runetobyte(arg, narg), dir.r, dir.nr, FALSE, aa, a, FALSE); run(nil, runetobyte(arg, narg), dir.r, dir.nr, FALSE, aa, a, FALSE);
} }
void void xkill(
xkill(Text *_0, Text *_1, Text *argt, int _2, int _3, Rune *arg, int narg) Text* _0, Text* _1, Text* argt, int _2, int _3, Rune* arg, int narg) {
{
Rune *a, *cmd, *r; Rune *a, *cmd, *r;
int na; int na;
@ -1262,9 +1232,7 @@ xkill(Text *_0, Text *_1, Text *argt, int _2, int _3, Rune *arg, int narg)
static Rune Lfix[] = {'f', 'i', 'x', 0}; static Rune Lfix[] = {'f', 'i', 'x', 0};
static Rune Lvar[] = {'v', 'a', 'r', 0}; static Rune Lvar[] = {'v', 'a', 'r', 0};
void void fontx(Text* et, Text* t, Text* argt, int _0, int _1, Rune* arg, int narg) {
fontx(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
{
Rune *a, *r, *flag, *file; Rune *a, *r, *flag, *file;
int na, nf; int na, nf;
char* aa; char* aa;
@ -1344,9 +1312,7 @@ fontx(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
free(flag); free(flag);
} }
void void incl(Text* et, Text* _0, Text* argt, int _1, int _2, Rune* arg, int narg) {
incl(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
{
Rune *a, *r; Rune *a, *r;
Window* w; Window* w;
int na, n, len; int na, n, len;
@ -1392,9 +1358,7 @@ enum {
IError = -1, IError = -1,
}; };
static int static int indentval(Rune* s, int n, int type) {
indentval(Rune *s, int n, int type)
{
static char* strs[] = { static char* strs[] = {
[SPACESINDENT] = "Spaces", [SPACESINDENT] = "Spaces",
[AUTOINDENT] = "Indent", [AUTOINDENT] = "Indent",
@ -1419,18 +1383,15 @@ indentval(Rune *s, int n, int type)
return IError; return IError;
} }
static void static void fixindent(Window* w, void* arg) {
fixindent(Window *w, void *arg)
{
int t; int t;
t = (int)arg; t = (int)arg;
w->indent[t] = globalindent[t]; w->indent[t] = globalindent[t];
} }
void void indent(
indent(Text *et, Text* _0, Text *argt, int type, int _1, Rune *arg, int narg) Text* et, Text* _0, Text* argt, int type, int _1, Rune* arg, int narg) {
{
Rune *a, *r; Rune *a, *r;
Window* w; Window* w;
int na, len, ival; int na, len, ival;
@ -1456,9 +1417,7 @@ indent(Text *et, Text* _0, Text *argt, int type, int _1, Rune *arg, int narg)
w->indent[type] = ival; w->indent[type] = ival;
} }
void void tab(Text* et, Text* _0, Text* argt, int _1, int _2, Rune* arg, int narg) {
tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
{
Rune *a, *r; Rune *a, *r;
Window* w; Window* w;
int na, len, tab; int na, len, tab;
@ -1493,12 +1452,15 @@ tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
winresize(w, w->r, FALSE, TRUE); winresize(w, w->r, FALSE, TRUE);
} }
} else } else
warning(nil, "%.*S: Tab %d\n", w->body.file->nname, w->body.file->name, w->body.tabstop); warning(
nil,
"%.*S: Tab %d\n",
w->body.file->nname,
w->body.file->name,
w->body.tabstop);
} }
void void runproc(void* argvp) {
runproc(void *argvp)
{
/* args: */ /* args: */
Window* win; Window* win;
char* s; char* s;
@ -1753,9 +1715,7 @@ Hard:
threadexits(nil); threadexits(nil);
} }
void void runwaittask(void* v) {
runwaittask(void *v)
{
Command* c; Command* c;
Channel* cpid; Channel* cpid;
void** a; void** a;
@ -1781,9 +1741,9 @@ runwaittask(void *v)
chanfree(cpid); chanfree(cpid);
} }
void void run(
run(Window *win, char *s, Rune *rdir, int ndir, int newns, char *argaddr, char *xarg, int iseditcmd) Window* win, char* s, Rune* rdir, int ndir, int newns, char* argaddr,
{ char* xarg, int iseditcmd) {
void** arg; void** arg;
Command* c; Command* c;
Channel* cpid; Channel* cpid;

65
file.c
View file

@ -23,8 +23,7 @@
*/ */
typedef struct Undo Undo; typedef struct Undo Undo;
struct Undo struct Undo {
{
short type; /* Delete, Insert, Filename */ short type; /* Delete, Insert, Filename */
short mod; /* modify bit */ short mod; /* modify bit */
uint seq; /* sequence number */ uint seq; /* sequence number */
@ -32,14 +31,9 @@ struct Undo
uint n; /* # runes in string or file name */ uint n; /* # runes in string or file name */
}; };
enum enum { Undosize = sizeof(Undo) / sizeof(Rune) };
{
Undosize = sizeof(Undo)/sizeof(Rune)
};
File* File* fileaddtext(File* f, Text* t) {
fileaddtext(File *f, Text *t)
{
if (f == nil) { if (f == nil) {
f = emalloc(sizeof(File)); f = emalloc(sizeof(File));
f->unread = TRUE; f->unread = TRUE;
@ -50,9 +44,7 @@ fileaddtext(File *f, Text *t)
return f; return f;
} }
void void filedeltext(File* f, Text* t) {
filedeltext(File *f, Text *t)
{
int i; int i;
for (i = 0; i < f->ntext; i++) for (i = 0; i < f->ntext; i++)
@ -71,9 +63,7 @@ filedeltext(File *f, Text *t)
f->curtext = f->text[0]; f->curtext = f->text[0];
} }
void void fileinsert(File* f, uint p0, Rune* s, uint ns) {
fileinsert(File *f, uint p0, Rune *s, uint ns)
{
if (p0 > f->b.nc) if (p0 > f->b.nc)
error("internal error: fileinsert"); error("internal error: fileinsert");
if (f->seq > 0) if (f->seq > 0)
@ -83,9 +73,7 @@ fileinsert(File *f, uint p0, Rune *s, uint ns)
f->mod = TRUE; f->mod = TRUE;
} }
void void fileuninsert(File* f, Buffer* delta, uint p0, uint ns) {
fileuninsert(File *f, Buffer *delta, uint p0, uint ns)
{
Undo u; Undo u;
/* undo an insertion by deleting */ /* undo an insertion by deleting */
@ -97,9 +85,7 @@ fileuninsert(File *f, Buffer *delta, uint p0, uint ns)
bufinsert(delta, delta->nc, (Rune*)&u, Undosize); bufinsert(delta, delta->nc, (Rune*)&u, Undosize);
} }
void void filedelete(File* f, uint p0, uint p1) {
filedelete(File *f, uint p0, uint p1)
{
if (!(p0 <= p1 && p0 <= f->b.nc && p1 <= f->b.nc)) if (!(p0 <= p1 && p0 <= f->b.nc && p1 <= f->b.nc))
error("internal error: filedelete"); error("internal error: filedelete");
if (f->seq > 0) if (f->seq > 0)
@ -109,9 +95,7 @@ filedelete(File *f, uint p0, uint p1)
f->mod = TRUE; f->mod = TRUE;
} }
void void fileundelete(File* f, Buffer* delta, uint p0, uint p1) {
fileundelete(File *f, Buffer *delta, uint p0, uint p1)
{
Undo u; Undo u;
Rune* buf; Rune* buf;
uint i, n; uint i, n;
@ -132,12 +116,9 @@ fileundelete(File *f, Buffer *delta, uint p0, uint p1)
} }
fbuffree(buf); fbuffree(buf);
bufinsert(delta, delta->nc, (Rune*)&u, Undosize); bufinsert(delta, delta->nc, (Rune*)&u, Undosize);
} }
void void filesetname(File* f, Rune* name, int n) {
filesetname(File *f, Rune *name, int n)
{
if (f->seq > 0) if (f->seq > 0)
fileunsetname(f, &f->delta); fileunsetname(f, &f->delta);
free(f->name); free(f->name);
@ -147,9 +128,7 @@ filesetname(File *f, Rune *name, int n)
f->unread = TRUE; f->unread = TRUE;
} }
void void fileunsetname(File* f, Buffer* delta) {
fileunsetname(File *f, Buffer *delta)
{
Undo u; Undo u;
/* undo a file name change by restoring old name */ /* undo a file name change by restoring old name */
@ -163,18 +142,14 @@ fileunsetname(File *f, Buffer *delta)
bufinsert(delta, delta->nc, (Rune*)&u, Undosize); bufinsert(delta, delta->nc, (Rune*)&u, Undosize);
} }
uint uint fileload(File* f, uint p0, int fd, int* nulls, DigestState* h) {
fileload(File *f, uint p0, int fd, int *nulls, DigestState *h)
{
if (f->seq > 0) if (f->seq > 0)
error("undo in file.load unimplemented"); error("undo in file.load unimplemented");
return bufload(&f->b, p0, fd, nulls, h); return bufload(&f->b, p0, fd, nulls, h);
} }
/* return sequence number of pending redo */ /* return sequence number of pending redo */
uint uint fileredoseq(File* f) {
fileredoseq(File *f)
{
Undo u; Undo u;
Buffer* delta; Buffer* delta;
@ -185,9 +160,7 @@ fileredoseq(File *f)
return u.seq; return u.seq;
} }
void void fileundo(File* f, int isundo, uint* q0p, uint* q1p) {
fileundo(File *f, int isundo, uint *q0p, uint *q1p)
{
Undo u; Undo u;
Rune* buf; Rune* buf;
uint i, j, n, up; uint i, j, n, up;
@ -278,17 +251,13 @@ fileundo(File *f, int isundo, uint *q0p, uint *q1p)
fbuffree(buf); fbuffree(buf);
} }
void void filereset(File* f) {
filereset(File *f)
{
bufreset(&f->delta); bufreset(&f->delta);
bufreset(&f->epsilon); bufreset(&f->epsilon);
f->seq = 0; f->seq = 0;
} }
void void fileclose(File* f) {
fileclose(File *f)
{
free(f->name); free(f->name);
f->nname = 0; f->nname = 0;
f->name = nil; f->name = nil;
@ -302,9 +271,7 @@ fileclose(File *f)
free(f); free(f);
} }
void void filemark(File* f) {
filemark(File *f)
{
if (f->epsilon.nc) if (f->epsilon.nc)
bufdelete(&f->epsilon, 0, f->epsilon.nc); bufdelete(&f->epsilon, 0, f->epsilon.nc);
f->seq = seq; f->seq = seq;

1
fns.h
View file

@ -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);

159
fsys.c
View file

@ -14,11 +14,7 @@
static int sfd; static int sfd;
enum enum { Nhash = 16, DEBUG = 0 };
{
Nhash = 16,
DEBUG = 0
};
static Fid* fids[Nhash]; static Fid* fids[Nhash];
@ -40,9 +36,7 @@ static Xfid* fsyswstat(Xfid*, Fid*);
Xfid* (*fcall[Tmax])(Xfid*, Fid*); Xfid* (*fcall[Tmax])(Xfid*, Fid*);
static void static void initfcall(void) {
initfcall(void)
{
fcall[Tflush] = fsysflush; fcall[Tflush] = fsysflush;
fcall[Tversion] = fsysversion; fcall[Tversion] = fsysversion;
fcall[Tauth] = fsysauth; fcall[Tauth] = fsysauth;
@ -62,23 +56,25 @@ char Eperm[] = "permission denied";
char Eexist[] = "file does not exist"; char Eexist[] = "file does not exist";
char Enotdir[] = "not a directory"; char Enotdir[] = "not a directory";
Dirtab dirtab[]= Dirtab dirtab[] = {
{
{".", QTDIR, Qdir, 0500 | DMDIR}, {".", QTDIR, Qdir, 0500 | DMDIR},
{"acme", QTDIR, Qacme, 0500 | DMDIR}, {"acme", QTDIR, Qacme, 0500 | DMDIR},
{"cons", QTFILE, Qcons, 0600}, {"cons", QTFILE, Qcons, 0600},
{"consctl", QTFILE, Qconsctl, 0000}, {"consctl", QTFILE, Qconsctl, 0000},
{ "draw", QTDIR, Qdraw, 0000|DMDIR }, /* to suppress graphics progs started in acme */ {"draw",
QTDIR,
Qdraw,
0000 | DMDIR}, /* to suppress graphics progs started in acme */
{"editout", QTFILE, Qeditout, 0200}, {"editout", QTFILE, Qeditout, 0200},
{"index", QTFILE, Qindex, 0400}, {"index", QTFILE, Qindex, 0400},
{"label", QTFILE, Qlabel, 0600}, {"label", QTFILE, Qlabel, 0600},
{"log", QTFILE, Qlog, 0400}, {"log", QTFILE, Qlog, 0400},
{"new", QTDIR, Qnew, 0500 | DMDIR}, {"new", QTDIR, Qnew, 0500 | DMDIR},
{ nil, }
};
Dirtab dirtabw[]=
{ {
nil,
}};
Dirtab dirtabw[] = {
{".", QTDIR, Qdir, 0500 | DMDIR}, {".", QTDIR, Qdir, 0500 | DMDIR},
{"addr", QTFILE, QWaddr, 0600}, {"addr", QTFILE, QWaddr, 0600},
{"body", QTAPPEND, QWbody, 0600 | DMAPPEND}, {"body", QTAPPEND, QWbody, 0600 | DMAPPEND},
@ -91,12 +87,12 @@ Dirtab dirtabw[]=
{"wrsel", QTFILE, QWwrsel, 0200}, {"wrsel", QTFILE, QWwrsel, 0200},
{"tag", QTAPPEND, QWtag, 0600 | DMAPPEND}, {"tag", QTAPPEND, QWtag, 0600 | DMAPPEND},
{"xdata", QTFILE, QWxdata, 0600}, {"xdata", QTFILE, QWxdata, 0600},
{ nil, } {
}; nil,
}};
typedef struct Mnt Mnt; typedef struct Mnt Mnt;
struct Mnt struct Mnt {
{
QLock lk; QLock lk;
int id; int id;
Mntdir* md; Mntdir* md;
@ -114,9 +110,7 @@ int messagesize = Maxblock+IOHDRSZ; /* good start */
void fsysproc(void*); void fsysproc(void*);
void void fsysinit(void) {
fsysinit(void)
{
int p[2]; int p[2];
char* u; char* u;
@ -132,9 +126,7 @@ fsysinit(void)
proccreate(fsysproc, nil, STACK); proccreate(fsysproc, nil, STACK);
} }
void void fsysproc(void* v) {
fsysproc(void *v)
{
int n; int n;
Xfid* x; Xfid* x;
Fid* f; Fid* f;
@ -146,7 +138,9 @@ fsysproc(void *v)
USED(v); USED(v);
x = nil; x = nil;
for (;;) { for (;;) {
buf = emalloc(messagesize+UTFmax); /* overflow for appending partial rune in xfidwrite */ buf = emalloc(
messagesize +
UTFmax); /* overflow for appending partial rune in xfidwrite */
n = read9pmsg(sfd, buf, messagesize); n = read9pmsg(sfd, buf, messagesize);
if (n <= 0) { if (n <= 0) {
if (closing) if (closing)
@ -189,9 +183,7 @@ fsysproc(void *v)
} }
} }
Mntdir* Mntdir* fsysaddid(Rune* dir, int ndir, Rune** incl, int nincl) {
fsysaddid(Rune *dir, int ndir, Rune **incl, int nincl)
{
Mntdir* m; Mntdir* m;
int id; int id;
@ -210,17 +202,13 @@ fsysaddid(Rune *dir, int ndir, Rune **incl, int nincl)
return m; return m;
} }
void void fsysincid(Mntdir* m) {
fsysincid(Mntdir *m)
{
qlock(&mnt.lk); qlock(&mnt.lk);
m->ref++; m->ref++;
qunlock(&mnt.lk); qunlock(&mnt.lk);
} }
void void fsysdelid(Mntdir* idm) {
fsysdelid(Mntdir *idm)
{
Mntdir *m, *prev; Mntdir *m, *prev;
int i; int i;
char buf[64]; char buf[64];
@ -257,15 +245,11 @@ fsysdelid(Mntdir *idm)
/* /*
* Called only in exec.c:/^run(), from a different FD group * Called only in exec.c:/^run(), from a different FD group
*/ */
Mntdir* Mntdir* fsysmount(Rune* dir, int ndir, Rune** incl, int nincl) {
fsysmount(Rune *dir, int ndir, Rune **incl, int nincl)
{
return fsysaddid(dir, ndir, incl, nincl); return fsysaddid(dir, ndir, incl, nincl);
} }
void void fsysclose(void) {
fsysclose(void)
{
closing = 1; closing = 1;
/* /*
* apparently this is not kosher on openbsd. * apparently this is not kosher on openbsd.
@ -275,9 +259,7 @@ fsysclose(void)
*/ */
} }
Xfid* Xfid* respond(Xfid* x, Fcall* t, char* err) {
respond(Xfid *x, Fcall *t, char *err)
{
int n; int n;
if (err) { if (err) {
@ -301,10 +283,7 @@ respond(Xfid *x, Fcall *t, char *err)
return x; return x;
} }
static static Xfid* fsysversion(Xfid* x, Fid* f) {
Xfid*
fsysversion(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
USED(f); USED(f);
@ -318,29 +297,20 @@ fsysversion(Xfid *x, Fid *f)
return respond(x, &t, nil); return respond(x, &t, nil);
} }
static static Xfid* fsysauth(Xfid* x, Fid* f) {
Xfid*
fsysauth(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
USED(f); USED(f);
return respond(x, &t, "acme: authentication not required"); return respond(x, &t, "acme: authentication not required");
} }
static static Xfid* fsysflush(Xfid* x, Fid* f) {
Xfid*
fsysflush(Xfid *x, Fid *f)
{
USED(f); USED(f);
sendp(x->c, (void*)xfidflush); sendp(x->c, (void*)xfidflush);
return nil; return nil;
} }
static static Xfid* fsysattach(Xfid* x, Fid* f) {
Xfid*
fsysattach(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
int id; int id;
Mntdir* m; Mntdir* m;
@ -374,10 +344,7 @@ fsysattach(Xfid *x, Fid *f)
return respond(x, &t, nil); return respond(x, &t, nil);
} }
static static Xfid* fsyswalk(Xfid* x, Fid* f) {
Xfid*
fsyswalk(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
int c, i, j, id; int c, i, j, id;
Qid q; Qid q;
@ -519,10 +486,7 @@ fsyswalk(Xfid *x, Fid *f)
return respond(x, &t, err); return respond(x, &t, err);
} }
static static Xfid* fsysopen(Xfid* x, Fid* f) {
Xfid*
fsysopen(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
int m; int m;
@ -554,27 +518,16 @@ fsysopen(Xfid *x, Fid *f)
return respond(x, &t, Eperm); return respond(x, &t, Eperm);
} }
static static Xfid* fsyscreate(Xfid* x, Fid* f) {
Xfid*
fsyscreate(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
USED(f); USED(f);
return respond(x, &t, Eperm); return respond(x, &t, Eperm);
} }
static static int idcmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int
idcmp(const void *a, const void *b)
{
return *(int*)a - *(int*)b;
}
static static Xfid* fsysread(Xfid* x, Fid* f) {
Xfid*
fsysread(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
uchar* b; uchar* b;
int i, id, n, o, e, j, k, *ids, nids; int i, id, n, o, e, j, k, *ids, nids;
@ -649,60 +602,44 @@ fsysread(Xfid *x, Fid *f)
return nil; return nil;
} }
static static Xfid* fsyswrite(Xfid* x, Fid* f) {
Xfid*
fsyswrite(Xfid *x, Fid *f)
{
USED(f); USED(f);
sendp(x->c, (void*)xfidwrite); sendp(x->c, (void*)xfidwrite);
return nil; return nil;
} }
static static Xfid* fsysclunk(Xfid* x, Fid* f) {
Xfid*
fsysclunk(Xfid *x, Fid *f)
{
fsysdelid(f->mntdir); fsysdelid(f->mntdir);
sendp(x->c, (void*)xfidclose); sendp(x->c, (void*)xfidclose);
return nil; return nil;
} }
static static Xfid* fsysremove(Xfid* x, Fid* f) {
Xfid*
fsysremove(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
USED(f); USED(f);
return respond(x, &t, Eperm); return respond(x, &t, Eperm);
} }
static static Xfid* fsysstat(Xfid* x, Fid* f) {
Xfid*
fsysstat(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
t.stat = emalloc(messagesize - IOHDRSZ); t.stat = emalloc(messagesize - IOHDRSZ);
t.nstat = dostat(WIN(x->f->qid), f->dir, t.stat, messagesize-IOHDRSZ, getclock()); t.nstat =
dostat(WIN(x->f->qid), f->dir, t.stat, messagesize - IOHDRSZ, getclock());
x = respond(x, &t, nil); x = respond(x, &t, nil);
free(t.stat); free(t.stat);
return x; return x;
} }
static static Xfid* fsyswstat(Xfid* x, Fid* f) {
Xfid*
fsyswstat(Xfid *x, Fid *f)
{
Fcall t; Fcall t;
USED(f); USED(f);
return respond(x, &t, Eperm); return respond(x, &t, Eperm);
} }
Fid* Fid* newfid(int fid) {
newfid(int fid)
{
Fid *f, *ff, **fh; Fid *f, *ff, **fh;
ff = nil; ff = nil;
@ -723,15 +660,9 @@ newfid(int fid)
return f; return f;
} }
uint uint getclock(void) { return time(0); }
getclock(void)
{
return time(0);
}
int int dostat(int id, Dirtab* dir, uchar* buf, int nbuf, uint clock) {
dostat(int id, Dirtab *dir, uchar *buf, int nbuf, uint clock)
{
Dir d; Dir d;
d.qid.path = QID(id, dir->qid); d.qid.path = QID(id, dir->qid);

31
logf.c
View file

@ -14,8 +14,7 @@
// State for global log file. // State for global log file.
typedef struct Log Log; typedef struct Log Log;
struct Log struct Log {
{
QLock lk; QLock lk;
Rendez r; Rendez r;
@ -39,9 +38,7 @@ struct Log
static Log eventlog; static Log eventlog;
void void xfidlogopen(Xfid* x) {
xfidlogopen(Xfid *x)
{
qlock(&eventlog.lk); qlock(&eventlog.lk);
if (eventlog.nf >= eventlog.mf) { if (eventlog.nf >= eventlog.mf) {
eventlog.mf = eventlog.mf * 2; eventlog.mf = eventlog.mf * 2;
@ -55,9 +52,7 @@ xfidlogopen(Xfid *x)
qunlock(&eventlog.lk); qunlock(&eventlog.lk);
} }
void void xfidlogclose(Xfid* x) {
xfidlogclose(Xfid *x)
{
int i; int i;
qlock(&eventlog.lk); qlock(&eventlog.lk);
@ -70,9 +65,7 @@ xfidlogclose(Xfid *x)
qunlock(&eventlog.lk); qunlock(&eventlog.lk);
} }
void void xfidlogread(Xfid* x) {
xfidlogread(Xfid *x)
{
char* p; char* p;
int i; int i;
Fcall fc; Fcall fc;
@ -82,7 +75,8 @@ xfidlogread(Xfid *x)
eventlog.mread = eventlog.mread * 2; eventlog.mread = eventlog.mread * 2;
if (eventlog.mread == 0) if (eventlog.mread == 0)
eventlog.mread = 8; eventlog.mread = 8;
eventlog.read = erealloc(eventlog.read, eventlog.mread*sizeof eventlog.read[0]); eventlog.read =
erealloc(eventlog.read, eventlog.mread * sizeof eventlog.read[0]);
} }
eventlog.read[eventlog.nread++] = x; eventlog.read[eventlog.nread++] = x;
@ -115,9 +109,7 @@ xfidlogread(Xfid *x)
free(p); free(p);
} }
void void xfidlogflush(Xfid* x) {
xfidlogflush(Xfid *x)
{
int i; int i;
Xfid* rx; Xfid* rx;
@ -153,9 +145,7 @@ xfidlogflush(Xfid *x)
* op == "del" for deleted window * op == "del" for deleted window
* - called from winclose * - called from winclose
*/ */
void void xfidlog(Window* w, char* op) {
xfidlog(Window *w, char *op)
{
int i, n; int i, n;
vlong min; vlong min;
File* f; File* f;
@ -175,7 +165,10 @@ xfidlog(Window *w, char *op)
free(eventlog.ev[i]); free(eventlog.ev[i]);
eventlog.nev -= n; eventlog.nev -= n;
eventlog.start += n; eventlog.start += n;
memmove(eventlog.ev, eventlog.ev+n, eventlog.nev*sizeof eventlog.ev[0]); memmove(
eventlog.ev,
eventlog.ev + n,
eventlog.nev * sizeof eventlog.ev[0]);
} }
// Otherwise grow. // Otherwise grow.

205
look.c
View file

@ -21,9 +21,7 @@ Window* openfile(Text*, Expand*);
int nuntitled; int nuntitled;
void void plumbthread(void* v) {
plumbthread(void *v)
{
CFid* fid; CFid* fid;
Plumbmsg* m; Plumbmsg* m;
Timer* t; Timer* t;
@ -70,18 +68,13 @@ plumbthread(void *v)
} }
} }
void void startplumbing(void) {
startplumbing(void)
{
cplumb = chancreate(sizeof(Plumbmsg*), 0); cplumb = chancreate(sizeof(Plumbmsg*), 0);
chansetname(cplumb, "cplumb"); chansetname(cplumb, "cplumb");
threadcreate(plumbthread, nil, STACK); threadcreate(plumbthread, nil, STACK);
} }
void look3(Text* t, uint q0, uint q1, int external) {
void
look3(Text *t, uint q0, uint q1, int external)
{
int n, c, f, expanded; int n, c, f, expanded;
Text* ct; Text* ct;
Expand e; Expand e;
@ -100,7 +93,9 @@ look3(Text *t, uint q0, uint q1, int external)
if (expanded == FALSE) if (expanded == FALSE)
return; return;
f = 0; f = 0;
if((e.u.at!=nil && t->w!=nil) || (e.nname>0 && lookfile(e.name, e.nname)!=nil)) if (
(e.u.at != nil && t->w != nil) ||
(e.nname > 0 && lookfile(e.name, e.nname) != nil))
f = 1; /* acme can do it without loading a file */ f = 1; /* acme can do it without loading a file */
if (q0 != e.q0 || q1 != e.q1) if (q0 != e.q0 || q1 != e.q1)
f |= 2; /* second (post-expand) message follows */ f |= 2; /* second (post-expand) message follows */
@ -167,9 +162,11 @@ look3(Text *t, uint q0, uint q1, int external)
q1 = t->q1; q1 = t->q1;
} else { } else {
p = q0; p = q0;
while(q0>0 && (c=tgetc(t, q0-1))!=' ' && c!='\t' && c!='\n') while (q0 > 0 && (c = tgetc(t, q0 - 1)) != ' ' && c != '\t' &&
c != '\n')
q0--; q0--;
while(q1<t->file->b.nc && (c=tgetc(t, q1))!=' ' && c!='\t' && c!='\n') while (q1 < t->file->b.nc && (c = tgetc(t, q1)) != ' ' && c != '\t' &&
c != '\n')
q1++; q1++;
if (q1 == q0) { if (q1 == q0) {
plumbfree(m); plumbfree(m);
@ -209,7 +206,9 @@ look3(Text *t, uint q0, uint q1, int external)
r = runemalloc(n); r = runemalloc(n);
bufread(&t->file->b, e.q0, r, n); bufread(&t->file->b, e.q0, r, n);
if (search(ct, r, n) && e.jump) if (search(ct, r, n) && e.jump)
moveto(mousectl, addpt(frptofchar(&ct->fr, ct->fr.p0), Pt(4, ct->fr.font->height-4))); moveto(
mousectl,
addpt(frptofchar(&ct->fr, ct->fr.p0), Pt(4, ct->fr.font->height - 4)));
if (t->w != ct->w) if (t->w != ct->w)
winunlock(ct->w); winunlock(ct->w);
free(r); free(r);
@ -220,9 +219,7 @@ look3(Text *t, uint q0, uint q1, int external)
free(e.bname); free(e.bname);
} }
int int plumbgetc(void* a, uint n) {
plumbgetc(void *a, uint n)
{
Rune* r; Rune* r;
r = a; r = a;
@ -231,14 +228,16 @@ plumbgetc(void *a, uint n)
return r[n]; return r[n];
} }
void void plumblook(Plumbmsg* m) {
plumblook(Plumbmsg *m)
{
Expand e; Expand e;
char* addr; char* addr;
if (m->ndata >= BUFSIZE) { if (m->ndata >= BUFSIZE) {
warning(nil, "insanely long file name (%d bytes) in plumb message (%.32s...)\n", m->ndata, m->data); warning(
nil,
"insanely long file name (%d bytes) in plumb message (%.32s...)\n",
m->ndata,
m->data);
return; return;
} }
e.q0 = 0; e.q0 = 0;
@ -262,9 +261,7 @@ plumblook(Plumbmsg *m)
free(e.u.at); free(e.u.at);
} }
void void plumbshow(Plumbmsg* m) {
plumbshow(Plumbmsg *m)
{
Window* w; Window* w;
Rune rb[256], *r; Rune rb[256], *r;
int nb, nr; int nb, nr;
@ -302,9 +299,7 @@ plumbshow(Plumbmsg *m)
xfidlog(w, "new"); xfidlog(w, "new");
} }
int int search(Text* ct, Rune* r, uint n) {
search(Text *ct, Rune *r, uint n)
{
uint q, nb, maxn; uint q, nb, maxn;
int around; int around;
Rune *s, *b, *c; Rune *s, *b, *c;
@ -375,9 +370,7 @@ search(Text *ct, Rune *r, uint n)
return FALSE; return FALSE;
} }
int int isfilec(Rune r) {
isfilec(Rune r)
{
static Rune Lx[] = {'.', '-', '+', '/', ':', 0}; static Rune Lx[] = {'.', '-', '+', '/', ':', 0};
if (isalnum(r)) if (isalnum(r))
return TRUE; return TRUE;
@ -387,9 +380,7 @@ isfilec(Rune r)
} }
/* Runestr wrapper for cleanname */ /* Runestr wrapper for cleanname */
Runestr Runestr cleanrname(Runestr rs) {
cleanrname(Runestr rs)
{
char* s; char* s;
int nb, nulls; int nb, nulls;
@ -400,9 +391,7 @@ cleanrname(Runestr rs)
return rs; return rs;
} }
Runestr Runestr includefile(Rune* dir, Rune* file, int nfile) {
includefile(Rune *dir, Rune *file, int nfile)
{
int m, n; int m, n;
char* a; char* a;
Rune* r; Rune* r;
@ -425,17 +414,36 @@ includefile(Rune *dir, Rune *file, int nfile)
static Rune* objdir; static Rune* objdir;
Runestr Runestr includename(Text* t, Rune* r, int n) {
includename(Text *t, Rune *r, int n)
{
Window* w; Window* w;
char buf[128]; char buf[128];
Rune Lsysinclude[] = { '/', 's', 'y', 's', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 }; Rune Lsysinclude[] =
Rune Lusrinclude[] = { '/', 'u', 's', 'r', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 }; {'/', 's', 'y', 's', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0};
Rune Lusrlocalinclude[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l', Rune Lusrinclude[] =
'/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 }; {'/', 'u', 's', 'r', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0};
Rune Lusrlocalplan9include[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l', Rune Lusrlocalinclude[] = {
'/', 'p', 'l', 'a', 'n', '9', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 }; '/',
'u',
's',
'r',
'/',
'l',
'o',
'c',
'a',
'l',
'/',
'i',
'n',
'c',
'l',
'u',
'd',
'e',
0};
Rune Lusrlocalplan9include[] = {'/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a',
'l', '/', 'p', 'l', 'a', 'n', '9', '/', 'i',
'n', 'c', 'l', 'u', 'd', 'e', 0};
Runestr file; Runestr file;
int i; int i;
@ -474,12 +482,10 @@ includename(Text *t, Rune *r, int n)
return runestr(r, n); return runestr(r, n);
} }
Runestr Runestr dirname(Text* t, Rune* r, int n) {
dirname(Text *t, Rune *r, int n) Rune* b;
{ uint nt;
Rune *b, c; int slash, i;
uint m, nt;
int slash;
Runestr tmp; Runestr tmp;
b = nil; b = nil;
@ -490,16 +496,14 @@ 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;
runemove(b + slash + 1, r, n); runemove(b + slash + 1, r, n);
@ -514,9 +518,7 @@ dirname(Text *t, Rune *r, int n)
return tmp; return tmp;
} }
static int static int texthas(Text* t, uint q0, Rune* r) {
texthas(Text *t, uint q0, Rune *r)
{
int i; int i;
if ((int)q0 < 0) if ((int)q0 < 0)
@ -527,9 +529,7 @@ texthas(Text *t, uint q0, Rune *r)
return TRUE; return TRUE;
} }
int int expandfile(Text* t, uint q0, uint q1, Expand* e) {
expandfile(Text *t, uint q0, uint q1, Expand *e)
{
int i, n, nname, colon, eval; int i, n, nname, colon, eval;
uint amin, amax; uint amin, amax;
Rune *r, c; Rune *r, c;
@ -542,15 +542,20 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
if (q1 == q0) { if (q1 == q0) {
colon = -1; colon = -1;
while (q1 < t->file->b.nc && isfilec(c = textreadc(t, q1))) { while (q1 < t->file->b.nc && isfilec(c = textreadc(t, q1))) {
if(c == ':' && !texthas(t, q1-4, Lhttpcss) && !texthas(t, q1-5, Lhttpscss)){ if (
c == ':' && !texthas(t, q1 - 4, Lhttpcss) &&
!texthas(t, q1 - 5, Lhttpscss)) {
colon = q1; colon = q1;
break; break;
} }
q1++; q1++;
} }
while(q0>0 && (isfilec(c=textreadc(t, q0-1)) || isaddrc(c) || isregexc(c))){ while (q0 > 0 &&
(isfilec(c = textreadc(t, q0 - 1)) || isaddrc(c) || isregexc(c))) {
q0--; q0--;
if(colon<0 && c==':' && !texthas(t, q0-4, Lhttpcss) && !texthas(t, q0-5, Lhttpscss)) if (
colon < 0 && c == ':' && !texthas(t, q0 - 4, Lhttpcss) &&
!texthas(t, q0 - 5, Lhttpscss))
colon = q0; colon = q0;
} }
/* /*
@ -602,7 +607,9 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
c = r[i]; c = r[i];
if (c == ':' && nname < 0) { if (c == ':' && nname < 0) {
if(q0+i+1<t->file->b.nc && (i==n-1 || isaddrc(textreadc(t, q0+i+1)))) if (
q0 + i + 1 < t->file->b.nc &&
(i == n - 1 || isaddrc(textreadc(t, q0 + i + 1))))
amin = q0 + i; amin = q0 + i;
else else
goto Isntfile; goto Isntfile;
@ -612,7 +619,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
if (nname == -1) if (nname == -1)
nname = n; nname = n;
for (i = 0; i < nname; i++) for (i = 0; i < nname; i++)
if(!isfilec(r[i])) if (!isfilec(r[i]) && r[i] != ' ')
goto Isntfile; goto Isntfile;
/* /*
* See if it's a file name in <>, and turn that into an include * See if it's a file name in <>, and turn that into an include
@ -620,12 +627,13 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
* restrictive enough syntax and checking for a #include earlier on the * restrictive enough syntax and checking for a #include earlier on the
* line would be silly. * line would be silly.
*/ */
if(q0>0 && textreadc(t, q0-1)=='<' && q1<t->file->b.nc && textreadc(t, q1)=='>'){ if (
q0 > 0 && textreadc(t, q0 - 1) == '<' && q1 < t->file->b.nc &&
textreadc(t, q1) == '>') {
rs = includename(t, r, nname); rs = includename(t, r, nname);
r = rs.r; r = rs.r;
nname = rs.nr; nname = rs.nr;
} } else if (amin == q0)
else if(amin == q0)
goto Isfile; goto Isfile;
else { else {
rs = dirname(t, r, nname); rs = dirname(t, r, nname);
@ -650,7 +658,17 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
e->u.at = t; e->u.at = t;
e->a0 = amin + 1; e->a0 = amin + 1;
eval = FALSE; eval = FALSE;
address(TRUE, nil, range(-1,-1), range(0,0), t, e->a0, amax, tgetc, &eval, (uint*)&e->a1); address(
TRUE,
nil,
range(-1, -1),
range(0, 0),
t,
e->a0,
amax,
tgetc,
&eval,
(uint*)&e->a1);
return TRUE; return TRUE;
Isntfile: Isntfile:
@ -658,9 +676,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
return FALSE; return FALSE;
} }
int int expand(Text* t, uint q0, uint q1, Expand* e) {
expand(Text *t, uint q0, uint q1, Expand *e)
{
memset(e, 0, sizeof *e); memset(e, 0, sizeof *e);
e->agetc = tgetc; e->agetc = tgetc;
/* if in selection, choose selection */ /* if in selection, choose selection */
@ -686,9 +702,7 @@ expand(Text *t, uint q0, uint q1, Expand *e)
return q1 > q0; return q1 > q0;
} }
Window* Window* lookfile(Rune* s, int n) {
lookfile(Rune *s, int n)
{
int i, j, k; int i, j, k;
Window* w; Window* w;
Column* c; Column* c;
@ -715,9 +729,7 @@ lookfile(Rune *s, int n)
return nil; return nil;
} }
Window* Window* lookid(int id, int dump) {
lookid(int id, int dump)
{
int i, j; int i, j;
Window* w; Window* w;
Column* c; Column* c;
@ -735,10 +747,7 @@ lookid(int id, int dump)
return nil; return nil;
} }
Window* openfile(Text* t, Expand* e) {
Window*
openfile(Text *t, Expand *e)
{
Range r; Range r;
Window *w, *ow; Window *w, *ow;
int eval, i, n; int eval, i, n;
@ -777,7 +786,8 @@ openfile(Text *t, Expand *e)
} }
if (w) { if (w) {
t = &w->body; t = &w->body;
if(!t->col->safe && t->fr.maxlines==0) /* window is obscured by full-column window */ if (!t->col->safe && t->fr.maxlines == 0) /* window is obscured by
full-column window */
colgrow(t->col, t->col->w[0], 1); colgrow(t->col, t->col->w[0], 1);
} else { } else {
ow = nil; ow = nil;
@ -810,7 +820,17 @@ openfile(Text *t, Expand *e)
eval = FALSE; eval = FALSE;
else { else {
eval = TRUE; eval = TRUE;
r = address(TRUE, t, range(-1,-1), range(t->q0, t->q1), e->u.at, e->a0, e->a1, e->agetc, &eval, &dummy); r = address(
TRUE,
t,
range(-1, -1),
range(t->q0, t->q1),
e->u.at,
e->a0,
e->a1,
e->agetc,
&eval,
&dummy);
if (r.q0 > r.q1) { if (r.q0 > r.q1) {
eval = FALSE; eval = FALSE;
warning(nil, "addresses out of order\n"); warning(nil, "addresses out of order\n");
@ -826,13 +846,14 @@ openfile(Text *t, Expand *e)
winsettag(t->w); winsettag(t->w);
seltext = t; seltext = t;
if (e->jump) if (e->jump)
moveto(mousectl, addpt(frptofchar(&t->fr, t->fr.p0), Pt(4, font->height-4))); moveto(
mousectl,
addpt(frptofchar(&t->fr, t->fr.p0), Pt(4, font->height - 4)));
return w; return w;
} }
void void new (
new(Text *et, Text *t, Text *argt, int flag1, int flag2, Rune *arg, int narg) Text* et, Text* t, Text* argt, int flag1, int flag2, Rune* arg, int narg) {
{
int ndone; int ndone;
Rune *a, *f; Rune *a, *f;
int na, nf; int na, nf;

View file

@ -7,9 +7,7 @@
#include <9pclient.h> #include <9pclient.h>
#include "dat.h" #include "dat.h"
char* char* formathtml(char* body, int* np) {
formathtml(char *body, int *np)
{
int i, j, p[2], q[2]; int i, j, p[2], q[2];
Exec* e; Exec* e;
char buf[1024]; char buf[1024];
@ -63,9 +61,7 @@ formathtml(char *body, int *np)
return body; return body;
} }
char* char* readbody(char* type, char* dir, int* np) {
readbody(char *type, char *dir, int *np)
{
char* body; char* body;
body = readfile(dir, "body", np); body = readfile(dir, "body", np);

Binary file not shown.

View file

@ -40,16 +40,15 @@ int shortmenu;
CFsys* mailfs; CFsys* mailfs;
CFsys* acmefs; CFsys* acmefs;
void void usage(void) {
usage(void) fprint(
{ 2,
fprint(2, "usage: Mail [-sS] [-n srvname] [-o outgoing] [mailboxname [directoryname]]\n"); "usage: Mail [-sS] [-n srvname] [-o outgoing] [mailboxname "
"[directoryname]]\n");
threadexitsall("usage"); threadexitsall("usage");
} }
void void removeupasfs(void) {
removeupasfs(void)
{
char buf[256]; char buf[256];
if (strcmp(mboxname, "mbox") == 0) if (strcmp(mboxname, "mbox") == 0)
@ -58,9 +57,7 @@ removeupasfs(void)
fswrite(mbox.ctlfd, buf, strlen(buf)); fswrite(mbox.ctlfd, buf, strlen(buf));
} }
int int ismaildir(char* s) {
ismaildir(char *s)
{
Dir* d; Dir* d;
int ret; int ret;
@ -72,9 +69,7 @@ ismaildir(char *s)
return ret; return ret;
} }
void void threadmain(int argc, char* argv[]) {
threadmain(int argc, char *argv[])
{
char *s, *name; char *s, *name;
char err[ERRMAX], *cmd; char err[ERRMAX], *cmd;
int i, newdir; int i, newdir;
@ -83,7 +78,8 @@ threadmain(int argc, char *argv[])
doquote = needsrcquote; doquote = needsrcquote;
quotefmtinstall(); quotefmtinstall();
/* open these early so we won't miss notification of new mail messages while we read mbox */ /* open these early so we won't miss notification of new mail messages while
* we read mbox */
if ((plumbsendfd = plumbopenfid("send", OWRITE | OCEXEC)) == nil) if ((plumbsendfd = plumbopenfid("send", OWRITE | OCEXEC)) == nil)
fprint(2, "warning: open plumb/send: %r\n"); fprint(2, "warning: open plumb/send: %r\n");
if ((plumbseemailfd = plumbopenfid("seemail", OREAD | OCEXEC)) == nil) if ((plumbseemailfd = plumbopenfid("seemail", OREAD | OCEXEC)) == nil)
@ -111,7 +107,8 @@ threadmain(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
}ARGEND }
ARGEND
acmefs = nsmount("acme", nil); acmefs = nsmount("acme", nil);
if (acmefs == nil) if (acmefs == nil)
@ -171,7 +168,8 @@ threadmain(int argc, char *argv[])
fsname = estrdup(name); fsname = estrdup(name);
if (newdir && argc > 0) { if (newdir && argc > 0) {
s = emalloc(5+strlen(mailboxdir)+strlen(mboxname)+strlen(name)+10+1); s = emalloc(
5 + strlen(mailboxdir) + strlen(mboxname) + strlen(name) + 10 + 1);
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
sprint(s, "open %s/%s %s", mailboxdir, mboxname, fsname); sprint(s, "open %s/%s %s", mailboxdir, mboxname, fsname);
if (fswrite(mbox.ctlfd, s, strlen(s)) >= 0) if (fswrite(mbox.ctlfd, s, strlen(s)) >= 0)
@ -241,9 +239,7 @@ threadmain(int argc, char *argv[])
plumbthread(); plumbthread();
} }
void void plumbproc(void* v) {
plumbproc(void* v)
{
Plumbmsg* m; Plumbmsg* m;
threadsetname("plumbproc"); threadsetname("plumbproc");
@ -255,9 +251,7 @@ plumbproc(void* v)
} }
} }
void void plumbshowproc(void* v) {
plumbshowproc(void* v)
{
Plumbmsg* m; Plumbmsg* m;
threadsetname("plumbshowproc"); threadsetname("plumbshowproc");
@ -269,9 +263,7 @@ plumbshowproc(void* v)
} }
} }
void void plumbsendproc(void* v) {
plumbsendproc(void* v)
{
Plumbmsg* m; Plumbmsg* m;
threadsetname("plumbsendproc"); threadsetname("plumbsendproc");
@ -283,9 +275,7 @@ plumbsendproc(void* v)
} }
} }
void void newmesg(char* name, char* digest) {
newmesg(char *name, char *digest)
{
Dir* d; Dir* d;
if (strncmp(name, mbox.name, strlen(mbox.name)) != 0) if (strncmp(name, mbox.name, strlen(mbox.name)) != 0)
@ -302,9 +292,7 @@ newmesg(char *name, char *digest)
free(d); free(d);
} }
void void showmesg(char* name, char* digest) {
showmesg(char *name, char *digest)
{
char* n; char* n;
char* mb; char* mb;
@ -318,9 +306,7 @@ showmesg(char *name, char *digest)
free(n); free(n);
} }
void void delmesg(char* name, char* digest, int dodel, char* save) {
delmesg(char *name, char *digest, int dodel, char *save)
{
Message* m; Message* m;
m = mesglookupfile(&mbox, name, digest); m = mesglookupfile(&mbox, name, digest);
@ -338,9 +324,7 @@ delmesg(char *name, char *digest, int dodel, char *save)
} }
} }
void void plumbthread(void) {
plumbthread(void)
{
Plumbmsg* m; Plumbmsg* m;
Plumbattr* a; Plumbattr* a;
char *type, *digest; char *type, *digest;
@ -363,9 +347,7 @@ plumbthread(void)
threadexits(nil); threadexits(nil);
} }
void void plumbshowthread(void* v) {
plumbshowthread(void *v)
{
Plumbmsg* m; Plumbmsg* m;
USED(v); USED(v);
@ -377,9 +359,7 @@ plumbshowthread(void *v)
threadexits(nil); threadexits(nil);
} }
void void plumbsendthread(void* v) {
plumbsendthread(void *v)
{
Plumbmsg* m; Plumbmsg* m;
USED(v); USED(v);
@ -391,9 +371,7 @@ plumbsendthread(void *v)
threadexits(nil); threadexits(nil);
} }
int int mboxcommand(Window* w, char* s) {
mboxcommand(Window *w, char *s)
{
char *args[10], **targs, *save; char *args[10], **targs, *save;
Window* sbox; Window* sbox;
Message *m, *next; Message *m, *next;
@ -466,7 +444,8 @@ mboxcommand(Window *w, char *s)
for (i = 0; s[i]; i++) for (i = 0; s[i]; i++)
if (s[i] == '\n') if (s[i] == '\n')
nargs++; nargs++;
targs = emalloc(nargs*sizeof(char*)); /* could be too many for a local array */ targs =
emalloc(nargs * sizeof(char*)); /* could be too many for a local array */
nargs = getfields(s, targs, nargs, 1, "\n"); nargs = getfields(s, targs, nargs, 1, "\n");
for (i = 0; i < nargs; i++) { for (i = 0; i < nargs; i++) {
if (!isdigit(targs[i][0])) if (!isdigit(targs[i][0]))
@ -517,14 +496,16 @@ mboxcommand(Window *w, char *s)
/* show results in reverse order */ /* show results in reverse order */
m = mbox.tail; m = mbox.tail;
save = nil; save = nil;
for(s=strrchr(res, ' '); s!=nil || save!=res; s=strrchr(res, ' ')){ for (s = strrchr(res, ' '); s != nil || save != res;
s = strrchr(res, ' ')) {
if (s != nil) { if (s != nil) {
save = s + 1; save = s + 1;
*s = '\0'; *s = '\0';
} } else
else save = res; save = res;
save = estrstrdup(save, "/"); save = estrstrdup(save, "/");
for(; m && strcmp(save, m->name) != 0; m=m->prev); for (; m && strcmp(save, m->name) != 0; m = m->prev)
;
free(save); free(save);
if (m == nil) if (m == nil)
break; break;
@ -539,9 +520,7 @@ mboxcommand(Window *w, char *s)
return 0; return 0;
} }
void void mainctl(void* v) {
mainctl(void *v)
{
Window* w; Window* w;
Event *e, *e2, *eq, *ea; Event *e, *e2, *eq, *ea;
int na, nopen; int na, nopen;
@ -641,4 +620,3 @@ mainctl(void *v)
} }
} }
} }

Binary file not shown.

View file

@ -7,10 +7,7 @@
#include <plumb.h> #include <plumb.h>
#include "dat.h" #include "dat.h"
enum enum { DIRCHUNK = 32 * sizeof(Dir) };
{
DIRCHUNK = 32*sizeof(Dir)
};
char regexchars[] = "\\/[].+?()*^$"; char regexchars[] = "\\/[].+?()*^$";
char deleted[] = "(deleted)-"; char deleted[] = "(deleted)-";
@ -23,17 +20,35 @@ struct{
char* port; char* port;
char* suffix; char* suffix;
} ports[] = { } ports[] = {
"text/", "edit", ".txt", /* must be first for plumbport() */ "text/",
"image/gif", "image", ".gif", "edit",
"image/jpeg", "image", ".jpg", ".txt", /* must be first for plumbport() */
"image/jpeg", "image", ".jpeg", "image/gif",
"image/png", "image", ".png", "image",
"application/postscript", "postscript", ".ps", ".gif",
"application/pdf", "postscript", ".pdf", "image/jpeg",
"application/msword", "msword", ".doc", "image",
"application/rtf", "msword", ".rtf", ".jpg",
nil, nil "image/jpeg",
}; "image",
".jpeg",
"image/png",
"image",
".png",
"application/postscript",
"postscript",
".ps",
"application/pdf",
"postscript",
".pdf",
"application/msword",
"msword",
".doc",
"application/rtf",
"msword",
".rtf",
nil,
nil};
char* goodtypes[] = { char* goodtypes[] = {
"text", "text",
@ -42,30 +57,13 @@ char *goodtypes[] = {
"text/richtext", "text/richtext",
"text/tab-separated-values", "text/tab-separated-values",
"application/octet-stream", "application/octet-stream",
nil nil};
};
char *okheaders[] = char* okheaders[] = {"From:", "Date:", "To:", "CC:", "Subject:", nil};
{
"From:",
"Date:",
"To:",
"CC:",
"Subject:",
nil
};
char *extraheaders[] = char* extraheaders[] = {"Resent-From:", "Resent-To:", "Sort:", nil};
{
"Resent-From:",
"Resent-To:",
"Sort:",
nil
};
char* char* line(char* data, char** pp) {
line(char *data, char **pp)
{
char *p, *q; char *p, *q;
for (p = data; *p != '\0' && *p != '\n'; p++) for (p = data; *p != '\0' && *p != '\n'; p++)
@ -79,9 +77,7 @@ line(char *data, char **pp)
return q; return q;
} }
static char* static char* mkaddrs(char* t, char** colon) {
mkaddrs(char *t, char **colon)
{
int i, nf, inquote; int i, nf, inquote;
char **f, *s; char **f, *s;
Fmt fmt; Fmt fmt;
@ -118,9 +114,7 @@ mkaddrs(char *t, char **colon)
return fmtstrflush(&fmt); return fmtstrflush(&fmt);
} }
int int loadinfo(Message* m, char* dir) {
loadinfo(Message *m, char *dir)
{
int n; int n;
char *data, *p, *s, *t; char *data, *p, *s, *t;
@ -198,9 +192,7 @@ loadinfo(Message *m, char *dir)
return 1; return 1;
} }
int int isnumeric(char* s) {
isnumeric(char *s)
{
while (*s) { while (*s) {
if (!isdigit(*s)) if (!isdigit(*s))
return 0; return 0;
@ -209,17 +201,13 @@ isnumeric(char *s)
return 1; return 1;
} }
CFid* CFid* mailopen(char* name, int mode) {
mailopen(char *name, int mode)
{
if (strncmp(name, "Mail/", 5) != 0) if (strncmp(name, "Mail/", 5) != 0)
return nil; return nil;
return fsopen(mailfs, name + 5, mode); return fsopen(mailfs, name + 5, mode);
} }
Dir* Dir* loaddir(char* name, int* np) {
loaddir(char *name, int *np)
{
CFid* fid; CFid* fid;
Dir* dp; Dir* dp;
@ -231,9 +219,7 @@ loaddir(char *name, int *np)
return dp; return dp;
} }
void void readmbox(Message* mbox, char* dir, char* subdir) {
readmbox(Message *mbox, char *dir, char *subdir)
{
char* name; char* name;
Dir *d, *dirp; Dir *d, *dirp;
int i, n; int i, n;
@ -252,9 +238,7 @@ readmbox(Message *mbox, char *dir, char *subdir)
} }
/* add message to box, in increasing numerical order */ /* add message to box, in increasing numerical order */
int int mesgadd(Message* mbox, char* dir, Dir* d, char* digest) {
mesgadd(Message *mbox, char *dir, Dir *d, char *digest)
{
Message* m; Message* m;
char* name; char* name;
int loaded; int loaded;
@ -268,8 +252,11 @@ mesgadd(Message *mbox, char *dir, Dir *d, char *digest)
name = estrstrdup(dir, m->name); name = estrstrdup(dir, m->name);
loaded = loadinfo(m, name); loaded = loadinfo(m, name);
free(name); free(name);
/* if two upas/fs are running, we can get misled, so check digest before accepting message */ /* if two upas/fs are running, we can get misled, so check digest before
if(loaded==0 || (digest!=nil && m->digest!=nil && strcmp(digest, m->digest)!=0)){ * accepting message */
if (
loaded == 0 ||
(digest != nil && m->digest != nil && strcmp(digest, m->digest) != 0)) {
mesgfreeparts(m); mesgfreeparts(m);
free(m); free(m);
return 0; return 0;
@ -287,9 +274,7 @@ mesgadd(Message *mbox, char *dir, Dir *d, char *digest)
return 1; return 1;
} }
int int thisyear(char* year) {
thisyear(char *year)
{
static char now[10]; static char now[10];
char* s; char* s;
@ -300,9 +285,7 @@ thisyear(char *year)
return strncmp(year, now, 4) == 0; return strncmp(year, now, 4) == 0;
} }
char* char* stripdate(char* as) {
stripdate(char *as)
{
int n; int n;
char *s, *fld[10]; char *s, *fld[10];
@ -329,9 +312,7 @@ stripdate(char *as)
return as; return as;
} }
char* char* readfile(char* dir, char* name, int* np) {
readfile(char *dir, char *name, int *np)
{
char *file, *data; char *file, *data;
int len; int len;
Dir* d; Dir* d;
@ -370,9 +351,7 @@ readfile(char *dir, char *name, int *np)
return data; return data;
} }
char* char* info(Message* m, int ind, int ogf) {
info(Message *m, int ind, int ogf)
{
char* i; char* i;
int j, len, lens; int j, len, lens;
char* p; char* p;
@ -406,7 +385,8 @@ info(Message *m, int ind, int ogf)
i = eappend(i, "\t", p); i = eappend(i, "\t", p);
i = egrow(i, "\t", stripdate(m->date)); i = egrow(i, "\t", stripdate(m->date));
if (ind == 0) { if (ind == 0) {
if(strcmp(m->type, "text")!=0 && strncmp(m->type, "text/", 5)!=0 && if (
strcmp(m->type, "text") != 0 && strncmp(m->type, "text/", 5) != 0 &&
strncmp(m->type, "multipart/", 10) != 0) strncmp(m->type, "multipart/", 10) != 0)
i = egrow(i, "\t(", estrstrdup(m->type, ")")); i = egrow(i, "\t(", estrstrdup(m->type, ")"));
} else if (strncmp(m->type, "multipart/", 10) != 0) } else if (strncmp(m->type, "multipart/", 10) != 0)
@ -420,9 +400,9 @@ info(Message *m, int ind, int ogf)
return i; return i;
} }
void void mesgmenu0(
mesgmenu0(Window *w, Message *mbox, char *realdir, char *dir, int ind, CFid *fd, int onlyone, int dotail) Window* w, Message* mbox, char* realdir, char* dir, int ind, CFid* fd,
{ int onlyone, int dotail) {
int i; int i;
Message* m; Message* m;
char *name, *tmp; char *name, *tmp;
@ -457,18 +437,14 @@ mesgmenu0(Window *w, Message *mbox, char *realdir, char *dir, int ind, CFid *fd,
} }
} }
void void mesgmenu(Window* w, Message* mbox) {
mesgmenu(Window *w, Message *mbox)
{
winopenbody(w, OWRITE); winopenbody(w, OWRITE);
mesgmenu0(w, mbox, mbox->name, "", 0, w->body, 0, !shortmenu); mesgmenu0(w, mbox, mbox->name, "", 0, w->body, 0, !shortmenu);
winclosebody(w); winclosebody(w);
} }
/* one new message has arrived, as mbox->tail */ /* one new message has arrived, as mbox->tail */
void void mesgmenunew(Window* w, Message* mbox) {
mesgmenunew(Window *w, Message *mbox)
{
Biobuf* b; Biobuf* b;
winselect(w, "0", 0); winselect(w, "0", 0);
@ -478,7 +454,8 @@ mesgmenunew(Window *w, Message *mbox)
free(b); free(b);
if (!mbox->dirty) if (!mbox->dirty)
winclean(w); winclean(w);
/* select tag line plus following indented lines, but not final newline (it's distinctive) */ /* select tag line plus following indented lines, but not final newline (it's
* distinctive) */
winselect(w, "0/.*\\n((\t.*\\n)*\t.*)?/", 1); winselect(w, "0/.*\\n((\t.*\\n)*\t.*)?/", 1);
fsclose(w->addr); fsclose(w->addr);
fsclose(w->data); fsclose(w->data);
@ -486,12 +463,11 @@ mesgmenunew(Window *w, Message *mbox)
w->data = nil; w->data = nil;
} }
char* char* name2regexp(char* prefix, char* s) {
name2regexp(char *prefix, char *s)
{
char *buf, *p, *q; char *buf, *p, *q;
buf = emalloc(strlen(prefix)+2*strlen(s)+50); /* leave room to append more */ buf = emalloc(
strlen(prefix) + 2 * strlen(s) + 50); /* leave room to append more */
p = buf; p = buf;
*p++ = '0'; *p++ = '0';
*p++ = '/'; *p++ = '/';
@ -508,12 +484,9 @@ name2regexp(char *prefix, char *s)
return buf; return buf;
} }
void void mesgmenumarkdel(Window* w, Message* mbox, Message* m, int writeback) {
mesgmenumarkdel(Window *w, Message *mbox, Message *m, int writeback)
{
char* buf; char* buf;
if (m->deleted) if (m->deleted)
return; return;
m->writebackdel = writeback; m->writebackdel = writeback;
@ -532,9 +505,7 @@ mesgmenumarkdel(Window *w, Message *mbox, Message *m, int writeback)
m->deleted = 1; m->deleted = 1;
} }
void void mesgmenumarkundel(Window* w, Message* v, Message* m) {
mesgmenumarkundel(Window *w, Message *v, Message *m)
{
char* buf; char* buf;
USED(v); USED(v);
@ -554,9 +525,7 @@ mesgmenumarkundel(Window *w, Message *v, Message *m)
m->deleted = 0; m->deleted = 0;
} }
void void mesgmenudel(Window* w, Message* mbox, Message* m) {
mesgmenudel(Window *w, Message *mbox, Message *m)
{
char* buf; char* buf;
if (w->data == nil) if (w->data == nil)
@ -573,15 +542,14 @@ mesgmenudel(Window *w, Message *mbox, Message *m)
m->deleted = 1; m->deleted = 1;
} }
void void mesgmenumark(Window* w, char* which, char* mark) {
mesgmenumark(Window *w, char *which, char *mark)
{
char* buf; char* buf;
if (w->data == nil) if (w->data == nil)
w->data = winopenfile(w, "data"); w->data = winopenfile(w, "data");
buf = name2regexp(deletedrx01, which); buf = name2regexp(deletedrx01, which);
if(winsetaddr(w, buf, 1) && winsetaddr(w, "+0-#1", 1)) /* go to end of line */ if (winsetaddr(w, buf, 1) && winsetaddr(w, "+0-#1", 1)) /* go to end of line
*/
fswrite(w->data, mark, strlen(mark)); fswrite(w->data, mark, strlen(mark));
free(buf); free(buf);
fsclose(w->data); fsclose(w->data);
@ -592,9 +560,7 @@ mesgmenumark(Window *w, char *which, char *mark)
winclean(w); winclean(w);
} }
void void mesgfreeparts(Message* m) {
mesgfreeparts(Message *m)
{
free(m->name); free(m->name);
free(m->replyname); free(m->replyname);
free(m->from); free(m->from);
@ -609,9 +575,7 @@ mesgfreeparts(Message *m)
free(m->digest); free(m->digest);
} }
void void mesgdel(Message* mbox, Message* m) {
mesgdel(Message *mbox, Message *m)
{
Message *n, *next; Message *n, *next;
if (m->opened) if (m->opened)
@ -634,9 +598,7 @@ mesgdel(Message *mbox, Message *m)
mesgfreeparts(m); mesgfreeparts(m);
} }
int int mesgsave(Message* m, char* s, int save) {
mesgsave(Message *m, char *s, int save)
{
int ofd, n, k, ret; int ofd, n, k, ret;
char *t, *raw, *unixheader, *all; char *t, *raw, *unixheader, *all;
@ -683,9 +645,7 @@ mesgsave(Message *m, char *s, int save)
return ret; return ret;
} }
int int mesgcommand(Message* m, char* cmd) {
mesgcommand(Message *m, char *cmd)
{
char* s; char* s;
char* args[10]; char* args[10];
int save, ok, ret, nargs; int save, ok, ret, nargs;
@ -729,7 +689,9 @@ mesgcommand(Message *m, char *cmd)
} }
if (strcmp(args[0], "Q") == 0) { if (strcmp(args[0], "Q") == 0) {
s = winselection(m->w); /* will be freed by mkreply */ s = winselection(m->w); /* will be freed by mkreply */
if(nargs>=3 && strcmp(args[1], "Reply")==0 && strcmp(args[2], "all")==0) if (
nargs >= 3 && strcmp(args[1], "Reply") == 0 &&
strcmp(args[2], "all") == 0)
mkreply(m, "QReplyall", nil, nil, s); mkreply(m, "QReplyall", nil, nil, s);
else else
mkreply(m, "QReply", nil, nil, s); mkreply(m, "QReply", nil, nil, s);
@ -776,9 +738,7 @@ mesgcommand(Message *m, char *cmd)
return ret; return ret;
} }
void void mesgtagpost(Message* m) {
mesgtagpost(Message *m)
{
if (m->tagposted) if (m->tagposted)
return; return;
wintagwrite(m->w, " Post", 5); wintagwrite(m->w, " Post", 5);
@ -788,9 +748,7 @@ mesgtagpost(Message *m)
/* need to expand selection more than default word */ /* need to expand selection more than default word */
#pragma varargck argpos eval 2 #pragma varargck argpos eval 2
long long eval(Window* w, char* s, ...) {
eval(Window *w, char *s, ...)
{
char buf[64]; char buf[64];
va_list arg; va_list arg;
@ -806,9 +764,7 @@ eval(Window *w, char *s, ...)
return strtol(buf, 0, 10); return strtol(buf, 0, 10);
} }
int int isemail(char* s) {
isemail(char *s)
{
int nat; int nat;
nat = 0; nat = 0;
@ -821,9 +777,7 @@ isemail(char *s)
} }
char addrdelim[] = "/[ \t\\n<>()\\[\\]]/"; char addrdelim[] = "/[ \t\\n<>()\\[\\]]/";
char* char* expandaddr(Window* w, Event* e) {
expandaddr(Window *w, Event *e)
{
char* s; char* s;
long q0, q1; long q0, q1;
@ -849,9 +803,7 @@ expandaddr(Window *w, Event *e)
return s; return s;
} }
int int replytoaddr(Window* w, Message* m, Event* e, char* s) {
replytoaddr(Window *w, Message *m, Event *e, char *s)
{
int did; int did;
char* buf; char* buf;
Plumbmsg* pm; Plumbmsg* pm;
@ -875,7 +827,9 @@ replytoaddr(Window *w, Message *m, Event *e, char *s)
if (m->subject && m->subject[0]) { if (m->subject && m->subject[0]) {
pm->attr = emalloc(sizeof(Plumbattr)); pm->attr = emalloc(sizeof(Plumbattr));
pm->attr->name = estrdup("Subject"); pm->attr->name = estrdup("Subject");
if(tolower(m->subject[0]) != 'r' || tolower(m->subject[1]) != 'e' || m->subject[2] != ':') if (
tolower(m->subject[0]) != 'r' || tolower(m->subject[1]) != 'e' ||
m->subject[2] != ':')
pm->attr->value = estrstrdup("Re: ", m->subject); pm->attr->value = estrstrdup("Re: ", m->subject);
else else
pm->attr->value = estrdup(m->subject); pm->attr->value = estrdup(m->subject);
@ -889,10 +843,7 @@ replytoaddr(Window *w, Message *m, Event *e, char *s)
return did; return did;
} }
void mesgctl(void* v) {
void
mesgctl(void *v)
{
Message* m; Message* m;
Window* w; Window* w;
Event *e, *eq, *e2, *ea; Event *e, *eq, *e2, *ea;
@ -974,7 +925,9 @@ mesgctl(void *v)
/* strip any known extensions */ /* strip any known extensions */
for (i = 0; ports[i].suffix != nil; i++) { for (i = 0; ports[i].suffix != nil; i++) {
j = strlen(ports[i].suffix); j = strlen(ports[i].suffix);
if(strlen(s)>j && strcmp(s+strlen(s)-j, ports[i].suffix)==0){ if (
strlen(s) > j &&
strcmp(s + strlen(s) - j, ports[i].suffix) == 0) {
s[strlen(s) - j] = '\0'; s[strlen(s) - j] = '\0';
break; break;
} }
@ -1008,16 +961,12 @@ mesgctl(void *v)
} }
} }
void void mesgline(Message* m, char* header, char* value) {
mesgline(Message *m, char *header, char *value)
{
if (strlen(value) > 0) if (strlen(value) > 0)
fsprint(m->w->body, "%s: %s\n", header, value); fsprint(m->w->body, "%s: %s\n", header, value);
} }
int int isprintable(char* type) {
isprintable(char *type)
{
int i; int i;
for (i = 0; goodtypes[i] != nil; i++) for (i = 0; goodtypes[i] != nil; i++)
@ -1026,9 +975,7 @@ isprintable(char *type)
return 0; return 0;
} }
char* char* ext(char* type) {
ext(char *type)
{
int i; int i;
for (i = 0; ports[i].type != nil; i++) for (i = 0; ports[i].type != nil; i++)
@ -1037,27 +984,31 @@ ext(char *type)
return ""; return "";
} }
void void mimedisplay(
mimedisplay(Message *m, char *name, char *rootdir, Window *w, int fileonly) Message* m, char* name, char* rootdir, Window* w, int fileonly) {
{
char* dest; char* dest;
if(strcmp(m->disposition, "file")==0 || strlen(m->filename)!=0 || !fileonly){ if (
strcmp(m->disposition, "file") == 0 || strlen(m->filename) != 0 ||
!fileonly) {
if (strlen(m->filename) == 0) if (strlen(m->filename) == 0)
dest = estrstrdup("a", ext(m->type)); dest = estrstrdup("a", ext(m->type));
else else
dest = estrdup(m->filename); dest = estrdup(m->filename);
if (m->filename[0] != '/') if (m->filename[0] != '/')
dest = egrow(estrdup(home), "/", dest); dest = egrow(estrdup(home), "/", dest);
fsprint(w->body, "\t9p read %s/%s/%sbody > %s\n", fsprint(
srvname, mboxname, name, dest); w->body,
"\t9p read %s/%s/%sbody > %s\n",
srvname,
mboxname,
name,
dest);
free(dest); free(dest);
} }
} }
void void printheader(char* dir, CFid* fid, char** okheaders) {
printheader(char *dir, CFid *fid, char **okheaders)
{
char* s; char* s;
char* lines[100]; char* lines[100];
int i, j, n; int i, j, n;
@ -1073,16 +1024,15 @@ printheader(char *dir, CFid *fid, char **okheaders)
free(s); free(s);
} }
void void mesgload(Message* m, char* rootdir, char* file, Window* w) {
mesgload(Message *m, char *rootdir, char *file, Window *w)
{
char *s, *subdir, *name, *dir; char *s, *subdir, *name, *dir;
Message *mp, *thisone; Message *mp, *thisone;
int n; int n;
dir = estrstrdup(rootdir, file); dir = estrstrdup(rootdir, file);
if(strcmp(m->type, "message/rfc822") != 0){ /* suppress headers of envelopes */ if (strcmp(m->type, "message/rfc822") != 0) { /* suppress headers of envelopes
*/
if (strlen(m->from) > 0) { if (strlen(m->from) > 0) {
fsprint(w->body, "From: %s\n", m->from); fsprint(w->body, "From: %s\n", m->from);
mesgline(m, "Date", m->date); mesgline(m, "Date", m->date);
@ -1127,7 +1077,12 @@ mesgload(Message *m, char *rootdir, char *file, Window *w)
name = estrstrdup(file, mp->name); name = estrstrdup(file, mp->name);
/* skip first element in name because it's already in window name */ /* skip first element in name because it's already in window name */
if (mp != m->head) if (mp != m->head)
fsprint(w->body, "\n===> %s (%s) [%s]\n", strchr(name, '/')+1, mp->type, mp->disposition); fsprint(
w->body,
"\n===> %s (%s) [%s]\n",
strchr(name, '/') + 1,
mp->type,
mp->disposition);
if (strcmp(mp->type, "text") == 0 || strncmp(mp->type, "text/", 5) == 0) { if (strcmp(mp->type, "text") == 0 || strncmp(mp->type, "text/", 5) == 0) {
mimedisplay(mp, name, rootdir, w, 1); mimedisplay(mp, name, rootdir, w, 1);
printheader(subdir, w->body, okheaders); printheader(subdir, w->body, okheaders);
@ -1137,7 +1092,9 @@ mesgload(Message *m, char *rootdir, char *file, Window *w)
winwritebody(w, s, n); winwritebody(w, s, n);
free(s); free(s);
} else { } else {
if(strncmp(mp->type, "multipart/", 10)==0 || strcmp(mp->type, "message/rfc822")==0){ if (
strncmp(mp->type, "multipart/", 10) == 0 ||
strcmp(mp->type, "message/rfc822") == 0) {
mp->w = w; mp->w = w;
mesgload(mp, rootdir, name, w); mesgload(mp, rootdir, name, w);
mp->w = nil; mp->w = nil;
@ -1151,9 +1108,7 @@ mesgload(Message *m, char *rootdir, char *file, Window *w)
free(dir); free(dir);
} }
int int tokenizec(char* str, char** args, int max, char* splitc) {
tokenizec(char *str, char **args, int max, char *splitc)
{
int i, na; int i, na;
int intok = 0; int intok = 0;
char* p; char* p;
@ -1161,7 +1116,8 @@ tokenizec(char *str, char **args, int max, char *splitc)
if (max <= 0) if (max <= 0)
return 0; return 0;
/* if(strchr(str, ',') || strchr(str, '"') || strchr(str, '<') || strchr(str, '(')) */ /* if(strchr(str, ',') || strchr(str, '"') || strchr(str, '<') || strchr(str,
* '(')) */
/* splitc = ","; */ /* splitc = ","; */
for (na = 0; *str != '\0'; str++) { for (na = 0; *str != '\0'; str++) {
if (strchr(splitc, *str) == nil) { if (strchr(splitc, *str) == nil) {
@ -1189,9 +1145,7 @@ tokenizec(char *str, char **args, int max, char *splitc)
return na; return na;
} }
Message* Message* mesglookup(Message* mbox, char* name, char* digest) {
mesglookup(Message *mbox, char *name, char *digest)
{
int n; int n;
Message* m; Message* m;
char* t; char* t;
@ -1221,9 +1175,7 @@ mesglookup(Message *mbox, char *name, char *digest)
/* /*
* Find plumb port, knowing type is text, given file name (by extension) * Find plumb port, knowing type is text, given file name (by extension)
*/ */
int int plumbportbysuffix(char* file) {
plumbportbysuffix(char *file)
{
char* suf; char* suf;
int i, nsuf, nfile; int i, nsuf, nfile;
@ -1241,9 +1193,7 @@ plumbportbysuffix(char *file)
/* /*
* Find plumb port using type and file name (by extension) * Find plumb port using type and file name (by extension)
*/ */
int int plumbport(char* type, char* file) {
plumbport(char *type, char *file)
{
int i; int i;
for (i = 0; ports[i].type != nil; i++) for (i = 0; ports[i].type != nil; i++)
@ -1256,9 +1206,7 @@ plumbport(char *type, char *file)
return -1; return -1;
} }
void void plumb(Message* m, char* dir) {
plumb(Message *m, char *dir)
{
int i; int i;
char* port; char* port;
Plumbmsg* pm; Plumbmsg* pm;
@ -1287,9 +1235,8 @@ plumb(Message *m, char *dir)
} }
} }
int int mesgopen(
mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *digest) Message* mbox, char* dir, char* s, Message* mesg, int plumbed, char* digest) {
{
char *t, *u, *v; char *t, *u, *v;
Message* m; Message* m;
char* direlem[10]; char* direlem[10];
@ -1315,7 +1262,8 @@ mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *di
m = mesglookup(mbox, direlem[0], digest); m = mesglookup(mbox, direlem[0], digest);
if (m == nil) if (m == nil)
goto Error; goto Error;
if(mesg!=nil && m!=mesg) /* string looked like subpart but isn't part of this message */ if (mesg != nil && m != mesg) /* string looked like subpart but isn't part of
this message */
goto Error; goto Error;
if (m->opened == 0) { if (m->opened == 0) {
if (m->w == nil) { if (m->w == nil) {
@ -1371,9 +1319,7 @@ mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *di
return 1; return 1;
} }
void void rewritembox(Window* w, Message* mbox) {
rewritembox(Window *w, Message *mbox)
{
Message *m, *next; Message *m, *next;
char *deletestr, *t; char *deletestr, *t;
int nopen; int nopen;
@ -1409,9 +1355,7 @@ rewritembox(Window *w, Message *mbox)
} }
/* name is a full file name, but it might not belong to us */ /* name is a full file name, but it might not belong to us */
Message* Message* mesglookupfile(Message* mbox, char* name, char* digest) {
mesglookupfile(Message *mbox, char *name, char *digest)
{
int k, n; int k, n;
k = strlen(name); k = strlen(name);

Binary file not shown.

Binary file not shown.

View file

@ -9,9 +9,7 @@
static int replyid; static int replyid;
int int quote(Message* m, CFid* fid, char* dir, char* quotetext) {
quote(Message *m, CFid *fid, char *dir, char *quotetext)
{
char *body, *type; char *body, *type;
int i, n, nlines; int i, n, nlines;
char** lines; char** lines;
@ -27,7 +25,9 @@ quote(Message *m, CFid *fid, char *dir, char *quotetext)
print("no type in %s\n", dir); print("no type in %s\n", dir);
return 0; return 0;
} }
if(strncmp(type, "multipart/", 10)==0 || strncmp(type, "message/", 8)==0){ if (
strncmp(type, "multipart/", 10) == 0 ||
strncmp(type, "message/", 8) == 0) {
dir = estrstrdup(dir, "1/"); dir = estrstrdup(dir, "1/");
if (quote(m, fid, dir, nil)) { if (quote(m, fid, dir, nil)) {
free(type); free(type);
@ -67,9 +67,8 @@ quote(Message *m, CFid *fid, char *dir, char *quotetext)
return 1; return 1;
} }
void void mkreply(
mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext) Message* m, char* label, char* to, Plumbattr* attr, char* quotetext) {
{
char buf[100]; char buf[100];
CFid* fd; CFid* fd;
Message* r; Message* r;
@ -134,7 +133,9 @@ mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext)
if (strlen(m->subject) > 0) { if (strlen(m->subject) > 0) {
t = "Subject: Re: "; t = "Subject: Re: ";
if (strlen(m->subject) >= 3) if (strlen(m->subject) >= 3)
if(tolower(m->subject[0])=='r' && tolower(m->subject[1])=='e' && m->subject[2]==':') if (
tolower(m->subject[0]) == 'r' && tolower(m->subject[1]) == 'e' &&
m->subject[2] == ':')
t = "Subject: "; t = "Subject: ";
fsprint(r->w->body, "%s%s\n", t, m->subject); fsprint(r->w->body, "%s%s\n", t, m->subject);
} }
@ -159,9 +160,7 @@ mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext)
windormant(r->w); windormant(r->w);
} }
void void delreply(Message* m) {
delreply(Message *m)
{
if (m->next == nil) if (m->next == nil)
replies.tail = m->prev; replies.tail = m->prev;
else else
@ -174,10 +173,9 @@ delreply(Message *m)
free(m); free(m);
} }
/* copy argv to stack and free the incoming strings, so we don't leak argument vectors */ /* copy argv to stack and free the incoming strings, so we don't leak argument
void * vectors */
buildargv(char **inargv, char *argv[NARGS+1], char args[NARGCHAR]) void buildargv(char** inargv, char* argv[NARGS + 1], char args[NARGCHAR]) {
{
int i, n; int i, n;
char *s, *a; char *s, *a;
@ -197,9 +195,7 @@ buildargv(char **inargv, char *argv[NARGS+1], char args[NARGCHAR])
argv[i] = nil; argv[i] = nil;
} }
void void execproc(void* v) {
execproc(void *v)
{
struct Exec* e; struct Exec* e;
int p[2], q[2]; int p[2], q[2];
char* prog; char* prog;
@ -234,28 +230,11 @@ execproc(void *v)
threadexits("can't exec"); threadexits("can't exec");
} }
enum{ enum { ATTACH, BCC, CC, FROM, INCLUDE, TO };
ATTACH,
BCC,
CC,
FROM,
INCLUDE,
TO
};
char *headers[] = { char* headers[] = {"attach:", "bcc:", "cc:", "from:", "include:", "to:", nil};
"attach:",
"bcc:",
"cc:",
"from:",
"include:",
"to:",
nil
};
int int whichheader(char* h) {
whichheader(char *h)
{
int i; int i;
for (i = 0; headers[i] != nil; i++) for (i = 0; headers[i] != nil; i++)
@ -271,9 +250,7 @@ int ncc, nbcc, nto;
char* attlist[200]; char* attlist[200];
char included[200]; char included[200];
int int addressed(char* name) {
addressed(char *name)
{
int i; int i;
for (i = 0; i < nto; i++) for (i = 0; i < nto; i++)
@ -288,9 +265,7 @@ addressed(char *name)
return 0; return 0;
} }
char* char* skipbl(char* s, char* e) {
skipbl(char *s, char *e)
{
while (s < e) { while (s < e) {
if (*s != ' ' && *s != '\t' && *s != ',') if (*s != ' ' && *s != '\t' && *s != ',')
break; break;
@ -299,9 +274,7 @@ skipbl(char *s, char *e)
return s; return s;
} }
char* char* findbl(char* s, char* e) {
findbl(char *s, char *e)
{
while (s < e) { while (s < e) {
if (*s == ' ' || *s == '\t' || *s == ',') if (*s == ' ' || *s == '\t' || *s == ',')
break; break;
@ -311,11 +284,10 @@ findbl(char *s, char *e)
} }
/* /*
* comma-separate possibly blank-separated strings in line; e points before newline * comma-separate possibly blank-separated strings in line; e points before
* newline
*/ */
void void commas(char* s, char* e) {
commas(char *s, char *e)
{
char* t; char* t;
/* may have initial blanks */ /* may have initial blanks */
@ -334,9 +306,7 @@ commas(char *s, char *e)
} }
} }
int int print2(int fd, int ofd, char* fmt, ...) {
print2(int fd, int ofd, char *fmt, ...)
{
int m, n; int m, n;
char* s; char* s;
va_list arg; va_list arg;
@ -353,9 +323,7 @@ print2(int fd, int ofd, char *fmt, ...)
return n; return n;
} }
void void write2(int fd, int ofd, char* buf, int n, int nofrom) {
write2(int fd, int ofd, char *buf, int n, int nofrom)
{
char *from, *p; char *from, *p;
int m; int m;
@ -388,9 +356,7 @@ write2(int fd, int ofd, char *buf, int n, int nofrom)
} }
} }
void void mesgsend(Message* m) {
mesgsend(Message *m)
{
char *s, *body, *to; char *s, *body, *to;
int i, j, h, n, natt, p[2]; int i, j, h, n, natt, p[2];
struct Exec* e; struct Exec* e;

Binary file not shown.

View file

@ -6,9 +6,7 @@
#include <9pclient.h> #include <9pclient.h>
#include "dat.h" #include "dat.h"
void* void* emalloc(uint n) {
emalloc(uint n)
{
void* p; void* p;
p = malloc(n); p = malloc(n);
@ -19,9 +17,7 @@ emalloc(uint n)
return p; return p;
} }
void* void* erealloc(void* p, uint n) {
erealloc(void *p, uint n)
{
p = realloc(p, n); p = realloc(p, n);
if (p == nil) if (p == nil)
error("can't realloc: %r"); error("can't realloc: %r");
@ -29,9 +25,7 @@ erealloc(void *p, uint n)
return p; return p;
} }
char* char* estrdup(char* s) {
estrdup(char *s)
{
char* t; char* t;
t = emalloc(strlen(s) + 1); t = emalloc(strlen(s) + 1);
@ -39,9 +33,7 @@ estrdup(char *s)
return t; return t;
} }
char* char* estrstrdup(char* s, char* t) {
estrstrdup(char *s, char *t)
{
char* u; char* u;
u = emalloc(strlen(s) + strlen(t) + 1); u = emalloc(strlen(s) + strlen(t) + 1);
@ -50,9 +42,7 @@ estrstrdup(char *s, char *t)
return u; return u;
} }
char* char* eappend(char* s, char* sep, char* t) {
eappend(char *s, char *sep, char *t)
{
char* u; char* u;
if (t == nil) if (t == nil)
@ -67,17 +57,13 @@ eappend(char *s, char *sep, char *t)
return u; return u;
} }
char* char* egrow(char* s, char* sep, char* t) {
egrow(char *s, char *sep, char *t)
{
s = eappend(s, sep, t); s = eappend(s, sep, t);
free(t); free(t);
return s; return s;
} }
void void error(char* fmt, ...) {
error(char *fmt, ...)
{
Fmt f; Fmt f;
char buf[64]; char buf[64];
va_list arg; va_list arg;
@ -92,9 +78,7 @@ error(char *fmt, ...)
threadexitsall(fmt); threadexitsall(fmt);
} }
void void ctlprint(CFid* fd, char* fmt, ...) {
ctlprint(CFid *fd, char *fmt, ...)
{
int n; int n;
va_list arg; va_list arg;
@ -104,4 +88,3 @@ ctlprint(CFid *fd, char *fmt, ...)
if (n <= 0) if (n <= 0)
error("control file write error: %r"); error("control file write error: %r");
} }

Binary file not shown.

View file

@ -6,9 +6,7 @@
#include <9pclient.h> #include <9pclient.h>
#include "dat.h" #include "dat.h"
Window* Window* newwindow(void) {
newwindow(void)
{
char buf[12]; char buf[12];
Window* w; Window* w;
@ -27,17 +25,13 @@ newwindow(void)
return w; return w;
} }
void void winincref(Window* w) {
winincref(Window *w)
{
qlock(&w->lk); qlock(&w->lk);
++w->ref; ++w->ref;
qunlock(&w->lk); qunlock(&w->lk);
} }
void void windecref(Window* w) {
windecref(Window *w)
{
qlock(&w->lk); qlock(&w->lk);
if (--w->ref > 0) { if (--w->ref > 0) {
qunlock(&w->lk); qunlock(&w->lk);
@ -48,18 +42,14 @@ windecref(Window *w)
free(w); free(w);
} }
void void winsetdump(Window* w, char* dir, char* cmd) {
winsetdump(Window *w, char *dir, char *cmd)
{
if (dir != nil) if (dir != nil)
ctlprint(w->ctl, "dumpdir %s\n", dir); ctlprint(w->ctl, "dumpdir %s\n", dir);
if (cmd != nil) if (cmd != nil)
ctlprint(w->ctl, "dump %s\n", cmd); ctlprint(w->ctl, "dump %s\n", cmd);
} }
void void wineventproc(void* v) {
wineventproc(void *v)
{
Window* w; Window* w;
int i; int i;
@ -72,9 +62,7 @@ wineventproc(void *v)
} }
} }
static CFid* static CFid* winopenfile1(Window* w, char* f, int m) {
winopenfile1(Window *w, char *f, int m)
{
char buf[64]; char buf[64];
CFid* fd; CFid* fd;
@ -85,15 +73,9 @@ winopenfile1(Window *w, char *f, int m)
return fd; return fd;
} }
CFid* CFid* winopenfile(Window* w, char* f) { return winopenfile1(w, f, ORDWR); }
winopenfile(Window *w, char *f)
{
return winopenfile1(w, f, ORDWR);
}
void void wintagwrite(Window* w, char* s, int n) {
wintagwrite(Window *w, char *s, int n)
{
CFid* fid; CFid* fid;
fid = winopenfile(w, "tag"); fid = winopenfile(w, "tag");
@ -102,9 +84,7 @@ wintagwrite(Window *w, char *s, int n)
fsclose(fid); fsclose(fid);
} }
void void winname(Window* w, char* s) {
winname(Window *w, char *s)
{
int len; int len;
char *ns, *sp; char *ns, *sp;
Rune r = L''; /* visible space */ Rune r = L''; /* visible space */
@ -123,9 +103,7 @@ winname(Window *w, char *s)
return; return;
} }
void void winopenbody(Window* w, int mode) {
winopenbody(Window *w, int mode)
{
char buf[256]; char buf[256];
CFid* fid; CFid* fid;
@ -136,31 +114,26 @@ winopenbody(Window *w, int mode)
error("can't open window body file: %r"); error("can't open window body file: %r");
} }
void void winclosebody(Window* w) {
winclosebody(Window *w)
{
if (w->body != nil) { if (w->body != nil) {
fsclose(w->body); fsclose(w->body);
w->body = nil; w->body = nil;
} }
} }
void void winwritebody(Window* w, char* s, int n) {
winwritebody(Window *w, char *s, int n)
{
if (w->body == nil) if (w->body == nil)
winopenbody(w, OWRITE); winopenbody(w, OWRITE);
if (fswrite(w->body, s, n) != n) if (fswrite(w->body, s, n) != n)
error("write error to window: %r"); error("write error to window: %r");
} }
int int wingetec(Window* w) {
wingetec(Window *w)
{
if (w->nbuf == 0) { if (w->nbuf == 0) {
w->nbuf = fsread(w->event, w->buf, sizeof w->buf); w->nbuf = fsread(w->event, w->buf, sizeof w->buf);
if (w->nbuf <= 0) { if (w->nbuf <= 0) {
/* probably because window has exited, and only called by wineventproc, so just shut down */ /* probably because window has exited, and only called by wineventproc, so
* just shut down */
windecref(w); windecref(w);
threadexits(nil); threadexits(nil);
} }
@ -170,9 +143,7 @@ wingetec(Window *w)
return *w->bufp++; return *w->bufp++;
} }
int int wingeten(Window* w) {
wingeten(Window *w)
{
int n, c; int n, c;
n = 0; n = 0;
@ -183,9 +154,7 @@ wingeten(Window *w)
return n; return n;
} }
int int wingeter(Window* w, char* buf, int* nb) {
wingeter(Window *w, char *buf, int *nb)
{
Rune r; Rune r;
int n; int n;
@ -201,9 +170,7 @@ wingeter(Window *w, char *buf, int *nb)
return r; return r;
} }
void void wingetevent(Window* w, Event* e) {
wingetevent(Window *w, Event *e)
{
int i, nb; int i, nb;
e->c1 = wingetec(w); e->c1 = wingetec(w);
@ -225,15 +192,11 @@ wingetevent(Window *w, Event *e)
error("event syntax error"); error("event syntax error");
} }
void void winwriteevent(Window* w, Event* e) {
winwriteevent(Window *w, Event *e)
{
fsprint(w->event, "%c%c%d %d\n", e->c1, e->c2, e->q0, e->q1); fsprint(w->event, "%c%c%d %d\n", e->c1, e->c2, e->q0, e->q1);
} }
void void winread(Window* w, uint q0, uint q1, char* data) {
winread(Window *w, uint q0, uint q1, char *data)
{
int m, n, nr; int m, n, nr;
char buf[256]; char buf[256];
@ -251,7 +214,9 @@ winread(Window *w, uint q0, uint q1, char *data)
error("reading data: %r"); error("reading data: %r");
nr = utfnlen(buf, n); nr = utfnlen(buf, n);
while (m + nr > q1) { while (m + nr > q1) {
do; while(n>0 && (buf[--n]&0xC0)==0x80); do
;
while (n > 0 && (buf[--n] & 0xC0) == 0x80);
--nr; --nr;
} }
if (n == 0) if (n == 0)
@ -263,9 +228,7 @@ winread(Window *w, uint q0, uint q1, char *data)
} }
} }
void void windormant(Window* w) {
windormant(Window *w)
{
if (w->addr != nil) { if (w->addr != nil) {
fsclose(w->addr); fsclose(w->addr);
w->addr = nil; w->addr = nil;
@ -280,10 +243,7 @@ windormant(Window *w)
} }
} }
int windel(Window* w, int sure) {
int
windel(Window *w, int sure)
{
if (sure) if (sure)
fswrite(w->ctl, "delete\n", 7); fswrite(w->ctl, "delete\n", 7);
else if (fswrite(w->ctl, "del\n", 4) != 4) else if (fswrite(w->ctl, "del\n", 4) != 4)
@ -295,15 +255,9 @@ windel(Window *w, int sure)
return 1; return 1;
} }
void void winclean(Window* w) { ctlprint(w->ctl, "clean\n"); }
winclean(Window *w)
{
ctlprint(w->ctl, "clean\n");
}
int int winsetaddr(Window* w, char* addr, int errok) {
winsetaddr(Window *w, char *addr, int errok)
{
if (w->addr == nil) if (w->addr == nil)
w->addr = winopenfile(w, "addr"); w->addr = winopenfile(w, "addr");
if (fswrite(w->addr, addr, strlen(addr)) < 0) { if (fswrite(w->addr, addr, strlen(addr)) < 0) {
@ -314,9 +268,7 @@ winsetaddr(Window *w, char *addr, int errok)
return 1; return 1;
} }
int int winselect(Window* w, char* addr, int errok) {
winselect(Window *w, char *addr, int errok)
{
if (winsetaddr(w, addr, errok)) { if (winsetaddr(w, addr, errok)) {
ctlprint(w->ctl, "dot=addr\n"); ctlprint(w->ctl, "dot=addr\n");
return 1; return 1;
@ -324,8 +276,9 @@ winselect(Window *w, char *addr, int errok)
return 0; return 0;
} }
char* char* winreadbody(
winreadbody(Window *w, int *np) /* can't use readfile because acme doesn't report the length */ Window* w,
int* np) /* can't use readfile because acme doesn't report the length */
{ {
char* s; char* s;
int m, na, n; int m, na, n;
@ -352,9 +305,7 @@ winreadbody(Window *w, int *np) /* can't use readfile because acme doesn't repor
return s; return s;
} }
char* char* winselection(Window* w) {
winselection(Window *w)
{
int m, n; int m, n;
char* buf; char* buf;
char tmp[256]; char tmp[256];

Binary file not shown.

119
regx.c
View file

@ -19,8 +19,7 @@ Rune *lastregexp;
* Machine Information * Machine Information
*/ */
typedef struct Inst Inst; typedef struct Inst Inst;
struct Inst struct Inst {
{
uint type; /* < OPERATOR ==> literal, otherwise action */ uint type; /* < OPERATOR ==> literal, otherwise action */
union { union {
int sid; int sid;
@ -43,8 +42,7 @@ Inst *bstartinst; /* same for backwards machine */
Channel* rechan; /* chan(Inst*) */ Channel* rechan; /* chan(Inst*) */
typedef struct Ilist Ilist; typedef struct Ilist Ilist;
struct Ilist struct Ilist {
{
Inst* inst; /* Instruction of the thread */ Inst* inst; /* Instruction of the thread */
Rangeset se; Rangeset se;
uint startp; /* first char of match */ uint startp; /* first char of match */
@ -88,8 +86,7 @@ static Rangeset sempty;
* Parser Information * Parser Information
*/ */
typedef struct Node Node; typedef struct Node Node;
struct Node struct Node {
{
Inst* first; Inst* first;
Inst* last; Inst* last;
}; };
@ -127,26 +124,20 @@ void evaluntil(int);
void optimize(Inst*); void optimize(Inst*);
void bldcclass(void); void bldcclass(void);
void void rxinit(void) {
rxinit(void)
{
rechan = chancreate(sizeof(Inst*), 0); rechan = chancreate(sizeof(Inst*), 0);
chansetname(rechan, "rechan"); chansetname(rechan, "rechan");
lastregexp = runemalloc(1); lastregexp = runemalloc(1);
} }
void void regerror(char* e) {
regerror(char *e)
{
lastregexp[0] = 0; lastregexp[0] = 0;
warning(nil, "regexp: %s\n", e); warning(nil, "regexp: %s\n", e);
sendp(rechan, nil); sendp(rechan, nil);
threadexits(nil); threadexits(nil);
} }
Inst * Inst* newinst(int t) {
newinst(int t)
{
if (progp >= &program[NPROG]) if (progp >= &program[NPROG])
regerror("expression too long"); regerror("expression too long");
progp->type = t; progp->type = t;
@ -155,9 +146,7 @@ newinst(int t)
return progp++; return progp++;
} }
void void realcompile(void* arg) {
realcompile(void *arg)
{
int token; int token;
Rune* s; Rune* s;
@ -190,9 +179,7 @@ realcompile(void *arg)
} }
/* r is null terminated */ /* r is null terminated */
int int rxcompile(Rune* r) {
rxcompile(Rune *r)
{
int i, nr; int i, nr;
Inst* oprogp; Inst* oprogp;
@ -223,9 +210,7 @@ rxcompile(Rune *r)
return TRUE; return TRUE;
} }
void void operand(int t) {
operand(int t)
{
Inst* i; Inst* i;
if (lastwasand) if (lastwasand)
operator(CAT); /* catenate is implicit */ operator(CAT); /* catenate is implicit */
@ -239,9 +224,7 @@ operand(int t)
lastwasand = TRUE; lastwasand = TRUE;
} }
void void operator(int t) {
operator(int t)
{
if (t == RBRA && --nbra < 0) if (t == RBRA && --nbra < 0)
regerror("unmatched `)'"); regerror("unmatched `)'");
if (t == LBRA) { if (t == LBRA) {
@ -258,9 +241,7 @@ operator(int t)
lastwasand = TRUE; /* these look like operands */ lastwasand = TRUE; /* these look like operands */
} }
void void pushand(Inst* f, Inst* l) {
pushand(Inst *f, Inst *l)
{
if (andp >= &andstack[NSTACK]) if (andp >= &andstack[NSTACK])
error("operand stack overflow"); error("operand stack overflow");
andp->first = f; andp->first = f;
@ -268,9 +249,7 @@ pushand(Inst *f, Inst *l)
andp++; andp++;
} }
void void pushator(int t) {
pushator(int t)
{
if (atorp >= &atorstack[NSTACK]) if (atorp >= &atorstack[NSTACK])
error("operator stack overflow"); error("operator stack overflow");
*atorp++ = t; *atorp++ = t;
@ -280,9 +259,7 @@ pushator(int t)
*subidp++ = cursubid; *subidp++ = cursubid;
} }
Node * Node* popand(int op) {
popand(int op)
{
char buf[64]; char buf[64];
if (andp <= &andstack[0]) if (andp <= &andstack[0])
@ -294,18 +271,14 @@ popand(int op)
return --andp; return --andp;
} }
int int popator() {
popator()
{
if (atorp <= &atorstack[0]) if (atorp <= &atorstack[0])
error("operator stack underflow"); error("operator stack underflow");
--subidp; --subidp;
return *--atorp; return *--atorp;
} }
void void evaluntil(int pri) {
evaluntil(int pri)
{
Node *op1, *op2, *t; Node *op1, *op2, *t;
Inst *inst1, *inst2; Inst *inst1, *inst2;
@ -373,10 +346,7 @@ evaluntil(int pri)
} }
} }
void optimize(Inst* start) {
void
optimize(Inst *start)
{
Inst *inst, *target; Inst *inst, *target;
for (inst = start; inst->type != END; inst++) { for (inst = start; inst->type != END; inst++) {
@ -387,16 +357,12 @@ optimize(Inst *start)
} }
} }
void void startlex(Rune* s) {
startlex(Rune *s)
{
exprp = s; exprp = s;
nbra = 0; nbra = 0;
} }
int lex(void) {
int
lex(void){
int c; int c;
c = *exprp++; c = *exprp++;
@ -445,9 +411,7 @@ lex(void){
return c; return c;
} }
int int nextrec(void) {
nextrec(void)
{
if (exprp[0] == 0 || (exprp[0] == '\\' && exprp[1] == 0)) if (exprp[0] == 0 || (exprp[0] == '\\' && exprp[1] == 0))
regerror("malformed `[]'"); regerror("malformed `[]'");
if (exprp[0] == '\\') { if (exprp[0] == '\\') {
@ -461,9 +425,7 @@ nextrec(void)
return *exprp++; return *exprp++;
} }
void void bldcclass(void) {
bldcclass(void)
{
int c1, c2, n, na; int c1, c2, n, na;
Rune* classp; Rune* classp;
@ -506,9 +468,7 @@ bldcclass(void)
class[nclass++] = classp; class[nclass++] = classp;
} }
int int classmatch(int classno, int c, int negate) {
classmatch(int classno, int c, int negate)
{
Rune* p; Rune* p;
p = class[classno]; p = class[classno];
@ -528,9 +488,7 @@ classmatch(int classno, int c, int negate)
* *l must be pending when addinst called; if *l has been looked * *l must be pending when addinst called; if *l has been looked
* at already, the optimization is a bug. * at already, the optimization is a bug.
*/ */
int int addinst(Ilist* l, Inst* inst, Rangeset* sep) {
addinst(Ilist *l, Inst *inst, Rangeset *sep)
{
Ilist* p; Ilist* p;
for (p = l; p->inst; p++) { for (p = l; p->inst; p++) {
@ -546,16 +504,10 @@ addinst(Ilist *l, Inst *inst, Rangeset *sep)
return 1; return 1;
} }
int int rxnull(void) { return startinst == nil || bstartinst == nil; }
rxnull(void)
{
return startinst==nil || bstartinst==nil;
}
/* either t!=nil or r!=nil, and we match the string in the appropriate place */ /* either t!=nil or r!=nil, and we match the string in the appropriate place */
int int rxexecute(Text* t, Rune* r, uint startp, uint eof, Rangeset* rp) {
rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp)
{
int flag; int flag;
Inst* inst; Inst* inst;
Ilist* tlp; Ilist* tlp;
@ -650,7 +602,9 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp)
goto Addinst; goto Addinst;
break; break;
case BOL: case BOL:
if(p==0 || (t!=nil && textreadc(t, p-1)=='\n') || (r!=nil && r[p-1]=='\n')){ if (
p == 0 || (t != nil && textreadc(t, p - 1) == '\n') ||
(r != nil && r[p - 1] == '\n')) {
Step: Step:
inst = inst->u1.next; inst = inst->u1.next;
goto Switchstmt; goto Switchstmt;
@ -688,17 +642,14 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp)
return sel.r[0].q0 >= 0; return sel.r[0].q0 >= 0;
} }
void void newmatch(Rangeset* sp) {
newmatch(Rangeset *sp) if (
{ sel.r[0].q0 < 0 || sp->r[0].q0 < sel.r[0].q0 ||
if(sel.r[0].q0<0 || sp->r[0].q0<sel.r[0].q0 ||
(sp->r[0].q0 == sel.r[0].q0 && sp->r[0].q1 > sel.r[0].q1)) (sp->r[0].q0 == sel.r[0].q0 && sp->r[0].q1 > sel.r[0].q1))
sel = *sp; sel = *sp;
} }
int int rxbexecute(Text* t, uint startp, Rangeset* rp) {
rxbexecute(Text *t, uint startp, Rangeset *rp)
{
int flag; int flag;
Inst* inst; Inst* inst;
Ilist* tlp; Ilist* tlp;
@ -827,12 +778,12 @@ rxbexecute(Text *t, uint startp, Rangeset *rp)
return sel.r[0].q0 >= 0; return sel.r[0].q0 >= 0;
} }
void void bnewmatch(Rangeset* sp) {
bnewmatch(Rangeset *sp)
{
int i; int i;
if(sel.r[0].q0<0 || sp->r[0].q0>sel.r[0].q1 || (sp->r[0].q0==sel.r[0].q1 && sp->r[0].q1<sel.r[0].q0)) if (
sel.r[0].q0 < 0 || sp->r[0].q0 > sel.r[0].q1 ||
(sp->r[0].q0 == sel.r[0].q1 && sp->r[0].q1 < sel.r[0].q0))
for (i = 0; i < NRange; i++) { /* note the reversal; q0<=q1 */ for (i = 0; i < NRange; i++) { /* note the reversal; q0<=q1 */
sel.r[i].q0 = sp->r[i].q1; sel.r[i].q0 = sp->r[i].q1;
sel.r[i].q1 = sp->r[i].q0; sel.r[i].q1 = sp->r[i].q0;

202
rows.c
View file

@ -13,43 +13,49 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
static Rune Lcolhdr[] = { static Rune Lcolhdr[] = {'N', 'e', 'w', 'c', 'o', 'l', ' ', 'K', 'i', 'l',
'N', 'e', 'w', 'c', 'o', 'l', ' ', 'l', ' ', 'P', 'u', 't', 'a', 'l', 'l', ' ', 'D',
'K', 'i', 'l', 'l', ' ', 'u', 'm', 'p', ' ', 'E', 'x', 'i', 't', ' ', 0};
'P', 'u', 't', 'a', 'l', 'l', ' ',
'D', 'u', 'm', 'p', ' ',
'E', 'x', 'i', 't', ' ',
0
};
void void rowinit(Row* row, Rectangle r) {
rowinit(Row *row, Rectangle r)
{
Rectangle r1; Rectangle r1;
Text* t; Text* t;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
row->r = r; row->r = r;
row->col = nil; row->col = nil;
row->ncol = 0; row->ncol = 0;
r1 = r; r1 = r;
r1.max.y = r1.min.y + font->height; r1.max.y = r1.min.y + font->height;
t = &row->tag; t = &row->tag;
textinit(t, fileaddtext(nil, t), r1, rfget(FALSE, FALSE, FALSE, nil), tagcols); textinit(
t,
fileaddtext(nil, t),
r1,
rfget(FALSE, FALSE, FALSE, nil),
tagcols);
t->what = Rowtag; t->what = Rowtag;
t->row = row; t->row = row;
t->w = nil; t->w = nil;
t->col = nil; t->col = nil;
r1.min.y = r1.max.y; r1.min.y = r1.max.y;
r1.max.y += Border; r1.max.y += Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
textinsert(t, 0, Lcolhdr, 29, TRUE); textinsert(t, 0, Lcolhdr, 29, TRUE);
textsetselect(t, t->file->b.nc, t->file->b.nc); textsetselect(t, t->file->b.nc, t->file->b.nc);
} }
Column* Column* rowadd(Row* row, Column* c, int x) {
rowadd(Row *row, Column *c, int x)
{
Rectangle r, r1; Rectangle r, r1;
Column* d; Column* d;
int i; int i;
@ -73,7 +79,12 @@ rowadd(Row *row, Column *c, int x)
r = d->r; r = d->r;
if (Dx(r) < 100) if (Dx(r) < 100)
return nil; return nil;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r1 = r; r1 = r;
r1.max.x = min(x - Border, r.max.x - 50); r1.max.x = min(x - Border, r.max.x - 50);
if (Dx(r1) < 50) if (Dx(r1) < 50)
@ -81,7 +92,12 @@ rowadd(Row *row, Column *c, int x)
colresize(d, r1); colresize(d, r1);
r1.min.x = r1.max.x; r1.min.x = r1.max.x;
r1.max.x = r1.min.x + Border; r1.max.x = r1.min.x + Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.min.x = r1.max.x; r.min.x = r1.max.x;
} }
if (c == nil) { if (c == nil) {
@ -100,9 +116,7 @@ rowadd(Row *row, Column *c, int x)
return c; return c;
} }
void void rowresize(Row* row, Rectangle r) {
rowresize(Row *row, Rectangle r)
{
int i, deltax; int i, deltax;
Rectangle or, r1, r2; Rectangle or, r1, r2;
Column* c; Column* c;
@ -115,7 +129,12 @@ rowresize(Row *row, Rectangle r)
textresize(&row->tag, r1, TRUE); textresize(&row->tag, r1, TRUE);
r1.min.y = r1.max.y; r1.min.y = r1.max.y;
r1.max.y += Border; r1.max.y += Border;
draw(screen, r1, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r1,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.min.y = r1.max.y; r.min.y = r1.max.y;
r1 = r; r1 = r;
r1.max.x = r1.min.x; r1.max.x = r1.min.x;
@ -130,16 +149,19 @@ rowresize(Row *row, Rectangle r)
if (i > 0) { if (i > 0) {
r2 = r1; r2 = r1;
r2.max.x = r2.min.x + Border; r2.max.x = r2.min.x + Border;
draw(screen, r2, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r2,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r1.min.x = r2.max.x; r1.min.x = r2.max.x;
} }
colresize(c, r1); colresize(c, r1);
} }
} }
void void rowdragcol(Row* row, Column* c, int _0) {
rowdragcol(Row *row, Column *c, int _0)
{
Rectangle r; Rectangle r;
int i, b, x; int i, b, x;
Point p, op; Point p, op;
@ -169,7 +191,9 @@ rowdragcol(Row *row, Column *c, int _0)
p = mouse->xy; p = mouse->xy;
if ((abs(p.x - op.x) < 5 && abs(p.y - op.y) < 5)) if ((abs(p.x - op.x) < 5 && abs(p.y - op.y) < 5))
return; return;
if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){ if (
(i > 0 && p.x < row->col[i - 1]->r.min.x) ||
(i < row->ncol - 1 && p.x > c->r.max.x)) {
/* shuffle */ /* shuffle */
x = c->r.min.x; x = c->r.min.x;
rowclose(row, c, FALSE); rowclose(row, c, FALSE);
@ -191,23 +215,31 @@ rowdragcol(Row *row, Column *c, int _0)
p.x = c->r.max.x - 80 - Scrollwid; p.x = c->r.max.x - 80 - Scrollwid;
r = d->r; r = d->r;
r.max.x = c->r.max.x; r.max.x = c->r.max.x;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.max.x = p.x; r.max.x = p.x;
colresize(d, r); colresize(d, r);
r = c->r; r = c->r;
r.min.x = p.x; r.min.x = p.x;
r.max.x = r.min.x; r.max.x = r.min.x;
r.max.x += Border; r.max.x += Border;
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
r.min.x = r.max.x; r.min.x = r.max.x;
r.max.x = c->r.max.x; r.max.x = c->r.max.x;
colresize(c, r); colresize(c, r);
colmousebut(c); colmousebut(c);
} }
void void rowclose(Row* row, Column* c, int dofree) {
rowclose(Row *row, Column *c, int dofree)
{
Rectangle r; Rectangle r;
int i; int i;
@ -223,7 +255,12 @@ rowclose(Row *row, Column *c, int dofree)
memmove(row->col + i, row->col + i + 1, (row->ncol - i) * sizeof(Column*)); memmove(row->col + i, row->col + i + 1, (row->ncol - i) * sizeof(Column*));
row->col = realloc(row->col, row->ncol * sizeof(Column*)); row->col = realloc(row->col, row->ncol * sizeof(Column*));
if (row->ncol == 0) { if (row->ncol == 0) {
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
return; return;
} }
if (i == row->ncol) { /* extend last column right */ if (i == row->ncol) { /* extend last column right */
@ -234,13 +271,16 @@ rowclose(Row *row, Column *c, int dofree)
c = row->col[i]; c = row->col[i];
r.max.x = c->r.max.x; r.max.x = c->r.max.x;
} }
draw(screen, r, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
colresize(c, r); colresize(c, r);
} }
Column* Column* rowwhichcol(Row* row, Point p) {
rowwhichcol(Row *row, Point p)
{
int i; int i;
Column* c; Column* c;
@ -252,9 +292,7 @@ rowwhichcol(Row *row, Point p)
return nil; return nil;
} }
Text* Text* rowwhich(Row* row, Point p) {
rowwhich(Row *row, Point p)
{
Column* c; Column* c;
if (ptinrect(p, row->tag.all)) if (ptinrect(p, row->tag.all))
@ -265,9 +303,7 @@ rowwhich(Row *row, Point p)
return nil; return nil;
} }
Text* Text* rowtype(Row* row, Rune r, Point p) {
rowtype(Row *row, Rune r, Point p)
{
Window* w; Window* w;
Text* t; Text* t;
@ -301,9 +337,7 @@ rowtype(Row *row, Rune r, Point p)
return t; return t;
} }
int int rowclean(Row* row) {
rowclean(Row *row)
{
int clean; int clean;
int i; int i;
@ -313,9 +347,7 @@ rowclean(Row *row)
return clean; return clean;
} }
void void rowdump(Row* row, char* file) {
rowdump(Row *row, char *file)
{
int i, j, fd, m, n, dumped; int i, j, fd, m, n, dumped;
uint q0, q1; uint q0, q1;
Biobuf* b; Biobuf* b;
@ -403,30 +435,51 @@ rowdump(Row *row, char *file)
a = emalloc(1); a = emalloc(1);
if (t->file->dumpid) { if (t->file->dumpid) {
dumped = FALSE; dumped = FALSE;
Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid, Bprint(
w->body.q0, w->body.q1, b,
"x%11d %11d %11d %11d %11.7f %s\n",
i,
t->file->dumpid,
w->body.q0,
w->body.q1,
100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r), 100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r),
fontname); fontname);
} else if (w->dumpstr) { } else if (w->dumpstr) {
dumped = FALSE; dumped = FALSE;
Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid, Bprint(
0, 0, b,
"e%11d %11d %11d %11d %11.7f %s\n",
i,
t->file->dumpid,
0,
0,
100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r), 100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r),
fontname); fontname);
} else if ((w->dirty == FALSE && access(a, 0) == 0) || w->isdir) { } else if ((w->dirty == FALSE && access(a, 0) == 0) || w->isdir) {
dumped = FALSE; dumped = FALSE;
t->file->dumpid = w->id; t->file->dumpid = w->id;
Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id, Bprint(
w->body.q0, w->body.q1, b,
"f%11d %11d %11d %11d %11.7f %s\n",
i,
w->id,
w->body.q0,
w->body.q1,
100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r), 100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r),
fontname); fontname);
} else { } else {
dumped = TRUE; dumped = TRUE;
t->file->dumpid = w->id; t->file->dumpid = w->id;
Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j, Bprint(
w->body.q0, w->body.q1, b,
"F%11d %11d %11d %11d %11.7f %11d %s\n",
i,
j,
w->body.q0,
w->body.q1,
100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r), 100.0 * (w->r.min.y - c->r.min.y) / Dy(c->r),
w->body.file->b.nc, fontname); w->body.file->b.nc,
fontname);
} }
free(a); free(a);
winctlprint(w, buf, 0); winctlprint(w, buf, 0);
@ -467,10 +520,7 @@ rowdump(Row *row, char *file)
fbuffree(buf); fbuffree(buf);
} }
static static char* rdline(Biobuf* b, int* linep) {
char*
rdline(Biobuf *b, int *linep)
{
char* l; char* l;
l = Brdline(b, '\n'); l = Brdline(b, '\n');
@ -482,9 +532,7 @@ rdline(Biobuf *b, int *linep)
/* /*
* Get font names from load file so we don't load fonts we won't use * Get font names from load file so we don't load fonts we won't use
*/ */
void void rowloadfonts(char* file) {
rowloadfonts(char *file)
{
int i; int i;
Biobuf* b; Biobuf* b;
char* l; char* l;
@ -511,9 +559,7 @@ rowloadfonts(char *file)
Bterm(b); Bterm(b);
} }
int int rowload(Row* row, char* file, int initing) {
rowload(Row *row, char *file, int initing)
{
int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done; int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done;
double percent; double percent;
Biobuf *b, *bout; Biobuf *b, *bout;
@ -584,12 +630,22 @@ rowload(Row *row, char *file, int initing)
r2.min.x = x; r2.min.x = x;
if (Dx(r1) < 50 || Dx(r2) < 50) if (Dx(r1) < 50 || Dx(r2) < 50)
continue; continue;
draw(screen, Rpt(r1.min, r2.max), allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
Rpt(r1.min, r2.max),
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
colresize(c1, r1); colresize(c1, r1);
colresize(c2, r2); colresize(c2, r2);
r2.min.x = x - Border; r2.min.x = x - Border;
r2.max.x = x; r2.max.x = x;
draw(screen, r2, allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x222222FF), nil, ZP); draw(
screen,
r2,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
nil,
ZP);
} }
if (i >= row->ncol) if (i >= row->ncol)
rowadd(row, nil, x); rowadd(row, nil, x);
@ -795,9 +851,7 @@ Rescue1:
return FALSE; return FALSE;
} }
void void allwindows(void (*f)(Window*, void*), void* arg) {
allwindows(void (*f)(Window*, void*), void *arg)
{
int i, j; int i, j;
Column* c; Column* c;

28
scrl.c
View file

@ -14,10 +14,7 @@
static Image* scrtmp; static Image* scrtmp;
static static Rectangle scrpos(Rectangle r, uint p0, uint p1, uint tot) {
Rectangle
scrpos(Rectangle r, uint p0, uint p1, uint tot)
{
Rectangle q; Rectangle q;
int h; int h;
@ -43,18 +40,19 @@ scrpos(Rectangle r, uint p0, uint p1, uint tot)
return q; return q;
} }
void void scrlresize(void) {
scrlresize(void)
{
freeimage(scrtmp); freeimage(scrtmp);
scrtmp = allocimage(display, Rect(0, 0, 32, screen->r.max.y), screen->chan, 0, DNofill); scrtmp = allocimage(
display,
Rect(0, 0, 32, screen->r.max.y),
screen->chan,
0,
DNofill);
if (scrtmp == nil) if (scrtmp == nil)
error("scroll alloc"); error("scroll alloc");
} }
void void textscrdraw(Text* t) {
textscrdraw(Text *t)
{
Rectangle r, r1, r2; Rectangle r, r1, r2;
Image* b; Image* b;
@ -79,9 +77,7 @@ textscrdraw(Text *t)
} }
} }
void void scrsleep(uint dt) {
scrsleep(uint dt)
{
Timer* timer; Timer* timer;
static Alt alts[3]; static Alt alts[3];
@ -104,9 +100,7 @@ scrsleep(uint dt)
} }
} }
void void textscroll(Text* t, int but) {
textscroll(Text *t, int but)
{
uint p0, oldp0; uint p0, oldp0;
Rectangle s; Rectangle s;
int x, y, my, h, first; int x, y, my, h, first;

260
text.c
View file

@ -21,9 +21,7 @@ enum{
TABDIR = 3 /* width of tabs in directory windows */ TABDIR = 3 /* width of tabs in directory windows */
}; };
void void textinit(Text* t, File* f, Rectangle r, Reffont* rf, Image* cols[NCOL]) {
textinit(Text *t, File *f, Rectangle r, Reffont *rf, Image *cols[NCOL])
{
t->file = f; t->file = f;
t->all = r; t->all = r;
t->scrollr = r; t->scrollr = r;
@ -38,9 +36,7 @@ textinit(Text *t, File *f, Rectangle r, Reffont *rf, Image *cols[NCOL])
textredraw(t, r, rf->f, screen, -1); textredraw(t, r, rf->f, screen, -1);
} }
void void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx) {
textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx)
{
int maxt; int maxt;
Rectangle rr; Rectangle rr;
@ -70,9 +66,7 @@ textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx)
} }
} }
int int textresize(Text* t, Rectangle r, int keepextra) {
textresize(Text *t, Rectangle r, int keepextra)
{
int odx; int odx;
if (Dy(r) <= 0) if (Dy(r) <= 0)
@ -97,9 +91,7 @@ textresize(Text *t, Rectangle r, int keepextra)
return t->all.max.y; return t->all.max.y;
} }
void void textclose(Text* t) {
textclose(Text *t)
{
free(t->cache); free(t->cache);
frclear(&t->fr, 1); frclear(&t->fr, 1);
filedeltext(t->file, t); filedeltext(t->file, t);
@ -117,9 +109,7 @@ textclose(Text *t)
barttext = nil; barttext = nil;
} }
int int dircmp(const void* a, const void* b) {
dircmp(const void *a, const void *b)
{
Dirlist *da, *db; Dirlist *da, *db;
int i, n; int i, n;
@ -132,9 +122,7 @@ dircmp(const void *a, const void *b)
return da->nr - db->nr; return da->nr - db->nr;
} }
void void textcolumnate(Text* t, Dirlist** dlp, int ndl) {
textcolumnate(Text *t, Dirlist **dlp, int ndl)
{
int i, j, w, colw, mint, maxt, ncol, nrow; int i, j, w, colw, mint, maxt, ncol, nrow;
Dirlist* dl; Dirlist* dl;
uint q1; uint q1;
@ -189,9 +177,7 @@ textcolumnate(Text *t, Dirlist **dlp, int ndl)
} }
} }
int int textload(Text* t, uint q0, char* file, int setqid) {
textload(Text *t, uint q0, char *file, int setqid)
{
Rune* rp; Rune* rp;
Dirlist *dl, **dlp; Dirlist *dl, **dlp;
int fd, i, j, n, ndl, nulls; int fd, i, j, n, ndl, nulls;
@ -226,7 +212,10 @@ textload(Text *t, uint q0, char *file, int setqid)
if (d->qid.type & QTDIR) { if (d->qid.type & QTDIR) {
/* this is checked in get() but it's possible the file changed underfoot */ /* this is checked in get() but it's possible the file changed underfoot */
if (t->file->ntext > 1) { if (t->file->ntext > 1) {
warning(nil, "%s is a directory; can't read with multiple windows on it\n", file); warning(
nil,
"%s is a directory; can't read with multiple windows on it\n",
file);
goto Rescue; goto Rescue;
} }
t->w->isdir = TRUE; t->w->isdir = TRUE;
@ -300,7 +289,8 @@ textload(Text *t, uint q0, char *file, int setqid)
for (i = 0; i < t->file->ntext; i++) { for (i = 0; i < t->file->ntext; i++) {
u = t->file->text[i]; u = t->file->text[i];
if (u != t) { if (u != t) {
if(u->org > u->file->b.nc) /* will be 0 because of reset(), but safety first */ if (u->org > u->file->b.nc) /* will be 0 because of reset(), but safety
first */
u->org = 0; u->org = 0;
textresize(u, u->all, TRUE); textresize(u, u->all, TRUE);
textbacknl(u, u->org, 0); /* go to beginning of line */ textbacknl(u, u->org, 0); /* go to beginning of line */
@ -317,13 +307,12 @@ textload(Text *t, uint q0, char *file, int setqid)
return -1; return -1;
} }
uint uint textbsinsert(Text* t, uint q0, Rune* r, uint n, int tofile, int* nrp) {
textbsinsert(Text *t, uint q0, Rune *r, uint n, int tofile, int *nrp)
{
Rune *bp, *tp, *up; Rune *bp, *tp, *up;
int i, initial; int i, initial;
if(t->what == Tag){ /* can't happen but safety first: mustn't backspace over file name */ if (t->what == Tag) { /* can't happen but safety first: mustn't backspace over
file name */
Err: Err:
textinsert(t, q0, r, n, tofile); textinsert(t, q0, r, n, tofile);
*nrp = n; *nrp = n;
@ -362,9 +351,7 @@ textbsinsert(Text *t, uint q0, Rune *r, uint n, int tofile, int *nrp)
goto Err; goto Err;
} }
void void textinsert(Text* t, uint q0, Rune* r, uint n, int tofile) {
textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
{
int c, i; int c, i;
Text* u; Text* u;
@ -388,7 +375,6 @@ textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
textscrdraw(u); textscrdraw(u);
} }
} }
} }
if (q0 < t->iq1) if (q0 < t->iq1)
t->iq1 += n; t->iq1 += n;
@ -411,18 +397,14 @@ textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
} }
} }
void void typecommit(Text* t) {
typecommit(Text *t)
{
if (t->w != nil) if (t->w != nil)
wincommit(t->w, t); wincommit(t->w, t);
else else
textcommit(t, TRUE); textcommit(t, TRUE);
} }
void void textfill(Text* t) {
textfill(Text *t)
{
Rune* rp; Rune* rp;
int i, n, m, nl; int i, n, m, nl;
@ -456,9 +438,7 @@ textfill(Text *t)
fbuffree(rp); fbuffree(rp);
} }
void void textdelete(Text* t, uint q0, uint q1, int tofile) {
textdelete(Text *t, uint q0, uint q1, int tofile)
{
uint n, p0, p1; uint n, p0, p1;
int i, c; int i, c;
Text* u; Text* u;
@ -513,16 +493,12 @@ textdelete(Text *t, uint q0, uint q1, int tofile)
} }
} }
void void textconstrain(Text* t, uint q0, uint q1, uint* p0, uint* p1) {
textconstrain(Text *t, uint q0, uint q1, uint *p0, uint *p1)
{
*p0 = min(q0, t->file->b.nc); *p0 = min(q0, t->file->b.nc);
*p1 = min(q1, t->file->b.nc); *p1 = min(q1, t->file->b.nc);
} }
Rune Rune textreadc(Text* t, uint q) {
textreadc(Text *t, uint q)
{
Rune r; Rune r;
if (t->cq0 <= q && q < t->cq0 + t->ncache) if (t->cq0 <= q && q < t->cq0 + t->ncache)
@ -532,9 +508,7 @@ textreadc(Text *t, uint q)
return r; return r;
} }
static int static int spacesindentbswidth(Text* t) {
spacesindentbswidth(Text *t)
{
uint q, col; uint q, col;
Rune r; Rune r;
@ -553,9 +527,7 @@ spacesindentbswidth(Text *t)
return t->q0 - q; return t->q0 - q;
} }
int int textbswidth(Text* t, Rune c) {
textbswidth(Text *t, Rune c)
{
uint q, eq; uint q, eq;
Rune r; Rune r;
int skipping; int skipping;
@ -587,9 +559,7 @@ textbswidth(Text *t, Rune c)
return t->q0 - q; return t->q0 - q;
} }
int int textfilewidth(Text* t, uint q0, int oneelement) {
textfilewidth(Text *t, uint q0, int oneelement)
{
uint q; uint q;
Rune r; Rune r;
@ -605,9 +575,7 @@ textfilewidth(Text *t, uint q0, int oneelement)
return q0 - q; return q0 - q;
} }
Rune* Rune* textcomplete(Text* t) {
textcomplete(Text *t)
{
int i, nstr, npath; int i, nstr, npath;
uint q; uint q;
Rune tmp[200]; Rune tmp[200];
@ -618,7 +586,8 @@ textcomplete(Text *t)
Runestr dir; Runestr dir;
/* control-f: filename completion; works back to white space or / */ /* control-f: filename completion; works back to white space or / */
if(t->q0<t->file->b.nc && textreadc(t, t->q0)>' ') /* must be at end of word */ if (t->q0 < t->file->b.nc && textreadc(t, t->q0) > ' ') /* must be at end of
word */
return nil; return nil;
nstr = textfilewidth(t, t->q0, TRUE); nstr = textfilewidth(t, t->q0, TRUE);
str = runemalloc(nstr); str = runemalloc(nstr);
@ -667,10 +636,14 @@ textcomplete(Text *t)
} }
if (!c->advance) { if (!c->advance) {
warning(nil, "%.*S%s%.*S*%s\n", warning(
dir.nr, dir.r, nil,
"%.*S%s%.*S*%s\n",
dir.nr,
dir.r,
dir.nr > 0 && dir.r[dir.nr - 1] != '/' ? "/" : "", dir.nr > 0 && dir.r[dir.nr - 1] != '/' ? "/" : "",
nstr, str, nstr,
str,
c->nmatch ? "" : ": no matches in:"); c->nmatch ? "" : ": no matches in:");
for (i = 0; i < c->nfile; i++) for (i = 0; i < c->nfile; i++)
warning(nil, " %s\n", c->filename[i]); warning(nil, " %s\n", c->filename[i]);
@ -687,9 +660,7 @@ textcomplete(Text *t)
free(path); free(path);
return rp; return rp;
} }
void void texttype(Text* t, Rune r) {
texttype(Text *t, Rune r)
{
uint q0, q1; uint q0, q1;
int nnb, nb, n, i; int nnb, nb, n, i;
int nr; int nr;
@ -746,7 +717,10 @@ texttype(Text *t, Rune r)
case Kpgdown: case Kpgdown:
n = 2 * t->fr.maxlines / 3; n = 2 * t->fr.maxlines / 3;
case_Down: case_Down:
q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+n*t->fr.font->height)); q0 =
t->org + frcharofpt(
&t->fr,
Pt(t->fr.r.min.x, t->fr.r.min.y + n * t->fr.font->height));
textsetorigin(t, q0, TRUE); textsetorigin(t, q0, TRUE);
return; return;
case Kup: case Kup:
@ -899,7 +873,8 @@ texttype(Text *t, Rune r)
nnb = textbswidth(t, r); nnb = textbswidth(t, r);
q1 = t->q0; q1 = t->q0;
q0 = q1 - nnb; q0 = q1 - nnb;
/* if selection is at beginning of window, avoid deleting invisible text */ /* if selection is at beginning of window, avoid deleting invisible text
*/
if (q0 < t->org) { if (q0 < t->org) {
q0 = t->org; q0 = t->org;
nnb = q1 - q0; nnb = q1 - q0;
@ -961,7 +936,8 @@ texttype(Text *t, Rune r)
} }
break; /* fall through to normal code */ break; /* fall through to normal code */
} }
/* otherwise ordinary character; just insert, typically in caches of all texts */ /* otherwise ordinary character; just insert, typically in caches of all texts
*/
for (i = 0; i < t->file->ntext; i++) { for (i = 0; i < t->file->ntext; i++) {
u = t->file->text[i]; u = t->file->text[i];
if (u->eq0 == ~0) if (u->eq0 == ~0)
@ -998,10 +974,7 @@ texttype(Text *t, Rune r)
t->iq1 = t->q0; t->iq1 = t->q0;
} }
void textcommit(Text* t, int tofile) {
void
textcommit(Text *t, int tofile)
{
if (t->ncache == 0) if (t->ncache == 0)
return; return;
if (tofile) if (tofile)
@ -1021,17 +994,13 @@ static uint selectq;
/* /*
* called from frame library * called from frame library
*/ */
void void framescroll(Frame* f, int dl) {
framescroll(Frame *f, int dl)
{
if (f != &selecttext->fr) if (f != &selecttext->fr)
error("frameselect not right frame"); error("frameselect not right frame");
textframescroll(selecttext, dl); textframescroll(selecttext, dl);
} }
void void textframescroll(Text* t, int dl) {
textframescroll(Text *t, int dl)
{
uint q0; uint q0;
if (dl == 0) { if (dl == 0) {
@ -1047,7 +1016,9 @@ textframescroll(Text *t, int dl)
} else { } else {
if (t->org + t->fr.nchars == t->file->b.nc) if (t->org + t->fr.nchars == t->file->b.nc)
return; return;
q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+dl*t->fr.font->height)); q0 = t->org + frcharofpt(
&t->fr,
Pt(t->fr.r.min.x, t->fr.r.min.y + dl * t->fr.font->height));
if (selectq > t->org + t->fr.p1) if (selectq > t->org + t->fr.p1)
textsetselect(t, t->org + t->fr.p1, selectq); textsetselect(t, t->org + t->fr.p1, selectq);
else else
@ -1056,10 +1027,7 @@ textframescroll(Text *t, int dl)
textsetorigin(t, q0, TRUE); textsetorigin(t, q0, TRUE);
} }
void textselect(Text* t) {
void
textselect(Text *t)
{
uint q0, q1; uint q0, q1;
int b, x, y; int b, x, y;
int state; int state;
@ -1084,7 +1052,8 @@ textselect(Text *t)
/* stay here until something interesting happens */ /* stay here until something interesting happens */
do do
readmouse(mousectl); readmouse(mousectl);
while(mouse->buttons==b && abs(mouse->xy.x-x)<3 && abs(mouse->xy.y-y)<3); while (mouse->buttons == b && abs(mouse->xy.x - x) < 3 &&
abs(mouse->xy.y - y) < 3);
mouse->xy.x = x; /* in case we're calling frselect */ mouse->xy.x = x; /* in case we're calling frselect */
mouse->xy.y = y; mouse->xy.y = y;
q0 = t->q0; /* may have changed */ q0 = t->q0; /* may have changed */
@ -1157,9 +1126,7 @@ textselect(Text *t)
} }
} }
void void textshow(Text* t, uint q0, uint q1, int doselect) {
textshow(Text *t, uint q0, uint q1, int doselect)
{
int qe; int qe;
int nl; int nl;
int tsd; int tsd;
@ -1205,10 +1172,7 @@ textshow(Text *t, uint q0, uint q1, int doselect)
} }
} }
static static int region(int a, int b) {
int
region(int a, int b)
{
if (a < b) if (a < b)
return -1; return -1;
if (a == b) if (a == b)
@ -1216,9 +1180,7 @@ region(int a, int b)
return 1; return 1;
} }
void void selrestore(Frame* f, Point pt0, uint p0, uint p1) {
selrestore(Frame *f, Point pt0, uint p0, uint p1)
{
if (p1 <= f->p0 || p0 >= f->p1) { if (p1 <= f->p0 || p0 >= f->p1) {
/* no overlap */ /* no overlap */
frdrawsel0(f, pt0, p0, p1, f->cols[BACK], f->cols[TEXT]); frdrawsel0(f, pt0, p0, p1, f->cols[BACK], f->cols[TEXT]);
@ -1240,16 +1202,20 @@ selrestore(Frame *f, Point pt0, uint p0, uint p1)
} }
/* after selection */ /* after selection */
if (p1 > f->p1) { if (p1 > f->p1) {
frdrawsel0(f, frptofchar(f, f->p1), f->p1, p1, f->cols[BACK], f->cols[TEXT]); frdrawsel0(
f,
frptofchar(f, f->p1),
f->p1,
p1,
f->cols[BACK],
f->cols[TEXT]);
p1 = f->p1; p1 = f->p1;
} }
/* inside selection */ /* inside selection */
frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]); frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]);
} }
void void textsetselect(Text* t, uint q0, uint q1) {
textsetselect(Text *t, uint q0, uint q1)
{
int p0, p1, ticked; int p0, p1, ticked;
/* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */ /* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */
@ -1277,7 +1243,14 @@ textsetselect(Text *t, uint q0, uint q1)
return; return;
} }
if (p0 > p1) if (p0 > p1)
sysfatal("acme: textsetselect p0=%d p1=%d q0=%ud q1=%ud t->org=%d nchars=%d", p0, p1, q0, q1, (int)t->org, (int)t->fr.nchars); sysfatal(
"acme: textsetselect p0=%d p1=%d q0=%ud q1=%ud t->org=%d nchars=%d",
p0,
p1,
q0,
q1,
(int)t->org,
(int)t->fr.nchars);
/* screen disagrees with desired selection */ /* screen disagrees with desired selection */
if (t->fr.p1 <= p0 || p1 <= t->fr.p0 || p0 == p1 || t->fr.p1 == t->fr.p0) { if (t->fr.p1 <= p0 || p1 <= t->fr.p0 || p0 == p1 || t->fr.p1 == t->fr.p0) {
/* no overlap or too easy to bother trying */ /* no overlap or too easy to bother trying */
@ -1311,13 +1284,11 @@ textsetselect(Text *t, uint q0, uint q1)
* Release the button in less than DELAY ms and it's considered a null selection * Release the button in less than DELAY ms and it's considered a null selection
* if the mouse hardly moved, regardless of whether it crossed a char boundary. * if the mouse hardly moved, regardless of whether it crossed a char boundary.
*/ */
enum { enum { DELAY = 2, MINMOVE = 4 };
DELAY = 2,
MINMOVE = 4
};
uint uint xselect(
xselect(Frame *f, Mousectl *mc, Image *col, uint *p1p) /* when called, button is down */ Frame* f, Mousectl* mc, Image* col,
uint* p1p) /* when called, button is down */
{ {
uint p0, p1, q, tmp; uint p0, p1, q, tmp;
ulong msec; ulong msec;
@ -1373,9 +1344,9 @@ xselect(Frame *f, Mousectl *mc, Image *col, uint *p1p) /* when called, button is
flushimage(f->display, 1); flushimage(f->display, 1);
readmouse(mc); readmouse(mc);
} while (mc->m.buttons == b); } while (mc->m.buttons == b);
if(mc->m.msec-msec < DELAY && p0!=p1 if (
&& abs(mp.x-mc->m.xy.x)<MINMOVE mc->m.msec - msec < DELAY && p0 != p1 && abs(mp.x - mc->m.xy.x) < MINMOVE &&
&& abs(mp.y-mc->m.xy.y)<MINMOVE) { abs(mp.y - mc->m.xy.y) < MINMOVE) {
if (reg > 0) if (reg > 0)
selrestore(f, pt0, p0, p1); selrestore(f, pt0, p0, p1);
else if (reg < 0) else if (reg < 0)
@ -1399,9 +1370,7 @@ xselect(Frame *f, Mousectl *mc, Image *col, uint *p1p) /* when called, button is
return p0; return p0;
} }
int int textselect23(Text* t, uint* q0, uint* q1, Image* high, int mask) {
textselect23(Text *t, uint *q0, uint *q1, Image *high, int mask)
{
uint p0, p1; uint p0, p1;
int buts; int buts;
@ -1417,9 +1386,7 @@ textselect23(Text *t, uint *q0, uint *q1, Image *high, int mask)
return buts; return buts;
} }
int int textselect2(Text* t, uint* q0, uint* q1, Text** tp) {
textselect2(Text *t, uint *q0, uint *q1, Text **tp)
{
int buts; int buts;
*tp = nil; *tp = nil;
@ -1433,9 +1400,7 @@ textselect2(Text *t, uint *q0, uint *q1, Text **tp)
return 1; return 1;
} }
int int textselect3(Text* t, uint* q0, uint* q1) {
textselect3(Text *t, uint *q0, uint *q1)
{
int h; int h;
h = (textselect23(t, q0, q1, but3col, 1 | 2) == 0); h = (textselect23(t, q0, q1, but3col, 1 | 2) == 0);
@ -1447,24 +1412,10 @@ static Rune right1[] = { '}', ']', ')', '>', 0xbb, 0 };
static Rune left2[] = {'\n', 0}; static Rune left2[] = {'\n', 0};
static Rune left3[] = {'\'', '"', '`', 0}; static Rune left3[] = {'\'', '"', '`', 0};
static static Rune* left[] = {left1, left2, left3, nil};
Rune *left[] = { static Rune* right[] = {right1, left2, left3, nil};
left1,
left2,
left3,
nil
};
static
Rune *right[] = {
right1,
left2,
left3,
nil
};
void void textdoubleclick(Text* t, uint* q0, uint* q1) {
textdoubleclick(Text *t, uint *q0, uint *q1)
{
int c, i; int c, i;
Rune *r, *l, *p; Rune *r, *l, *p;
uint q; uint q;
@ -1512,9 +1463,7 @@ textdoubleclick(Text *t, uint *q0, uint *q1)
(*q0)--; (*q0)--;
} }
int int textclickmatch(Text* t, int cl, int cr, int dir, uint* q) {
textclickmatch(Text *t, int cl, int cr, int dir, uint *q)
{
Rune c; Rune c;
int nest; int nest;
@ -1543,9 +1492,7 @@ textclickmatch(Text *t, int cl, int cr, int dir, uint *q)
// Is the text starting at location q an html tag? // Is the text starting at location q an html tag?
// Return 1 for <a>, -1 for </a>, 0 for no tag or <a />. // Return 1 for <a>, -1 for </a>, 0 for no tag or <a />.
// Set *q1, if non-nil, to the location after the tag. // Set *q1, if non-nil, to the location after the tag.
static int static int ishtmlstart(Text* t, uint q, uint* q1) {
ishtmlstart(Text *t, uint q, uint *q1)
{
int c, c1, c2; int c, c1, c2;
if (q + 2 > t->file->b.nc) if (q + 2 > t->file->b.nc)
@ -1573,9 +1520,7 @@ ishtmlstart(Text *t, uint q, uint *q1)
// Is the text ending at location q an html tag? // Is the text ending at location q an html tag?
// Return 1 for <a>, -1 for </a>, 0 for no tag or <a />. // Return 1 for <a>, -1 for </a>, 0 for no tag or <a />.
// Set *q0, if non-nil, to the start of the tag. // Set *q0, if non-nil, to the start of the tag.
static int static int ishtmlend(Text* t, uint q, uint* q0) {
ishtmlend(Text *t, uint q, uint *q0)
{
int c, c1, c2; int c, c1, c2;
if (q < 2) if (q < 2)
@ -1600,9 +1545,7 @@ ishtmlend(Text *t, uint q, uint *q0)
return 1; return 1;
} }
int int textclickhtmlmatch(Text* t, uint* q0, uint* q1) {
textclickhtmlmatch(Text *t, uint *q0, uint *q1)
{
int depth, n; int depth, n;
uint q, nq; uint q, nq;
@ -1646,9 +1589,7 @@ textclickhtmlmatch(Text *t, uint *q0, uint *q1)
return 0; return 0;
} }
uint uint textbacknl(Text* t, uint p, uint n) {
textbacknl(Text *t, uint p, uint n)
{
int i, j; int i, j;
/* look for start of this line if n==0 */ /* look for start of this line if n==0 */
@ -1667,9 +1608,7 @@ textbacknl(Text *t, uint p, uint n)
return p; return p;
} }
void void textsetorigin(Text* t, uint org, int exact) {
textsetorigin(Text *t, uint org, int exact)
{
int i, a, fixup; int i, a, fixup;
Rune* r; Rune* r;
uint n; uint n;
@ -1689,9 +1628,9 @@ textsetorigin(Text *t, uint org, int exact)
fixup = 0; fixup = 0;
if (a >= 0 && a < t->fr.nchars) { if (a >= 0 && a < t->fr.nchars) {
frdelete(&t->fr, 0, a); frdelete(&t->fr, 0, a);
fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */ fixup = 1; /* frdelete can leave end of last line in wrong selection mode;
} it doesn't know what follows */
else if(a<0 && -a<t->fr.nchars){ } else if (a < 0 && -a < t->fr.nchars) {
n = t->org - org; n = t->org - org;
r = runemalloc(n); r = runemalloc(n);
bufread(&t->file->b, org, r, n); bufread(&t->file->b, org, r, n);
@ -1704,12 +1643,15 @@ textsetorigin(Text *t, uint org, int exact)
textscrdraw(t); textscrdraw(t);
textsetselect(t, t->q0, t->q1); textsetselect(t, t->q0, t->q1);
if (fixup && t->fr.p1 > t->fr.p0) if (fixup && t->fr.p1 > t->fr.p0)
frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p1-1), t->fr.p1-1, t->fr.p1, 1); frdrawsel(
&t->fr,
frptofchar(&t->fr, t->fr.p1 - 1),
t->fr.p1 - 1,
t->fr.p1,
1);
} }
void void textreset(Text* t) {
textreset(Text *t)
{
t->file->seq = 0; t->file->seq = 0;
t->eq0 = ~0; t->eq0 = ~0;
/* do t->delete(0, t->nc, TRUE) without building backup stuff */ /* do t->delete(0, t->nc, TRUE) without building backup stuff */

33
time.c
View file

@ -15,30 +15,16 @@
static Channel* ctimer; /* chan(Timer*)[100] */ static Channel* ctimer; /* chan(Timer*)[100] */
static Timer* timer; static Timer* timer;
static static uint msec(void) { return nsec() / 1000000; }
uint
msec(void)
{
return nsec()/1000000;
}
void void timerstop(Timer* t) {
timerstop(Timer *t)
{
t->next = timer; t->next = timer;
timer = t; timer = t;
} }
void void timercancel(Timer* t) { t->cancel = TRUE; }
timercancel(Timer *t)
{
t->cancel = TRUE;
}
static static void timerproc(void* v) {
void
timerproc(void *v)
{
int i, nt, na, dt, del; int i, nt, na, dt, del;
Timer **t, *x; Timer **t, *x;
uint old, new; uint old, new;
@ -51,7 +37,8 @@ timerproc(void *v)
nt = 0; nt = 0;
old = msec(); old = msec();
for (;;) { for (;;) {
sleep(10); /* longer sleeps here delay recv on ctimer, but 10ms should not be noticeable */ sleep(10); /* longer sleeps here delay recv on ctimer, but 10ms should not
be noticeable */
new = msec(); new = msec();
dt = new - old; dt = new - old;
old = new; old = new;
@ -95,17 +82,13 @@ timerproc(void *v)
} }
} }
void void timerinit(void) {
timerinit(void)
{
ctimer = chancreate(sizeof(Timer*), 100); ctimer = chancreate(sizeof(Timer*), 100);
chansetname(ctimer, "ctimer"); chansetname(ctimer, "ctimer");
proccreate(timerproc, nil, STACK); proccreate(timerproc, nil, STACK);
} }
Timer* Timer* timerstart(int dt) {
timerstart(int dt)
{
Timer* t; Timer* t;
t = timer; t = timer;

117
util.c
View file

@ -15,9 +15,7 @@
static Point prevmouse; static Point prevmouse;
static Window* mousew; static Window* mousew;
Range Range range(int q0, int q1) {
range(int q0, int q1)
{
Range r; Range r;
r.q0 = q0; r.q0 = q0;
@ -25,9 +23,7 @@ range(int q0, int q1)
return r; return r;
} }
Runestr Runestr runestr(Rune* r, uint n) {
runestr(Rune *r, uint n)
{
Runestr rs; Runestr rs;
rs.r = r; rs.r = r;
@ -35,9 +31,7 @@ runestr(Rune *r, uint n)
return rs; return rs;
} }
void void cvttorunes(char* p, int n, Rune* r, int* nb, int* nr, int* nulls) {
cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
{
uchar* q; uchar* q;
Rune* s; Rune* s;
int j, w; int j, w;
@ -68,16 +62,12 @@ cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
*nr = s - r; *nr = s - r;
} }
void void error(char* s) {
error(char *s)
{
fprint(2, "acme: %s: %r\n", s); fprint(2, "acme: %s: %r\n", s);
threadexitsall(nil); threadexitsall(nil);
} }
Window* Window* errorwin1(Rune* dir, int ndir, Rune** incl, int nincl) {
errorwin1(Rune *dir, int ndir, Rune **incl, int nincl)
{
Window* w; Window* w;
Rune* r; Rune* r;
int i, n; int i, n;
@ -113,9 +103,7 @@ errorwin1(Rune *dir, int ndir, Rune **incl, int nincl)
} }
/* make new window, if necessary; return with it locked */ /* make new window, if necessary; return with it locked */
Window* Window* errorwin(Mntdir* md, int owner) {
errorwin(Mntdir *md, int owner)
{
Window* w; Window* w;
for (;;) { for (;;) {
@ -137,9 +125,7 @@ errorwin(Mntdir *md, int owner)
* It will be unlocked and returned window * It will be unlocked and returned window
* will be locked in its place. * will be locked in its place.
*/ */
Window* Window* errorwinforwin(Window* w) {
errorwinforwin(Window *w)
{
int i, n, nincl, owner; int i, n, nincl, owner;
Rune** incl; Rune** incl;
Runestr dir; Runestr dir;
@ -185,10 +171,7 @@ struct Warning{
static Warning* warnings; static Warning* warnings;
static static void addwarningtext(Mntdir* md, Rune* r, int nr) {
void
addwarningtext(Mntdir *md, Rune *r, int nr)
{
Warning* warn; Warning* warn;
for (warn = warnings; warn; warn = warn->next) { for (warn = warnings; warn; warn = warn->next) {
@ -208,9 +191,7 @@ addwarningtext(Mntdir *md, Rune *r, int nr)
} }
/* called while row is locked */ /* called while row is locked */
void void flushwarnings(void) {
flushwarnings(void)
{
Warning *warn, *next; Warning *warn, *next;
Window* w; Window* w;
Text* t; Text* t;
@ -257,9 +238,7 @@ flushwarnings(void)
warnings = nil; warnings = nil;
} }
void void warning(Mntdir* md, char* s, ...) {
warning(Mntdir *md, char *s, ...)
{
Rune* r; Rune* r;
va_list arg; va_list arg;
@ -272,33 +251,25 @@ warning(Mntdir *md, char *s, ...)
free(r); free(r);
} }
int int runeeq(Rune* s1, uint n1, Rune* s2, uint n2) {
runeeq(Rune *s1, uint n1, Rune *s2, uint n2)
{
if (n1 != n2) if (n1 != n2)
return FALSE; return FALSE;
return memcmp(s1, s2, n1 * sizeof(Rune)) == 0; return memcmp(s1, s2, n1 * sizeof(Rune)) == 0;
} }
uint uint min(uint a, uint b) {
min(uint a, uint b)
{
if (a < b) if (a < b)
return a; return a;
return b; return b;
} }
uint uint max(uint a, uint b) {
max(uint a, uint b)
{
if (a > b) if (a > b)
return a; return a;
return b; return b;
} }
char* char* runetobyte(Rune* r, int n) {
runetobyte(Rune *r, int n)
{
char* s; char* s;
if (r == nil) if (r == nil)
@ -309,9 +280,7 @@ runetobyte(Rune *r, int n)
return s; return s;
} }
Rune* Rune* bytetorune(char* s, int* ip) {
bytetorune(char *s, int *ip)
{
Rune* r; Rune* r;
int nb, nr; int nb, nr;
@ -323,9 +292,7 @@ bytetorune(char *s, int *ip)
return r; return r;
} }
int int isalnum(Rune c) {
isalnum(Rune c)
{
/* /*
* Hard to get absolutely right. Use what we know about ASCII * Hard to get absolutely right. Use what we know about ASCII
* and assume anything above the Latin control characters is * and assume anything above the Latin control characters is
@ -340,15 +307,9 @@ isalnum(Rune c)
return TRUE; return TRUE;
} }
int int rgetc(void* v, uint n) { return ((Rune*)v)[n]; }
rgetc(void *v, uint n)
{
return ((Rune*)v)[n];
}
int int tgetc(void* a, uint n) {
tgetc(void *a, uint n)
{
Text* t; Text* t;
t = a; t = a;
@ -357,9 +318,7 @@ tgetc(void *a, uint n)
return textreadc(t, n); return textreadc(t, n);
} }
Rune* Rune* skipbl(Rune* r, int n, int* np) {
skipbl(Rune *r, int n, int *np)
{
while (n > 0 && (*r == ' ' || *r == '\t' || *r == '\n')) { while (n > 0 && (*r == ' ' || *r == '\t' || *r == '\n')) {
--n; --n;
r++; r++;
@ -368,9 +327,7 @@ skipbl(Rune *r, int n, int *np)
return r; return r;
} }
Rune* Rune* findbl(Rune* r, int n, int* np) {
findbl(Rune *r, int n, int *np)
{
while (n > 0 && *r != ' ' && *r != '\t' && *r != '\n') { while (n > 0 && *r != ' ' && *r != '\t' && *r != '\n') {
--n; --n;
r++; r++;
@ -379,16 +336,12 @@ findbl(Rune *r, int n, int *np)
return r; return r;
} }
void void savemouse(Window* w) {
savemouse(Window *w)
{
prevmouse = mouse->xy; prevmouse = mouse->xy;
mousew = w; mousew = w;
} }
int int restoremouse(Window* w) {
restoremouse(Window *w)
{
int did; int did;
did = 0; did = 0;
@ -400,15 +353,9 @@ restoremouse(Window *w)
return did; return did;
} }
void void clearmouse() { mousew = nil; }
clearmouse()
{
mousew = nil;
}
char* char* estrdup(char* s) {
estrdup(char *s)
{
char* t; char* t;
t = strdup(s); t = strdup(s);
@ -418,9 +365,7 @@ estrdup(char *s)
return t; return t;
} }
void* void* emalloc(uint n) {
emalloc(uint n)
{
void* p; void* p;
p = malloc(n); p = malloc(n);
@ -431,9 +376,7 @@ emalloc(uint n)
return p; return p;
} }
void* void* erealloc(void* p, uint n) {
erealloc(void *p, uint n)
{
p = realloc(p, n); p = realloc(p, n);
if (p == nil) if (p == nil)
error("realloc failed"); error("realloc failed");
@ -444,9 +387,7 @@ erealloc(void *p, uint n)
/* /*
* Heuristic city. * Heuristic city.
*/ */
Window* Window* makenewwindow(Text* t) {
makenewwindow(Text *t)
{
Column* c; Column* c;
Window *w, *bigw, *emptyw; Window *w, *bigw, *emptyw;
Text* emptyb; Text* emptyb;
@ -475,7 +416,9 @@ makenewwindow(Text *t)
/* use >= to choose one near bottom of screen */ /* use >= to choose one near bottom of screen */
if (w->body.fr.maxlines >= bigw->body.fr.maxlines) if (w->body.fr.maxlines >= bigw->body.fr.maxlines)
bigw = w; bigw = w;
if(w->body.fr.maxlines-w->body.fr.nlines >= emptyw->body.fr.maxlines-emptyw->body.fr.nlines) if (
w->body.fr.maxlines - w->body.fr.nlines >=
emptyw->body.fr.maxlines - emptyw->body.fr.nlines)
emptyw = w; emptyw = w;
} }
emptyb = &emptyw->body; emptyb = &emptyw->body;

193
wind.c
View file

@ -14,9 +14,7 @@
int winid; int winid;
void void wininit(Window* w, Window* clone, Rectangle r) {
wininit(Window *w, Window *clone, Rectangle r)
{
Rectangle r1, br; Rectangle r1, br;
File* f; File* f;
Reffont* rf; Reffont* rf;
@ -94,9 +92,7 @@ wininit(Window *w, Window *clone, Rectangle r)
/* /*
* Draw the appropriate button. * Draw the appropriate button.
*/ */
void void windrawbutton(Window* w) {
windrawbutton(Window *w)
{
Image* b; Image* b;
Rectangle br; Rectangle br;
@ -109,9 +105,7 @@ windrawbutton(Window *w)
draw(screen, br, b, nil, b->r.min); draw(screen, br, b, nil, b->r.min);
} }
int int delrunepos(Window* w) {
delrunepos(Window *w)
{
int n; int n;
Rune rune; Rune rune;
@ -126,24 +120,22 @@ delrunepos(Window *w)
return n; return n;
} }
void void movetodel(Window* w) {
movetodel(Window *w)
{
int n; int n;
n = delrunepos(w); n = delrunepos(w);
if (n < 0) if (n < 0)
return; return;
moveto(mousectl, addpt(frptofchar(&w->tag.fr, n), Pt(4, w->tag.fr.font->height-4))); moveto(
mousectl,
addpt(frptofchar(&w->tag.fr, n), Pt(4, w->tag.fr.font->height - 4)));
} }
/* /*
* Compute number of tag lines required * Compute number of tag lines required
* to display entire tag text. * to display entire tag text.
*/ */
int int wintaglines(Window* w, Rectangle r) {
wintaglines(Window *w, Rectangle r)
{
int n; int n;
Rune rune; Rune rune;
Point p; Point p;
@ -181,9 +173,7 @@ wintaglines(Window *w, Rectangle r)
return n; return n;
} }
int int winresize(Window* w, Rectangle r, int safe, int keepextra) {
winresize(Window *w, Rectangle r, int safe, int keepextra)
{
int oy, y, mouseintag, mouseinbody; int oy, y, mouseintag, mouseinbody;
Point p; Point p;
Rectangle r1; Rectangle r1;
@ -253,17 +243,13 @@ winresize(Window *w, Rectangle r, int safe, int keepextra)
return w->r.max.y; return w->r.max.y;
} }
void void winlock1(Window* w, int owner) {
winlock1(Window *w, int owner)
{
incref(&w->ref); incref(&w->ref);
qlock(&w->lk); qlock(&w->lk);
w->owner = owner; w->owner = owner;
} }
void void winlock(Window* w, int owner) {
winlock(Window *w, int owner)
{
int i; int i;
File* f; File* f;
@ -272,9 +258,7 @@ winlock(Window *w, int owner)
winlock1(f->text[i]->w, owner); winlock1(f->text[i]->w, owner);
} }
void void winunlock(Window* w) {
winunlock(Window *w)
{
int i; int i;
File* f; File* f;
@ -292,16 +276,13 @@ winunlock(Window *w)
} }
} }
void void winmousebut(Window* w) {
winmousebut(Window *w) moveto(
{ mousectl,
moveto(mousectl, addpt(w->tag.scrollr.min, addpt(w->tag.scrollr.min, divpt(Pt(Dx(w->tag.scrollr), font->height), 2)));
divpt(Pt(Dx(w->tag.scrollr), font->height), 2)));
} }
void void windirfree(Window* w) {
windirfree(Window *w)
{
int i; int i;
Dirlist* dl; Dirlist* dl;
@ -317,9 +298,7 @@ windirfree(Window *w)
w->ndl = 0; w->ndl = 0;
} }
void void winclose(Window* w) {
winclose(Window *w)
{
int i; int i;
if (decref(&w->ref) == 0) { if (decref(&w->ref) == 0) {
@ -337,9 +316,7 @@ winclose(Window *w)
} }
} }
void void windelete(Window* w) {
windelete(Window *w)
{
Xfid* x; Xfid* x;
x = w->eventx; x = w->eventx;
@ -352,9 +329,7 @@ windelete(Window *w)
} }
} }
void void winundo(Window* w, int isundo) {
winundo(Window *w, int isundo)
{
Text* body; Text* body;
int i; int i;
File* f; File* f;
@ -376,9 +351,7 @@ winundo(Window *w, int isundo)
winsettag(w); winsettag(w);
} }
void void winsetname(Window* w, Rune* name, int n) {
winsetname(Window *w, Rune *name, int n)
{
Text* t; Text* t;
Window* v; Window* v;
int i; int i;
@ -401,9 +374,7 @@ winsetname(Window *w, Rune *name, int n)
} }
} }
void void wintype(Window* w, Text* t, Rune r) {
wintype(Window *w, Text *t, Rune r)
{
int i; int i;
texttype(t, r); texttype(t, r);
@ -413,19 +384,13 @@ wintype(Window *w, Text *t, Rune r)
winsettag(w); winsettag(w);
} }
void void wincleartag(Window* w) {
wincleartag(Window *w)
{
int i, n; int i, n;
Rune* r; Rune* r;
/* w must be committed */ /* w must be committed */
n = w->tag.file->b.nc; n = w->tag.file->b.nc;
r = runemalloc(n); r = parsetag(w, &i);
bufread(&w->tag.file->b, 0, r, n);
for(i=0; i<n; i++)
if(r[i]==' ' || r[i]=='\t')
break;
for (; i < n; i++) for (; i < n; i++)
if (r[i] == '|') if (r[i] == '|')
break; break;
@ -442,14 +407,47 @@ wincleartag(Window *w)
textsetselect(&w->tag, w->tag.q0, w->tag.q1); textsetselect(&w->tag, w->tag.q0, w->tag.q1);
} }
void Rune* parsetag(Window* w, int* len) {
winsettag1(Window *w) static Rune Ldelsnarf[] =
{ {' ', 'D', 'e', 'l', ' ', 'S', 'n', 'a', 'r', 'f', 0};
static Rune Lspacepipe[] = {' ', '|', 0};
static Rune Ltabpipe[] = {' ', '|', 0};
int i;
Rune *r, *p, *pipe;
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;
/*
* " |" or "\t|" ends left half of tag
* If we find " Del Snarf" in the left half of the tag
* (before the pipe), that ends the file name.
*/
pipe = runestrstr(r, Lspacepipe);
if ((p = runestrstr(r, Ltabpipe)) != nil && (pipe == nil || p < pipe))
pipe = p;
if ((p = runestrstr(r, Ldelsnarf)) != nil && (pipe == nil || p < pipe))
i = p - r;
else {
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) {
int i, j, k, n, bar, dirty, resize; int i, j, k, n, bar, dirty, resize;
Rune* new, *old, *r; Rune* new, *old, *r;
uint q0, q1; uint q0, q1;
static Rune Ldelsnarf[] = { ' ', 'D', 'e', 'l', ' ', static Rune Ldelsnarf[] =
'S', 'n', 'a', 'r', 'f', 0 }; {' ', 'D', 'e', 'l', ' ', 'S', 'n', 'a', 'r', 'f', 0};
static Rune Lundo[] = {' ', 'U', 'n', 'd', 'o', 0}; static Rune Lundo[] = {' ', 'U', 'n', 'd', 'o', 0};
static Rune Lredo[] = {' ', 'R', 'e', 'd', 'o', 0}; static Rune Lredo[] = {' ', 'R', 'e', 'd', 'o', 0};
static Rune Lget[] = {' ', 'G', 'e', 't', 0}; static Rune Lget[] = {' ', 'G', 'e', 't', 0};
@ -457,15 +455,12 @@ winsettag1(Window *w)
static Rune Llook[] = {' ', 'L', 'o', 'o', 'k', ' ', 0}; static Rune Llook[] = {' ', 'L', 'o', 'o', 'k', ' ', 0};
static Rune Lpipe[] = {' ', '|', 0}; static Rune Lpipe[] = {' ', '|', 0};
/* 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
old = runemalloc(w->tag.file->b.nc+1); contents */
bufread(&w->tag.file->b, 0, old, w->tag.file->b.nc); old = parsetag(w, &i);
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);
@ -491,7 +486,8 @@ winsettag1(Window *w)
runemove(new + i, Lredo, 5); runemove(new + i, Lredo, 5);
i += 5; i += 5;
} }
dirty = w->body.file->nname && (w->body.ncache || w->body.file->seq!=w->putseq); dirty =
w->body.file->nname && (w->body.ncache || w->body.file->seq != w->putseq);
if (!w->isdir && dirty) { if (!w->isdir && dirty) {
runemove(new + i, Lput, 4); runemove(new + i, Lput, 4);
i += 4; i += 4;
@ -556,9 +552,7 @@ winsettag1(Window *w)
} }
} }
void void winsettag(Window* w) {
winsettag(Window *w)
{
int i; int i;
File* f; File* f;
Window* v; Window* v;
@ -571,9 +565,7 @@ winsettag(Window *w)
} }
} }
void void wincommit(Window* w, Text* t) {
wincommit(Window *w, Text *t)
{
Rune* r; Rune* r;
int i; int i;
File* f; File* f;
@ -585,11 +577,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);
@ -601,9 +589,7 @@ wincommit(Window *w, Text *t)
free(r); free(r);
} }
void void winaddincl(Window* w, Rune* r, int n) {
winaddincl(Window *w, Rune *r, int n)
{
char* a; char* a;
Dir* d; Dir* d;
Runestr rs; Runestr rs;
@ -647,10 +633,9 @@ Rescue:
return; return;
} }
int int winclean(Window* w, int conservative) {
winclean(Window *w, int conservative) if (w->isscratch || w->isdir) /* don't whine if it's a guide file, error
{ window, etc. */
if(w->isscratch || w->isdir) /* don't whine if it's a guide file, error window, etc. */
return TRUE; return TRUE;
if (!conservative && w->nopen[QWevent] > 0) if (!conservative && w->nopen[QWevent] > 0)
return TRUE; return TRUE;
@ -668,20 +653,26 @@ winclean(Window *w, int conservative)
return TRUE; return TRUE;
} }
char* char* winctlprint(Window* w, char* buf, int fonts) {
winctlprint(Window *w, char *buf, int fonts) sprint(
{ buf,
sprint(buf, "%11d %11d %11d %11d %11d ", w->id, w->tag.file->b.nc, "%11d %11d %11d %11d %11d ",
w->body.file->b.nc, w->isdir, w->dirty); w->id,
w->tag.file->b.nc,
w->body.file->b.nc,
w->isdir,
w->dirty);
if (fonts) if (fonts)
return smprint("%s%11d %q %11d ", buf, Dx(w->body.fr.r), return smprint(
w->body.reffont->f->name, w->body.fr.maxtab); "%s%11d %q %11d ",
buf,
Dx(w->body.fr.r),
w->body.reffont->f->name,
w->body.fr.maxtab);
return buf; return buf;
} }
void void winevent(Window* w, char* fmt, ...) {
winevent(Window *w, char *fmt, ...)
{
int n; int n;
char* b; char* b;
Xfid* x; Xfid* x;

165
xfid.c
View file

@ -12,10 +12,7 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
enum enum { Ctlsize = 5 * 12 };
{
Ctlsize = 5*12
};
char Edel[] = "deleted window"; char Edel[] = "deleted window";
char Ebadctl[] = "ill-formed control message"; char Ebadctl[] = "ill-formed control message";
@ -25,10 +22,7 @@ char Einuse[] = "already in use";
char Ebadevent[] = "bad event syntax"; char Ebadevent[] = "bad event syntax";
extern char Eperm[]; extern char Eperm[];
static static void clampaddr(Window* w) {
void
clampaddr(Window *w)
{
if (w->addr.q0 < 0) if (w->addr.q0 < 0)
w->addr.q0 = 0; w->addr.q0 = 0;
if (w->addr.q1 < 0) if (w->addr.q1 < 0)
@ -39,9 +33,7 @@ clampaddr(Window *w)
w->addr.q1 = w->body.file->b.nc; w->addr.q1 = w->body.file->b.nc;
} }
void void xfidctl(void* arg) {
xfidctl(void *arg)
{
Xfid* x; Xfid* x;
void (*f)(Xfid*); void (*f)(Xfid*);
@ -55,9 +47,7 @@ xfidctl(void *arg)
} }
} }
void void xfidflush(Xfid* x) {
xfidflush(Xfid *x)
{
Fcall fc; Fcall fc;
int i, j; int i, j;
Window* w; Window* w;
@ -89,9 +79,7 @@ out:
respond(x, &fc, nil); respond(x, &fc, nil);
} }
void void xfidopen(Xfid* x) {
xfidopen(Xfid *x)
{
Fcall fc; Fcall fc;
Window* w; Window* w;
Text* t; Text* t;
@ -186,8 +174,7 @@ xfidopen(Xfid *x)
break; break;
} }
winunlock(w); winunlock(w);
} } else {
else{
switch (q) { switch (q) {
case Qlog: case Qlog:
xfidlogopen(x); xfidlogopen(x);
@ -206,9 +193,7 @@ xfidopen(Xfid *x)
respond(x, &fc, nil); respond(x, &fc, nil);
} }
void void xfidclose(Xfid* x) {
xfidclose(Xfid *x)
{
Fcall fc; Fcall fc;
Window* w; Window* w;
int q; int q;
@ -263,9 +248,13 @@ xfidclose(Xfid *x)
case QWwrsel: case QWwrsel:
w->nomark = FALSE; w->nomark = FALSE;
t = &w->body; t = &w->body;
/* before: only did this if !w->noscroll, but that didn't seem right in practice */ /* before: only did this if !w->noscroll, but that didn't seem right in
textshow(t, min(w->wrselrange.q0, t->file->b.nc), * practice */
min(w->wrselrange.q1, t->file->b.nc), 1); textshow(
t,
min(w->wrselrange.q0, t->file->b.nc),
min(w->wrselrange.q1, t->file->b.nc),
1);
textscrdraw(t); textscrdraw(t);
break; break;
case QWeditout: case QWeditout:
@ -274,8 +263,7 @@ xfidclose(Xfid *x)
} }
winunlock(w); winunlock(w);
winclose(w); winclose(w);
} } else {
else{
switch (q) { switch (q) {
case Qeditout: case Qeditout:
qunlock(&editoutlk); qunlock(&editoutlk);
@ -285,9 +273,7 @@ xfidclose(Xfid *x)
respond(x, &fc, nil); respond(x, &fc, nil);
} }
void void xfidread(Xfid* x) {
xfidread(Xfid *x)
{
Fcall fc; Fcall fc;
int n, q; int n, q;
uint off; uint off;
@ -404,24 +390,23 @@ xfidread(Xfid *x)
winunlock(w); winunlock(w);
} }
static int static int shouldscroll(Text* t, uint q0, int qid) {
shouldscroll(Text *t, uint q0, int qid)
{
if (qid == Qcons) if (qid == Qcons)
return TRUE; return TRUE;
return t->org <= q0 && q0 <= t->org + t->fr.nchars; return t->org <= q0 && q0 <= t->org + t->fr.nchars;
} }
static Rune* static Rune* fullrunewrite(Xfid* x, int* inr) {
fullrunewrite(Xfid *x, int *inr)
{
int q, cnt, c, nb, nr; int q, cnt, c, nb, nr;
Rune* r; Rune* r;
q = x->f->nrpart; q = x->f->nrpart;
cnt = x->fcall.count; cnt = x->fcall.count;
if (q > 0) { if (q > 0) {
memmove(x->fcall.data+q, x->fcall.data, cnt); /* there's room; see fsysproc */ memmove(
x->fcall.data + q,
x->fcall.data,
cnt); /* there's room; see fsysproc */
memmove(x->fcall.data, x->f->rpart, q); memmove(x->fcall.data, x->f->rpart, q);
cnt += q; cnt += q;
x->f->nrpart = 0; x->f->nrpart = 0;
@ -443,9 +428,7 @@ fullrunewrite(Xfid *x, int *inr)
return r; return r;
} }
void void xfidwrite(Xfid* x) {
xfidwrite(Xfid *x)
{
Fcall fc; Fcall fc;
int c, qid, nb, nr, eval; int c, qid, nb, nr, eval;
char buf[64], *err; char buf[64], *err;
@ -486,7 +469,17 @@ xfidwrite(Xfid *x)
t = &w->body; t = &w->body;
wincommit(w, t); wincommit(w, t);
eval = TRUE; eval = TRUE;
a = address(FALSE, t, w->limit, w->addr, r, 0, nr, rgetc, &eval, (uint*)&nb); a = address(
FALSE,
t,
w->limit,
w->addr,
r,
0,
nr,
rgetc,
&eval,
(uint*)&nb);
free(r); free(r);
if (nb < nr) { if (nb < nr) {
respond(x, &fc, Ebadaddr); respond(x, &fc, Ebadaddr);
@ -595,7 +588,10 @@ xfidwrite(Xfid *x)
filemark(t->file); filemark(t->file);
} }
q0 = textbsinsert(t, q0, r, nr, TRUE, &nr); q0 = textbsinsert(t, q0, r, nr, TRUE, &nr);
textsetselect(t, t->q0, t->q1); /* insert could leave it somewhere else */ textsetselect(
t,
t->q0,
t->q1); /* insert could leave it somewhere else */
if (qid != QWwrsel && shouldscroll(t, q0, qid)) if (qid != QWwrsel && shouldscroll(t, q0, qid))
textshow(t, q0 + nr, q0 + nr, 1); textshow(t, q0 + nr, q0 + nr, 1);
textscrdraw(t); textscrdraw(t);
@ -618,9 +614,7 @@ xfidwrite(Xfid *x)
winunlock(w); winunlock(w);
} }
void void xfidctlwrite(Xfid* x, Window* w) {
xfidctlwrite(Xfid *x, Window *w)
{
Fcall fc; Fcall fc;
int i, m, n, nb, nr, nulls; int i, m, n, nb, nr, nulls;
Rune* r; Rune* r;
@ -647,13 +641,11 @@ xfidctlwrite(Xfid *x, Window *w)
qlock(&w->ctllock); qlock(&w->ctllock);
w->ctlfid = x->f->fid; w->ctlfid = x->f->fid;
m = 4; m = 4;
}else } else if (strncmp(p, "unlock", 6) == 0) { /* release exclusive use */
if(strncmp(p, "unlock", 6) == 0){ /* release exclusive use */
w->ctlfid = ~0; w->ctlfid = ~0;
qunlock(&w->ctllock); qunlock(&w->ctllock);
m = 6; m = 6;
}else } else if (strncmp(p, "clean", 5) == 0) { /* mark window 'clean', seq=0 */
if(strncmp(p, "clean", 5) == 0){ /* mark window 'clean', seq=0 */
t = &w->body; t = &w->body;
t->eq0 = ~0; t->eq0 = ~0;
filereset(t->file); filereset(t->file);
@ -661,21 +653,19 @@ xfidctlwrite(Xfid *x, Window *w)
w->dirty = FALSE; w->dirty = FALSE;
settag = TRUE; settag = TRUE;
m = 5; m = 5;
}else } else if (strncmp(p, "dirty", 5) == 0) { /* mark window 'dirty' */
if(strncmp(p, "dirty", 5) == 0){ /* mark window 'dirty' */
t = &w->body; t = &w->body;
/* doesn't change sequence number, so "Put" won't appear. it shouldn't. */ /* doesn't change sequence number, so "Put" won't appear. it shouldn't.
*/
t->file->mod = TRUE; t->file->mod = TRUE;
w->dirty = TRUE; w->dirty = TRUE;
settag = TRUE; settag = TRUE;
m = 5; m = 5;
}else } else if (strncmp(p, "show", 4) == 0) { /* show dot */
if(strncmp(p, "show", 4) == 0){ /* show dot */
t = &w->body; t = &w->body;
textshow(t, t->q0, t->q1, 1); textshow(t, t->q0, t->q1, 1);
m = 4; m = 4;
}else } else if (strncmp(p, "name ", 5) == 0) { /* set file name */
if(strncmp(p, "name ", 5) == 0){ /* set file name */
pp = p + 5; pp = p + 5;
m = 5; m = 5;
q = memchr(pp, '\n', e - pp); q = memchr(pp, '\n', e - pp);
@ -700,8 +690,7 @@ out:
filemark(w->body.file); filemark(w->body.file);
winsetname(w, r, nr); winsetname(w, r, nr);
m += (q + 1) - pp; m += (q + 1) - pp;
}else } else if (strncmp(p, "dump ", 5) == 0) { /* set dump string */
if(strncmp(p, "dump ", 5) == 0){ /* set dump string */
pp = p + 5; pp = p + 5;
m = 5; m = 5;
q = memchr(pp, '\n', e - pp); q = memchr(pp, '\n', e - pp);
@ -718,8 +707,7 @@ out:
} }
w->dumpstr = runetobyte(r, nr); w->dumpstr = runetobyte(r, nr);
m += (q + 1) - pp; m += (q + 1) - pp;
}else } else if (strncmp(p, "dumpdir ", 8) == 0) { /* set dump directory */
if(strncmp(p, "dumpdir ", 8) == 0){ /* set dump directory */
pp = p + 8; pp = p + 8;
m = 8; m = 8;
q = memchr(pp, '\n', e - pp); q = memchr(pp, '\n', e - pp);
@ -736,28 +724,23 @@ out:
} }
w->dumpdir = runetobyte(r, nr); w->dumpdir = runetobyte(r, nr);
m += (q + 1) - pp; m += (q + 1) - pp;
}else } else if (strncmp(p, "delete", 6) == 0) { /* delete for sure */
if(strncmp(p, "delete", 6) == 0){ /* delete for sure */
colclose(w->col, w, TRUE); colclose(w->col, w, TRUE);
m = 6; m = 6;
}else } else if (strncmp(p, "del", 3) == 0) { /* delete, but check dirty */
if(strncmp(p, "del", 3) == 0){ /* delete, but check dirty */
if (!winclean(w, TRUE)) { if (!winclean(w, TRUE)) {
err = "file dirty"; err = "file dirty";
break; break;
} }
colclose(w->col, w, TRUE); colclose(w->col, w, TRUE);
m = 3; m = 3;
}else } else if (strncmp(p, "get", 3) == 0) { /* get file */
if(strncmp(p, "get", 3) == 0){ /* get file */
get(&w->body, nil, nil, FALSE, XXX, nil, 0); get(&w->body, nil, nil, FALSE, XXX, nil, 0);
m = 3; m = 3;
}else } else if (strncmp(p, "put", 3) == 0) { /* put file */
if(strncmp(p, "put", 3) == 0){ /* put file */
put(&w->body, nil, nil, XXX, XXX, nil, 0); put(&w->body, nil, nil, XXX, XXX, nil, 0);
m = 3; m = 3;
}else } else if (strncmp(p, "dot=addr", 8) == 0) { /* set dot */
if(strncmp(p, "dot=addr", 8) == 0){ /* set dot */
textcommit(&w->body, TRUE); textcommit(&w->body, TRUE);
clampaddr(w); clampaddr(w);
w->body.q0 = w->addr.q0; w->body.q0 = w->addr.q0;
@ -765,40 +748,33 @@ out:
textsetselect(&w->body, w->body.q0, w->body.q1); textsetselect(&w->body, w->body.q0, w->body.q1);
settag = TRUE; settag = TRUE;
m = 8; m = 8;
}else } else if (strncmp(p, "addr=dot", 8) == 0) { /* set addr */
if(strncmp(p, "addr=dot", 8) == 0){ /* set addr */
w->addr.q0 = w->body.q0; w->addr.q0 = w->body.q0;
w->addr.q1 = w->body.q1; w->addr.q1 = w->body.q1;
m = 8; m = 8;
}else } else if (strncmp(p, "limit=addr", 10) == 0) { /* set limit */
if(strncmp(p, "limit=addr", 10) == 0){ /* set limit */
textcommit(&w->body, TRUE); textcommit(&w->body, TRUE);
clampaddr(w); clampaddr(w);
w->limit.q0 = w->addr.q0; w->limit.q0 = w->addr.q0;
w->limit.q1 = w->addr.q1; w->limit.q1 = w->addr.q1;
m = 10; m = 10;
}else } else if (strncmp(p, "nomark", 6) == 0) { /* turn off automatic marking */
if(strncmp(p, "nomark", 6) == 0){ /* turn off automatic marking */
w->nomark = TRUE; w->nomark = TRUE;
m = 6; m = 6;
}else } else if (strncmp(p, "mark", 4) == 0) { /* mark file */
if(strncmp(p, "mark", 4) == 0){ /* mark file */
seq++; seq++;
filemark(w->body.file); filemark(w->body.file);
settag = TRUE; settag = TRUE;
m = 4; m = 4;
}else } else if (strncmp(p, "nomenu", 6) == 0) { /* turn off automatic menu */
if(strncmp(p, "nomenu", 6) == 0){ /* turn off automatic menu */
w->filemenu = FALSE; w->filemenu = FALSE;
settag = TRUE; settag = TRUE;
m = 6; m = 6;
}else } else if (strncmp(p, "menu", 4) == 0) { /* enable automatic menu */
if(strncmp(p, "menu", 4) == 0){ /* enable automatic menu */
w->filemenu = TRUE; w->filemenu = TRUE;
settag = TRUE; settag = TRUE;
m = 4; m = 4;
}else } else if (strncmp(p, "cleartag", 8) == 0) { /* wipe tag right of bar */
if(strncmp(p, "cleartag", 8) == 0){ /* wipe tag right of bar */
wincleartag(w); wincleartag(w);
settag = TRUE; settag = TRUE;
m = 8; m = 8;
@ -824,9 +800,7 @@ out:
textscrdraw(&w->body); textscrdraw(&w->body);
} }
void void xfideventwrite(Xfid* x, Window* w) {
xfideventwrite(Xfid *x, Window *w)
{
Fcall fc; Fcall fc;
int m, n; int m, n;
Rune* r; Rune* r;
@ -889,7 +863,6 @@ xfideventwrite(Xfid *x, Window *w)
goto Rescue; goto Rescue;
} }
qunlock(&row.lk); qunlock(&row.lk);
} }
Out: Out:
@ -908,9 +881,7 @@ xfideventwrite(Xfid *x, Window *w)
goto Out; goto Out;
} }
void void xfidutfread(Xfid* x, Text* t, uint q1, int qid) {
xfidutfread(Xfid *x, Text *t, uint q1, int qid)
{
Fcall fc; Fcall fc;
Window* w; Window* w;
Rune* r; Rune* r;
@ -973,9 +944,7 @@ xfidutfread(Xfid *x, Text *t, uint q1, int qid)
fbuffree(b1); fbuffree(b1);
} }
int int xfidruneread(Xfid* x, Text* t, uint q0, uint q1) {
xfidruneread(Xfid *x, Text *t, uint q0, uint q1)
{
Fcall fc; Fcall fc;
Window* w; Window* w;
Rune *r, junk; Rune *r, junk;
@ -1027,9 +996,7 @@ xfidruneread(Xfid *x, Text *t, uint q0, uint q1)
return q - q0; return q - q0;
} }
void void xfideventread(Xfid* x, Window* w) {
xfideventread(Xfid *x, Window *w)
{
Fcall fc; Fcall fc;
int i, n; int i, n;
@ -1064,9 +1031,7 @@ xfideventread(Xfid *x, Window *w)
} }
} }
void void xfidindexread(Xfid* x) {
xfidindexread(Xfid *x)
{
Fcall fc; Fcall fc;
int i, j, m, n, nmax, isbuf, cnt, off; int i, j, m, n, nmax, isbuf, cnt, off;
Window* w; Window* w;