GCOBOL(3)
GCOBOL(3) πβ¨
okay bestie, sit down, we're doing the GCC COBOL Compiler front-end I/O function API and honestly? it's giving interface design, it's giving plug me in, it's giving "the library isn't implemented yet but the vibes are immaculate". let's go π«Ά
β¨ NAME β¨
gcobol β the GCC COBOL Front-end I/O function API π
π LIBRARY π
libgcobol π
β¨ SYNOPSIS β¨
#include <symbols.h>
#include <io.h>
#include <gcobolio.h>
gcobol_io_t
gcobol_fileops();
class gcobol_io_t {
public:
static const char constexpr marquee[64];
typedef void (open_t)( cblc_file_t *file,
char *filename,
int mode_char,
int is_quoted );
typedef void (close_t)( cblc_file_t *file,
int how );
typedef void (start_t)( cblc_file_t *file,
int relop, // needs enum
int first_last_key,
size_t length );
typedef void (read_t)( cblc_file_t *file,
int where );
typedef void (write_t)( cblc_file_t *file,
unsigned char *data,
size_t length,
int after,
int lines,
int is_random );
typedef void (rewrite_t)( cblc_file_t *file,
size_t length, bool is_random );
typedef void (delete_t)( cblc_file_t *file,
bool is_random );
open_t *Open;
close_t *Close;
start_t *Start;
read_t *Read;
write_t *Write;
rewrite_t *Rewrite;
delete_t *Delete;
...
};
like look at that struct. she's structured. she's typed. she has a marquee. iconic behavior only. π
π DESCRIPTION π
okay so here's the tea, bestie: gcobol supplies replaceable I/O functionality via gcobol_fileops(). that function returns a pointer to a structure of C function pointers, and those pointers implement sequential, relative, and indexed file operations over files whose On Disk Format (ODF) is defined by gcobol. π₯
so like, if you're a user and you want to use another library that does the same stuff over a different ODF? totally valid, go off. you just have to supply a different implementation of gcobol_fileops(), plus 7 functions, as described in this document. that's it, that's the deal, no cap. β¨
the pointers to those user-implemented functions get placed in a C++ object of type gcobol_io_t, and an instantiation of that type is what gcobol_fileops() returns. the compiled program initializes I/O operations by calling that function the first time any file is opened. first-open energy, main character energy, periodt. π
π¦ about cblc_file_t π¦
every single function takes as its first argument a pointer to a cblc_file_t object, which is analogous to a FILE object used in the C stdio functions. yes bestie, it's that kind of relationship. π
the cblc_file_t structure acts as a communication area between the compiled program and the I/O library. any information needed about the file is kept there. and notably: the outcome of any operation is stored in that structure in the file_status member, not as a return code. (not me realizing it's not a return code π). information about the operation (as opposed to the file) appears as parameters to the function.
cblc_file_t has one member, not used by gcobol, that is reserved for the user:
void * implementation.
user-supplied I/O functions may assign and dereference implementation. gcobol will preserve the value, but never references it. so it's yours, bestie. a lil pocket of space. do what you want with it, she won't look. π
π the 7 function pointers in gcobol_io_t π
Open β void open_t(cblc_file_t *file, char *filename, int mode_char, int is_quoted)
parameters:
filenameβ is the filename, as known to the OS πmode_charβ is one of:'r'β OPEN INPUT: read-only mode'w'β OPEN OUTPUT: create a new file or overwrite an existing one'a'β EXTEND: append to sequential file'+'β modify existing file
is_quotedβ If true,filenameis taken literally. If false,filenameis interpreted as the name of an environment variable, the contents of which, if extant, are taken as the name of the file to be opened. If no such variable exists, thenfilenameis used verbatim.
the way is_quoted does double duty as a secret env-var lookup?? she's clever. she's unhinged. she's both. π
Close β void close_t(cblc_file_t *file, int how)
parameters:
howβ A value of0x08closes a βREEL unitβ. Because no such thing is supported, the function sets the file status toβ07β, meaning not a tape.
Start β void start_t(cblc_file_t *file, int relop, int first_last_key, size_t length)
parameters:
relopβ is one of:0β means'<'1β means'<='2β means'='3β means'!='4β means'>='5β means'>'
first_last_keyβ is the key number (starting at 1) of the key within thecblc_file_tstructure.lengthβ is the size of the key (TODO: per the START statement?)
Read β void read_t(cblc_file_t *file, int where)
parameters:
where-2β PREVIOUS-1β NEXTNβ represents a key number, starting with 1, in thecblc_file_tstructure. The value of that key is used to find the record, and read it.
Write β void write_t(cblc_file_t *file, unsigned char *data, size_t length, int after, int lines, int is_random)
parameters:
dataβ address of in-memory buffer to writelengthβ length of in-memory buffer to writeafterβ has the value1if the
AFTER ADVANCING n LINES
phrase was present in the WRITE statement, else 0
linesβ may be one of:-666β ADVANCING PAGE-1β no ADVANCING phrase appeared0β ADVANCING 0 LINES is valid>0β the value of n in ADVANCING n LINES
is_randomβ is true if the access mode is RANDOM
-666 bestie. SIX SIX SIX. that's the page-advancing sentinel and i am screaming. ππ₯ whoever picked that number was in their villain era and honestly? respect.
Rewrite β void rewrite_t(cblc_file_t *file, size_t length, bool is_random)
parameters:
lengthβ number of bytes to writeis_randomβ true if access mode is RANDOM
Delete β void delete_t(cblc_file_t *file, bool is_random)
parameters:
is_randomβ true if access mode is RANDOM
π§ the one function the binary calls directly π§
the library implements one function that the gcobol-produced binary calls directly:
gcobol_io_t * gcobol_fileops()
This function populates a gcobol_io_t object with the above function pointers. The compiled binary begins by calling gcobol_fileops(), and then uses the supplied pointers to effect I/O. β¨
π RETURN VALUES π
I/O functions return void. gcobol_fileops() returns gcobol_io_t*. that's it, that's the whole vibe check, no surprises here bestie π«Ά
πΈ STANDARDS πΈ
The I/O library supplied by gcobol, libgcobolio.so, supports the I/O semantics defined by ISO COBOL. It is not intended to be compatible with any other ODF. That is, libgcobolio.so cannot be used to exchange data with any other COBOL implementation. π (she's exclusive. she doesn't share her ODF. she's a closed circuit. respect.)
The purpose of the gcobol_io_t structure is to allow the use of other I/O implementations with other ODF representations. so like, she won't play nice with others, but she built you a door so you can. that's growth. π
β οΈ CAVEATS β οΈ
The library is not well tested, not least because it is not implemented.
okay so. bestie. hear me. the library is not well tested AND the reason it's not well tested is that it doesn't exist yet. that's not a red flag that's a red banner. that's a whole red parade. π but we're here for the spec, and the spec ate. π
π BUGS π
The future is yet to come.
and that's not even a bug, that's just poetry. periodt. β¨
this has been gcobol (3) from the GCC COBOL Compiler corner of the universe β landing on Linux, dated March 2024, and yes she is still signing her name GCOBOL(3) at the bottom like the icon she is. mwah. πππ¦β¨
π¦ where this page comes from
- ubuntu resolute: libgcobol-16-dev 16-20260322-1ubuntu1
- ubuntu stonking: libgcobol-16-dev 16.2.0-3ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms