home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * COND.C
- *
- * $Header: Beta:src/uucp/src/dmail/RCS/cond.c,v 1.1 90/02/02 12:03:39 dillon Exp Locker: dillon $
- *
- * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- *
- * Conditional routines.
- *
- * if [!]variable
- * else
- * endif
- *
- */
-
- #include <stdio.h>
- #include "dmail.h"
-
- #define MAXIF 16
-
- static int Disable_if, Disable_case;
-
- static int If_level;
- static char If_state[MAXIF];
-
- do_if()
- {
- char *str = av[1];
- int result = 0;
-
- if (ac != 2) {
- puts ("if: bad args");
- return(-1);
- }
- if (Disable_if) {
- ++Disable_if;
- return (1);
- }
- if (If_level == MAXIF) {
- puts ("Too many level's of IF's");
- return (-1);
- }
- if (*str == '!') {
- ++str;
- result = 1;
- }
- if (get_var(LEVEL_SET, str))
- result = 1 - result;
- if (!result)
- ++Disable_if;
- If_state[If_level++] = result;
- XDisable = Disable_if + Disable_case;
- return (1);
- }
-
- do_else()
- {
- if (Disable_if > 1)
- return (1);
- if (If_level < 1) {
- puts ("else without if");
- return (-1);
- }
- Disable_if = !(If_state[If_level - 1] = 1 - If_state[If_level - 1]);
- XDisable = Disable_if + Disable_case;
- return (1);
- }
-
- do_endif()
- {
- if (Disable_if == 1) {
- --If_level;
- Disable_if = 0;
- } else
- if (Disable_if > 1) {
- --Disable_if;
- } else {
- if (If_level == 0) {
- puts ("endif without if");
- return (-1);
- }
- --If_level;
- Disable_if = 0;
- }
- XDisable = Disable_if + Disable_case;
- return (1);
- }
-
-
-