home *** CD-ROM | disk | FTP | other *** search
- /*
- * std_lib.h - macros, types, and function declarations
- * for the MOAL C (tm) Standard Library
- *
- * Copyright (c) 1996, MOAL Languages. All rights reserved.
- *
- *
- * this version of std_lib.h should be used when the C code generated by
- * the MOAL C compiler is compiled by the Microsoft Visual C/C++ 32-bit
- * ANSI C compiler.
- *
- * the following macros can have their values changed when porting this
- * include file for use with a different ANSI C compiler (VERY IMPORTANT:
- * do not change the values of any other macros except the ones listed
- * below):
- *
- * CLOCKS_PER_SEC // copy the integer value from time.h
- * FOPEN_MAX // copy the integer value from stdio.h
- * FILENAME_MAX // copy the integer value from stdio.h
- * TMP_MAX // copy the integer value from stdio.h
- * CHAR_MIN // depends on whether the ANSI C compiler
- * CHAR_MAX // treats type char as signed or unsigned
- */
-
- #ifndef _INC_STD_LIB
- #define _INC_STD_LIB
-
-
- /*
- * typedef's
- */
-
- typedef unsigned long time_t;
- typedef unsigned long clock_t;
- typedef unsigned int size_t;
- typedef unsigned int moal_t;
-
-
- /*
- * type, macros, and prototypes for communication with the environment
- */
-
- struct ar {
- char var text[];
- };
-
- #define EXIT_SUCCESS 0
- #define EXIT_FAILURE 1
-
- main(struct ar args[]) int status;
- exit(int status);
- getenv(char name[]) char var value[];
- system(char command[]) int status;
-
-
- /*
- * macros and prototypes for formatting functions
- */
-
- #define APPEND 1
- #define REPLACE 0
-
- printf(char format[], ...) int sent;
- fprintf(int file, char format[], ...) int sent;
- sprintf(char out[], int append, char format[], ...) int added;
-
- scanf(char format[], ...) int assignments;
- fscanf(int file, char format[], ...) int assignments;
- sscanf(char source[], char format[], ...) int assignments;
-
-
- /*
- * external table, macros, and prototypes for character functions
- */
-
- extern signed char var _MC_ctype[];
-
- #define isalpha(c) (_MC_ctype[(unsigned char)(c)] & 6)
- #define islower(c) (_MC_ctype[(unsigned char)(c)] & 2)
- #define isupper(c) (_MC_ctype[(unsigned char)(c)] & 4)
- #define isdigit(c) (_MC_ctype[(unsigned char)(c)] & 8)
- #define isalnum(c) (_MC_ctype[(unsigned char)(c)] & 14)
- #define isspace(c) (_MC_ctype[(unsigned char)(c)] & 1)
-
- // isalpha(char character) int answer;
- // islower(char character) int answer;
- // isupper(char character) int answer;
- // isdigit(char character) int answer;
- // isalnum(char character) int answer;
- // isspace(char character) int answer;
-
- extern unsigned char var _MC_lower[];
- extern unsigned char var _MC_upper[];
-
- #define tolower(c) ((char)_MC_lower[(unsigned char)(c)])
- #define toupper(c) ((char)_MC_upper[(unsigned char)(c)])
-
- // tolower(char character) char lower_case;
- // toupper(char character) char upper_case;
-
-
- /*
- * prototypes for string operations
- */
-
- #define MATCH_CASE 1
- #define IGNORE_CASE 0
-
- strcat(char out[], char source[]);
- strcpy(char out[], char source[]);
- strpart(char source[], size_t from_offset, size_t to_offset) char var part[];
- strrpl(char out[], size_t out_offset,
- size_t cut_length, char insert[]) int error, long net_change;
- strcmp(char s1[], char s2[]) int result;
- strncmp(char s1[], char s2[], size_t n) int result;
- strfnd(char search[], size_t from_offset, size_t to_offset,
- int match_case, char find[]) int error, size_t subscript;
- strtod(char source[], size_t source_offset)
- int error, double number, size_t next_offset;
- strtol(char source[], size_t source_offset)
- int error, long number, size_t next_offset;
- strtoul(char source[], size_t source_offset)
- int error, unsigned long number, size_t next_offset;
- strerror(int error) char var description[];
- stresc(char source[]) char var translation[];
-
-
- /*
- * prototypes for pattern searching (regular expressions)
- *
- * the components of structure type rg are for internal use only --
- * do not reference or assign values to any of these components
- */
-
- struct _fsm {
- int next1, // next state 1
- next2; // next state 2
- char var cset[]; // each element: 0 if character not allowed
- char type; // r - or node, c - closure node,
- // s - single character, t - character set
- unsigned char single; // single character to match
- };
-
- struct rg {
- struct _fsm var st[]; // finite-state machine
- int match_longest, // zero (false) or nonzero (true)
- match_case, // zero (false) or nonzero (true)
- align_left, // 0 - none, 1 - boundary, 2 - boundary or \n
- align_right; // 0 - none, 1 - boundary, 2 - boundary or \n
-
- // work areas used by strfndr()
- int var m[].resize[0], var start[].resize[0];
- };
-
- #define LONGEST 1
- #define SHORTEST 0
-
- strreg(char expression[], int match_longest, int match_case)
- int error, struct rg machine;
- strfndr(char search[], size_t from_offset, size_t to_offset,
- struct rg machine) int error, size_t subscript, size_t length;
-
-
- /*
- * prototypes for associative arrays
- *
- * the components of structure type ky are for internal use only --
- * do not reference or assign values to any of these components
- */
-
- struct ky {
- int initialized[1]; // true if occurs is nonzero
- int match_case; // zero (false) or nonzero (true)
- struct _tx {
- char var text[].resize[0]; // text of key
- } var key[]; // the keys in added order
- struct _bn {
- int key, red, l, r; // node of red-black tree
- } var bin[]; // red-black tree
- int var map[]; // map to keys in sorted order
- };
-
- strknew(int match_case) struct ky keys;
- strkey(char key[], struct ky keys) size_t subscript;
-
- #define MAP_TO_SORTED 1
- #define MAP_TO_ADDED 0
-
- strkmap(size_t sub, int map_to_sorted, struct ky keys)
- int error, char var key[], size_t subscript;
- strkfnd(char key[], struct ky keys) int error, size_t subscript;
-
-
- /*
- * macros and prototypes for file I/O
- */
-
- #define FOPEN_MAX 20
- #define FILENAME_MAX 260
- #define TMP_MAX 32767
-
- #define stdin 1
- #define stdout 2
- #define stderr 3
-
- #define SEEK_CUR 1
- #define SEEK_END 2
- #define SEEK_BGN 3
-
- fopen(char filename[], char mode[]) int error, int file;
- fclose(int file) int error;
- fseek(int file, long offset, int from_where) int error;
- ftell(int file) int error, long current_position;
- fgetc(int file) int error, char character;
- fgets(char out[], size_t count, int file) int error;
- fread(char out[], size_t out_offset,
- size_t read_count, int file) int error, size_t read;
- fputc(char character, int file) int error;
- fputs(char source[], int file) int error;
- fwrite(char source[], size_t source_offset,
- size_t write_count, int file) int error;
- tmpfile() int error, int file;
- tmpnam() char var filename[];
- remove(char filename[]) int error;
- rename(char current_filename[], char new_filename[]) int error;
-
- #define TEXT 1
- #define BINARY 0
-
- fgetall(char filename[], int convert_text) int error, char var data[];
- fputall(char filename[], int convert_text, char data[]) int error;
-
-
- /*
- * macro, structure type, and prototypes for time
- */
-
- #define CLOCKS_PER_SEC 1000
-
- struct tm {
- int tm_sec; // seconds after the minute (0 - 61)
- int tm_min; // minutes after the hour (0 - 59)
- int tm_hour; // hours since midnight (0 - 23)
- int tm_mday; // day of the month (1 - 31)
- int tm_mon; // months since January (0 - 11)
- int tm_year; // years since 1900
- int tm_wday; // days since Sunday (0 - 6)
- int tm_yday; // days since January 1st (0 - 365)
- int tm_isdst; // Daylight Saving Time flag
- };
-
- time() time_t current_time;
- difftime(time_t any_time, time_t subtract_time) double seconds;
- localtime(time_t any_time) struct tm time_info;
- gmtime(time_t any_time) struct tm time_info;
- mktime(struct tm time_info) time_t the_time;
- ctime(time_t any_time) char var text[];
- strftime(char format[], struct tm time_info) char var text[];
- clock() clock_t clocks;
-
-
- /*
- * prototypes for sort and search
- */
-
- qsort(any [], fun (any struct, any struct)(int) compare);
- bsearch(any struct, any [],
- fun (any struct, any struct)(int) compare)
- int error, size_t subscript;
-
-
- /*
- * prototypes for math
- */
-
- merr(double x) int error;
- abs(int x) int answer;
- labs(long x) long answer;
- fabs(double x) double answer;
- div(int x, int divide_by) int quotient, int remainder;
- ldiv(long x, long divide_by) long quotient, long remainder;
- rand(int prev) int next;
- fmod(double x, double divide_by) double answer;
- ceil(double x) double answer;
- floor(double x) double answer;
- log(double x) double answer;
- log10(double x) double answer;
- pow(double x, double power) double answer;
- sqrt(double x) double answer;
- exp(double x) double answer;
- sin(double x) double answer;
- cos(double x) double answer;
- tan(double x) double answer;
- asin(double x) double answer;
- acos(double x) double answer;
- atan(double x) double answer;
- atan2(double y, double x) double answer;
-
-
- /*
- * max and min macros
- */
-
- #define max(a, b) (((a) > (b)) ? (a) : (b))
- #define min(a, b) (((a) < (b)) ? (a) : (b))
-
-
- /*
- * assert macro
- */
-
- #undef assert
- #ifdef NDEBUG
- #define assert(test) (1)
- #else
- #define _STR(x) #x
- #define assert(test) ((test) ? 1 : (fprintf(stderr, "Assertion \
- failed: " #test ", file " __FILE__ ", line " _STR(__LINE__) "\n"), \
- exit(EXIT_FAILURE), 0))
- #endif
-
-
- /*
- * limits for integral types
- */
-
- // number of bits in a char
- #define CHAR_BIT 8
-
- // signed char
- #define SCHAR_MIN (-128)
- #define SCHAR_MAX 127
- #define UCHAR_MAX 255
-
- // char (assuming type char is signed)
- #define CHAR_MIN SCHAR_MIN
- #define CHAR_MAX SCHAR_MAX
-
- // short
- #define SHRT_MIN (-32768)
- #define SHRT_MAX 32767
- #define USHRT_MAX 65535
-
- // int
- #define INT_MIN (-2147483647 - 1)
- #define INT_MAX 2147483647
- #define UINT_MAX 4294967295U
-
- // long
- #define LONG_MIN (-2147483647L - 1)
- #define LONG_MAX 2147483647L
- #define ULONG_MAX 4294967295LU
-
-
- /*
- * limits for floating-point types
- */
-
- // rounding mode for addition: 1 means rounding is to the nearest value
- #define FLT_ROUNDS 1
-
- // the base of the exponent
- #define FLT_RADIX 2
-
- // base-radix digits in mantissa (same as number of bits, since radix is 2)
- #define FLT_MANT_DIG 24
- #define DBL_MANT_DIG 53
-
- // decimal digits of precision
- #define FLT_DIG 6
- #define DBL_DIG 15
-
- // smallest valid base-radix exponent
- #define FLT_MIN_EXP (-125)
- #define DBL_MIN_EXP (-1021)
-
- // smallest valid decimal exponent
- #define FLT_MIN_10_EXP (-37)
- #define DBL_MIN_10_EXP (-307)
-
- // largest valid base-radix exponent
- #define FLT_MAX_EXP 128
- #define DBL_MAX_EXP 1024
-
- // largest valid decimal exponent
- #define FLT_MAX_10_EXP 38
- #define DBL_MAX_10_EXP 308
-
- // largest valid positive number
- #define FLT_MAX 3.402823466e+38
- #define DBL_MAX 1.7976931348623158e+308
-
- // smallest positive number such that 1.0 + EPSILON != 1.0
- #define FLT_EPSILON 1.192092896e-7
- #define DBL_EPSILON 2.2204460492503131e-16
-
- // smallest valid positive number
- #define FLT_MIN 1.175494351e-38
- #define DBL_MIN 2.2250738585072014e-308
-
- // type long double
- #define LDBL_MANT_DIG DBL_MANT_DIG
- #define LDBL_DIG DBL_DIG
- #define LDBL_MIN_EXP DBL_MIN_EXP
- #define LDBL_MIN_10_EXP DBL_MIN_10_EXP
- #define LDBL_MAX_EXP DBL_MAX_EXP
- #define LDBL_MAX_10_EXP DBL_MAX_10_EXP
- #define LDBL_MAX DBL_MAX
- #define LDBL_EPSILON DBL_EPSILON
- #define LDBL_MIN DBL_MIN
-
-
- /*
- * common macros
- */
-
- #define MEMORY_FAILURE 32000 /* MOAL C's one predefined exception */
-
- #define TRUE 1
- #define FALSE 0
-
- #define EOF (-1)
- #define NOT_FOUND (-2)
- #define NaN (-3)
- #define pINF (-4)
- #define nINF (-5)
-
-
- #endif /* _INC_STD_LIB */
-