ALT Linux repos
5.0: | 4.64L-alt5.1 |
4.1: | 4.64L-alt5 |
4.0: | 4.64L-alt4.1 |
3.0: | 4.58L-alt4 |
+backports: | 4.64L-alt0.M30.4 |
Group :: Networking/Mail
RPM: pine
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
recodeg.c 0100644 0000766 0000766 00000006640 07657142534 011346 0 ustar ivan ivan /*
The recode table creator for multiply translations
Copyright (C) 1999 Lev Levitin <lev@mccme.ru>
Systemizing document and system-known charset names.
Enhancements.
Copyright (C) 2000-2003 Ivan Zakharyaschev <vanyaz@mccme.ru>
*/
/*#define FDEBUG*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "recodeg.h"
#include <pure_recode.h>
#include <chains.h>
struct Chain * recodeg_rules(void) {
static struct Chain * global_rules = NULL;
return global_rules ? : (global_rules = chain_createEmpty());
}
/* We do not need this function -- will pass the selected rules as
an argument in the place where the pipe is created. */
#if 0
#ifdef FDEBUG
#include <singleconv.h>
#endif
MultipleConverter *recodeg_pipe(void) {
#ifdef FDEBUG
MultipleConverter * result;
fprintf(stderr, __FUNCTION__ " start\n");
result = multiple_conv_open(rules()->first);
fprintf(stderr, __FUNCTION__ ": unused %d\n",
((SingleConverter *)result->first->value)->inbuf);
return result;
#else
return multiple_conv_open(recodeg_rules()->first);
#endif
}
#endif /* 0 */
#include <docconv.h>
int recodeg_addrule(const char *from, const char *to) {
return addRecodeRule(recodeg_rules(), from, to);
}
void recodeg_dellast(void) {
dellastRecodeRule(recodeg_rules());
}
void recodeg_delall(void) {
delallRecodeRules(recodeg_rules());
}
char * recodeg_info(void) {
return infoOnRecodeRules(recodeg_rules());
}
int recodeg_used(void) {
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
return ! chain_isEmpty(recodeg_rules());
}
static int auto_recode = 1;;
int recodeg_auto(void) {
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
return auto_recode;
}
void recodeg_setauto(int flag) {
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
auto_recode = flag;
}
#ifdef RECODEG_PINE
#include "headers.h"
void recodeg_autosolve(BODY *body) {
char *charset = rfc2231_get_param(body->parameter,
"charset", NULL, NULL);
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
recodeg_delall();
if(!charset)
return;
if( strucmp(charset, "us-ascii")
&& ps_global->VAR_CHAR_SET
&& strucmp(charset, ps_global->VAR_CHAR_SET))
{
recodeg_addrule(charset, ps_global->VAR_CHAR_SET);
}
fs_give((void **)&charset);
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ " ret\n");
#endif
}
#endif
char * recodeg_validcharset(char * const in_charset) {
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
if (recodeg_used()) {
const char * const our_charset =
((const struct RecodeRule *)chain_last(recodeg_rules()))->to;
fs_give((void **) &in_charset);
return my_fs_dup(our_charset);
}
else
return in_charset;
}
const char * recodeg_validcharset_static(const char * const in_charset) {
#ifdef FDEBUG
fprintf(stderr, __FUNCTION__ "\n");
#endif
if (recodeg_used()) {
const char * const our_charset =
((const struct RecodeRule *)chain_last(recodeg_rules()))->to;
return our_charset;
}
else
return in_charset;
}
/* Utility functions not related to recoding directly; */
char * my_fs_dup(const char * const S) {
const size_t l = strlen(S);
char * const copy = fs_get( (l+1) * sizeof(char) );
copy[l] = '\0';
strncpy(copy, S, l);
return copy;
}
char * my_fs_move(const char * const S) {
char * const copy = my_fs_dup(S);
free((char*)S);
return copy;
}