tadd .ei for else-if - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 1076c720dff8ea5f05dfc8f5c7c1cd192330eb63
parent baa6e34b72e5d978fb0da4266c4527e7e582e675
Author: rsc 
Date:   Wed, 14 Dec 2005 19:58:32 +0000

add .ei for else-if

Diffstat:
  M src/cmd/troff/fns.h                 |       1 +
  M src/cmd/troff/n5.c                  |      23 +++++++++++++++++------
  M src/cmd/troff/ni.c                  |       1 +

3 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/cmd/troff/fns.h b/src/cmd/troff/fns.h
t@@ -172,6 +172,7 @@ void        casefl(void);
 void        caseev(void);
 void        envcopy(Env *e1, Env *e2);
 void        caseel(void);
+void caseei(void);
 void        caseie(void);
 void        casexif(void);
 void        caseif(void);
diff --git a/src/cmd/troff/n5.c b/src/cmd/troff/n5.c
t@@ -8,7 +8,7 @@
 #include "fns.h"
 #include "ext.h"
 
-int        iflist[NIF];
+int        iflist[NIF];        /* whether 'else' is true */
 int        ifx;
 int        ifnum = 0;        /* trying numeric expression for .if or .ie condition */
 
t@@ -612,6 +612,16 @@ void envcopy(Env *e1, Env *e2)        /* copy env e2 to e1 */
 }
 
 
+void caseei(void)
+{
+        if (--ifx < 0) {
+                ifx = 0;
+                iflist[0] = 0;
+        }
+        caseif1(1);
+        ifx++;
+}
+
 void caseel(void)
 {
         if (--ifx < 0) {
t@@ -621,7 +631,6 @@ void caseel(void)
         caseif1(2);
 }
 
-
 void caseie(void)
 {
         if (ifx >= NIF) {
t@@ -629,11 +638,11 @@ void caseie(void)
                 ifx = 0;
                 edone(040);
         }
+        iflist[ifx] = 1;
         caseif1(1);
         ifx++;
 }
 
-
 void caseif(void)
 {
         caseif1(0);
t@@ -645,7 +654,7 @@ void caseif1(int x)
         int notflag, true;
         Tchar i;
 
-        if (x == 2) {
+        if (x == 2) {        /* .el */
                 notflag = 0;
                 true = iflist[ifx];
                 goto i1;
t@@ -691,8 +700,10 @@ void caseif1(int x)
         }
 i1:
         true ^= notflag;
-        if (x == 1)
-                iflist[ifx] = !true;
+        if (x == 1) {        /* .ie or .ei */
+                true = true && iflist[ifx];
+                iflist[ifx] = iflist[ifx] && !true;
+        }
         if (true) {
 i2:
                 while ((cbits(i = getch())) == ' ')
diff --git a/src/cmd/troff/ni.c b/src/cmd/troff/ni.c
t@@ -70,6 +70,7 @@ Contab contab[NM] = {
         C(PAIR('n', 'r'), casenr),
         C(PAIR('i', 'f'), caseif),
         C(PAIR('i', 'e'), caseie),
+        C(PAIR('e', 'i'), caseei),
         C(PAIR('e', 'l'), caseel),
         C(PAIR('p', 'o'), casepo),
         C(PAIR('t', 'l'), casetl),