LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-28-2018, 04:44 PM   #1
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
Question Using libmenu and ncurses, listing stops if char ’ is encountered


The problem is that I'm populating a menu array with file names. If any of the filenames contains a " ’ ", the menu list selection will only show up to (but not including) the file that has the " ’ " in the filename.

The menu gets populated by items that were sorted and put into a binary search tree.

My program is working as intended when there are no filenames that contain the " ’ ". Using gdb, When I look at the function at the time when items are being copied to the menu array that post_menu() uses, everything looks fine. But when post_menu() and refresh() are executed, the menu doesn't show the full list.

For example, if there is a file called custer’s last stand, at the menu selection window, I would see

Quote:
...
carp
copying
culvert
and the listing would be ended. I can still scroll up and back down, and do everything as normal. I can quit the program and get a "0" for a return code.

The ’ character appears to be 146 on the extended ASCII chart. I can reproduce the problem every time.

I normally build the program with ncurses 5.9, but I tried with the latest, 6.1, and the result was the same.

When it's not using ncurses, my program operates on filenames with the ’ character fine, as far as I can tell.

lines 350-376 of restore_rmw.c
Code:
    ITEM **my_items;
    MENU *my_menu;
    /* Initialize items */
    my_items = (ITEM **) calloc (n_choices + 1, sizeof (ITEM *));
    populate_menu (root, my_items, true);

    my_items[n_choices] = (ITEM *)NULL;

    my_menu = new_menu ((ITEM **) my_items);
    menu_opts_off (my_menu, O_ONEVALUE);

    mvprintw (LINES - 7, 0, "== %s ==", waste_curr->files);
    mvprintw (LINES - 6, 0,
          ngettext ("== contains %d file ==", "== contains %d files ==", n_choices), n_choices);

    /* TRANSLATORS: I believe the words between the < and > can be translated
     */
    mvprintw (LINES - 4, 0, _("<CURSOR-RIGHT / CURSOR-LEFT> - switch waste folders"));
    mvprintw (LINES - 3, 0, _("\
<SPACE> - select or unselect an item. / <ENTER> - restore selected items"));

    /* TRANSLATORS: the 'q' can not be translated. rmw can only accept a 'q'
     * for input in this case.
    */
    mvprintw (LINES - 2, 0, _("'q' - quit"));
    post_menu (my_menu);
    refresh ();
Lines 81-98 of bstc.
Code:
void
populate_menu (node * node, ITEM ** my_items, bool level_one)
{
  static int i;
  if (level_one)
    i = 0;

  if (node == NULL)
    return;

  /* first recur on left child */
  populate_menu (node->left, my_items, false);

  my_items[i] = new_item (node->data, node->desc);
  i++;

  /* now recur on right child */
  populate_menu (node->right, my_items, false);
}
If anyone is interested in trying to reproduce this problem, just use the git code from the rmw repo (it only take a few seconds to build).
 
Old 11-28-2018, 09:56 PM   #2
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
I got an email from Norm saying that the fix for this is to link against ncursesw and menuw (to enable "wide-character" support.

Did that, and it works on Debian 9 now, but the OpenBSD and OSX build is now broken. I should be able to fix that tomorrow.
 
Old 11-28-2018, 10:47 PM   #3
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
146=0x92 is a non-printable control-character in ISO-8859-1/Unicode, it's called PU2

On the other hand, in windows-1252 it is indeed a printable character:
Code:
Cp1252. Unicode Description
0x92	0x2019	#RIGHT SINGLE QUOTATION MARK
Iconv might help but I suggest simply deleting every files that have non-ASCII characters in their names.

Last edited by NevemTeve; 11-28-2018 at 10:53 PM.
 
1 members found this post helpful.
Old 11-29-2018, 10:37 AM   #4
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by NevemTeve View Post
Iconv might help but I suggest simply deleting every files that have non-ASCII characters in their names.
That would be impossible in this case. The program is a console "recycle bin". I found the bug completely by chance because I had a single file present in my trashcan that had this silly char.
 
Old 11-30-2018, 05:23 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
Or convert any non 0x21-0x5b,0x5d-0x7e character to \xXX sequence.
 
Old 12-02-2018, 12:25 AM   #6
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
That could get pretty tricky. What's displayed in the list are the names of the files in the "Waste" folder; from there, selecting one or multiple files will restore them. If a filename gets changed, then it can't get restored.

The only way I can think of off the top of my head to do that would be keep track of the file that has it's name changed, the character that it was previously. And if it's selected for restoration, change it back.

I remodelled by autoconf file and the build is working on OpenBSD and Mac OSX again. Though I'm not too sure if wide-char support is available on osx yet. On the Travis code integration logs, it's showing that ncursesw and menuw can't be found; and it's linking against the "non-w" libraries.

As for iconv, I've heard of it course but I'm not at all familiar with it. Are you suggesting that would be a better long-term solution than using ncurses with wide-character support enabled?
 
Old 12-02-2018, 06:47 AM   #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
> If a filename gets changed, then it can't get restored.

Trust me: the change I've suggested _is_ reversible, eg: tűző -> t\xc5\xb1z\xc5\x91 -> tűző

Last edited by NevemTeve; 12-02-2018 at 06:51 AM.
 
  


Reply

Tags
menu, ncurses



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
how to write char by char using write() doughyi8u Programming 7 10-18-2014 11:07 PM
Error encountered for the stage 5.13. Ncurses-5.6 just.srad Linux From Scratch 7 09-18-2008 08:35 AM
how to print text in color by ncurses without opening a ncurses window Greatrebel Programming 0 12-20-2006 09:15 AM
Trailing whitespaces ( space char) and Ncurses terminal refreshes bretzeltux Programming 0 03-02-2004 02:47 PM
ncurses-5.2-28 conflicts with file from package ncurses-5.2-12 tubby Linux - Software 4 06-16-2002 12:00 AM

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

All times are GMT -5. The time now is 06:23 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