Commit 33920779 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(CHK_ASSIGN): Macro rewritten as the new chk_assign() function, with a

	slightly different API.  This was mainly done to get rid of
	the error message "invalid field name: xyzzy" that occured if
	the value of xyzzy was bogus, even if xyzzy itself was a valid
	name.  All callers updated.
(CHK_FLAG_A): Similarly rewritten as chk_flag_a().
(assign): Check for valid field name and valid field content
	separately, so that the "invalid field name: xyzzy" message
	isn't printed just because the content is bad.
(chk_assign): New name for former aux_item_def_check_assign.  New
	arguments: found and good; return status via them.
(chk_flag_a): New function.
(aux_item_def_check_trigger): New arguments: found and good;
	return status via them.
(aux_item_def_check_validate): Ditto.
parent 15ddac15
%{
/*
* $Id: aux-item-def-parse.y,v 1.22 2003/08/23 16:38:18 ceder Exp $
* $Id: aux-item-def-parse.y,v 1.23 2004/07/21 07:12:44 ceder Exp $
* Copyright (C) 1994-1996, 1999, 2001-2003 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -103,25 +103,6 @@ BUGDECL;
static Aux_item_definition def;
static Bool errorFlag = FALSE;
#define CHK_ASSIGN(_i_, _f_, _t_, _d_, _e_, _l_) \
found = found || aux_item_def_check_assign(_i_,_d_,&def._f_,_t_,&(_e_),_l_)
#define CHK_FLAG_A(_i_, _f_, _d_, _e_, _l_) \
if (!s_strcmp(s_fcrea_str(_i_),_d_)) \
{ \
found = 1; \
if (_e_.type != BOOLEAN ) \
{ \
aux_item_def_error_line = _l_; \
yyerror("invalid type: expected %s, got %s", \
aux_item_def_typename(BOOLEAN), \
aux_item_def_typename(_e_.type)); \
} \
if (_e_.val.num) { def.set_flags._f_ = 1; } \
else { def.clear_flags._f_ = 1; } \
}
extern int yylex(void);
static char *inputFile;
......@@ -139,27 +120,39 @@ void yyerror();
#endif
struct aux_item_def_value_type;
static int aux_item_def_check_assign(const char *,
String,
void *,
int,
struct aux_item_def_value_type *,
int);
static void chk_assign(int *,
int *,
const char *,
void *,
int,
String,
struct aux_item_def_value_type *,
int);
static Aux_item_flags * chk_flag_a(int *found,
int *good,
const char *id,
String data,
struct aux_item_def_value_type *val,
int lineno);
static const char *aux_item_def_typename(int);
static
short aux_item_def_check_trigger(const char *check_name,
int type,
String trigger_name,
String function_name,
unsigned long *counter,
Aux_item_trigger **triggers);
static
short aux_item_def_check_validate(const char *check_name,
String field_name,
int type,
String data,
Aux_item_definition *def);
static void
aux_item_def_check_trigger(int *found,
int *good,
const char *check_name,
int type,
String trigger_name,
String function_name,
unsigned long *counter,
Aux_item_trigger **triggers);
static void
aux_item_def_check_validate(int *found,
int *good,
const char *check_name,
String field_name,
int type,
String data,
Aux_item_definition *def);
#define YYERROR_VERBOSE
......@@ -259,65 +252,84 @@ body : body assign
assign : ID '=' value ';'
{
int found = 0;
CHK_ASSIGN("author-only", author_only, BOOLEAN,
$1, $3, @3.first_line);
CHK_ASSIGN("supervisor-only", supervisor_only,
BOOLEAN, $1, $3, @3.first_line);
CHK_ASSIGN("system-only", system_only,
BOOLEAN, $1, $3, @3.first_line);
CHK_ASSIGN("inherit-limit", inherit_limit, NUMBER,
$1, $3, @3.first_line);
CHK_ASSIGN("unique", one_per_person, BOOLEAN,
$1, $3, @3.first_line);
CHK_ASSIGN("unique-data", unique_data, BOOLEAN,
$1, $3, @3.first_line);
CHK_ASSIGN("permanent", may_not_delete, BOOLEAN,
$1, $3, @3.first_line);
CHK_ASSIGN("owner-delete", owner_delete, BOOLEAN,
$1, $3, @3.first_line);
CHK_FLAG_A("inherit", inherit, $1, $3, @3.first_line);
CHK_FLAG_A("secret", secret, $1, $3, @3.first_line);
CHK_FLAG_A("hide-creator", hide_creator,
$1, $3, @3.first_line);
CHK_FLAG_A("dont-garb", dont_garb, $1, $3, @3.first_line);
CHK_FLAG_A("reserved-2", reserved3, $1, $3, @3.first_line);
CHK_FLAG_A("reserved-3", reserved4, $1, $3, @3.first_line);
CHK_FLAG_A("reserved-4", reserved5, $1, $3, @3.first_line);
found = found ? 1 :
aux_item_def_check_validate("validate",
$1,
$3.type,
$3.val.str,
&def);
found = found ? 1 :
aux_item_def_check_trigger("delete-trigger",
$3.type,
$1,
$3.val.str,
&def.num_delete_triggers,
&def.delete_triggers);
found = found ? 1 :
aux_item_def_check_trigger("undelete-trigger",
$3.type,
$1,
$3.val.str,
&def.num_undelete_triggers,
&def.undelete_triggers);
found = found ? 1 :
aux_item_def_check_trigger("add-trigger",
$3.type,
$1,
$3.val.str,
&def.num_add_triggers,
&def.add_triggers);
int good = 0;
Aux_item_flags *f;
chk_assign(&found, &good, "author-only", &def.author_only,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "supervisor-only",
&def.supervisor_only,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "system-only", &def.system_only,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "inherit-limit", &def.inherit_limit,
NUMBER, $1, &$3, @3.first_line);
chk_assign(&found, &good, "unique", &def.one_per_person,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "unique-data", &def.unique_data,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "permanent", &def.may_not_delete,
BOOLEAN, $1, &$3, @3.first_line);
chk_assign(&found, &good, "owner-delete", &def.owner_delete,
BOOLEAN, $1, &$3, @3.first_line);
if ((f = chk_flag_a(&found, &good, "inherit",
$1, &$3, @3.first_line)) != NULL)
f->inherit = 1;
if ((f = chk_flag_a(&found, &good, "secret",
$1, &$3, @3.first_line)) != NULL)
f->secret = 1;
if ((f = chk_flag_a(&found, &good, "hide-creator",
$1, &$3, @3.first_line)) != NULL)
f->hide_creator = 1;
if ((f = chk_flag_a(&found, &good, "dont-garb",
$1, &$3, @3.first_line)) != NULL)
f->dont_garb = 1;
if ((f = chk_flag_a(&found, &good, "reserved-2",
$1, &$3, @3.first_line)) != NULL)
f->reserved3 = 1;
if ((f = chk_flag_a(&found, &good, "reserved-3",
$1, &$3, @3.first_line)) != NULL)
f->reserved4 = 1;
if ((f = chk_flag_a(&found, &good, "reserved-4",
$1, &$3, @3.first_line)) != NULL)
f->reserved5 = 1;
aux_item_def_check_validate(&found, &good,
"validate",
$1,
$3.type,
$3.val.str,
&def);
aux_item_def_check_trigger(&found, &good, "delete-trigger",
$3.type,
$1,
$3.val.str,
&def.num_delete_triggers,
&def.delete_triggers);
aux_item_def_check_trigger(&found, &good, "undelete-trigger",
$3.type,
$1,
$3.val.str,
&def.num_undelete_triggers,
&def.undelete_triggers);
aux_item_def_check_trigger(&found, &good, "add-trigger",
$3.type,
$1,
$3.val.str,
&def.num_add_triggers,
&def.add_triggers);
if (found == 0)
......@@ -393,22 +405,30 @@ static const char *aux_item_def_typename(int type)
}
}
static int aux_item_def_check_assign(const char *id,
String field,
void *data,
int type,
struct aux_item_def_value_type *val,
int lineno)
static void
chk_assign(int *found,
int *good,
const char *id,
void *data,
int type,
String field,
struct aux_item_def_value_type *val,
int lineno)
{
if (*found)
return;
if (!s_strcmp(s_fcrea_str(id), field))
{
*found = 1;
if (type != val->type)
{
aux_item_def_error_line = lineno;
yyerror("invalid type: expected %s, got %s",
aux_item_def_typename(type),
aux_item_def_typename(val->type));
return 0;
*good = 0;
return;
}
else if (type == STRING)
{
......@@ -427,32 +447,71 @@ static int aux_item_def_check_assign(const char *id,
restart_kom("Internal error: bad type in aux-item definition "
"assignment (can't happen.)\n");
}
return 1;
*good = 1;
}
else
}
static Aux_item_flags *
chk_flag_a(int *found,
int *good,
const char *id,
String field,
struct aux_item_def_value_type *val,
int lineno)
{
if (*found)
return NULL;
if (!s_strcmp(s_fcrea_str(id), field))
{
return 0;
*found = 1;
if (val->type != BOOLEAN )
{
aux_item_def_error_line = lineno;
yyerror("invalid type: expected %s, got %s",
aux_item_def_typename(BOOLEAN),
aux_item_def_typename(val->type));
*good = 0;
}
else
{
*good = 1;
if (val->val.num)
return &def.set_flags;
else
return &def.clear_flags;
}
}
return NULL;
}
static short aux_item_def_check_trigger(const char *check_name,
int type,
String trigger_name,
String function_name,
unsigned long *counter,
Aux_item_trigger **triggers)
static void
aux_item_def_check_trigger(int *found,
int *good,
const char *check_name,
int type,
String trigger_name,
String function_name,
unsigned long *counter,
Aux_item_trigger **triggers)
{
Aux_item_trigger trigger;
char *tmp_string;
if (*found)
return;
if (s_strcmp(s_fcrea_str(check_name), trigger_name) == 0)
{
*found = 1;
if (type != ID)
{
yyerror("invalid type: expected %s, got %s",
aux_item_def_typename(ID),
aux_item_def_typename(type));
return 0;
return;
}
tmp_string = s_crea_c_str(function_name);
......@@ -463,7 +522,7 @@ static short aux_item_def_check_trigger(const char *check_name,
{
yyerror("undefined function: %s",
tmp_string);
return 1;
return;
}
*counter += 1;
......@@ -473,9 +532,8 @@ static short aux_item_def_check_trigger(const char *check_name,
sizeof(Aux_item_trigger));
*triggers[*counter-1] = trigger;
return 1;
*good = 1;
}
return 0;
}
void parse_aux_item_definitions(char *file)
......@@ -548,17 +606,24 @@ void parse_aux_item_definitions(char *file)
}
static short aux_item_def_check_validate(const char *check_name,
String field_name,
int type,
String data,
Aux_item_definition *def)
static void aux_item_def_check_validate(int *found,
int *good,
const char *check_name,
String field_name,
int type,
String data,
Aux_item_definition *def)
{
Aux_item_validation_function validator;
char *tmp_string;
if (*found)
return;
if (s_strcmp(s_fcrea_str(check_name), field_name) == 0)
{
*found = 1;
/*
* Validator is a function
*/
......@@ -573,7 +638,7 @@ static short aux_item_def_check_validate(const char *check_name,
{
yyerror("undefined function: %s",
tmp_string);
return 1;
return;
}
def->num_validators += 1;
......@@ -583,9 +648,7 @@ static short aux_item_def_check_validate(const char *check_name,
def->validators[def->num_validators-1].type = AUX_VALIDATE_FUNCTION;
def->validators[def->num_validators-1].v.fn.function = validator;
return 1;
*good = 1;
}
else if (type == STRING)
{
......@@ -602,6 +665,7 @@ static short aux_item_def_check_validate(const char *check_name,
def->validators[def->num_validators-1].type = AUX_VALIDATE_REGEXP;
def->validators[def->num_validators-1].v.re.regexp = s_crea_c_str(data);
def->validators[def->num_validators-1].v.re.cached_re_buf = NULL;
*good = 1;
}
else
{
......@@ -609,10 +673,6 @@ static short aux_item_def_check_validate(const char *check_name,
aux_item_def_typename(ID),
aux_item_def_typename(STRING),
aux_item_def_typename(type));
return 0;
}
return 1;
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment