ref: e8bec45dfe627c52384a65f856d00bcc0de454dc
parent: 93d2c8708ddb2bf4e3f4c4ffd801d425064910b0
author: Ali Gholami Rudi <ali@rudi.ir>
date: Tue Apr 23 13:10:19 EDT 2013
reg: add \n(.$
--- a/in.c
+++ b/in.c
@@ -133,6 +133,17 @@
return cur && cur->args && cur->args[i - 1] ? cur->args[i - 1] : "";
}
+int in_nargs(void)
+{
+ struct inbuf *cur = buf;
+ int n = 0;
+ while (cur && !cur->args)
+ cur = cur->prev;
+ while (cur && cur->args && cur->args[n])
+ n++;
+ return n;
+}
+
char *in_filename(void)
{
struct inbuf *cur = buf;
--- a/reg.c
+++ b/reg.c
@@ -72,6 +72,9 @@
case REG('.', 'F'):
sprintf(numbuf, "%s", in_filename());
break;
+ case REG('.', '$'):
+ sprintf(numbuf, "%d", in_nargs());
+ break;
default:
sprintf(numbuf, "%d", *nreg(id));
}
--- a/xroff.h
+++ b/xroff.h
@@ -104,6 +104,7 @@
void in_source(char *path); /* .so request */
void in_queue(char *path); /* next input file */
char *in_arg(int i); /* look up argument */
+int in_nargs(void); /* number of arguments */
void in_back(int c); /* push back input character */
char *in_filename(void); /* current filename */
void cp_back(int c); /* push back copy-mode character */