| 1 |
.ds lang COBOL |
| 2 |
.ds gcobol GCC\ \*[lang]\ Front-end |
| 3 |
.Dd \& March 2024 |
| 4 |
.Dt GCOBOL 3\& "GCC \*[lang] Compiler" |
| 5 |
.Os Linux |
| 6 |
.Sh NAME |
| 7 |
.Nm gcobol |
| 8 |
.Nd \*[gcobol] I/O function API |
| 9 |
.Sh LIBRARY |
| 10 |
.Pa libgcobol |
| 11 |
. |
| 12 |
.Sh SYNOPSIS |
| 13 |
.In symbols.h |
| 14 |
.In io.h |
| 15 |
.In gcobolio.h |
| 16 |
. |
| 17 |
.Ft gcobol_io_t Fn gcobol_fileops |
| 18 |
.Bd -literal |
| 19 |
class gcobol_io_t { |
| 20 |
public: |
| 21 |
static const char constexpr marquee[64]; |
| 22 |
typedef void (open_t)( cblc_file_t *file, |
| 23 |
char *filename, |
| 24 |
int mode_char, |
| 25 |
int is_quoted ); |
| 26 |
typedef void (close_t)( cblc_file_t *file, |
| 27 |
int how ); |
| 28 |
typedef void (start_t)( cblc_file_t *file, |
| 29 |
int relop, // needs enum |
| 30 |
int first_last_key, |
| 31 |
size_t length ); |
| 32 |
typedef void (read_t)( cblc_file_t *file, |
| 33 |
int where ); |
| 34 |
typedef void (write_t)( cblc_file_t *file, |
| 35 |
unsigned char *data, |
| 36 |
size_t length, |
| 37 |
int after, |
| 38 |
int lines, |
| 39 |
int is_random ); |
| 40 |
typedef void (rewrite_t)( cblc_file_t *file, |
| 41 |
size_t length, bool is_random ); |
| 42 |
typedef void (delete_t)( cblc_file_t *file, |
| 43 |
bool is_random ); |
| 44 |
open_t *Open; |
| 45 |
close_t *Close; |
| 46 |
start_t *Start; |
| 47 |
read_t *Read; |
| 48 |
write_t *Write; |
| 49 |
rewrite_t *Rewrite; |
| 50 |
delete_t *Delete; |
| 51 |
\0\0... |
| 52 |
}; |
| 53 |
.Ed |
| 54 |
. |
| 55 |
.Sh DESCRIPTION |
| 56 |
.Nm |
| 57 |
supplies replaceable I/O functionality via |
| 58 |
.Fn gcobol_fileops . |
| 59 |
It returns a pointer to a structure of C function pointers that |
| 60 |
implement sequential, relative, and indexed file operations over files |
| 61 |
whose On Disk Format (ODF) is defined by |
| 62 |
.Nm . |
| 63 |
A user wishing to use another library that implements the same |
| 64 |
functionality over a different ODF must supply a different implementation of |
| 65 |
.Fn gcobol_fileops , |
| 66 |
plus 7 functions, as described in this document. The pointers to |
| 67 |
those user-implemented functions are placed in a C++ object of type |
| 68 |
.Vt gcobol_io_t |
| 69 |
and an instantiation of that type is returned by |
| 70 |
.Fn gcobol_fileops . |
| 71 |
The compiled program initializes I/O operations by calling that |
| 72 |
function the first time any file is opened. |
| 73 |
.Pp |
| 74 |
Each function takes as its first argument a pointer to a |
| 75 |
.Vt cblc_file_t |
| 76 |
object, which is analogous to a |
| 77 |
.Vt FILE |
| 78 |
object used in the C |
| 79 |
.Sy stdio |
| 80 |
functions. The |
| 81 |
.Vt cblc_file_t |
| 82 |
structure acts as a communication area between the compiled program |
| 83 |
and the I/O library. Any information needed about the file is kept |
| 84 |
there. Notably, the outcome of any operation is stored in that |
| 85 |
structure in the |
| 86 |
.Va file_status |
| 87 |
member, not as a return code. Information about the |
| 88 |
.Em operation |
| 89 |
(as opposed to the |
| 90 |
.Em file ) |
| 91 |
appear as parameters to the function. |
| 92 |
.Pp |
| 93 |
.Vt cblc_file_t |
| 94 |
has one member, not used by |
| 95 |
.Nm , |
| 96 |
that is reserved for the user: |
| 97 |
.Dl Vt "void *" Pa implementation . |
| 98 |
.Pp |
| 99 |
User-supplied I/O functions may assign and dereference |
| 100 |
.Pa implementation . |
| 101 |
.Nm |
| 102 |
will preserve the value, but never references it. |
| 103 |
.Pp |
| 104 |
The 7 function pointers in |
| 105 |
.Vt gcobol_io_t |
| 106 |
are |
| 107 |
.Bl -hang -width Rewrite |
| 108 |
.It Open |
| 109 |
.Ft void |
| 110 |
.Fn open_t "cblc_file_t *file" "char *filename" "int mode_char" "int is_quoted" |
| 111 |
.br |
| 112 |
parameters: |
| 113 |
.Bl -tag -width mode_char -compact |
| 114 |
.It Ar filename |
| 115 |
is the filename, as known to the OS |
| 116 |
.It Ar mode_char |
| 117 |
is one of |
| 118 |
.Bl -hang -width MM -compact |
| 119 |
.It Sq r |
| 120 |
OPEN INPUT: read-only mode |
| 121 |
.It Sq w |
| 122 |
OPEN OUTPUT: create a new file or overwrite an existing one |
| 123 |
.It Sq a |
| 124 |
EXTEND: append to sequential file |
| 125 |
.It Sq + |
| 126 |
modify existing file |
| 127 |
.El |
| 128 |
.It Ar is_quoted |
| 129 |
If |
| 130 |
.Sy true , |
| 131 |
.Ar filename |
| 132 |
is taken literally. If |
| 133 |
.Sy false , |
| 134 |
.Ar filename |
| 135 |
is interpreted as the name of an environment variable, the contents of |
| 136 |
which, if extant, are taken as the name of the file to be opened. If |
| 137 |
no such variable exists, then |
| 138 |
.Ar filename |
| 139 |
is used verbatim. |
| 140 |
.El |
| 141 |
.It Close |
| 142 |
.Ft void |
| 143 |
.Fn close_t "cblc_file_t *file" "int how" |
| 144 |
.br |
| 145 |
parameters: |
| 146 |
.Bl -hang -width how -compact |
| 147 |
.It Ar how |
| 148 |
A value of 0x08 closes a |
| 149 |
.Dq REEL\ unit . |
| 150 |
Because no such thing is supported, the function sets the file status to |
| 151 |
.Dq 07 , |
| 152 |
meaning |
| 153 |
.Em "not a tape" . |
| 154 |
.El |
| 155 |
.It Start |
| 156 |
.Ft void |
| 157 |
.Fn start_t "cblc_file_t *file" "int relop" "int first_last_key" "size_t length" |
| 158 |
.br |
| 159 |
parameters: |
| 160 |
.Bl -tag -width length -compact |
| 161 |
.It Ar relop |
| 162 |
is one of |
| 163 |
.Bl -hang -width LT -compact |
| 164 |
.It Li 0 |
| 165 |
means |
| 166 |
.Sq < |
| 167 |
.It Li 1 |
| 168 |
means |
| 169 |
.Sq <= |
| 170 |
.It Li 2 |
| 171 |
means |
| 172 |
.Sq = |
| 173 |
.It Li 3 |
| 174 |
means |
| 175 |
.Sq != |
| 176 |
.It Li 4 |
| 177 |
means |
| 178 |
.Sq >= |
| 179 |
.It Li 5 |
| 180 |
means |
| 181 |
.Sq > |
| 182 |
.El |
| 183 |
.It Ar first_last_key |
| 184 |
is the key number (starting at 1) of the key within the |
| 185 |
.Vt cblc_file_t |
| 186 |
structure. |
| 187 |
.It Ar length |
| 188 |
is the size of the key (TODO: per the START statement?) |
| 189 |
.El |
| 190 |
.It Read |
| 191 |
.Ft void |
| 192 |
.Fn read_t "cblc_file_t *file" "int where" |
| 193 |
parameters: |
| 194 |
.Bl -tag -width where -compact |
| 195 |
.It Ar where |
| 196 |
.Bl -hang -width 000 -compact |
| 197 |
.It Li -2 |
| 198 |
PREVIOUS |
| 199 |
.It Li -1 |
| 200 |
NEXT |
| 201 |
.It Ar \0N |
| 202 |
represents a key number, starting with 1, in the |
| 203 |
.Vt cblc_file_t |
| 204 |
structure. The value of that key is used to find the record, and read it. |
| 205 |
.El |
| 206 |
.El |
| 207 |
.It Write |
| 208 |
.Ft void |
| 209 |
.Fn write_t "cblc_file_t *file" "unsigned char *data" \ |
| 210 |
"size_t length" "int after" "int lines" "int is_random" |
| 211 |
.br |
| 212 |
parameters: |
| 213 |
.Bl -hang -width is_random -compact |
| 214 |
.It Ar data |
| 215 |
address of in-memory buffer to write |
| 216 |
.It Ar length |
| 217 |
length of in-memory buffer to write |
| 218 |
.It Ar after |
| 219 |
has the value 1 if the |
| 220 |
.D1 "AFTER ADVANCING n LINES" |
| 221 |
phrase was present in the |
| 222 |
.Sy WRITE |
| 223 |
statement, else 0 |
| 224 |
.It Ar lines |
| 225 |
may be one of |
| 226 |
.Bl -hang -width 00000 -compact |
| 227 |
.It Li -666 |
| 228 |
ADVANCING PAGE |
| 229 |
.It Li \0\0-1 |
| 230 |
no |
| 231 |
.Sy ADVANCING |
| 232 |
phrase appeared |
| 233 |
.It \0\0\00 |
| 234 |
ADVANCING 0 LINES |
| 235 |
is valid |
| 236 |
.It \0\0>0 |
| 237 |
the value of |
| 238 |
.Ar n |
| 239 |
in |
| 240 |
ADVANCING |
| 241 |
.Ar n |
| 242 |
LINES |
| 243 |
.El |
| 244 |
.It Ar is_random |
| 245 |
is |
| 246 |
.Sy true |
| 247 |
if the |
| 248 |
.Em "access mode" |
| 249 |
is RANDOM |
| 250 |
.El |
| 251 |
.It Rewrite |
| 252 |
.Ft void |
| 253 |
.Fn rewrite_t "cblc_file_t *file" "size_t length" "bool is_random" |
| 254 |
parameters: |
| 255 |
.Bl -hang -width is_random -compact |
| 256 |
.It Ar length |
| 257 |
number of bytes to write |
| 258 |
.It Ar is_random |
| 259 |
.Sy true |
| 260 |
if |
| 261 |
.Em "access mode" |
| 262 |
is RANDOM |
| 263 |
.El |
| 264 |
.It Delete |
| 265 |
.Ft void |
| 266 |
.Fn delete_t "cblc_file_t *file" "bool is_random" |
| 267 |
parameters: |
| 268 |
.Bl -hang -width is_random -compact |
| 269 |
.It Ar is_random |
| 270 |
.Sy true |
| 271 |
if |
| 272 |
.Em "access mode" |
| 273 |
is RANDOM |
| 274 |
.El |
| 275 |
.El |
| 276 |
. |
| 277 |
.Pp |
| 278 |
The library implements one function that the |
| 279 |
.Nm Ns |
| 280 |
-produced binary calls directly: |
| 281 |
.Bl -item |
| 282 |
.It |
| 283 |
.Ft gcobol_io_t * |
| 284 |
.Fn gcobol_fileops |
| 285 |
.br |
| 286 |
This function populates a |
| 287 |
.Vt gcobol_io_t |
| 288 |
object with the above function pointers. The compiled binary begins |
| 289 |
by calling |
| 290 |
.Fn gcobol_fileops Ns , |
| 291 |
and then uses the supplied pointers to effect I/O. |
| 292 |
.El |
| 293 |
. |
| 294 |
.\" The following commands should be uncommented and |
| 295 |
.\" used where appropriate. |
| 296 |
.\" .Sh IMPLEMENTATION NOTES |
| 297 |
.\" This next command is for sections 2, 3, and 9 only |
| 298 |
.\" (function return values). |
| 299 |
.Sh RETURN VALUES |
| 300 |
I/O functions return |
| 301 |
.Sy void . |
| 302 |
.Fn gcobol_fileops |
| 303 |
returns |
| 304 |
.Vt gcobol_io_t* . |
| 305 |
.\" .Sh FILES |
| 306 |
.\" .Sh COMPATIBILITY |
| 307 |
.\" This next command is for sections 2, 3, 4, and 9 only |
| 308 |
.\" (settings of the errno variable). |
| 309 |
.\" .Sh ERRORS |
| 310 |
.\" .Sh SEE ALSO |
| 311 |
.Sh STANDARDS |
| 312 |
The I/O library supplied by |
| 313 |
.Nm , |
| 314 |
.Sy libgcobolio.so , |
| 315 |
supports the I/O semantics defined by ISO \*[lang]. |
| 316 |
It is not intended to be compatible with any other ODF. That is, |
| 317 |
.Sy libgcobolio.so |
| 318 |
cannot be used to exchange data with any other \*[lang] implementation. |
| 319 |
.Pp |
| 320 |
The purpose of the |
| 321 |
.Vt gcobol_io_t |
| 322 |
structure is to allow the use of other I/O implementations with other ODF representations. |
| 323 |
.\" .Sh HISTORY |
| 324 |
.\" .Sh AUTHORS |
| 325 |
.Sh CAVEATS |
| 326 |
The library is not well tested, not least because it is not implemented. |
| 327 |
.Sh BUGS |
| 328 |
The future is yet to come. |