#line 982 "../../src/builtin/snarf.m4"
/* -*- buffer-read-only: t -*- vi: set ro:
   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
*/
#line 982
#ifdef HAVE_CONFIG_H
#line 982
# include <config.h>
#line 982
#endif
#line 982
#include <sys/types.h>
#line 982

#line 982
#include "mailfromd.h"
#line 982
#include "prog.h"
#line 982
#include "builtin.h"
#line 982

#line 982

#line 1022 "../../src/builtin/snarf.m4"

/* End of snarf.m4 */
#line 1 "body.bi"
/* This file is part of Mailfromd.             -*- c -*-
   Copyright (C) 2008-2022 Sergey Poznyakoff

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */



#include "msg.h"


void
#line 22
bi_body_string(eval_environ_t env)
#line 22

#line 22

#line 22 "body.bi"
{
#line 22
	
#line 22

#line 22

#line 22
void * MFL_DATASEG text;
#line 22
        long  length;
#line 22
        
#line 22
get_pointer_arg(env, 0, &text);
#line 22
        get_numeric_arg(env, 1, &length);
#line 22
        
#line 22

#line 22
        adjust_stack(env, 2);
#line 22

#line 22

#line 22
	if (builtin_module_trace(BUILTIN_IDX_body))
#line 22
		prog_trace(env, "body_string %p %lu",text, length);;
#line 22

{
	size_t off;
	char *s = (char*) env_data_ref(env, (off = heap_reserve(env, length + 1)));
	memcpy(s, text, length);
	s[length] = 0;
	
#line 28
do {
#line 28
  push(env, (STKVAL) (mft_size) (off));
#line 28
  goto endlab;
#line 28
} while (0);
}
endlab:
#line 30
        env_function_cleanup_flush(env, NULL);
#line 30
	return;
#line 30
}


void
#line 33
bi_body_has_nulls(eval_environ_t env)
#line 33

#line 33

#line 33 "body.bi"
{
#line 33
	
#line 33

#line 33

#line 33
void *  text;
#line 33
        long  length;
#line 33
        
#line 33
get_pointer_arg(env, 0, &text);
#line 33
        get_numeric_arg(env, 1, &length);
#line 33
        
#line 33

#line 33
        adjust_stack(env, 2);
#line 33

#line 33

#line 33
	if (builtin_module_trace(BUILTIN_IDX_body))
#line 33
		prog_trace(env, "body_has_nulls %p %lu",text, length);;
#line 33

{
	
#line 35
do {
#line 35
  push(env, (STKVAL)(mft_number)(memchr(text, 0, length) != NULL));
#line 35
  goto endlab;
#line 35
} while (0);
}
endlab:
#line 37
        env_function_cleanup_flush(env, NULL);
#line 37
	return;
#line 37
}
	
/* number current_message() */


void
#line 42
bi_current_message(eval_environ_t env)
#line 42

#line 42

#line 42 "body.bi"
{
#line 42
	
#line 42

#line 42

#line 42

#line 42

#line 42

#line 42
        adjust_stack(env, 0);
#line 42

#line 42

#line 42
	if (builtin_module_trace(BUILTIN_IDX_body))
#line 42
		prog_trace(env, "current_message");;
#line 42

{
	
#line 44
do {
#line 44
  push(env, (STKVAL)(mft_number)(bi_get_current_message(env, NULL)));
#line 44
  goto endlab;
#line 44
} while (0);
}
endlab:
#line 46
        env_function_cleanup_flush(env, NULL);
#line 46
	return;
#line 46
}

void
#line 48
bi_replbody(eval_environ_t env)
#line 48

#line 48

#line 48 "body.bi"
{
#line 48
	
#line 48

#line 48

#line 48
char *  text;
#line 48
        
#line 48
get_string_arg(env, 0, &text);
#line 48
        
#line 48

#line 48
        adjust_stack(env, 1);
#line 48

#line 48

#line 48
	if (builtin_module_trace(BUILTIN_IDX_body))
#line 48
		prog_trace(env, "replbody %s",text);;
#line 48

{
	env_msgmod_append(env, body_repl, "BODY", text, 0);
}

#line 52
        env_function_cleanup_flush(env, NULL);
#line 52
	return;
#line 52
}

void
#line 54
bi_replbody_fd(eval_environ_t env)
#line 54

#line 54

#line 54 "body.bi"
{
#line 54
	
#line 54

#line 54

#line 54
long  fd;
#line 54
        
#line 54
get_numeric_arg(env, 0, &fd);
#line 54
        
#line 54

#line 54
        adjust_stack(env, 1);
#line 54

#line 54

#line 54
	if (builtin_module_trace(BUILTIN_IDX_body))
#line 54
		prog_trace(env, "replbody_fd %lu",fd);;
#line 54

{
	env_msgmod_append(env, body_repl_fd, "BODYFD", NULL, _bi_io_fd(env, fd, 0));
}

#line 58
        env_function_cleanup_flush(env, NULL);
#line 58
	return;
#line 58
}

#line 982 "../../src/builtin/snarf.m4"

#line 982

#line 982

#line 982
void
#line 982
body_init_builtin(void)
#line 982
{
#line 982
	
#line 982
	#line 22 "body.bi"
va_builtin_install_ex("body_string", bi_body_string, STATMASK(smtp_state_body), dtype_string, 2, 0, 0|0, dtype_pointer, dtype_number);
#line 33 "body.bi"
va_builtin_install_ex("body_has_nulls", bi_body_has_nulls, STATMASK(smtp_state_body), dtype_number, 2, 0, 0|0, dtype_pointer, dtype_number);
#line 42 "body.bi"
va_builtin_install_ex("current_message", bi_current_message, STATMASK(smtp_state_eom), dtype_number, 0, 0, MFD_BUILTIN_CAPTURE|0, dtype_unspecified);
#line 48 "body.bi"
va_builtin_install_ex("replbody", bi_replbody, 0, dtype_unspecified, 1, 0, 0|0, dtype_string);
#line 54 "body.bi"
va_builtin_install_ex("replbody_fd", bi_replbody_fd, 0, dtype_unspecified, 1, 0, 0|0, dtype_number);

#line 982 "../../src/builtin/snarf.m4"
	
#line 982
}
#line 982 "../../src/builtin/snarf.m4"

