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

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dos
#define NOTIFYSIZE   48 /* sizeof(struct NotifyRequest) */
#define NNOTIFY   64
#define notifys   (notifys_ + 1)
#define filelens   (filelens_ + 1)
#define AT(tab, off)

Functions

void _addnotify (void)
void _remnotify (void)
void _checknotify (void)
void _waitnotify (void)
void _lockdoslist (void)
void ridoslib_nextlistitem (void)
void _unlockdoslist (void)
void _notifyport (void)
void _getfilename (void)
void _getpathname (void)
void _dosentrytype (void)
void ridoslib_libinit (void)
void ridoslib_libfinit (void)
void notifyidchk (void)
static ULONG getfilename_c (const UBYTE *s, const ULONG *lens)
 GetFileName(filepath$): the part behind the last / or :.
static ULONG getpathname_c (const UBYTE *s, const ULONG *lens)
 GetPathName(filepath$): the part up to and including the last / or :.
static ULONG notifyport_c (void)
 NotifyPort: the message port of the notifications.
static ULONG dochecknotify (void)
static ULONG checknotify_c (void)
 CheckNotify: the id of the next notification message.
static ULONG waitnotify_c (void)
 WaitNotify: waits for a notification message and returns its id.
static ULONG remnotify_c (LONG id)
 RemNotify notify#: ends a notification and frees its request and the name copy.
static BB_BOOL addnotify_c (ULONG id, STRPTR file, const ULONG *lens)
 AddNotify(idno,filespec$): starts a notification for a file.
static ULONG libinit_c (void)
 init: opens dos.library V36 (_dosbase) and creates the message port of all notifications.
static void libfinit_c (void)
 finit: ends the notifications still active, closes dos.library and deletes the port.
static BB_BOOL lockdoslist_c (UWORD flags, struct DosLibrary *dos)
 GetDeviceList(flags): locks the DOS device list (LockDosList(flags | LDF_READ)).
static ULONG nextlistitem_c (struct DosLibrary *dos)
 NextDevice: the name of the next entry of the locked list (NextDosEntry), "" at the end.
static ULONG dosentrytype_c (void)
 DeviceEntryType: dol_Type of the current entry (dev 0, dir 1, vol 2, late 3, nonbind 4).
static ULONG unlockdoslist_c (ULONG incoming, struct DosLibrary *dos)
 FreeDeviceList: unlocks the DOS device list (UnLockDosList).
static void notifyidchk_c (ULONG id)
 The error check of AddNotify and RemNotify (debugger only).

Variables

static UWORD notifycnt
static struct DosList * mydosentry
static struct DosList * mydoslist
static UWORD doslistflags
static ULONG entrytype = (ULONG)-1
static struct DosLibrary * dosbase_
static const char dosname [] = "dos.library"
static STRPTR fileptr
static ULONG filelen
static UBYTE * filecop
static ULONG notifys_ [1+NNOTIFY]
static ULONG filelens_ [1+NNOTIFY]
static struct NotifyRequest * notify
static ULONG notifynum
static struct MsgPort * msgport

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ AT

#define AT ( tab,
off )
Value:
(*(ULONG *)((UBYTE *)(tab) + (off)))
static void tab(struct out *o)
Definition basictest_write.c:87

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dos

◆ filelens

#define filelens   (filelens_ + 1)

◆ NNOTIFY

#define NNOTIFY   64

◆ notifys

#define notifys   (notifys_ + 1)

◆ NOTIFYSIZE

#define NOTIFYSIZE   48 /* sizeof(struct NotifyRequest) */

Function Documentation

◆ _addnotify()

void _addnotify ( void )

◆ _checknotify()

void _checknotify ( void )

◆ _dosentrytype()

void _dosentrytype ( void )

◆ _getfilename()

void _getfilename ( void )

◆ _getpathname()

void _getpathname ( void )

◆ _lockdoslist()

void _lockdoslist ( void )

◆ _notifyport()

void _notifyport ( void )

◆ _remnotify()

void _remnotify ( void )

◆ _unlockdoslist()

void _unlockdoslist ( void )

◆ _waitnotify()

void _waitnotify ( void )

◆ addnotify_c()

BB_BOOL addnotify_c ( ULONG id,
STRPTR file,
const ULONG * lens )
static

