/[LeafOK_CVS]/lbbs/src/io.c
ViewVC logotype

Diff of /lbbs/src/io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.55 by sysadm, Sat Oct 18 05:02:15 2025 UTC Revision 1.56 by sysadm, Sun Oct 19 01:30:38 2025 UTC
# Line 31  Line 31 
31  #include <libssh/libssh.h>  #include <libssh/libssh.h>
32  #include <libssh/server.h>  #include <libssh/server.h>
33    
34  char stdio_charset[20] = BBS_DEFAULT_CHARSET;  char stdio_charset[32] = BBS_DEFAULT_CHARSET;
35    
36  // static input / output buffer  // static input / output buffer
37  static char stdin_buf[LINE_BUFFER_LEN];  static char stdin_buf[LINE_BUFFER_LEN];
# Line 381  int igetch(int timeout) Line 381  int igetch(int timeout)
381  #ifdef _DEBUG  #ifdef _DEBUG
382                          for (int j = stdin_buf_offset; j < stdin_buf_len; j++)                          for (int j = stdin_buf_offset; j < stdin_buf_len; j++)
383                          {                          {
384                                  log_common("Debug: <--[%u]\n", (stdin_buf[j] + 256) % 256);                                  log_error("Debug input: <--[%u]\n", (stdin_buf[j] + 256) % 256);
385                          }                          }
386  #endif  #endif
387                  }                  }
# Line 400  int igetch(int timeout) Line 400  int igetch(int timeout)
400                          {                          {
401                                  log_error("io_buf_conv(stdin, %d, %d, %d) error\n", stdin_buf_len, stdin_buf_offset, stdin_conv_len);                                  log_error("io_buf_conv(stdin, %d, %d, %d) error\n", stdin_buf_len, stdin_buf_offset, stdin_conv_len);
402                          }                          }
403    
404                            // For debug
405    #ifdef _DEBUG
406                            for (int j = stdin_conv_offset; j < stdin_conv_len; j++)
407                            {
408                                    log_error("Debug input_conv: <--[%u]\n", (stdin_conv[j] + 256) % 256);
409                            }
410    #endif
411                  }                  }
412          }          }
413    
# Line 863  int igetch(int timeout) Line 871  int igetch(int timeout)
871  #ifdef _DEBUG  #ifdef _DEBUG
872          if (out != KEY_TIMEOUT && out != KEY_NULL)          if (out != KEY_TIMEOUT && out != KEY_NULL)
873          {          {
874                  log_common("Debug: -->[0x %x]\n", out);                  log_error("Debug: -->[0x %x]\n", out);
875          }          }
876  #endif  #endif
877    
# Line 899  int io_buf_conv(iconv_t cd, char *p_buf, Line 907  int io_buf_conv(iconv_t cd, char *p_buf,
907          size_t in_bytes;          size_t in_bytes;
908          size_t out_bytes;          size_t out_bytes;
909          int ret;          int ret;
910            int in_control = 0;
911            size_t i = 0;
912    
913          if (cd == NULL || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL)          if (cd == NULL || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL)
914          {          {
# Line 913  int io_buf_conv(iconv_t cd, char *p_buf, Line 923  int io_buf_conv(iconv_t cd, char *p_buf,
923    
924          while (in_bytes > 0)          while (in_bytes > 0)
925          {          {
926                    if ((unsigned char)(*in_buf) == KEY_CONTROL)
927                    {
928                            if (in_control == 0)
929                            {
930                                    in_control = 1;
931                                    i = 0;
932                            }
933                    }
934    
935                    if (in_control)
936                    {
937                            if (out_bytes <= 0)
938                            {
939                                    log_error("iconv(inbytes=%d, outbytes=%d) error: EILSEQ and E2BIG\n", in_bytes, out_bytes);
940                                    return -2;
941                            }
942    
943                            *out_buf = *in_buf;
944                            in_buf++;
945                            out_buf++;
946                            in_bytes--;
947                            out_bytes--;
948    
949                            (*p_buf_offset)++;
950                            *p_conv_len = (int)(conv_size - out_bytes);
951    
952                            i++;
953                            if (i >= 2)
954                            {
955                                    in_control = 0;
956                            }
957                            continue;
958                    }
959    
960                  ret = (int)iconv(cd, &in_buf, &in_bytes, &out_buf, &out_bytes);                  ret = (int)iconv(cd, &in_buf, &in_bytes, &out_buf, &out_bytes);
961                  if (ret == -1)                  if (ret == -1)
962                  {                  {
963                          if (errno == EINVAL) // Incomplete                          if (errno == EINVAL) // Incomplete
964                          {                          {
965  #ifdef _DEBUG  #ifdef _DEBUG
966                                  log_error("iconv(inbytes=%d, outbytes=%d) error: EINVAL\n", in_bytes, out_bytes);                                  log_error("iconv(inbytes=%d, outbytes=%d) error: EINVAL, in_buf[0]=%d\n", in_bytes, out_bytes, in_buf[0]);
967  #endif  #endif
968                                  *p_buf_len = (int)(p_buf + *p_buf_len - in_buf);                                  if (p_buf != in_buf)
969                                  *p_buf_offset = 0;                                  {
970                                  *p_conv_len = (int)(conv_size - out_bytes);                                          *p_buf_len = (int)(p_buf + *p_buf_len - in_buf);
971                                  memmove(p_buf, in_buf, (size_t)(*p_buf_len));                                          *p_buf_offset = 0;
972                                            *p_conv_len = (int)(conv_size - out_bytes);
973                                            memmove(p_buf, in_buf, (size_t)(*p_buf_len));
974                                    }
975    
976                                  break;                                  break;
977                          }                          }
# Line 973  int io_conv_init(const char *charset) Line 1020  int io_conv_init(const char *charset)
1020    
1021          io_conv_cleanup();          io_conv_cleanup();
1022    
1023          strncpy(stdio_charset, charset, sizeof(stdio_charset) - 1);          snprintf(stdio_charset, sizeof(stdio_charset), "%s//TRANSLIT", charset);
         stdio_charset[sizeof(stdio_charset) - 1] = '\0';  
1024    
1025          stdin_cd = iconv_open(BBS_DEFAULT_CHARSET, stdio_charset);          stdin_cd = iconv_open(BBS_DEFAULT_CHARSET, stdio_charset);
1026          if (stdin_cd == (iconv_t)(-1))          if (stdin_cd == (iconv_t)(-1))


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1