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 >
Wrap
C/C++ Source or Header
|
1990-01-28
|
1KB
|
89 lines
/*
* COND.C
*
* (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);
}