29 |
|
|
30 |
#include <stdlib.h> |
#include <stdlib.h> |
31 |
#include <string.h> |
#include <string.h> |
32 |
|
#include <setjmp.h> |
33 |
#include "headers.h" |
#include "headers.h" |
34 |
#include "extern.h" |
#include "extern.h" |
35 |
#include "rcfile.h" |
#include "rcfile.h" |
252 |
} |
} |
253 |
; |
; |
254 |
|
|
255 |
expr : msgpart meq optlist string |
expr : msgpart optlist meq optlist string |
256 |
{ |
{ |
257 |
$$ = rc_node_create(rc_node_expr); |
$$ = rc_node_create(rc_node_expr); |
258 |
$$->v.expr.part = $1.part; |
$$->v.expr.part = $1.part; |
259 |
$$->v.expr.key = $1.key; |
$$->v.expr.key = $1.key; |
260 |
$$->v.expr.re = anubis_regex_compile($4, $3); |
$$->v.expr.re = anubis_regex_compile($5, $4|$2); |
261 |
} |
} |
262 |
; |
; |
263 |
|
|
320 |
| IDENT |
| IDENT |
321 |
; |
; |
322 |
|
|
323 |
inst_stmt: ADD msgpart string |
inst_stmt: STOP |
324 |
|
{ |
325 |
|
$$ = rc_stmt_create(rc_stmt_inst); |
326 |
|
$$->v.inst.opcode = inst_stop; |
327 |
|
$$->v.inst.part = NIL; |
328 |
|
$$->v.inst.key = NULL; |
329 |
|
$$->v.inst.key2 = NULL; |
330 |
|
$$->v.inst.arg = NULL; |
331 |
|
} |
332 |
|
| CALL string |
333 |
|
{ |
334 |
|
$$ = rc_stmt_create(rc_stmt_inst); |
335 |
|
$$->v.inst.opcode = inst_call; |
336 |
|
$$->v.inst.key = $2; |
337 |
|
$$->v.inst.part = NIL; |
338 |
|
$$->v.inst.key2 = NULL; |
339 |
|
$$->v.inst.arg = NULL; |
340 |
|
} |
341 |
|
| ADD msgpart string |
342 |
{ |
{ |
343 |
$$ = rc_stmt_create(rc_stmt_inst); |
$$ = rc_stmt_create(rc_stmt_inst); |
344 |
$$->v.inst.opcode = inst_add; |
$$->v.inst.opcode = inst_add; |
599 |
inst_name(enum rc_inst_opcode opcode) |
inst_name(enum rc_inst_opcode opcode) |
600 |
{ |
{ |
601 |
switch (opcode) { |
switch (opcode) { |
602 |
|
case inst_stop: |
603 |
|
return "STOP"; |
604 |
|
case inst_call: |
605 |
|
return "CALL"; |
606 |
case inst_add: |
case inst_add: |
607 |
return "ADD"; |
return "ADD"; |
608 |
case inst_remove: |
case inst_remove: |
617 |
rc_inst_print(RC_INST *inst, int level) |
rc_inst_print(RC_INST *inst, int level) |
618 |
{ |
{ |
619 |
rc_level_print(level, inst_name(inst->opcode)); |
rc_level_print(level, inst_name(inst->opcode)); |
620 |
printf(" %s[%s]", part_string(inst->part), |
switch (inst->opcode) { |
621 |
inst->key ? inst->key : ""); |
case inst_stop: |
622 |
if (inst->key2) |
break; |
623 |
printf(" [%s]", inst->key2); |
|
624 |
if (inst->arg) |
case inst_call: |
625 |
printf(" \"%s\"", inst->arg); |
printf(" %s", inst->key); |
626 |
|
break; |
627 |
|
|
628 |
|
default: |
629 |
|
printf(" %s[%s]", part_string(inst->part), |
630 |
|
inst->key ? inst->key : ""); |
631 |
|
if (inst->key2) |
632 |
|
printf(" [%s]", inst->key2); |
633 |
|
if (inst->arg) |
634 |
|
printf(" \"%s\"", inst->arg); |
635 |
|
} |
636 |
} |
} |
637 |
|
|
638 |
/* Statements */ |
/* Statements */ |
798 |
void *data; |
void *data; |
799 |
int refcnt; |
int refcnt; |
800 |
char **refstr; |
char **refstr; |
801 |
|
jmp_buf jmp; |
802 |
}; |
}; |
803 |
|
|
804 |
static void asgn_eval(struct eval_env *env, RC_ASGN *asgn); |
static void asgn_eval(struct eval_env *env, RC_ASGN *asgn); |
825 |
} |
} |
826 |
|
|
827 |
switch (inst->opcode) { |
switch (inst->opcode) { |
828 |
|
case inst_stop: |
829 |
|
longjmp(env->jmp, 1); |
830 |
|
break; |
831 |
|
|
832 |
|
case inst_call: |
833 |
|
rcfile_call_section(env->method, inst->key, |
834 |
|
env->data, env->msg); |
835 |
|
break; |
836 |
|
|
837 |
case inst_add: |
case inst_add: |
838 |
if (inst->part == BODY) |
if (inst->part == BODY) |
839 |
message_add_body(env->msg, inst->key, arg); |
message_add_body(env->msg, inst->key, arg); |
1007 |
} |
} |
1008 |
|
|
1009 |
void |
void |
1010 |
|
eval_section(int method, RC_SECTION *sec, struct rc_secdef *secdef, |
1011 |
|
void *data, MESSAGE *msg) |
1012 |
|
{ |
1013 |
|
struct eval_env env; |
1014 |
|
env.method = method; |
1015 |
|
env.child = secdef->child; |
1016 |
|
env.refcnt = 0; |
1017 |
|
env.refstr = NULL; |
1018 |
|
env.msg = msg; |
1019 |
|
env.data = data; |
1020 |
|
|
1021 |
|
if (setjmp(env.jmp) == 0) |
1022 |
|
stmt_list_eval(&env, sec->stmt); |
1023 |
|
|
1024 |
|
if (env.refstr) |
1025 |
|
xfree_pptr(env.refstr); |
1026 |
|
} |
1027 |
|
|
1028 |
|
void |
1029 |
rc_run_section(int method, RC_SECTION *sec, struct rc_secdef *secdef, |
rc_run_section(int method, RC_SECTION *sec, struct rc_secdef *secdef, |
1030 |
void *data, MESSAGE *msg) |
void *data, MESSAGE *msg) |
1031 |
{ |
{ |
1033 |
return; |
return; |
1034 |
for (; secdef->name; secdef++) |
for (; secdef->name; secdef++) |
1035 |
if (strcmp(sec->name, secdef->name) == 0) { |
if (strcmp(sec->name, secdef->name) == 0) { |
1036 |
struct eval_env env; |
eval_section(method, sec, secdef, data, msg); |
|
env.method = method; |
|
|
env.child = secdef->child; |
|
|
env.refcnt = 0; |
|
|
env.refstr = NULL; |
|
|
env.msg = msg; |
|
|
env.data = data; |
|
|
|
|
|
stmt_list_eval(&env, sec->stmt); |
|
|
if (env.refstr) |
|
|
xfree_pptr(env.refstr); |
|
|
|
|
1037 |
return; |
return; |
1038 |
} |
} |
1039 |
anubis_error(SOFT, |
anubis_error(SOFT, |
1041 |
} |
} |
1042 |
|
|
1043 |
void |
void |
1044 |
|
rc_call_section(int method, RC_SECTION *sec, struct rc_secdef *secdef, |
1045 |
|
void *data, MESSAGE *msg) |
1046 |
|
{ |
1047 |
|
if (!sec) |
1048 |
|
return; |
1049 |
|
for (; secdef->name; secdef++) |
1050 |
|
if (strcmp(secdef->name, "RULE") == 0) { |
1051 |
|
eval_section(method, sec, secdef, data, msg); |
1052 |
|
return; |
1053 |
|
} |
1054 |
|
} |
1055 |
|
|
1056 |
|
void |
1057 |
rc_run_section_list(int method, RC_SECTION *sec, struct rc_secdef *secdef) |
rc_run_section_list(int method, RC_SECTION *sec, struct rc_secdef *secdef) |
1058 |
{ |
{ |
1059 |
for (; sec; sec = sec->next) |
for (; sec; sec = sec->next) |