home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 341b.lha / uucp1_v1.03d / src / dmail / cond.c < prev    next >
C/C++ Source or Header  |  1990-01-28  |  1KB  |  89 lines

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