From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f196.google.com ([209.85.222.196]) by ewsd; Thu Jun 4 23:28:18 EDT 2020 Received: by mail-qk1-f196.google.com with SMTP id n141so8433086qke.2 for <9front@9front.org>; Thu, 04 Jun 2020 20:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition; bh=bkeokR3Odi1m6revAMMtC5LKmAKlt+KyObRp1fVnVHs=; b=rpA6i1kqceHFCf0EBhsPTi4476XWecGr0eFhjlZLswfH7QxkHqnEGzRtOQBQtRHiwQ ucIWm4gcBg61JM0niVk0XMhhfRnpSEdzJQP2abTMsoTAottnZSqNWWmNCqXeyo6dBafp W0YQYG2lgiOhWE0+ooFE8CUWGFHjrq9LID3IfJHhmT6TvsfqfEjsK1WzpfOUgLEEUQZl 8C20YWt/eiFf0cvSFUlkKQjvhxh0g64Dd7wF5N0/kBZ2nlnrtvCkFPLmnP3G7D2UfQ2B vCO4MhR8/ZQASaGG4Da77i+D5lu2YY7GxaE7oVTvzg0nWtvZd0i23MswWCbP38jKf6bW QnTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=bkeokR3Odi1m6revAMMtC5LKmAKlt+KyObRp1fVnVHs=; b=nwzEq7f2eDHEUYzUBZuiYyxZeQWzkGdXqMtJ7sHyL7UU9Lf69L8L3Cx8zhjvb20fWP 37iZN+OhfAoIM7r86Df0T6yERbGSTSFbJ6RSr1Hz4+JNDgnKxiBlbuYp4aXfxs8ya9Px e6YvIZ0O+nyB7imfVw4iQracwXo9SW8YEYYOnAsAo3o4MseSS/wzR/KPf5XwzkcKlT96 uJxBHCbM/u7oA0+JFLVTm//eE9+o9TfRWwIkHk8dbe5uBJDc29XJKv/lMQOqo2RKhAtQ XnC0fOsXwP/hDbhWZBDiIA1xnVQoPB5hKiWPT2wUnbUlq5l9I7xfzafzRnHL/IgoGkt6 dkkQ== X-Gm-Message-State: AOAM5337dmoEWIgcbihjOYkHXybbKbvoPHzfNBIB0cfi/6CzlwuOhdvR WEu9snwkFd9NbSSauXhHWdh2yOXn X-Google-Smtp-Source: ABdhPJz9Sf41wkd92dc5NrAz2wEGHdTXq0pgcmjnS0yhaIEKW4AhTmuoVz459q8625nFKeVVj5SCLw== X-Received: by 2002:a37:b901:: with SMTP id j1mr7115192qkf.427.1591327693128; Thu, 04 Jun 2020 20:28:13 -0700 (PDT) Return-Path: Received: from delta.localdomain (pool-96-246-81-93.nycmny.fios.verizon.net. [96.246.81.93]) by smtp.gmail.com with ESMTPSA id 185sm6009497qke.92.2020.06.04.20.28.11 for <9front@9front.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 20:28:11 -0700 (PDT) Date: Thu, 4 Jun 2020 23:28:09 -0400 From: Fazlul Shahriar To: 9front@9front.org Subject: [PATCH] acme: add log file in acme root directory Message-ID: <20200605032809.GA888508@delta.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: managed anonymous ACPI over WEB2.0 polling database framework-oriented software-aware solution Hi, This patch is copied from plan9port acme, with minor fixes. This should allow greater compatibility with acme clients in the wild. The changes are from the following commits: https://github.com/9fans/plan9port/commit/4a3fb87264f8bc03fc62f00ef335056f30d18023 https://github.com/9fans/plan9port/commit/45f8ba54143323f08a21343633764caa59aa3ea3 https://github.com/9fans/plan9port/commit/fdf6ef333705c844bcf3ccf2f93b2773f1a6aa41 diff -r ff6b294d07a9 sys/man/4/acme --- a/sys/man/4/acme Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/man/4/acme Thu Jun 04 23:17:01 2020 -0400 @@ -89,7 +89,7 @@ The window is created if necessary, but not until text is actually written. .TP .B consctl -Is an empty unwritable file present only for compatibility; there is no way +is an empty unwritable file present only for compatibility; there is no way to turn off `echo', for example, under .IR acme . .TP @@ -111,8 +111,33 @@ is an empty file, writable without effect, present only for compatibility with .BR rio . .TP +.B log +reports a log of window operations since the opening of the +.B log +file. +Each line describes a single operation using three fields separated by single spaces: +the decimal window ID, the operation, and the window name. +Reading from +.B log +blocks until there is an operation to report, so reading the file +can be used to monitor editor activity and react to changes. +The reported operations are +.L new +(window creation), +.L zerox +(window creation via zerox), +.LR get , +.LR put , +.L del +(window deletion), and +.L focus +(window focus change). +The window name can be the empty string; in particular it is empty in +.L new +log entries corresponding to windows created by external programs. +.TP .B new -A directory analogous to the numbered directories +is a directory analogous to the numbered directories .RI ( q.v. ). Accessing any file in diff -r ff6b294d07a9 sys/src/cmd/acme/acme.c --- a/sys/src/cmd/acme/acme.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/acme.c Thu Jun 04 23:17:01 2020 -0400 @@ -258,6 +258,7 @@ winsettag(w); textscrdraw(&w->body); textsetselect(&w->tag, w->tag.file->nc, w->tag.file->nc); + xfidlog(w, "new"); } char *oknotes[] ={ @@ -487,6 +488,12 @@ m = mousectl->Mouse; qlock(&row); t = rowwhich(&row, m.xy); + + if((t!=mousetext && t!=nil && t->w!=nil) && + (mousetext==nil || mousetext->w==nil || t->w->id!=mousetext->w->id)) { + xfidlog(t->w, "focus"); + } + if(t!=mousetext && mousetext!=nil && mousetext->w!=nil){ winlock(mousetext->w, 'M'); mousetext->eq0 = ~0; @@ -773,6 +780,7 @@ recvp(cnewwindow); w = makenewwindow(nil); winsettag(w); + xfidlog(w, "new"); sendp(cnewwindow, w); } } diff -r ff6b294d07a9 sys/src/cmd/acme/dat.h --- a/sys/src/cmd/acme/dat.h Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/dat.h Thu Jun 04 23:17:01 2020 -0400 @@ -8,6 +8,7 @@ Qeditout, Qindex, Qlabel, + Qlog, Qnew, QWaddr, @@ -396,6 +397,7 @@ Mntdir *mntdir; int nrpart; uchar rpart[UTFmax]; + vlong logoff; // for putlog }; @@ -408,7 +410,6 @@ Fid *f; uchar *buf; int flushed; - }; void xfidctl(void *); @@ -423,6 +424,10 @@ void xfidindexread(Xfid*); void xfidutfread(Xfid*, Text*, uint, int); int xfidruneread(Xfid*, Text*, uint, uint); +void xfidlogopen(Xfid*); +void xfidlogread(Xfid*); +void xfidlogflush(Xfid*); +void xfidlog(Window*, char*); struct Reffont { diff -r ff6b294d07a9 sys/src/cmd/acme/exec.c --- a/sys/src/cmd/acme/exec.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/exec.c Thu Jun 04 23:17:01 2020 -0400 @@ -297,10 +297,14 @@ newcol(Text *et, Text*, Text*, int, int, Rune*, int) { Column *c; + Window *w; c = rowadd(et->row, nil, -1); - if(c) - winsettag(coladd(c, nil, nil, -1)); + if(c) { + w = coladd(c, nil, nil, -1); + winsettag(w); + xfidlog(w, "new"); + } } void @@ -496,6 +500,7 @@ nw = coladd(t->w->col, nil, t->w, -1); /* ugly: fix locks so w->unlock works */ winlock1(nw, t->w->owner); + xfidlog(nw, "zerox"); } if(locked) winunlock(t->w); @@ -559,6 +564,7 @@ textsetselect(&u->w->tag, u->w->tag.file->nc, u->w->tag.file->nc); textscrdraw(u); } + xfidlog(w, "get"); } void @@ -695,6 +701,7 @@ } namer = bytetorune(name, &nname); putfile(f, 0, f->nc, namer, nname); + xfidlog(w, "put"); free(name); } diff -r ff6b294d07a9 sys/src/cmd/acme/fsys.c --- a/sys/src/cmd/acme/fsys.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/fsys.c Thu Jun 04 23:17:01 2020 -0400 @@ -69,6 +69,7 @@ { "editout", QTFILE, Qeditout, 0200 }, { "index", QTFILE, Qindex, 0400 }, { "label", QTFILE, Qlabel, 0600 }, + { "log", QTFILE, Qlog, 0400 }, { "new", QTDIR, Qnew, 0500|DMDIR }, { nil, } }; diff -r ff6b294d07a9 sys/src/cmd/acme/logf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/acme/logf.c Thu Jun 04 23:17:01 2020 -0400 @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" + +// State for global log file. +typedef struct Log Log; +struct Log +{ + QLock lk; + Rendez r; + + vlong start; // msg[0] corresponds to 'start' in the global sequence of events + + // queued events (nev=entries in ev, mev=capacity of p) + char **ev; + int nev; + int mev; + + // open acme/put files that need to read events + Fid **f; + int nf; + int mf; + + // active (blocked) reads waiting for events + Xfid **read; + int nread; + int mread; +}; + +static Log eventlog; + +void +xfidlogopen(Xfid *x) +{ + qlock(&eventlog.lk); + if(eventlog.nf >= eventlog.mf) { + eventlog.mf = eventlog.mf*2; + if(eventlog.mf == 0) + eventlog.mf = 8; + eventlog.f = erealloc(eventlog.f, eventlog.mf*sizeof eventlog.f[0]); + } + eventlog.f[eventlog.nf++] = x->f; + x->f->logoff = eventlog.start + eventlog.nev; + + qunlock(&eventlog.lk); +} + +void +xfidlogclose(Xfid *x) +{ + int i; + + qlock(&eventlog.lk); + for(i=0; if) { + eventlog.f[i] = eventlog.f[--eventlog.nf]; + break; + } + } + qunlock(&eventlog.lk); +} + +void +xfidlogread(Xfid *x) +{ + char *p; + int i; + Fcall fc; + + qlock(&eventlog.lk); + if(eventlog.nread >= eventlog.mread) { + eventlog.mread = eventlog.mread*2; + if(eventlog.mread == 0) + eventlog.mread = 8; + eventlog.read = erealloc(eventlog.read, eventlog.mread*sizeof eventlog.read[0]); + } + eventlog.read[eventlog.nread++] = x; + + if(eventlog.r.l == nil) + eventlog.r.l = &eventlog.lk; + x->flushed = FALSE; + while(x->f->logoff >= eventlog.start+eventlog.nev && !x->flushed) + rsleep(&eventlog.r); + + for(i=0; iflushed) { + qunlock(&eventlog.lk); + return; + } + + i = x->f->logoff - eventlog.start; + p = estrdup(eventlog.ev[i]); + x->f->logoff++; + qunlock(&eventlog.lk); + + fc.data = p; + fc.count = strlen(p); + respond(x, &fc, nil); + free(p); +} + +void +xfidlogflush(Xfid *x) +{ + int i; + Xfid *rx; + + qlock(&eventlog.lk); + for(i=0; itag == x->oldtag) { + rx->flushed = TRUE; + rwakeupall(&eventlog.r); + } + } + qunlock(&eventlog.lk); +} + +/* + * add a log entry for op on w. + * expected calls: + * + * op == "new" for each new window + * - caller of coladd or makenewwindow responsible for calling + * xfidlog after setting window name + * - exception: zerox + * + * op == "zerox" for new window created via zerox + * - called from zeroxx + * + * op == "get" for Get executed on window + * - called from get + * + * op == "put" for Put executed on window + * - called from put + * + * op == "del" for deleted window + * - called from winclose + * + * op == "focus" for window focus change + * - called from mousethread + */ +void +xfidlog(Window *w, char *op) +{ + int i, n; + vlong min; + File *f; + char *name; + + qlock(&eventlog.lk); + if(eventlog.nev >= eventlog.mev) { + // Remove and free any entries that all readers have read. + min = eventlog.start + eventlog.nev; + for(i=0; i eventlog.f[i]->logoff) + min = eventlog.f[i]->logoff; + } + if(min > eventlog.start) { + n = min - eventlog.start; + for(i=0; i= eventlog.mev) { + eventlog.mev = eventlog.mev*2; + if(eventlog.mev == 0) + eventlog.mev = 8; + eventlog.ev = erealloc(eventlog.ev, eventlog.mev*sizeof eventlog.ev[0]); + } + } + f = w->body.file; + name = runetobyte(f->name, f->nname); + if(name == nil) + name = estrdup(""); + eventlog.ev[eventlog.nev++] = smprint("%d %s %s\n", w->id, op, name); + free(name); + if(eventlog.r.l == nil) + eventlog.r.l = &eventlog.lk; + rwakeupall(&eventlog.r); + qunlock(&eventlog.lk); +} diff -r ff6b294d07a9 sys/src/cmd/acme/look.c --- a/sys/src/cmd/acme/look.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/look.c Thu Jun 04 23:17:01 2020 -0400 @@ -233,6 +233,7 @@ winsettag(w); textscrdraw(&w->body); textsetselect(&w->tag, w->tag.file->nc, w->tag.file->nc); + xfidlog(w, "new"); } int @@ -668,6 +669,7 @@ }else for(i=0; i < NINDENT; i++) w->indent[i] = globalindent[i]; + xfidlog(w, "new"); } if(e->a1 == e->a0) eval = FALSE; @@ -697,6 +699,7 @@ int na, nf; Expand e; Runestr rs; + Window *w; getarg(argt, FALSE, TRUE, &a, &na); if(a){ @@ -708,8 +711,11 @@ for(ndone=0; ; ndone++){ a = findbl(arg, narg, &na); if(a == arg){ - if(ndone==0 && et->col!=nil) - winsettag(coladd(et->col, nil, nil, -1)); + if(ndone==0 && et->col!=nil) { + w = coladd(et->col, nil, nil, -1); + winsettag(w); + xfidlog(w, "new"); + } break; } nf = narg-na; diff -r ff6b294d07a9 sys/src/cmd/acme/mkfile --- a/sys/src/cmd/acme/mkfile Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/mkfile Thu Jun 04 23:17:01 2020 -0400 @@ -15,6 +15,7 @@ exec.$O\ file.$O\ fsys.$O\ + logf.$O\ look.$O\ regx.$O\ rows.$O\ diff -r ff6b294d07a9 sys/src/cmd/acme/rows.c --- a/sys/src/cmd/acme/rows.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/rows.c Thu Jun 04 23:17:01 2020 -0400 @@ -697,6 +697,7 @@ q0 = q1 = 0; textshow(&w->body, q0, q1, 1); w->maxlines = min(w->body.nlines, max(w->maxlines, w->body.maxlines)); + xfidlog(w, "new"); } Bterm(b); fbuffree(buf); diff -r ff6b294d07a9 sys/src/cmd/acme/util.c --- a/sys/src/cmd/acme/util.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/util.c Thu Jun 04 23:17:01 2020 -0400 @@ -77,6 +77,7 @@ w = coladd(row.col[row.ncol-1], nil, nil, -1); w->filemenu = FALSE; winsetname(w, r, n); + xfidlog(w, "new"); } free(r); for(i=nincl; --i>=0; ){ diff -r ff6b294d07a9 sys/src/cmd/acme/wind.c --- a/sys/src/cmd/acme/wind.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/wind.c Thu Jun 04 23:17:01 2020 -0400 @@ -313,6 +313,7 @@ int i; if(decref(w) == 0){ + xfidlog(w, "del"); windirfree(w); textclose(&w->tag); textclose(&w->body); @@ -633,7 +634,7 @@ } int -winclean(Window *w, int conservative) /* as it stands, conservative is always TRUE */ +winclean(Window *w, int conservative) { if(w->isscratch || w->isdir) /* don't whine if it's a guide file, error window, etc. */ return TRUE; diff -r ff6b294d07a9 sys/src/cmd/acme/xfid.c --- a/sys/src/cmd/acme/xfid.c Mon Jun 01 00:07:01 2020 +0200 +++ b/sys/src/cmd/acme/xfid.c Thu Jun 04 23:17:01 2020 -0400 @@ -63,6 +63,8 @@ Column *c; Xfid *wx; + xfidlogflush(x); + /* search windows for matching tag */ qlock(&row); for(j=0; jf->w; t = &w->body; + q = FILE(x->f->qid); if(w){ winlock(w, 'E'); - q = FILE(x->f->qid); switch(q){ case QWaddr: if(w->nopen[q]++ == 0){ @@ -179,6 +181,13 @@ } winunlock(w); } + else{ + switch(q){ + case Qlog: + xfidlogopen(x); + break; + } + } fc.qid = x->f->qid; fc.iounit = messagesize-IOHDRSZ; x->f->open = TRUE; @@ -274,6 +283,9 @@ case Qindex: xfidindexread(x); return; + case Qlog: + xfidlogread(x); + return; default: warning(nil, "unknown qid %d\n", q); break;