/* given an interpretor and a script, produce an executable script */ int sieve_script_parse(sieve_interp_t *interp, FILE *script, void *script_context, sieve_script_t **ret) { sieve_script_t *s; int res = SIEVE_OK; extern int yylineno; res = interp_verify(interp); if (res != SIEVE_OK) { return res; } s = (sieve_script_t *) xmalloc(sizeof(sieve_script_t)); s->interp = *interp; s->script_context = script_context; /* clear all support bits */ memset(&s->support, 0, sizeof(struct sieve_support)); s->err = 0; yylineno = 1; /* reset line number */ s->cmds = sieve_parse(s, script); if (s->err > 0) { if (s->cmds) { free_tree(s->cmds); } s->cmds = NULL; res = SIEVE_PARSE_ERROR; } *ret = s; return res; }
struct sieve_binary *sieve_compile_script (struct sieve_script *script, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r) { struct sieve_ast *ast; struct sieve_binary *sbin; enum sieve_error error, *errorp; if ( error_r != NULL ) errorp = error_r; else errorp = &error; *errorp = SIEVE_ERROR_NONE; /* Parse */ if ( (ast = sieve_parse(script, ehandler, errorp)) == NULL ) { switch ( *errorp ) { case SIEVE_ERROR_NOT_FOUND: if (error_r == NULL) { sieve_error(ehandler, sieve_script_name(script), "script not found"); } break; default: sieve_error(ehandler, sieve_script_name(script), "parse failed"); } return NULL; } /* Validate */ if ( !sieve_validate(ast, ehandler, flags, errorp) ) { sieve_error(ehandler, sieve_script_name(script), "validation failed"); sieve_ast_unref(&ast); return NULL; } /* Generate */ if ( (sbin=sieve_generate(ast, ehandler, flags, errorp)) == NULL ) { sieve_error(ehandler, sieve_script_name(script), "code generation failed"); sieve_ast_unref(&ast); return NULL; } /* Cleanup */ sieve_ast_unref(&ast); return sbin; }