GCC Issue
David Gee (1833) 268 posts |
I’ve been attempting to compile the open-source database sqlite3 with GCC (4.1.2) on RISC OS (Raspberry Pi, to be precise). I can compile it successfully and get the shell program to run—however, the issue is that, if I backspace in the shell, instead of doing what I expect, ^H is generated instead. The sqlite3 shell works correctly on Windows as well as Linux, so it’s unlikely to be something UNIX-specific; the code that reads a line uses fgets (since the shell can be set to accept input from a file), and the function that actually inputs a line is as follows:
Any suggestions? Is there an easy fix or do I need a different way of inputting a string? |
Ronald May (387) 407 posts |
A quick fix for a StrongED taskwindow is to edit the !StrongEd.Defaults.Modes.Taskwindow.Modefile The RISC OS filer for one, does not work well with <127> replacing <8>, so it can’t be done system wide. |
David Gee (1833) 268 posts |
Well, it’s a Unixlib problem—I created a small test program, and exactly the same happened; not with the -mlibscl option however, that was fine, but SQLite3 won’t compile with -mlibscl. I’ve “fixed” the problem for the moment—in the test program at any rate—by replacing fgets with a routine my_fgets which uses fgets only if the source is not stdin, and makes use of OSLib where the source is stdin:
It would be better if UNIXLib were fixed though. Now to see if the fix works correctly in SQLite! |
David Gee (1833) 268 posts |
Well, this fix didn’t work as it stood (even though it appeared to in my test program) because fgets adds a LF character (ASCII 10) before the terminating NUL and the OS routine terminates strings with CR (ASCII 13). However, the final version of the routine shown here does work and SQLite3 is now running under RISC OS.
It just remains to package SQLite up in a RISC OS-friendly way and make it available. |
Ronald May (387) 407 posts |
The only thing I have found that seems to be related to Backspace is in the termios.h. I gathered from other sources that VERASE2 is referring to Backspace and ^H and the value I think should be in |
Chris Gransden (337) 1207 posts |
I’ve been using the version of sqlite3 in the GCCSDK autobuilder for some time now. I’ve not noticed any problems with ^H appearing. I did reproduce the problem with !Edit running the Task window on a Raspberry Pi. Works OK with StrongED. |
David Gee (1833) 268 posts |
I didn’t double-click it, but I did try running it from the window you get by pressing F12 (which I believe is single-tasking) and got the same result. The “fixed” version is fine though. |
Ronald May (387) 407 posts |
I had things back to front, this will assign the Backspace key to what the Delete key was doing, and gives the Delete key the function of kill, which turns out to be delete everything on that line. Please correct or improve my useage if you see what I’m trying to do. |
Ronald May (387) 407 posts |
After finding a book on the subject, I have found examples on termios struct useage and can correct my last effort.
It is obviously the way to do it, no need to worry about the buffer size, STDIN_FILENO is defined in unistd.h. sg_kill is normally ^U but the Delete key was outputting a literal ^? once I took sg_erase from it. A similar technique using tcgetattr and tcsetattr (termios.h) is supposed to allow a full configuration. I think the root of the original problem is not the ^H as such, (it /is/ the <8> key) but the terminal stdin was not set to do anything with it. |
Ronald May (387) 407 posts |
The sgtty.h method has few options, and I got a better result by using termios.h and struct termios like this:
My attempt to get backspace and delete to do the same task by using the VERASE2 constant 7 failed, so the next best thing was to assign the Delete key to word erase. Actually, working in a shell with command arguments, I think it is handy to have anyway. ^X and ^R appear to be of little use and could be left out. Changing the same things in the defaults section of the gccsdk recipe termios.h and rebuilding cross, appears to do the job, so after a bit more testing, I will ask if a change can be permanently done, then the above code would not be needed. |
David Gee (1833) 268 posts |
On non-RISC OS platforms, Delete is forward-delete, not backspace — it only appears to be on RISC OS computers where it’s this way (possibly the original keyboards used didn’t have both keys?); isn’t it possible to make Delete be a forward-delete? |
Steve Pampling (1551) 8173 posts |
You probably want Steve Fryatts PCKeys |
Ronald May (387) 407 posts |
David, the way I see it, this is very basic terminal io that is getting used here, it only recognises characters up to 127 so not only the arrow keys that would be needed for forward delete to be of use aren’t available, but that function isn’t supplied either. I think different platforms have implemented termios.h different ways so it may be possible to change functionality. I think ncurses style libraries are used when a terminal that is more than a command line is needed. |
Bryan Hogan (339) 593 posts |
Would running it in a Nettle ANSI Taskwindow help? |
Ronald May (387) 407 posts |
Running ports that were printing ^H instead of doing a backspace was not being fixed by running it in a !Nettle ANSI Taskwindow. Maybe it is because it is not compiled with like for like unixlib. I’m unsure of how it is actually built though. The sash is done with unixlib and when executing another unixlib port, this port seems to be inheriting the features. (maybe because of fork taking a copy) !Nettle is doing a translation of ansi codes to a RISC OS window, so it probably departs from unixlib in a few areas. A Chox11/Desklib approach might keep things in the unixlib domain, but I doubt if it would work and display as nice. |