| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
io.c - description |
/* |
| 3 |
------------------- |
* io |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - basic terminal-based user input / output features |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* 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 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
| 9 |
#include "common.h" |
#include "common.h" |
| 10 |
#include "io.h" |
#include "io.h" |
| 23 |
#include <libssh/libssh.h> |
#include <libssh/libssh.h> |
| 24 |
#include <libssh/server.h> |
#include <libssh/server.h> |
| 25 |
|
|
| 26 |
char stdio_charset[20] = BBS_DEFAULT_CHARSET; |
const char BBS_default_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
| 27 |
|
char stdio_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
| 28 |
|
|
| 29 |
// static input / output buffer |
// static input / output buffer |
| 30 |
static char stdin_buf[LINE_BUFFER_LEN]; |
static char stdin_buf[LINE_BUFFER_LEN]; |
| 1027 |
|
|
| 1028 |
int io_conv_init(const char *charset) |
int io_conv_init(const char *charset) |
| 1029 |
{ |
{ |
| 1030 |
char tocode[32]; |
char tocode[CHARSET_MAX_LEN + 20]; |
| 1031 |
|
|
| 1032 |
if (charset == NULL) |
if (charset == NULL) |
| 1033 |
{ |
{ |
| 1040 |
strncpy(stdio_charset, charset, sizeof(stdio_charset) - 1); |
strncpy(stdio_charset, charset, sizeof(stdio_charset) - 1); |
| 1041 |
stdio_charset[sizeof(stdio_charset) - 1] = '\0'; |
stdio_charset[sizeof(stdio_charset) - 1] = '\0'; |
| 1042 |
|
|
| 1043 |
snprintf(tocode, sizeof(tocode), "%s%s", BBS_DEFAULT_CHARSET, |
snprintf(tocode, sizeof(tocode), "%s%s", BBS_default_charset, |
| 1044 |
(strcasecmp(stdio_charset, BBS_DEFAULT_CHARSET) == 0 ? "" : "//IGNORE")); |
(strcasecmp(stdio_charset, BBS_default_charset) == 0 ? "" : "//IGNORE")); |
| 1045 |
stdin_cd = iconv_open(tocode, stdio_charset); |
stdin_cd = iconv_open(tocode, stdio_charset); |
| 1046 |
if (stdin_cd == (iconv_t)(-1)) |
if (stdin_cd == (iconv_t)(-1)) |
| 1047 |
{ |
{ |
| 1050 |
} |
} |
| 1051 |
|
|
| 1052 |
snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset, |
snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset, |
| 1053 |
(strcasecmp(BBS_DEFAULT_CHARSET, stdio_charset) == 0 ? "" : "//TRANSLIT")); |
(strcasecmp(BBS_default_charset, stdio_charset) == 0 ? "" : "//TRANSLIT")); |
| 1054 |
stdout_cd = iconv_open(tocode, BBS_DEFAULT_CHARSET); |
stdout_cd = iconv_open(tocode, BBS_default_charset); |
| 1055 |
if (stdout_cd == (iconv_t)(-1)) |
if (stdout_cd == (iconv_t)(-1)) |
| 1056 |
{ |
{ |
| 1057 |
log_error("iconv_open(%s->%s) error: %d\n", BBS_DEFAULT_CHARSET, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); |
| 1058 |
iconv_close(stdin_cd); |
iconv_close(stdin_cd); |
| 1059 |
return -2; |
return -2; |
| 1060 |
} |
} |