home *** CD-ROM | disk | FTP | other *** search
- /*
- * COND.C
- *
- * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- *
- * Conditional routines.
- *
- * if [!]variable
- * else
- * endif
- *
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #include "dmail.h"
-
- #define MAXIF 16
-
- static int Disable_if, Disable_case;
-
- static int If_level;
- static char If_state[MAXIF];
-
- Prototype int do_if (char *garbage, int com);
- Prototype int do_else (char *garbage, int com);
- Prototype int do_endif (char *garbage, int com);
-
- int
- do_if (char *garbage, int com)
- {
- 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;
- }
-
- int
- do_else (char *garbage, int com)
- {
- 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;
- }
-
- int
- do_endif (char *garbage, int com)
- {
- 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;
- }
-