Hello,
I was unable to locate change files for Knuth's original TANGLE and CWEAVE programs on CTAN, so I've written a port of the system for the gpc version 20060325.
I reverted the file I/O in Knuth's code that he ported to C back to GNU Pascal. I might have preserved Knuth's I/O routines in C, except that GNU Pascal changed the way it makes file structures available to the programmer since Knuth wrote his port (around 2000). The GNU PASCAL function GetFile() might have been used to pass a C-style FILE pointer to this code, but GetFile() is no longer availble. In its place, GNU PASCAL provides a BindingType data structure and related functions; these might have been usable if they had provided a valid file descriptor, but on my Debian Linux system, the value of BindingType.Handle is always -1 (if I may abuse the PASCAL language by referring to a variable of BindingType by its type).
Am I mistaken about this?
Florian
P.S. I've made the change files, the mysterious GPCtypes.h file and a modified tangext.c file available at
http://research.gc.cuny.edu/wiki/index.php/Port_of_Knuth%27s_TANGLE_and_WEAV...
FL wrote:
I reverted the file I/O in Knuth's code that he ported to C back to GNU Pascal. I might have preserved Knuth's I/O routines in C, except that GNU Pascal changed the way it makes file structures available to the programmer since Knuth wrote his port (around 2000). The GNU PASCAL function GetFile() might have been used to pass a C-style FILE pointer to this code, but GetFile() is no longer availble.
Indeed. GPC used to use C FILE pointers internally back then, but later switched to using file handles (file descriptors). This change was necessary due to some subtle semantic differences between C and Pascal files (yes, I really mean subtle -- the obvious big differences could be overcome by a library layer, but some smaller problems were hard or impossible to solve).
If you need both Pascal and C files simultaneously, you can only open them separately (and be carefuly about synchronisation unless read-only). So if you can work with a fd, as it seems you plan to, this is preferable.
In its place, GNU PASCAL provides a BindingType data structure and related functions; these might have been usable if they had provided a valid file descriptor, but on my Debian Linux system, the value of BindingType.Handle is always -1 (if I may abuse the PASCAL language by referring to a variable of BindingType by its type).
Am I mistaken about this?
BindingType.Handle can be used to assign (bind) a Pascal file to a given file handle.
For the opposite way (which you're interested in), there's the FileHandle function (declared in gpc.pas). This works:
program Foo;
uses GPC;
var f: Text;
begin Reset (f, '/dev/null'); WriteLn (FileHandle (f)) end.
I should check whether we could use BindingType.Handle also for this purpose. (I suppose we can, but I'd have to check if there are any implications.) I agree that it's not very obvious now ...
Frank