view f-demime/b2q_in.c @ 4:612c4d0df768

f-demime: rework for unboundedly long lines
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 09:02:12 +0000
parents 7e0d08176f32
children
line wrap: on
line source

/*
 * This module implements the input side of base64-to-QP conversion.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "defs.h"

extern void (*dec_outf)();
extern FILE *tempfile;

static int cr_state;

static void
output_func(ch)
{
	if (cr_state) {
		cr_state = 0;
		if (ch == '\n') {
			putc('\n', tempfile);
			return;
		} else
			putc('\r', tempfile);
	}
	if (ch == '\r')
		cr_state = 1;
	else
		putc(ch, tempfile);
}

void
b2q_conv_init()
{
	dec_outf = output_func;
	cr_state = 0;
}

void
b2q_conv_finish()
{
	if (cr_state)
		putc('\r', tempfile);
}