Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 67f9b1ed authored by rswindell's avatar rswindell

Create and use new str_util.c function: utf8_to_cp437_str(), which is just a

wrapper for utf8_normalize_str() and utf8_replace_chars with the proper
arguments.
This will fix *a* problem with UTF-8 message not being converted to CP437 in
QWK packets correctly (we were just normalizing, not fully converting).
Also got rid of the defunct DLLCALL usage str_util.c
parent 8deab15b
......@@ -40,8 +40,6 @@
#include "sbbs.h"
#include "utf8.h"
#include "unicode.h"
#include "cp437defs.h"
/****************************************************************************/
/* Loads an SMB message from the open msg base the fastest way possible */
......@@ -146,11 +144,7 @@ const char* sbbs_t::msghdr_field(const smbmsg_t* msg, const char* str, char* buf
buf = msgghdr_field_cp437_str;
strncpy(buf, str, sizeof(msgghdr_field_cp437_str));
utf8_normalize_str(buf);
utf8_replace_chars(buf, unicode_to_cp437
,/* unsupported char: */CP437_INVERTED_QUESTION_MARK
,/* unsupported zero-width ch: */0
,/* decode error char: */CP437_INVERTED_EXCLAMATION_MARK);
utf8_to_cp437_str(buf);
return buf;
}
......
......@@ -263,7 +263,7 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, smb_t* smb
if(mode&QM_UTF8)
qwk_newline = '\n';
else
utf8_normalize_str(buf);
utf8_to_cp437_str(buf);
}
fprintf(qwk_fp,"%*s",QWK_BLOCK_LEN,""); /* Init header to space */
......
......@@ -1142,30 +1142,31 @@ extern "C" {
DLLEXPORT int DLLCALL update_uldate(scfg_t* cfg, file_t* f);
/* str_util.c */
DLLEXPORT char * DLLCALL remove_ctrl_a(const char* instr, char* outstr);
DLLEXPORT char DLLCALL ctrl_a_to_ascii_char(char code);
DLLEXPORT char * DLLCALL truncstr(char* str, const char* set);
DLLEXPORT char * DLLCALL ascii_str(uchar* str);
DLLEXPORT char DLLCALL exascii_to_ascii_char(uchar ch);
DLLEXPORT BOOL DLLCALL findstr(const char *insearch, const char *fname);
DLLEXPORT BOOL DLLCALL findstr_in_string(const char* insearchof, char* string);
DLLEXPORT BOOL DLLCALL findstr_in_list(const char* insearchof, str_list_t list);
DLLEXPORT str_list_t DLLCALL findstr_list(const char* fname);
DLLEXPORT BOOL DLLCALL trashcan(scfg_t* cfg, const char *insearch, const char *name);
DLLEXPORT char * DLLCALL trashcan_fname(scfg_t* cfg, const char *name, char* fname, size_t);
DLLEXPORT str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name);
DLLEXPORT char * DLLCALL strip_exascii(const char *str, char* dest);
DLLEXPORT char * DLLCALL strip_space(const char *str, char* dest);
DLLEXPORT char * DLLCALL prep_file_desc(const char *str, char* dest);
DLLEXPORT char * DLLCALL strip_ctrl(const char *str, char* dest);
DLLEXPORT char * DLLCALL net_addr(net_t* net);
DLLEXPORT BOOL DLLCALL valid_ctrl_a_attr(char a);
DLLEXPORT BOOL DLLCALL valid_ctrl_a_code(char a);
DLLEXPORT size_t DLLCALL strip_invalid_attr(char *str);
DLLEXPORT char * DLLCALL ultoac(ulong l,char *str);
DLLEXPORT char * DLLCALL rot13(char* str);
DLLEXPORT uint32_t DLLCALL str_to_bits(uint32_t currval, const char *str);
DLLEXPORT BOOL DLLCALL str_is_ascii(const char*);
DLLEXPORT char * remove_ctrl_a(const char* instr, char* outstr);
DLLEXPORT char ctrl_a_to_ascii_char(char code);
DLLEXPORT char * truncstr(char* str, const char* set);
DLLEXPORT char * ascii_str(uchar* str);
DLLEXPORT char exascii_to_ascii_char(uchar ch);
DLLEXPORT BOOL findstr(const char *insearch, const char *fname);
DLLEXPORT BOOL findstr_in_string(const char* insearchof, char* string);
DLLEXPORT BOOL findstr_in_list(const char* insearchof, str_list_t list);
DLLEXPORT str_list_t findstr_list(const char* fname);
DLLEXPORT BOOL trashcan(scfg_t* cfg, const char *insearch, const char *name);
DLLEXPORT char * trashcan_fname(scfg_t* cfg, const char *name, char* fname, size_t);
DLLEXPORT str_list_t trashcan_list(scfg_t* cfg, const char* name);
DLLEXPORT char * strip_exascii(const char *str, char* dest);
DLLEXPORT char * strip_space(const char *str, char* dest);
DLLEXPORT char * prep_file_desc(const char *str, char* dest);
DLLEXPORT char * strip_ctrl(const char *str, char* dest);
DLLEXPORT char * net_addr(net_t* net);
DLLEXPORT BOOL valid_ctrl_a_attr(char a);
DLLEXPORT BOOL valid_ctrl_a_code(char a);
DLLEXPORT size_t strip_invalid_attr(char *str);
DLLEXPORT char * ultoac(ulong l,char *str);
DLLEXPORT char * rot13(char* str);
DLLEXPORT uint32_t str_to_bits(uint32_t currval, const char *str);
DLLEXPORT BOOL str_is_ascii(const char*);
DLLEXPORT char * utf8_to_cp437_str(char* str);
/* msg_id.c */
DLLEXPORT char * DLLCALL ftn_msgid(sub_t*, smbmsg_t*, char* msgid, size_t);
......
......@@ -34,6 +34,9 @@
****************************************************************************/
#include "sbbs.h"
#include "utf8.h"
#include "unicode.h"
#include "cp437defs.h"
/****************************************************************************/
/* For all the functions that take a 'dest' argument, pass NULL to have the */
......@@ -43,7 +46,7 @@
/****************************************************************************/
/* Removes ctrl-a codes from the string 'str' */
/****************************************************************************/
char* DLLCALL remove_ctrl_a(const char *str, char *dest)
char* remove_ctrl_a(const char *str, char *dest)
{
int i,j;
......@@ -64,7 +67,7 @@ char* DLLCALL remove_ctrl_a(const char *str, char *dest)
return dest;
}
char* DLLCALL strip_ctrl(const char *str, char* dest)
char* strip_ctrl(const char *str, char* dest)
{
int i,j;
......@@ -86,7 +89,7 @@ char* DLLCALL strip_ctrl(const char *str, char* dest)
return dest;
}
char* DLLCALL strip_exascii(const char *str, char* dest)
char* strip_exascii(const char *str, char* dest)
{
int i,j;
......@@ -99,7 +102,7 @@ char* DLLCALL strip_exascii(const char *str, char* dest)
return dest;
}
char* DLLCALL strip_space(const char *str, char* dest)
char* strip_space(const char *str, char* dest)
{
int i,j;
......@@ -112,7 +115,7 @@ char* DLLCALL strip_space(const char *str, char* dest)
return dest;
}
char* DLLCALL prep_file_desc(const char *str, char* dest)
char* prep_file_desc(const char *str, char* dest)
{
int i,j;
......@@ -142,7 +145,7 @@ char* DLLCALL prep_file_desc(const char *str, char* dest)
/****************************************************************************/
/* Pattern matching string search of 'insearchof' in 'string'. */
/****************************************************************************/
BOOL DLLCALL findstr_in_string(const char* insearchof, char* string)
BOOL findstr_in_string(const char* insearchof, char* string)
{
char* p;
char str[256];
......@@ -245,7 +248,7 @@ static BOOL is_cidr_match(const char *p, uint32_t ip_addr, uint32_t cidr, unsign
/****************************************************************************/
/* Pattern matching string search of 'insearchof' in 'list'. */
/****************************************************************************/
BOOL DLLCALL findstr_in_list(const char* insearchof, str_list_t list)
BOOL findstr_in_list(const char* insearchof, str_list_t list)
{
size_t index;
BOOL found=FALSE;
......@@ -272,7 +275,7 @@ BOOL DLLCALL findstr_in_list(const char* insearchof, str_list_t list)
/****************************************************************************/
/* Pattern matching string search of 'insearchof' in 'fname'. */
/****************************************************************************/
BOOL DLLCALL findstr(const char* insearchof, const char* fname)
BOOL findstr(const char* insearchof, const char* fname)
{
char str[256];
BOOL found=FALSE;
......@@ -307,7 +310,7 @@ BOOL DLLCALL findstr(const char* insearchof, const char* fname)
/* Searches the file <name>.can in the TEXT directory for matches */
/* Returns TRUE if found in list, FALSE if not. */
/****************************************************************************/
BOOL DLLCALL trashcan(scfg_t* cfg, const char* insearchof, const char* name)
BOOL trashcan(scfg_t* cfg, const char* insearchof, const char* name)
{
char fname[MAX_PATH+1];
......@@ -315,7 +318,7 @@ BOOL DLLCALL trashcan(scfg_t* cfg, const char* insearchof, const char* name)
}
/****************************************************************************/
char* DLLCALL trashcan_fname(scfg_t* cfg, const char* name, char* fname, size_t maxlen)
char* trashcan_fname(scfg_t* cfg, const char* name, char* fname, size_t maxlen)
{
safe_snprintf(fname,maxlen,"%s%s.can",cfg->text_dir,name);
return fname;
......@@ -328,7 +331,7 @@ static char* process_findstr_item(size_t index, char *str, void* cbdata)
}
/****************************************************************************/
str_list_t DLLCALL findstr_list(const char* fname)
str_list_t findstr_list(const char* fname)
{
FILE* fp;
str_list_t list;
......@@ -345,7 +348,7 @@ str_list_t DLLCALL findstr_list(const char* fname)
}
/****************************************************************************/
str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name)
str_list_t trashcan_list(scfg_t* cfg, const char* name)
{
char fname[MAX_PATH+1];
......@@ -356,7 +359,7 @@ str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name)
/* Returns in 'string' a character representation of the number in l with */
/* commas. */
/****************************************************************************/
char* DLLCALL ultoac(ulong l, char *string)
char* ultoac(ulong l, char *string)
{
char str[256];
int i,j,k;
......@@ -376,7 +379,7 @@ char* DLLCALL ultoac(ulong l, char *string)
/****************************************************************************/
/* Truncate string at first occurrence of char in specified character set */
/****************************************************************************/
char* DLLCALL truncstr(char* str, const char* set)
char* truncstr(char* str, const char* set)
{
char* p;
......@@ -390,7 +393,7 @@ char* DLLCALL truncstr(char* str, const char* set)
/****************************************************************************/
/* rot13 encoder/decoder - courtesy of Mike Acar */
/****************************************************************************/
char* DLLCALL rot13(char* str)
char* rot13(char* str)
{
char ch, cap;
char* p;
......@@ -487,7 +490,7 @@ uint hptoi(const char *str)
/****************************************************************************/
/* Returns TRUE if a is a valid ctrl-a "attribute" code, FALSE if it isn't. */
/****************************************************************************/
BOOL DLLCALL valid_ctrl_a_attr(char a)
BOOL valid_ctrl_a_attr(char a)
{
switch(toupper(a)) {
case '+': /* push attr */
......@@ -521,7 +524,7 @@ BOOL DLLCALL valid_ctrl_a_attr(char a)
/****************************************************************************/
/* Returns TRUE if a is a valid QWKnet compatible Ctrl-A code, else FALSE */
/****************************************************************************/
BOOL DLLCALL valid_ctrl_a_code(char a)
BOOL valid_ctrl_a_code(char a)
{
switch(toupper(a)) {
case 'P': /* Pause */
......@@ -534,7 +537,7 @@ BOOL DLLCALL valid_ctrl_a_code(char a)
/****************************************************************************/
/****************************************************************************/
char DLLCALL ctrl_a_to_ascii_char(char a)
char ctrl_a_to_ascii_char(char a)
{
switch(toupper(a)) {
case 'L': /* cls */
......@@ -553,7 +556,7 @@ char DLLCALL ctrl_a_to_ascii_char(char a)
/* Strips invalid Ctrl-Ax "attribute" sequences from str */
/* Returns number of ^A's in line */
/****************************************************************************/
size_t DLLCALL strip_invalid_attr(char *str)
size_t strip_invalid_attr(char *str)
{
char* dest;
size_t a,c,d;
......@@ -580,7 +583,7 @@ size_t DLLCALL strip_invalid_attr(char *str)
/****************************************************************************/
/****************************************************************************/
char DLLCALL exascii_to_ascii_char(uchar ch)
char exascii_to_ascii_char(uchar ch)
{
/* Seven bit table for EXASCII to ASCII conversion */
const char *sbtbl="CUeaaaaceeeiiiAAEaAooouuyOUcLYRfaiounNao?--24!<>"
......@@ -592,7 +595,7 @@ char DLLCALL exascii_to_ascii_char(uchar ch)
return ch;
}
BOOL DLLCALL str_is_ascii(const char* str)
BOOL str_is_ascii(const char* str)
{
for(const char* p = str; *p != 0; p++) {
if(*p < 0)
......@@ -604,7 +607,7 @@ BOOL DLLCALL str_is_ascii(const char* str)
/****************************************************************************/
/* Convert string from IBM extended ASCII to just ASCII */
/****************************************************************************/
char* DLLCALL ascii_str(uchar* str)
char* ascii_str(uchar* str)
{
uchar* p=str;
......@@ -616,7 +619,7 @@ char* DLLCALL ascii_str(uchar* str)
return((char*)str);
}
uint32_t DLLCALL str_to_bits(uint32_t val, const char *str)
uint32_t str_to_bits(uint32_t val, const char *str)
{
/* op can be 0 for replace, + for add, or - for remove */
int op=0;
......@@ -648,3 +651,12 @@ uint32_t DLLCALL str_to_bits(uint32_t val, const char *str)
return val;
}
/* Convert a UTF-8 encoded string to a CP437-encoded string */
char* utf8_to_cp437_str(char* str)
{
utf8_normalize_str(str);
return utf8_replace_chars(str, unicode_to_cp437
,/* unsupported char: */CP437_INVERTED_QUESTION_MARK
,/* unsupported zero-width ch: */0
,/* decode error char: */CP437_INVERTED_EXCLAMATION_MARK);
}
......@@ -37,8 +37,6 @@
#include "sbbs.h"
#include "wordwrap.h"
#include "utf8.h"
#include "unicode.h"
#include "cp437defs.h"
#define MAX_LINES 10000
#define MAX_LINE_LEN (cols - 1)
......@@ -113,11 +111,7 @@ bool sbbs_t::quotemsg(smb_t* smb, smbmsg_t* msg, bool tails)
&& (!useron_xedit || (cfg.xedit[useron_xedit-1]->misc&XTRN_UTF8)))
is_utf8 = TRUE;
else {
utf8_normalize_str(buf);
utf8_replace_chars(buf, unicode_to_cp437
,/* unsupported char: */CP437_INVERTED_QUESTION_MARK
,/* unsupported zero-width ch: */0
,/* decode error char: */CP437_INVERTED_EXCLAMATION_MARK);
utf8_to_cp437_str(buf);
}
} else { // CP437
char* orgtxt;
......@@ -566,11 +560,7 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, long mode,
if(!str_is_ascii(subj)) {
if(utf8_str_is_valid(subj)) {
if(!term_supports(UTF8) || !(cfg.xedit[useron_xedit-1]->misc & XTRN_UTF8)) {
utf8_normalize_str(subj);
utf8_replace_chars(subj, unicode_to_cp437
,/* unsupported char: */CP437_INVERTED_QUESTION_MARK
,/* unsupported zero-width ch: */0
,/* decode error char: */CP437_INVERTED_EXCLAMATION_MARK);
utf8_to_cp437_str(subj);
}
} else { // CP437
if(term_supports(UTF8) && (cfg.xedit[useron_xedit-1]->misc & XTRN_UTF8)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment