aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acme/addr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/acme/addr.c')
-rw-r--r--src/cmd/acme/addr.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cmd/acme/addr.c b/src/cmd/acme/addr.c
index 861e5e01..2ccae960 100644
--- a/src/cmd/acme/addr.c
+++ b/src/cmd/acme/addr.c
@@ -49,6 +49,27 @@ isregexc(int r)
return FALSE;
}
+// nlcounttopos starts at q0 and advances nl lines,
+// being careful not to walk past the end of the text,
+// and then nr chars, being careful not to walk past
+// the end of the current line.
+// It returns the final position.
+long
+nlcounttopos(Text *t, long q0, long nl, long nr)
+{
+ while(nl > 0 && q0 < t->file->b.nc) {
+ if(textreadc(t, q0++) == '\n')
+ nl--;
+ }
+ if(nl > 0)
+ return q0;
+ while(nr > 0 && q0 < t->file->b.nc && textreadc(t, q0) != '\n') {
+ q0++;
+ nr--;
+ }
+ return q0;
+}
+
Range
number(uint showerr, Text *t, Range r, int line, int dir, int size, int *evalp)
{