LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2019, 09:42 AM   #1
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Rep: Reputation: 4
multibyte input in terminal


Hello friends

I'm doing c programming in linux and trying to use fgetws with xfce4-terminal. and the problem is after typing multibyte string into terminal using fgetws function, when I delete with backspace, it only deletes half of the character. after pressing enter, fgetws(line,MAXLINES, stdin) != NULL dies off prematurely.

is there alternate to fgetws or terminal library or alternate to stdin with wide stream or other possible solution to this?
 
Old 08-24-2019, 10:08 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
As a start, please quote the output of command `locale`
 
Old 08-24-2019, 10:23 AM   #3
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
Code:
LANG=ko_KR.UTF-8
LC_CTYPE="ko_KR.UTF-8"
LC_NUMERIC="ko_KR.UTF-8"
LC_TIME="ko_KR.UTF-8"
LC_COLLATE=C
LC_MONETARY="ko_KR.UTF-8"
LC_MESSAGES="ko_KR.UTF-8"
LC_PAPER="ko_KR.UTF-8"
LC_NAME="ko_KR.UTF-8"
LC_ADDRESS="ko_KR.UTF-8"
LC_TELEPHONE="ko_KR.UTF-8"
LC_MEASUREMENT="ko_KR.UTF-8"
LC_IDENTIFICATION="ko_KR.UTF-8"
LC_ALL=
 
Old 08-24-2019, 11:35 AM   #4
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
I have a question. what function of library do xfce4-terminal use for command line input? does anyone know?
 
Old 08-24-2019, 11:37 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Did you try other terminal-emulators like xterm, rxvt, konsole, gnome-terminal, eterm, etc?
You might find out that the problem isn't related with this xfce4-terminal.

Edit: Did you call setlocale(LC_ALL,"") in your code?

Last edited by NevemTeve; 08-24-2019 at 11:42 AM.
 
Old 08-24-2019, 11:58 AM   #6
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
I did include setlocale at the beginning of the main() in source code.
when I use xfce4-terminal, it seems to me in the command line that for multibyte letters, it deletes twice for functioning properly.
for ascii, the terminal deletes one character, for multibytes, it deletes two characters for each backspace stroke.

wonder what function from of what library the terminal uses..
 
Old 08-24-2019, 01:03 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Actually it is bash (actually: readline) that does this editing.

Did you try other terminal-emulators like xterm, rxvt, konsole, gnome-terminal, eterm, etc?
You might find out that the problem isn't related with this xfce4-terminal.
 
Old 08-24-2019, 01:03 PM   #8
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
I searched. and the answer was to use readline library
Thank NevemTeve for fast replying

edit: I used xterm with utf8 setting, and fgetws did the same
it deletes only half the character when pressing backspace but internally deletes a wide character

Last edited by babbab; 08-24-2019 at 01:08 PM.
 
Old 08-26-2019, 01:40 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I've just started experimenting, first test: read(2):

Code:
terminal LC_CTYPE    stty   test    result
8-bit    .ISO-8859-2 -iutf8 read(2) single-byte, backspace ok
utf8     .UTF-8      iutf8  read(2) utf8-sequences, backspace ok
utf8     .UTF-8      -iutf8 read(2) utf8-sequences, backspace NOT ok
fread(3), fgets(3): same as read(2) -- well, they do call read(2)

Edit: also tried on AIX: very similar, except it doesn't have 'stty iutf8' option, so backscpace (and Ctrl+W) always does the wrong thing.

Edit: Testing fgetws
Code:
terminal LC_CTYPE    stty   test      result
8-bit    .ISO-8859-2 -iutf8 fgetws(3) wide characters, backspace ok
utf8     .UTF8       iutf8  fgetws(3) wide characters, backspace ok
utf8     .UTF8       -iutf8 fgetws(3) errno=84: Invalid or incomplete multibyte or wide character
Note: 'fgetws' doesn't work after 'fgets'; so I created a copy via dup+fdopen
Code:
        int h= dup (0);
        FILE *wstdin= fdopen (h, "r");

Last edited by NevemTeve; 08-26-2019 at 09:15 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
MySQL and PHP: Multibyte Character Support Magsol Programming 4 04-26-2005 10:24 PM
mysql query for multibyte string onnyloh Programming 3 12-03-2004 08:29 PM
C Multibyte character encoding ugenn Programming 0 12-14-2003 07:44 AM
Invalid or incomplete multibyte or wide character chanys Linux - General 1 03-13-2003 10:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration