home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / telecom / uucp_442 / src / dmail / cond.c < prev    next >
C/C++ Source or Header  |  1990-02-02  |  1KB  |  91 lines

  1.  
  2. /*
  3.  * COND.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/dmail/RCS/cond.c,v 1.1 90/02/02 12:03:39 dillon Exp Locker: dillon $
  6.  *
  7.  *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
  8.  *
  9.  * Conditional routines.
  10.  *
  11.  * if [!]variable
  12.  * else
  13.  * endif
  14.  *
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "dmail.h"
  19.  
  20. #define MAXIF    16
  21.  
  22. static int Disable_if, Disable_case;
  23.  
  24. static int If_level;
  25. static char If_state[MAXIF];
  26.  
  27. do_if()
  28. {
  29.     char *str = av[1];
  30.     int result = 0;
  31.  
  32.     if (ac != 2) {
  33.     puts ("if: bad args");
  34.     return(-1);
  35.     }
  36.     if (Disable_if) {
  37.     ++Disable_if;
  38.     return (1);
  39.     }
  40.     if (If_level == MAXIF) {
  41.     puts ("Too many level's of IF's");
  42.     return (-1);
  43.     }
  44.     if (*str == '!') {
  45.     ++str;
  46.     result = 1;
  47.     }
  48.     if (get_var(LEVEL_SET, str))
  49.     result = 1 - result;
  50.     if (!result)
  51.     ++Disable_if;
  52.     If_state[If_level++] = result;
  53.     XDisable = Disable_if + Disable_case;
  54.     return (1);
  55. }
  56.  
  57. do_else()
  58. {
  59.     if (Disable_if > 1)
  60.     return (1);
  61.     if (If_level < 1) {
  62.     puts ("else without if");
  63.     return (-1);
  64.     }
  65.     Disable_if = !(If_state[If_level - 1] = 1 - If_state[If_level - 1]);
  66.     XDisable = Disable_if + Disable_case;
  67.     return (1);
  68. }
  69.  
  70. do_endif()
  71. {
  72.     if (Disable_if == 1) {
  73.     --If_level;
  74.     Disable_if = 0;
  75.     } else
  76.     if (Disable_if > 1) {
  77.     --Disable_if;
  78.     } else {
  79.     if (If_level == 0) {
  80.         puts ("endif without if");
  81.         return (-1);
  82.     }
  83.     --If_level;
  84.     Disable_if = 0;
  85.     }
  86.     XDisable = Disable_if + Disable_case;
  87.     return (1);
  88. }
  89.  
  90.  
  91.