Commit graph

64 commits

Author SHA1 Message Date
Igor Böhm 873f381e29 acme: fix hiding of top windows when loading a dump file (thanks Xiao-Yong)
When loading an acme dump file that contains a window with only one
tag line, there are cases where acme hides that window (i.e.  not even
its tag is visible).

The following commands reproduce the issue:

 % ed <<EOE
1
i
/tmp
/lib/font/bit/pelm/unicode.8.font
/lib/font/bit/pelm/unicode.8.font
          0
f          0           5         175         175           1
          5          40         175           1           0 /sys/src/cmd/acme/ Del Snarf Get | Look
f          0           4         330         330           3
          4          27         330           1           0 /tmp/ Del Snarf Get | Look
.
,w /tmp/test.dump
Q
EOE
 % window -dx 900 -dy 600  'acme -l /tmp/test.dump'

This issue was introduced in commit 47b7dc5ccd.
2022-03-15 10:49:00 +00:00
Igor Böhm 47b7dc5ccd acme: fix window and scrollbar display glitches at bottom fringe of column
The following patch fixes acme display glitches at the bottom fringe
of columns when adding/moving/resizing windows.

Here an example of an easy to reproduce case:

• https://invidio.xamh.de/watch?v=iLekQrxycaM

…opening acme and resizing a column to the right is all that is needed.

The functions winresize(…) and textresize(…) are extended with an
additional parameter `fillfringe` to indicate if a window/tag shall
fill a potential fringe area that would otherwise remain white.

The changes have been inspired by the approach taken in plan9port
acme.
2022-01-04 19:11:07 +00:00
Igor Böhm efa6937460 acme: fix leaking memory allocated by getenv("font")
If the font chosen for acme is retrieved via `getenv("font")` its
memory is leaked:

<snip>
	if(fontnames[0] == nil)
		fontnames[0] = getenv("font");
		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> getenv(…) mallocs memory

	if(fontnames[0] == nil)
		fontnames[0] = "/lib/font/bit/vga/unicode.font";
	if(access(fontnames[0], 0) < 0){
		fprint(2, "acme: can't access %s: %r\n", fontnames[0]);
		exits("font open");
	}
	if(fontnames[1] == nil)
		fontnames[1] = fontnames[0];
	fontnames[0] = estrdup(fontnames[0]);
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> if the `getenv("font")` path was taken above, this assignment
> will leak its memory.
</snap>

The following leak/acid session demonstrates the issue:

<snip>
cpu% leak -s 212252
src(0x002000cb); // 1
cpu% acid 212252
/proc/212252/text:amd64 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/amd64
acid: src(0x002000cb)
/sys/src/cmd/acme/acme.c:107
 102			fprint(2, "usage: acme [-aib] [-c ncol] [-f font] [-F fixedfont] [-l loadfile | file...]\n");
 103			exits("usage");
 104		}ARGEND
 105
 106		if(fontnames[0] == nil)
