[sysbase0.h] Standard Definitions ( Part 0 )

contents



#include "styconf0.h"
#include "syscbhdl.h"




Global Types


#ifdef _MSDOS
typedef long     INT;
typedef long     LONG_INT;
#define __FAR    __far
#define __HUGE   __huge
typedef void     __HUGE *HugeCPtr;
#else
typedef int      INT;
typedef long     int LONG_INT;
#define __FAR
#define __HUGE
#define HugeCPtr StdCPtr
#define NewHMem  NewMem
#define FreeHMem FreeMem
#endif


typedef void *StdCPtr;


#if !defined( __GNUC__ )
typedef signed char      c_int8;
typedef signed short     c_int16;
typedef signed long      c_int32;
typedef unsigned char    c_uint8;
typedef unsigned short   c_uint16;
typedef unsigned long    c_uint32;
#if defined(STYX_CONFIG_OSMS) && defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64
#define STYX_CONFIG_TINT64
typedef signed   __int64 c_int64;
typedef unsigned __int64 c_uint64;
#endif
#else /*__GNUC__*/
#define STYX_CONFIG_TINT64
typedef int8_t           c_int8;
typedef int16_t          c_int16;
typedef int32_t          c_int32;
typedef int64_t          c_int64;
typedef u_int8_t         c_uint8;
typedef u_int16_t        c_uint16;
typedef u_int32_t        c_uint32;
typedef u_int64_t        c_uint64;
#endif


#define AbstractType(TYPENAME) typedef StdCPtr TYPENAME


#define AbstractHugeType( TYPENAME ) \
typedef HugeCPtr TYPENAME


Abs_T abstract type
Any_T abstract type

#define c_bool  int
#define C_False 0
#define C_True  1
#ifndef __cplusplus
#define bool  c_bool
#define False C_False
#define True  C_True
#endif


typedef c_byte           *c_bstring; /* sizeof(long) Bytes Len, Len Bytes */
typedef char             *c_string;
#ifndef __cplusplus
typedef c_string          string;
#endif
#if defined(WEOF)
typedef wint_t            wc_int;
typedef wchar_t           wc_char;
typedef wchar_t          *wc_string;
#define WCHAR_LITERAL(c) L##c
#else
typedef unsigned long     wc_int;
typedef unsigned long     wc_char;
typedef unsigned long    *wc_string;
#define WCHAR_LITERAL(c) ((unsigned long)c)
#endif



CommandLine I/O & Exception

FILE* StdOutFile(void)
#define STDOUT StdOutFile()
stdout
FILE* StdErrFile(void)
#define STDERR StdErrFile()
stderr
void fprint_raw(FILE* fp, c_string s, size_t size)
prints string 's' in a printable form to file 'fp'
'size' >= 0: number of characters to print

void prMsg_stdout(c_string s)
prints string 's' in a printable form to stdout
void prMsg_stderr(c_string s)
prints string 's' in a printable form to stderr
void AbortApp(c_string errmsg)
#define STD_ERREXIT AbortApp("")
aborts application with error message 'errmsg'
PHDL_TRAP getTrapHdl(void)
gets the trap handler
void setTrapHdl(PHDL_TRAP h_trap)
sets a trap handler
( xaron error callback )

PHDL_ABORT getErrExitHdl(void)
gets the abort handler
void setErrExitHdl(PHDL_ABORT h_abort)
sets an abort handler
PHDL_FREEMEM getFreeMemHdl(void)
gets the handler to organize free memory from heap
void setFreeMemHdl(PHDL_FREEMEM h_freemem)
sets a handler to organize free memory from heap
void initStdFiles(FILE* out, FILE* err)
overwrites stdout, stderr
void quitStdFiles(void)
resets stdout, stderr


Thread/Process Synchronisation

StdCPtr initSem(c_string id, int maxcnt, int initcnt)
creates or opens semaphore 'id [NULL]' to synchronize
a maximum of 'maxcnt' concurrent threads
with an initial value of 'initcnt'
RC: semaphore or NULL
non-MS: 'id', 'maxcnt' not used

c_bool quitSem(StdCPtr sem)
closes and - on OK - destroys semaphore 'sem'
RC: True=OK

int waitSem(StdCPtr sem)

waits and enters critical section 'sem' ( blocking )
RC: 1=OK, 0=occupied, -1=error

int trySem(StdCPtr sem)

tries to enter critical section 'sem' ( non-blocking )
RC: 1=OK, 0=occupied, -1=error

c_bool postSem(StdCPtr sem, int cnt)

leaves critical section 'sem' and releases 'cnt' resources
RC: True=OK
non-MS: 'cnt' not used (=1)



Error Handling


typedef void (*PF_ERROR)(c_bool cond, c_string format, ...);

void ForceCore(void)
since we didn't find an appropriate function in the c-lib
PF_ERROR _AssCheck(c_string kind, c_string file, int line)
saves assertion type, source position and
returns assert function


#define c_assert (*(_AssCheck("Restriction error",__FILE__,__LINE__)))
#define c_bug    (*(_AssCheck("Internal error",   __FILE__,__LINE__)))
#define C_BUG    c_bug(C_False,"")
#ifndef __cplusplus
#define assert   c_assert
#define bug      c_bug
#define BUG      C_BUG
#endif


   Usage of the macros 'assert', 'bug':
   assert | bug ( condition, which has to be true,
                  message format string ( see printf ),
                  any further parameter, according to the above format string );



System-Init & Quit

void sysbase_init(void)
initializes module ( for thread-savety )
void sysbase_quit(void)
terminates module ( for thread-savety )
StdCPtr sysbase_sem(void)
system semaphore ( for thread-savety )


Global Macros


#define STR_EMPTY(s)      ( (s) == (c_string)NULL || *(s) == '\0' )
#define INRANGE(a,x,b)    ( ( (a) <= (x) ) && ( (x) <= (b) ) )
#define ABS(x)            ( (x) < 0 ? - (x) : (x) )
#define MAX(a,b)          ( (a) < (b) ? (b) : (a) )
#define MIN(a,b)          ( (a) < (b) ? ( a ) : (b) )
#define EQSIGN(a,b)       ( ( ( (a) <= 0 ) && ( (b) <= 0 ) ) || \
                            ( ( (a) >= 0 ) && ( (b) >= 0 ) ) )