[Mirror] Plan 9 from User Space: https://github.com/9fans/plan9port
Find a file
Martin Kühl 73ea36569e plumb/basic: avoid wrap around in file:1:2 (#158)
Fixes #122, #140.

As reported in #122, `file:1:1` moves to the end of the file,
and `file:1:2` fails with “address out of range”.

I’ll use file:2:3 as an example so we can tell the line and column number apart.

What’s happening is this:
plumb/basic matches `2:3` using twocolonaddr (from plumb/fileaddr),
then sets addr to `2-#1+#3`
(the 1 is constant and was introduced because column numbers are 1-based).
Acme interprets this in three steps:

1. find the range (q0, q1) that contains line 2
2. create the range (q2, q2) where q2 = q0 - 1
3. create the range (q3, q3) where q3 = q2 + 3

The second step has a branch where if q0 == 0 and 1 > 0
(remember that 1 is constant and comes form plumb/basic),
q0 is set to the end of the file.
This makes addressing things at the end of the file easier.

The problem then is that if we select line 1,
which starts at the beginning of the file,
q0 is always 0 and the branch in step 2) will always be used.
`1:1` is interpreted as `1-#1+#1` which starts at 0, wraps around to the end of the file, then moves 1 character backwards and then forwards again, ending at the end of the file.
`1:2` is interpretes as `1-#1+#2` which starts at 0, wraps around to the end od the file, then moves 1 character backwards and tries moving 2 characters forwards beyond the end of the file, resulting in the out of range error.

In #140 @rsc proposed transforming `:X:Y` into `:X-#0+#Y-#1` instead since that
avoids wrapping around by not moving backwards at first.
This change modifies `plumb/basic` to do that.
2018-11-13 23:59:04 -05:00
acid merge 2012-03-05 16:36:31 -05:00
bin 9l: drop xcode text-based stub warning 2018-11-12 11:09:39 -05:00
dict all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
dist all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
face faces for lp. 2005-09-13 01:24:50 +00:00
font font: s/10/11 in ascent for unicode.7x13.font 2016-04-18 18:07:22 +00:00
include 9term, win: work around bsd linker nonsense 2017-01-06 20:20:33 +00:00
lib keyboard: add compose sequences lc and rc for ceiling brackets (#126) 2018-11-13 23:14:20 -05:00
lp all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
mac devdraw: plumb drag-n-dropped files 2015-06-03 15:26:27 +00:00
mail all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
man xd: add -R for runewise dump 2017-10-01 11:46:06 +02:00
ndb ndb/local: remove rsc-specific entries (oops) 2008-06-04 13:28:05 -04:00
news odds and ends 2004-04-21 23:43:46 +00:00
plumb plumb/basic: avoid wrap around in file:1:2 (#158) 2018-11-13 23:59:04 -05:00
postscript all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
proto forgotten files 2005-01-13 04:56:07 +00:00
sky all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
src devdraw: make ctrl generate 1-click while mouse down (#119) 2018-11-13 23:57:56 -05:00
tmac tmac.an: insert spaces after .?? request names 2008-11-11 11:01:03 -08:00
troff troff: import HB, HI and HX fonts from Plan 9 2017-06-15 19:09:58 +00:00
unix all: remove .cvsignore files 2017-09-14 17:25:17 +02:00
.gitignore .gitignore: ignore files created for astro(1) and scat(1) 2018-03-23 11:54:04 +01:00
.travis.yml .travis.yml: configure build matrix to build on OS X and Linux (thanks Michaelian Ennis) 2017-09-22 13:26:38 +02:00
CHANGES CHANGES: add pointer to web version 2008-05-10 13:38:21 -04:00
configure For annoying people like Uriel. 2005-11-25 13:18:11 +00:00
CONTRIBUTING.md codereview: delete, now using GitHub pull requests 2017-09-01 13:25:20 -04:00
CONTRIBUTORS venti: fix venti graph on 64-bit 2017-07-23 11:11:56 +00:00
INSTALL all: update site from swtch.com to 9fans.github.io 2017-09-01 13:25:20 -04:00
install.txt install.txt: regenerate (9 man 1 intro >install.txt) 2014-12-02 01:24:34 +00:00
LICENSE allow less restricted use of plan9port-specific code 2009-08-14 21:08:23 -07:00
Makefile For annoying people like Uriel. 2005-11-25 13:18:11 +00:00
rcmain rcmain: use new $termprog variable 2013-08-13 12:46:38 -04:00
README.md README: update links 2017-09-14 17:25:17 +02:00
TODO Note 9P2000.u 2005-08-31 04:00:14 +00:00

This is a port of many Plan 9 libraries and programs to Unix.

Installation

To install, run ./INSTALL. It builds mk and then uses mk to run the rest of the installation.

For more details, see install(1), at install.txt in this directory and at https://9fans.github.io/plan9port/man/man1/install.html.

Documentation

See https://9fans.github.io/plan9port/man/ for more documentation. (Documentation is also in this tree, but you need to run a successful install first. After that, "9 man 1 intro".)

Intro(1) contains a list of man pages that describe new features or differences from Plan 9.

Helping out

If you'd like to help out, great! The TODO file contains a small list.

If you port this code to other architectures, please share your changes so others can benefit.

Git

You can use Git to keep your local copy up-to-date as we make changes and fix bugs. See the git(1) man page here ("9 man git") for details on using Git.

Status

Build Status Coverity Scan Build Status

Contact