BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
fileiolib.c File Reference
#include "blitzlib.h"
#include <dos/dos.h>
#include <proto/dos.h>

Data Structures

struct  rec
struct  bfile

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dosbase
#define FLAGSVALID(f)

Functions

void dofileoutput (void)
void dofileinput (void)
void doloc (void)
void doeof (void)
void dodbufflen (void)
void fileiolib_codeinit (void)
void racchk (void)
void fileiolib_fchk (void)
void dbchk (void)
ULONG doexists (const UBYTE *name, struct Library *dosbase)
 Exists(Filename$): the size of a file.
void dowritemem (ULONG fileno, struct bfile *f, const UBYTE *mem, ULONG len, struct Library *dosbase)
 WriteMem File#,Address,Length: write memory to a file.
void doreadmem (ULONG fileno, struct bfile *f, UBYTE *mem, ULONG len, struct Library *dosbase)
 ReadMem File#,Address,Length: read from a file into memory.
ULONG dolof (struct bfile *f, struct Library *dosbase)
 Lof(File#): the length of the file.
void dofileseek (ULONG fileno, struct bfile *f, ULONG where, struct Library *dosbase)
 FileSeek File#,Position: set the position in the file.
void dofreefile (struct Library *dosbase)
 CloseFile File#, and _free of a File object: close the file.
BB_BOOL doopenfile (struct bfile *f, UBYTE *name, const ULONG *lens, struct Library *dosbase)
 OpenFile(File#,Filename$): open a file for reading and writing.
BB_BOOL doreadfile (struct bfile *f, UBYTE *name, const ULONG *lens, struct Library *dosbase)
 ReadFile(File#,Filename$): open an existing file.
BB_BOOL dowritefile (struct bfile *f, UBYTE *name, const ULONG *lens, struct Library *dosbase)
 WriteFile(File#,Filename$): create a new file.
static void dorecord (UWORD n, const UBYTE *args)
 Fields File#,Var1[,Var2...]: the variables of a record.
void doput (ULONG fileno, UWORD record, struct Library *dosbase)
 Put File#,Record: write the fields of a record.
void doget (ULONG fileno, UWORD record, struct Library *dosbase)
 Get File#,Record: read the fields of a record.
void dokillfile (const UBYTE *name, struct Library *dosbase)
 KillFile Filename$: delete a file.
static void myflush (struct bfile *f, struct Library *dosbase)
static ULONG mywrite (ULONG result, struct bfile *f, const UBYTE *src, ULONG len, struct Library *dosbase)
static ULONG myread (ULONG result, struct bfile *f, UBYTE *dst, ULONG len, struct Library *dosbase)
static ULONG myseek (ULONG result, struct bfile *f, ULONG where, LONG mode, struct Library *dosbase)
static void dodbufflen_c (ULONG n)
 DosBuffLen Bytes: the size of the buffer of files opened later.
 BLITZ_ALIAS (dodbufflen, dodbufflen_c)
static BB_BOOL doeof_c (ULONG fileno, struct bfile *f, struct Library *dosbase)
 Eof(File#): at the end of the file?
 BLITZ_ALIAS (doeof, doeof_c)
static ULONG doloc_c (const struct bfile *f)
 Loc(File#): the position in the file.
 BLITZ_ALIAS (doloc, doloc_c)
static void codeinit_c (struct Library *dos)
static void freefile (struct bfile *f, struct Library *dosbase)
static BB_BOOL realopen (WORD mode, struct bfile *f, UBYTE *name, const ULONG *lens, struct Library *dosbase)
static void transdata (int put, ULONG fileno, UWORD record, struct Library *dosbase)
void inputhandler (void)
void outputhandler (void)
static void dofileinput_c (void)
 FileInput File#: read the input from a file.
 BLITZ_ALIAS (dofileinput, dofileinput_c)
static void dofileoutput_c (void)
 FileOutput File#: send the output to a file.
 BLITZ_ALIAS (dofileoutput, dofileoutput_c)
static ULONG inchar_c (void)
static ULONG instring_c (UBYTE *buf, ULONG max)
static ULONG outchar_c (UBYTE c)
static ULONG outstring_c (const UBYTE *s, ULONG len)
static void outcstring_c (const UBYTE *s)
void inhandle2 (void)
void outhandle2 (void)
void outhandle3 (void)
void handlers (void)
static void racchk_c (void)
static void fchk_c (const struct bfile *f)
static void dbchk_c (ULONG n)

Variables

static struct Library * dosbase_g
static UBYTE iobyte
static struct bfile * infile
static struct bfile * outfile
static ULONG doslen = 2048
static const char mess1 [] = "Invalid Input File"
static const char mess2 [] = "Invalid Output File"
static const char mess3 [] = "Can't Find Record"
static const char mess6 [] = "Can't FileSeek Position"
static const char mess7 [] = "Error Reading/Writing File"

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dosbase

◆ FLAGSVALID

#define FLAGSVALID ( f)
Value:
(*(ULONG *)&(f)->flags)
UBYTE flags[2]
Definition 2dlib.c:297

Function Documentation

◆ BLITZ_ALIAS() [1/5]

BLITZ_ALIAS ( dodbufflen ,
dodbufflen_c  )

◆ BLITZ_ALIAS() [2/5]

BLITZ_ALIAS ( doeof ,
doeof_c  )

◆ BLITZ_ALIAS() [3/5]

BLITZ_ALIAS ( dofileinput ,
dofileinput_c  )

◆ BLITZ_ALIAS() [4/5]

BLITZ_ALIAS ( dofileoutput ,
dofileoutput_c  )

◆ BLITZ_ALIAS() [5/5]

BLITZ_ALIAS ( doloc ,
doloc_c  )

◆ codeinit_c()

void codeinit_c ( struct Library * dos)
static

◆ dbchk()

void dbchk ( void )

◆ dbchk_c()

void dbchk_c ( ULONG n)
static

◆ dodbufflen()

void dodbufflen ( void )

◆ dodbufflen_c()

void dodbufflen_c ( ULONG n)
static

DosBuffLen Bytes: the size of the buffer of files opened later.

MOVE.l d0,doslen (default 2048). Errors (debugger, dbchk): "Illegal Dos Buffer Length" above 32767.

Parameters
nd0: the size in bytes

◆ doeof()

void doeof ( void )

◆ doeof_c()

BB_BOOL doeof_c ( ULONG fileno,
struct bfile * f,
struct Library * dosbase )
static

Eof(File#): at the end of the file?

False while the position is in the buffer's valid bytes; otherwise true if a dos seek one byte further fails (else it seeks back). Fixed (#144): the failed seek leaves the position as it was (the original's Loc and Lof were 1 too high afterwards). The original keeps a0/a1 when the position is in the buffer. Errors (debugger, fchk): "Non-Existant File".

Parameters
filenod0: File#
fa2: the file (!libs fileiolib,$1280)
dosbasea6: dos.library
Returns
d0: BB_TRUE at the end of the file, BB_FALSE before it

◆ doexists()

ULONG doexists ( const UBYTE * name,
struct Library * dosbase )

Exists(Filename$): the size of a file.

Lock, Examine into a FileInfoBlock from memlib globalloc (not checked, #139), UnLock. BUG(orig) (#143), won't fix: an empty file gives 0 like a missing one (Exists returns the length, the manual says so, and programs use it as the length). Fixed (#1026): -1 for every directory type, 0 if Examine fails (the original: -1 only for type 2, and the FileInfoBlock's contents after a failed Examine).

Parameters
named0: the file name
dosbasea6: dos.library
Returns
d0: the size, -1 for a drawer or a volume (fib_DirEntryType > 0), 0 if the file is not there or cannot be examined

◆ dofileinput()

void dofileinput ( void )

◆ dofileinput_c()

void dofileinput_c ( void )
static

FileInput File#: read the input from a file.

a3 = the file; it becomes the input file and inputhandler the input handler of inputoutputlib (setin, keeps d1/a1). The handler reads one character (-1 at the end) or a line up to CR/LF. Errors (handler, in the normal code, DIFF): "Invalid Input File", "Error Reading/Writing File".

◆ dofileoutput()

void dofileoutput ( void )

◆ dofileoutput_c()

void dofileoutput_c ( void )
static

FileOutput File#: send the output to a file.

a3 = the file; it becomes the output file and outputhandler the output handler of inputoutputlib (setout, keeps d1/a1). Errors (handler, in the normal code, DIFF): "Invalid Output File", "Error Reading/Writing File".

◆ dofileseek()

void dofileseek ( ULONG fileno,
struct bfile * f,
ULONG where,
struct Library * dosbase )

FileSeek File#,Position: set the position in the file.

Inside the buffer only the position in it changes, otherwise the buffer is flushed and dos Seek called. Errors: "Can't FileSeek Position" if Seek fails (in the normal code, DIFF: the original jumps into the error check area); debugger (fchk): "Non-Existant File".

Parameters
filenod0: File#
fa2: the file (!libs fileiolib,$1280)
whered1: the position from the beginning
dosbasea6: dos.library

◆ dofreefile()

void dofreefile ( struct Library * dosbase)

CloseFile File#, and _free of a File object: close the file.

a3 = the file. If it is open: flush the buffer, Close, free the buffer and the record fields. Fixed (#140): the pointer to the record fields and the record length are cleared (the original left them).

Parameters
dosbasea6: dos.library

◆ doget()

void doget ( ULONG fileno,
UWORD record,
struct Library * dosbase )

Get File#,Record: read the fields of a record.

As Put, reading every field. Errors as Put.

Parameters
filenod0: File#
recordd1: the record number
dosbasea6: dos.library

◆ dokillfile()

void dokillfile ( const UBYTE * name,
struct Library * dosbase )

KillFile Filename$: delete a file.

JMP _DeleteFile(a6); the result is ignored.

Parameters
named0: the file name
dosbasea6: dos.library

◆ doloc()

void doloc ( void )

◆ doloc_c()

ULONG doloc_c ( const struct bfile * f)
static

Loc(File#): the position in the file.

The file position of the buffer + the position in it. Errors (debugger, fchk): "Non-Existant File".

Parameters
fa2: the file (!libs fileiolib,$1280)
Returns
d0: the position

◆ dolof()

ULONG dolof ( struct bfile * f,
struct Library * dosbase )

Lof(File#): the length of the file.

The dos length (seek to the end and back), at least the end of the buffer: not a bug, it does not flush and counts the buffered data. Errors (debugger, fchk): "Non-Existant File".

Parameters
fa2: the file (!libs fileiolib,$1280)
dosbasea6: dos.library
Returns
d0: the length

◆ doopenfile()

BB_BOOL doopenfile ( struct bfile * f,
UBYTE * name,
const ULONG * lens,
struct Library * dosbase )

OpenFile(File#,Filename$): open a file for reading and writing.

Closes the File# first, then opens an existing file, or a new one if it is not found (realopen, mode 0). The record fields and the buffer (DosBuffLen bytes, memlib globalloc, not checked: #139) are set up. Fixed (#138): the original read the name length from -4(0) if the old file had Fields, and cut the name there.

Parameters
fa1: the file (!libs fileiolib,$1180)
named1: the file name
lensa2: the argument stack, its length at -4
dosbasea6: dos.library
Returns
d0: BB_TRUE if the file was opened, BB_FALSE if not

◆ doput()

void doput ( ULONG fileno,
UWORD record,
struct Library * dosbase )

Put File#,Record: write the fields of a record.

a3 = the file. Seeks to record * record length (word multiply), then writes every field. Errors: "Can't Find Record" if the seek fails, "Error Reading/Writing File" (in the normal code, DIFF); debugger (racchk): "Non-Existant File", "No Record Set".

Parameters
filenod0: File#
recordd1: the record number
dosbasea6: dos.library

◆ doreadfile()

BB_BOOL doreadfile ( struct bfile * f,
UBYTE * name,
const ULONG * lens,
struct Library * dosbase )

ReadFile(File#,Filename$): open an existing file.

As OpenFile, but only an existing file (MODE_OLDFILE). Fixed (#138) as OpenFile.

Parameters
fa1: the file (!libs fileiolib,$1180)
named1: the file name
lensa2: the argument stack, its length at -4
dosbasea6: dos.library
Returns
d0: BB_TRUE if the file was opened, BB_FALSE if not

◆ doreadmem()

void doreadmem ( ULONG fileno,
struct bfile * f,
UBYTE * mem,
ULONG len,
struct Library * dosbase )

ReadMem File#,Address,Length: read from a file into memory.

Through the file's buffer (myread; more than the buffer length is read directly). Errors of Read are ignored. Errors (debugger, fchk): "Non-Existant File".

Parameters
filenod0: File#
fa2: the file (!libs fileiolib,$1280)
memd1: the address
lend2: the length
dosbasea6: dos.library

◆ dorecord()

void dorecord ( UWORD n,
const UBYTE * args )
static

Fields File#,Var1[,Var2...]: the variables of a record.

a3 = the file. Per variable on the argument stack (read downwards from a2): the type (word), then the address (long). Types 1/2/7 have 1/2/(long at address-8)+6 bytes (strings start at address-4), all others 4. The list is built backwards: Put/Get transfer the fields in the reverse order (#142, not a bug). Not a defect (#141): it adds to the fields already set and to the record length ("record len so far"), a further Fields continues the record. The field nodes come from memlib globalloc (not checked).

Parameters
nd7: the number of variables
argsa2: the argument stack

◆ dowritefile()

BB_BOOL dowritefile ( struct bfile * f,
UBYTE * name,
const ULONG * lens,
struct Library * dosbase )

WriteFile(File#,Filename$): create a new file.

As OpenFile, but always a new file (MODE_NEWFILE). Fixed (#138) as OpenFile.

Parameters
fa1: the file (!libs fileiolib,$1180)
named1: the file name
lensa2: the argument stack, its length at -4
dosbasea6: dos.library
Returns
d0: BB_TRUE if the file was opened, BB_FALSE if not

◆ dowritemem()

void dowritemem ( ULONG fileno,
struct bfile * f,
const UBYTE * mem,
ULONG len,
struct Library * dosbase )

WriteMem File#,Address,Length: write memory to a file.

Through the file's buffer (mywrite; more than the buffer length is written directly). Errors of Write are ignored. Errors (debugger, fchk): "Non-Existant File".

Parameters
filenod0: File#
fa2: the file (!libs fileiolib,$1280)
memd1: the address
lend2: the length
dosbasea6: dos.library

◆ fchk_c()

void fchk_c ( const struct bfile * f)
static

◆ fileiolib_codeinit()

void fileiolib_codeinit ( void )

◆ fileiolib_fchk()

void fileiolib_fchk ( void )

◆ freefile()

void freefile ( struct bfile * f,
struct Library * dosbase )
static

◆ handlers()

void handlers ( void )

◆ inchar_c()

ULONG inchar_c ( void )
static

◆ inhandle2()

void inhandle2 ( void )

◆ inputhandler()

void inputhandler ( void )

◆ instring_c()

ULONG instring_c ( UBYTE * buf,
ULONG max )
static

◆ myflush()

void myflush ( struct bfile * f,
struct Library * dosbase )
static

◆ myread()

ULONG myread ( ULONG result,
struct bfile * f,
UBYTE * dst,
ULONG len,
struct Library * dosbase )
static

◆ myseek()

ULONG myseek ( ULONG result,
struct bfile * f,
ULONG where,
LONG mode,
struct Library * dosbase )
static

◆ mywrite()

ULONG mywrite ( ULONG result,
struct bfile * f,
const UBYTE * src,
ULONG len,
struct Library * dosbase )
static

◆ outchar_c()

ULONG outchar_c ( UBYTE c)
static

◆ outcstring_c()

void outcstring_c ( const UBYTE * s)
static

◆ outhandle2()

void outhandle2 ( void )

◆ outhandle3()

void outhandle3 ( void )

◆ outputhandler()

void outputhandler ( void )

◆ outstring_c()

ULONG outstring_c ( const UBYTE * s,
ULONG len )
static

◆ racchk()

void racchk ( void )

◆ racchk_c()

void racchk_c ( void )
static

◆ realopen()

BB_BOOL realopen ( WORD mode,
struct bfile * f,
UBYTE * name,
const ULONG * lens,
struct Library * dosbase )
static

◆ transdata()

void transdata ( int put,
ULONG fileno,
UWORD record,
struct Library * dosbase )
static

Variable Documentation

◆ dosbase_g

struct Library* dosbase_g
static

◆ doslen

ULONG doslen = 2048
static

◆ infile

struct bfile* infile
static

◆ iobyte

UBYTE iobyte
static

◆ mess1

const char mess1[] = "Invalid Input File"
static

◆ mess2

const char mess2[] = "Invalid Output File"
static

◆ mess3

const char mess3[] = "Can't Find Record"
static

◆ mess6

const char mess6[] = "Can't FileSeek Position"
static

◆ mess7

const char mess7[] = "Error Reading/Writing File"
static

◆ outfile

struct bfile * outfile
static