>107			fontnames[0] = getenv("font");
 108		if(fontnames[0] == nil)
 109			fontnames[0] = "/lib/font/bit/vga/unicode.font";
 110		if(access(fontnames[0], 0) < 0){
 111			fprint(2, "acme: can't access %s: %r\n", fontnames[0]);
 112			exits("font open");
acid:
</snap>

The fix tries to first check if a font has been set via
command line options in which case the font string is
malloced via estrdup(…).

If no font has been selected on the command line getenv("font")
is used. If no getenv("font") var is found we malloc a default
font via estrdup(…).

<snip>
	if(fontnames[0] != nil)
		fontnames[0] = estrdup(fontnames[0]);
	else
		if((fontnames[0] = getenv("font")) == nil)
			fontnames[0] = estrdup("/lib/font/bit/vga/unicode.font");
	if(access(fontnames[0], 0) < 0){
		fprint(2, "acme: can't access %s: %r\n", fontnames[0]);
		exits("font open");
	}
	if(fontnames[1] == nil)
		fontnames[1] = fontnames[0];
	fontnames[1] = estrdup(fontnames[1]);
</snap>

This resolves the memory leak reported by leak(1).
2021-11-05 23:51:55 +00:00
cinap_lenrek 6c70026fa4 acme: fix plumb message leaks (thanks igor) 2021-11-05 18:49:40 +00:00
Igor Böhm 24bd67f990 acme: remove superfluous print arguments (patch from plan9port) 2021-10-05 09:40:30 +00:00
james palmer a8ad3fb3d0 acme: don't let tag button draw over tag border. 2021-10-06 09:19:58 +00:00
Ori Bernstein 0256a34560 acme: fix border size, autoindent undo: imported from plan9port (thanks jxy)
origin:

https://github.com/9fans/plan9port/pull/493
https://github.com/9fans/plan9port/pull/489
https://github.com/9fans/plan9port/pull/461
2021-04-14 20:30:24 -07:00
cinap_lenrek afa5800b5b acme: fix suicide *and* resource leak in ecmd.c (thanks igor)
To reproduce the suicide try running the following in acme:

• 'Edit B <ls lib'

by select and middle clicking in a window that is in your $home.

There is a very high chance acme will commit suicide like this:

<snip>
cpu% broke
echo kill>/proc/333310/ctl # acme
cpu% acid 333310
/proc/333310/text:amd64 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/amd64
acid: lstk()
edittext(nr=0x31,q=0x0,r=0x45aa10)+0x8 /sys/src/cmd/acme/ecmd.c:135
xfidwrite(x=0x461230)+0x28a /sys/src/cmd/acme/xfid.c:479
        w=0x0
        qid=0x5
        fc=0x461390
        t=0x1
        nr=0x100000031
        r=0x45aa10
        eval=0x3100000000
        a=0x405621
        nb=0x500000001
        err=0x419310
        q0=0x100000000
        tq0=0x80
        tq1=0x8000000000
        buf=0x41e8d800000000
xfidctl(arg=0x461230)+0x35 /sys/src/cmd/acme/xfid.c:52
        x=0x461230
launcheramd64(arg=0x461230,f=0x22357e)+0x10 /sys/src/libthread/amd64.c:11
0xfefefefefefefefe ?file?:0
</snap>

The suicide issue is caused by the following chain of events:

• /sys/src/cmd/acme/ecmd.c:/^edittext is called at
/sys/src/cmd/acme/xfid.c:479 passing nil as its first parameter:

<snip>
...
        case QWeditout:
                r = fullrunewrite(x, &nr);
                if(w)
                        err = edittext(w, w->wrselrange.q1, r, nr);
                else
                        err = edittext(nil, 0, r, nr);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
</snap>

...and /sys/src/cmd/acme/ecmd.c:/^edittext dereferences the
first parameter that is *nil* at the first statement:

<snip>
char*
edittext(Window *w, int q, Rune *r, int nr)
{
        File *f;

        f = w->body.file;
^^^^^^^^^^^^^^^^^^^^^
This will crash if 'w' is *nil*

        switch(editing){
...
</snap>

Moving the the derefernce of 'w' into the case where it is
needed (see above patch) fixes the suicude.

The memory leak is fixed in /sys/src/cmd/acme/ecmd.c:/^filelist.  The
current implementation of filelist(...) breaks its contract with its
caller, thereby leading to a memory leak in /sys/src/cmd/acme/ecmd.c:/^B_cmd
and /sys/src/cmd/acme/ecmd.c:/^D_cmd.

The contract /sys/src/cmd/acme/ecmd.c:/^filelist seems to have with
its callers is that in case of success it fills up a 'collection' that
callers can then clear with a call to clearcollection(...).

The fix above honours this contract and thereby removes the leak.

After you apply the patch the following two tests should succeed:

• Execute by select and middle click in a Tag:
        'Edit B lib/profile'

• Execute by select and middle click in a Tag:
        'Edit B <ls lib'

The former lead to a resource leak that is now fixed.

The latter lead to a suicide that is now fixed by moving the statement
that dereferences the parameter to the location where it is needed,
which is not the path used in the case of 'Edit B <ls'.

Cheers,
Igor
2021-04-02 15:51:15 +02:00
cinap_lenrek 01ab07ef72 acme: fix use after free in warning() call (thanks igor) 2021-02-03 01:19:19 +01:00
cinap_lenrek ba20914d01 acme: use global user string variable instead of getuser() 2020-12-19 15:50:30 +01:00
cinap_lenrek c7fc69bd6a acme: use getuser() in fsinit() 2020-12-19 15:36:07 +01:00
Ori Bernstein c63cd980a4 acme: revert stray changes
forgot I had local changes when testing, re-revert scrolling.
2020-09-29 07:28:47 -07:00
Ori Bernstein 313aebb964 acme: import changes from plan9port (thanks jxy)
Import the following improvements and bugfixes from plan9port:

	4650064a acme: scale window bodies on resize, not including tag space
	d28913a9 acme: save/restore multiline tags in Dump/Load
	d2df5d6c acme: fix crash in X |cat with multiple windows
	3d6e5cb5 acme: preserve window position and selection during Get
2020-09-22 11:42:15 -07:00
cinap_lenrek c4cf92b99e merge 2020-08-03 21:52:22 +02:00
cinap_lenrek 053a6526e2 acme: reverting scroll change, causes continuous scrolling with scrollwheel 2020-08-03 21:51:25 +02:00
kvik e5894dccea pre-lib9p servers: fix incorrect Tversion handling
version(5) says:

	If the server does not understand the client's version
	string, it should respond with an Rversion message (not
	Rerror) with the version string the 7 characters
	``unknown''.

Pre-lib9p file servers -- all except cwfs(4) -- do return Rerror.

lib9p(2) follows the above spec, although ignoring the next part
concerning comparison after period-stripping.  It assumes an
Fcall.version starting with "9P" is correctly formed and returns
the only supported version of the protocol, which seems alright.

This patch brings pre-lib9p servers in accordance with the spec.
2020-08-01 15:27:28 +02:00
kvik 57362e0c8c acme: implement position-dependent scroll-wheel scrolling
This brings acme scrolling behaviour in line with that of 9front's rio
and sam, where the amount scrolled varies with a vertical position of
the pointer within the window, similar to how the scrollbar works.

At some point it would be good to implement a line-at-a-time scrolling
when the Shift key is pressed, as seen in rio.  For this to happen the
acme keyboard input needs to be rewritten in terms of /dev/kbd instead
of relying on keyboard(2) -- that is, the /dev/cons interface.
2020-06-11 15:33:57 +02:00
cinap_lenrek 7c8d75a309 acme: add missing logf.c 2020-06-07 17:06:33 +02:00
Ori Bernstein d2be4787c6 acme: import event log from plan9port (thanks fshahriar)
Based off the following 3 commits:

	4a3fb87264f8bc03fc62f00ef335056f30d18023
	45f8ba54143323f08a21343633764caa59aa3ea3
	fdf6ef333705c844bcf3ccf2f93b2773f1a6aa41

Reading /mnt/acme/log reports a log of window create,
put, focus, and delete events, as they happen. It blocks
until the next event is available.

Example log output:

	8 new /Users/rsc/foo.go
	8 put /Users/rsc/foo.go
	8 del /Users/rsc/foo.go

This lets acme-aware programs react to file writes, for example
compiling code, running a test, or updating an import block.
2020-06-06 19:05:00 -07:00
kvik 8918bd5981 acme: implement 'scratch' ctl command (thanks Drew DeVault)
The new command marks the target window as a scratch window -- a window
whose state cannot be "dirtied" by changes made to its body, therefore
avoiding warnings about unsaved changes when deleting the window or
exiting acme.

Existing examples of scratch windows are error, directory, and guide
windows, whose scratchness is set internally.

With the new command users and programs alike can create their own
scratch windows.  This is put to use in acme's own win(1).
2020-05-31 22:39:46 +02:00
kvik 1c3a6fc67e acme: add missed error checks 2020-05-10 03:18:57 +02:00
Ori Bernstein ec4011acf7 fix typo: mouse->xy, not w->mc.xy 2020-05-07 13:23:15 -07:00
Ori Bernstein 0dc9c8d019 Reset click count on mouse motion. 2020-05-06 13:38:39 -07:00
cinap_lenrek ac88ce4f7f make bind(2) error handling consistent
The mount() and bind() syscalls return -1 on error,
and the mountid sequence number on success.

The manpage states that the mountid sequence number
is a positive integer, but the kernels implementation
currently uses a unsigned 32-bit integer and does not
guarantee that the mountid will not become negative.

Most code just cares about the error, so test for
the -1 error value only.
2020-05-02 17:32:01 +02:00
Ori Bernstein 60c34ebb2d tweak selection criteria
grow selection from point of click, not start of selection region.
starting at the beginning of the selection region causes the match
logic to kick in, which is confusing.
2020-04-25 15:18:04 -07:00
Ori Bernstein 8bc290cc0f triple click selection in acme
see the last 2 commits.
2020-04-25 08:59:14 -07:00
spew 234aafb38d acme(1): fix scrolling when swiping text at the top or bottom of a frame 2020-02-13 16:09:25 -05:00
Ori Bernstein 8ce18a6338 fix double free in acme.
in acmerrorproc():
		sendp(s);
		free(s);

	in waitthread():
		recv(&err)
		free(err)

	We only want waitthread to free.
2020-01-31 09:25:39 -08:00
cinap_lenrek 09eac381e5 merge 2020-01-19 19:21:10 +01:00
Roberto E. Vargas Caballero 47bae09b33 Apply http://www.9paste.net/qrstuv/patch/acme-movetodelmesg/ 2020-01-19 19:18:12 +01:00
cinap_lenrek a898d31f76 acme: fix off by one in colclose(), make dellist() code consistent 2020-01-19 18:43:51 +01:00
Roberto E. Vargas Caballero b099753597 acme: Restore call to movetodel() in colclose 2020-01-19 18:36:50 +01:00
Ori Bernstein 480d7b8f5f fix some acme memory leaks
(imported from plan9port 7ca1c90109e17dced4b38fbaadea9d2cf39871b7,
some tag restoration lines not relevant.)
2019-12-06 12:08:00 -08:00
Ori Bernstein 7c55ca5fff acme: Apply each -/+ only once (#156)
When plumbing an address like `3-`, Acme selects line 1,
and similarly `3+` selects line 5.
The same problem can be observed for character addresses (`#123+`)
but _not_ for ones like `+`, `.+` or `/foo/+`:
The problem only occurs when a number is followed by a direction (`-`/`+`).

Following along with the example `3-` through `address` (in addr.c):
We read `3` into `c` and match the `case` on line 239.
The `while` loop on line 242ff reads additional digits into `c`
and puts the first non-digit back by decrementing the index `q`.
Then we find the range for line 3 on line 251 and continue.

On the next iteration, we set `prevc` to the last `c`,
but since that part read ahead _into `c`_,
`c` is currently the _next_ character we will read, `-`,
and now `prevc` is too.

Then in the case block (line 210) the condition on line 211 holds
and Acme believes that it has read two `-` in sequence
and modifies the range to account for the “first” `-`.
The “second” `-` gets applied after the loop is done, on line 292.

So the general problem is:
While reading numbers, Acme reads the next character after the number into `c`.
It decrements the counter to ensure it will read it again on the next iteration,
but it still uses it to update `prevc`.

This change solves the problem by reading digits into `nc` instead.
This variable is used to similar effect in the block for directions (line 212)
and fills the role of “local `c` that we can safely use to read ahead” nicely.

(imported from plan9front a82a8b6368274d77d42f526e379b74e79c137e26)
2019-12-04 12:55:03 -08:00
Ori Bernstein 2b5db0d9d4 acme: avoid division by zero when resizing col (#189)
To reproduce, create a column with at least two windows and resize
acme to have almost zero height.

(imported from plan9port commit 76b9347a5fa3a0970527c6ee1b97ef1c714f636b)
2019-12-04 12:37:07 -08:00
Ori Bernstein a181f3dd3e acme, sam: handle >1GB files correctly
imported from plan9port, edfe3c016fe6ef10c55f7a17aab668214ec21efc
2019-12-04 11:46:42 -08:00
cinap_lenrek b4eb667f02 acme: fix fd checks - initialize Window.rdselfd to -1 not 0 2018-10-20 23:57:50 +02:00
BurnZeZ 84e019aba3 fix misleading/wrong fd checks 2018-10-20 18:44:09 +00:00
cinap_lenrek 209a6b4b55 acme: pass pointer to int type to avoid pointer to int cast warning 2018-08-03 16:53:50 +02:00
spew 4757debd0b acme: add spacesindent mode 2018-08-01 11:14:59 -04:00
ftrvxmtrx 0930f44feb cmd: remove a bit of unused stuff 2016-11-17 02:59:40 +01:00
cinap_lenrek a0d4c5e208 make error handling in 9p service loops consistent
when we get eof, stop the loop immidiately and do not
rely on the read to eventually return an error.

when convM2S() fails to decode the message, error out
and stop the loop. there is no point in continuing.
2016-07-24 02:21:32 +02:00
mischief 84f45a4491 acme: allow typing '\n' in window tags 2014-12-17 14:27:31 -08:00
cinap_lenrek 854d028db9 acme: fix buffer overrun in xfidutfread() and xfidruneread(), cleanup
the utf8 buffers b1 where allocated from fbufalloc() which gives
us BUFSIZE bytes, but Xfid->count can be bigger than that. so just
emalloc() the requested number of bytes.

when converting from Runes to utf-8, we have to account for the
terminating '\0' byte snprint() places, so fix the maxrune number
calculation instead of using BUFSIZE+1 as buffer size.
2014-12-11 20:20:47 +01:00
BurnZeZ 62a8bf1846 acme: remove unused #include 2014-09-11 12:47:04 -04:00
iru 0bc51a90b0 Fix acme crash: Get D in a new window with D being an existing directory 2014-08-16 18:50:42 -03:00
cinap_lenrek 50e2c9b4d4 sam, acme: fix character classes quoting for 21-bit runes
quote handling was broken with 21-bit runes. nextrec()
returned quoted rune as long rune | (Runemax+1) to escape
it.

with 16-bit runes, storing that long into 16-bit Rune
would automatically remove the escaping, but with 21-bit
runes, Rune is uint32 so the escaping would remain. we
now use (Runemask+1) instead, and mask the escaping off
explicitely when storing back to Rune.
2014-04-01 06:04:00 +02:00
cinap_lenrek 91c7e0b127 acme: fix arrow key oddity (thanks mark van atten and erik)
from 9atom/acmearrowfun patch:

	reported by mark van atten

		In Plan 9 acme, if you type

		{}

		then go back and type text between the brackets

		{Curiouser and curiouser!}

		the right arrow is blocked when you want to go over the closing
		bracket to continue typing to its right. (If you first go to the left,
		and then back to the right, it works.)

		Same for the other brackets: [ ], ( ), < >.

	noted that brackets are not necessary.  same behavior with any
	character.

	fix is to textcommit before moving.
2013-11-22 19:19:37 +01:00
cinap_lenrek 95c865a497 acme: attempt to fix tag lines collapsing to zero height on window move (issue 189)
we'r getting a rectangle taller than a single line from
coladd() which causes textresize() to collapse the tag
text to zero height.

should probably fix coladd() instead.
2013-10-20 22:38:35 +02:00
cinap_lenrek be5992955d acme: use threadexitsall() to tear down mouse and keyboard procs on error 2013-09-11 21:23:45 +02:00