Frank Heckenbach wrote (quoted message below).
Frank, thanks very much for all your advice. I'm trying to get up to speed here.
Ok, I'm now using MedCard for chtype in ncurses.h (assuming typedef unsigned long chtype) CBoolean for "bool" in ncurses.h (assuming typedef unsigned int bool) CBoolean for an "int" which contains only TRUE or FALSE CInteger for an "int" used as an integer (on older gpc I use "integer") tacs now uses index of char128 = #0 .. #127
The c translation types are very useful! Thanks. Did I understand you to say I should use CBoolean in both the above cases?
To create the ncurses.h file, I have to run ./configure within the ncurses source directory. I could run this several times for different hosts, to find what the range of types are. Right? Could you suggest a couple of different hosts to try out? Say, the most common? or perhaps, the most different? or better, how do I read the configuration file directly? I see that "configure" is a readable text file, but I can't find a list of alternative "bool" (for example) definitions in that configuration file.
In fact, I can't figure out what my own host (Mac OSX) is called, when I try
./configure host=powerpc-apple-darwin
I get an "unknown host" message. Any suggestions?
When you said:
BTW (unrelated), I'd suggest to rename the package to `gpc-ncurses-...' or `ncurses-gpc-...', to avoid confusion with an ncurses library package.
Did you mean to name the interface file, e.g. ncurses.pas -> gpc-ncurses.pas
or the unit, e.g. unit ncurses; -> unit gpc-ncurses;
(If the latter, wouldn't gpc_ncurses be a more standard Pascal name than gpc-ncurses?)
To do more things like reading the ncurses.h headers and then automatically configuring ncurses.pas types to be consistent, that's a bit beyond me. Beyond, both in that I wouldn't know how to and that I don't have time to learn how to and test all these. I wouldn't want to write c wrappers, a lot of work and then we're stuck with double calls. What I'm thinking now is to use all your MedCard, CBoolean, etc types, and put in the documentation warnings about what types of hosts would need edits before use. and/or how to check ncurses.h and hand-modify ncurses.pas.
Does this approach and the above modifications seem reasonable?
Rick Engebretson wrote:
There are many C libraries that use ncurses. Menu, panel, CDK to name a few.
But all the added C constructs can be done better through Pascal. Instead of working to access these ncurses derivatives, perhaps object pascal and ncurses is enough.
Rick, thanks for trying to save me some time. I'm thinking I'd like to use menu, which is already documented and tested, rather than writing my own. So I might do that interface. The others I would definately leave. (Panel is said to be buggy) Or were you volunteering to write a Pascal version of menu?
Willett Kempton
On 25 Apr 2005, at 10:21, Frank Heckenbach wrote:
willett wrote:
GPC Pascal programmers:
I have gotten a complete ncurses interface working for GNU Pascal. I have tested it on MaxOSX (using unix prompt), although more testing is needed. This is the UNIX terminal ncurses, no graphics.
The interface file (ncurses.pas), one-page documentation (ncurses.txt) and a few test files (*.pas) are attached as a gzip tar file (16k). Any testing or suggestions are welcome.
Sorry, but I see a number of type problems here (typical for direct C interfaces):
: - many int32 apparently should be ShortInt (int16), not fully investigated
C interfaces in GPC should always use the types provided for C compatibility. As ncurses doesn't use fixed-size types, int32 is probably not right here.
E.g., ncurses.h on my system contains:
typedef unsigned long chtype;
This would be translated to `MedCard' (see manual). On some systems, this is in fact 32 bits, but on others it's 64 bit, so it would break there.
However, I see that on some targets ncurses uses `unsigned int' for chtype (see its configure script) which would be `CCardinal', which further complicates the issue.
Direct linking to a C interface in a portable way is tricky sometimes. A safe way is writing C wrappers (some more overhead) or a fully automatic header translator (quite hard), otherwise you'll have to figure out a way to deal with it. (For specific cases such as this, you could check the installed ncurses.h and adjust according to it.)
: IntBool = MedBool; { was int in c (signed 32 bit integer), used only as a boolean }
BTW, if it's `int' in C, it should be `CBoolean'. `MedBool' corresponds to `[unsigned] long'.
Such problems are hard to detect tested on just one system as many wrong types happen to match anyway.
: tacs_map = ARRAY [char] OF chtype; { 128-byte, re-settable array, initially char->chtype }
In Pascal, this is no 128 byte array. Char has a range of 256 values (currently), and chtype is at least 32 bits. So the array has 256 elements and at least 1024 bytes.
BTW (unrelated), I'd suggest to rename the package to `gpc-ncurses-...' or `ncurses-gpc-...', to avoid confusion with an ncurses library package.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8