AddNotify(idno,filespec$): starts a notification for a file.

A NotifyRequest (48 bytes, MEMF_CLEAR) with a copy of the name, UserData = id, NRF_SEND_MESSAGE to the port; kept in notifys[id]. Without memory for the name copy or the request it returns 0 and leaves the table alone (fixed, #619: the original used AllocMem's results unchecked). An id outside 0..63 writes outside the tables (64 entries, the offset id*4 as a word): an invalid argument, refused by notifyidchk with runtime error checking (#626). A request already in the entry of the id is ended and freed first, as RemNotify does (fixed, #620: the original overwrote the entry, the old request stayed active and could no longer be ended). A request whose StartNotify fails is taken out of the table and freed with its name copy (fixed, #621: the original left it there, uncounted).

Parameters
idd0: the id
filed1: the file name
lensa2: the argument stack, the name's length at -4(a2)
Returns
d0: BB_TRUE if StartNotify worked, BB_FALSE otherwise, without memory or without dos.library or port

◆ checknotify_c()

ULONG checknotify_c ( void )
static

CheckNotify: the id of the next notification message.

The message is replied.

Returns
d0: the id (the request's UserData), 0 if there is none or no port

◆ dochecknotify()

ULONG dochecknotify ( void )
static

◆ dosentrytype_c()

ULONG dosentrytype_c ( void )
static

DeviceEntryType: dol_Type of the current entry (dev 0, dir 1, vol 2, late 3, nonbind 4).

The type noted by GetDeviceList and NextDevice while the list was locked; no entry is read, so the result stays the same after FreeDeviceList (fixed, #622: the original read dol_Type of the current entry also after the unlock, when it may have been freed).

Returns
d0: the type, -1 if there is no entry

◆ getfilename_c()

ULONG getfilename_c ( const UBYTE * s,
const ULONG * lens )
static

GetFileName(filepath$): the part behind the last / or :.

The argument's string space is given back (a3 - length - 1) and the result copied to its start, from the character behind the last separator on (the result is never longer than the argument and lies behind its start: a forward copy); no 0 written, a3 on the end of the characters (the compiler adds it). Fixed (#627): the original built the result in a 256 byte buffer first, without a limit. Fixed (#628): the original took the length as a word.

Parameters
sd0: the path
lensa2: the argument stack, the length (a long) at -4(a2)
Returns
d0: the length of the result

◆ getpathname_c()

ULONG getpathname_c ( const UBYTE * s,
const ULONG * lens )
static

GetPathName(filepath$): the part up to and including the last / or :.

Searched from the end; the argument's string space is given back and the result copied to its start with its 0 (a forward copy: the result is the argument's beginning); a3 ends on the 0 (fixed, #618: the original left it behind the 0). Fixed (#627): the original built the result in a 256 byte buffer first, without a limit. Fixed (#624): the original never looked at the first character ("/abc" and ":x" gave "", like a name without separator). Fixed (#628): the original took the length as a word.

Parameters
sd0: the path
lensa2: the argument stack, the length (a long) at -4(a2)
Returns
d0: the length of the result, 0 without separator

◆ libfinit_c()

void libfinit_c ( void )
static

finit: ends the notifications still active, closes dos.library and deletes the port.

All 64 entries are looked at, from id 63 down (fixed, #621: the original stopped when the counter was 0). The port is deleted only if dos.library was open (always, where CreateMsgPort exists: no defect). A DOS list GetDeviceList still holds is unlocked before dos.library is closed (fixed, #1081: the original had the call commented out, the list stayed locked after the program).

◆ libinit_c()

ULONG libinit_c ( void )
static

init: opens dos.library V36 (_dosbase) and creates the message port of all notifications.

Fixed (#1142): the port only when dos.library V36 opened (exec V36, CreateMsgPort, is there with it); the original called CreateMsgPort anyway, a crash on Kickstart 1.x.

Returns
d0: the port, 0 below Kickstart 2.0 (init's result is not used: BL_NORET)

◆ lockdoslist_c()

BB_BOOL lockdoslist_c ( UWORD flags,
struct DosLibrary * dos )
static

GetDeviceList(flags): locks the DOS device list (LockDosList(flags | LDF_READ)).

The current entry is the list itself until NextDevice; its dol_Type is noted for DeviceEntryType (#622). A list still locked by an earlier GetDeviceList is unlocked first (fixed, #1081: the original locked it a second time, and one FreeDeviceList released only one of the locks). Without _dosbase (below Kickstart 2.0) 0, no list (fixed, #1142: the original called LockDosList, dos V36, a crash on Kickstart 1.x).

Parameters
flagsd0.w: the LDF_ flags
dosa6: the program's dos base (!libs doslib,la6)
Returns
d0: BB_TRUE, BB_FALSE if LockDosList fails or there is no _dosbase

◆ nextlistitem_c()

ULONG nextlistitem_c ( struct DosLibrary * dos)
static

NextDevice: the name of the next entry of the locked list (NextDosEntry), "" at the end.

The name is copied to a3 up to its 0 (DOS BSTRs have one); a3 ends on the 0 (fixed, #618: the original left it behind the 0). Without a locked list the result is "" (fixed, #625: the original returned with d0 unchanged, the string's length whatever d0 was).

Parameters
dosa6: the program's dos base
Returns
d0: the length byte of the name, 0 at the end or without a list

◆ notifyidchk()

void notifyidchk ( void )

◆ notifyidchk_c()

void notifyidchk_c ( ULONG id)
static

The error check of AddNotify and RemNotify (debugger only).

Fixed (#626), not in the original (ridoslib had no error check area): the id indexes the two tables of 64 entries without a check, so an id outside 0..63 made AddNotify write and RemNotify read, EndNotify and free the library's data around the tables. The release code is unchanged (an invalid argument).

Errors: "Notify number must be 0 to 63".

Parameters
idd0: the id

◆ notifyport_c()

ULONG notifyport_c ( void )
static

NotifyPort: the message port of the notifications.

Returns
d0: the port (init's CreateMsgPort), 0 if there is none

◆ remnotify_c()

ULONG remnotify_c ( LONG id)
static

RemNotify notify#: ends a notification and frees its request and the name copy.

filelens[id] stays set and the original sets d4 to $12345678 (a debugging leftover, no result): no defects. An id outside 0..63 reads outside the table (offset id*4): an invalid argument, refused by notifyidchk with runtime error checking (#626).

Parameters
idd0: the id
Returns
d0: unchanged (id) without dos.library or port, id*4 if the entry is empty, else the address of the freed name (a statement: the value is not used)

◆ ridoslib_libfinit()

void ridoslib_libfinit ( void )

◆ ridoslib_libinit()

void ridoslib_libinit ( void )

◆ ridoslib_nextlistitem()

void ridoslib_nextlistitem ( void )

◆ unlockdoslist_c()

ULONG unlockdoslist_c ( ULONG incoming,
struct DosLibrary * dos )
static

FreeDeviceList: unlocks the DOS device list (UnLockDosList).

Only a list that GetDeviceList locked is unlocked (fixed, #623: the original did not check it, and UnLockDosList released the semaphore once too often and called Permit once too often). The current entry stays; DeviceEntryType does not read it (#622).

Parameters
incomingd0: the caller's d0
dosa6: the program's dos base (the original goes through init's _dosbase: the same pointer)
Returns
d0: -1, 0 without a locked list, the caller's d0 without _dosbase

◆ waitnotify_c()

ULONG waitnotify_c ( void )
static

WaitNotify: waits for a notification message and returns its id.

WaitPort, then as CheckNotify.

Returns
d0: the id, 0 without a port

Variable Documentation

◆ dosbase_

struct DosLibrary* dosbase_
static

◆ doslistflags

UWORD doslistflags
static

◆ dosname

const char dosname[] = "dos.library"
static

◆ entrytype

ULONG entrytype = (ULONG)-1
static

◆ filecop

UBYTE* filecop
static

◆ filelen

ULONG filelen
static

◆ filelens_

ULONG filelens_[1+NNOTIFY]
static

◆ fileptr

STRPTR fileptr
static

◆ msgport

struct MsgPort* msgport
static

◆ mydosentry

struct DosList* mydosentry
static

◆ mydoslist

struct DosList * mydoslist
static

◆ notify

struct NotifyRequest* notify
static

◆ notifycnt

UWORD notifycnt
static

◆ notifynum

ULONG notifynum
static

◆ notifys_

ULONG notifys_[1+NNOTIFY]
static