home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09964.iso / program / mc.exe / STD_LIB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-06  |  12.0 KB  |  430 lines

  1. /*
  2. * std_lib.h - macros, types, and function declarations
  3. *             for the MOAL C (tm) Standard Library
  4. *
  5. *    Copyright (c) 1996, MOAL Languages. All rights reserved.
  6. *
  7. *
  8. * this version of std_lib.h should be used when the C code generated by
  9. * the MOAL C compiler is compiled by the Microsoft Visual C/C++ 32-bit
  10. * ANSI C compiler.
  11. *
  12. * the following macros can have their values changed when porting this
  13. * include file for use with a different ANSI C compiler (VERY IMPORTANT:
  14. * do not change the values of any other macros except the ones listed
  15. * below):
  16. *
  17. *     CLOCKS_PER_SEC  // copy the integer value from time.h
  18. *     FOPEN_MAX       // copy the integer value from stdio.h
  19. *     FILENAME_MAX    // copy the integer value from stdio.h
  20. *     TMP_MAX         // copy the integer value from stdio.h
  21. *     CHAR_MIN        // depends on whether the ANSI C compiler
  22. *     CHAR_MAX        // treats type char as signed or unsigned
  23. */
  24.  
  25. #ifndef _INC_STD_LIB
  26. #define _INC_STD_LIB
  27.  
  28.  
  29. /*
  30. * typedef's
  31. */
  32.  
  33. typedef  unsigned long  time_t;
  34. typedef  unsigned long  clock_t;
  35. typedef  unsigned int   size_t;
  36. typedef  unsigned int   moal_t;
  37.  
  38.  
  39. /*
  40. * type, macros, and prototypes for communication with the environment
  41. */
  42.  
  43. struct ar {
  44.     char var text[];
  45. };
  46.  
  47. #define EXIT_SUCCESS 0
  48. #define EXIT_FAILURE 1
  49.  
  50.  main(struct ar args[]) int status;
  51.  exit(int status);
  52.  getenv(char name[]) char var value[];
  53.  system(char command[]) int status;
  54.  
  55.  
  56. /*
  57. * macros and prototypes for formatting functions
  58. */
  59.  
  60. #define APPEND   1
  61. #define REPLACE  0
  62.  
  63.  printf(char format[], ...) int sent;
  64.  fprintf(int file, char format[], ...) int sent;
  65.  sprintf(char out[], int append, char format[], ...) int added;
  66.  
  67.  scanf(char format[], ...) int assignments;
  68.  fscanf(int file, char format[], ...) int assignments;
  69.  sscanf(char source[], char format[], ...) int assignments;
  70.  
  71.  
  72. /*
  73. * external table, macros, and prototypes for character functions
  74. */
  75.  
  76. extern signed char var _MC_ctype[];
  77.  
  78. #define isalpha(c)   (_MC_ctype[(unsigned char)(c)] & 6)
  79. #define islower(c)   (_MC_ctype[(unsigned char)(c)] & 2)
  80. #define isupper(c)   (_MC_ctype[(unsigned char)(c)] & 4)
  81. #define isdigit(c)   (_MC_ctype[(unsigned char)(c)] & 8)
  82. #define isalnum(c)   (_MC_ctype[(unsigned char)(c)] & 14)
  83. #define isspace(c)   (_MC_ctype[(unsigned char)(c)] & 1)
  84.  
  85. // isalpha(char character) int answer;
  86. // islower(char character) int answer;
  87. // isupper(char character) int answer;
  88. // isdigit(char character) int answer;
  89. // isalnum(char character) int answer;
  90. // isspace(char character) int answer;
  91.  
  92. extern unsigned char var _MC_lower[];
  93. extern unsigned char var _MC_upper[];
  94.  
  95. #define tolower(c)   ((char)_MC_lower[(unsigned char)(c)])
  96. #define toupper(c)   ((char)_MC_upper[(unsigned char)(c)])
  97.  
  98. // tolower(char character) char lower_case;
  99. // toupper(char character) char upper_case;
  100.  
  101.  
  102. /*
  103. * prototypes for string operations
  104. */
  105.  
  106. #define MATCH_CASE   1
  107. #define IGNORE_CASE  0
  108.  
  109.  strcat(char out[], char source[]);
  110.  strcpy(char out[], char source[]);
  111.  strpart(char source[], size_t from_offset, size_t to_offset) char var part[];
  112.  strrpl(char out[], size_t out_offset,
  113.         size_t cut_length, char insert[]) int error, long net_change;
  114.  strcmp(char s1[], char s2[]) int result;
  115.  strncmp(char s1[], char s2[], size_t n) int result;
  116.  strfnd(char search[], size_t from_offset, size_t to_offset,
  117.         int match_case, char find[]) int error, size_t subscript;
  118.  strtod(char source[], size_t source_offset)
  119.         int error, double number, size_t next_offset;
  120.  strtol(char source[], size_t source_offset)
  121.         int error, long number, size_t next_offset;
  122.  strtoul(char source[], size_t source_offset)
  123.          int error, unsigned long number, size_t next_offset;
  124.  strerror(int error) char var description[];
  125.  stresc(char source[]) char var translation[];
  126.  
  127.  
  128. /*
  129. * prototypes for pattern searching (regular expressions)
  130. *
  131. * the components of structure type rg are for internal use only --
  132. * do not reference or assign values to any of these components
  133. */
  134.  
  135. struct _fsm {
  136.     int next1,             // next state 1
  137.         next2;             // next state 2
  138.     char var cset[];       // each element: 0 if character not allowed
  139.     char type;             // r - or node, c - closure node,
  140.                            // s - single character, t - character set
  141.     unsigned char single;  // single character to match
  142. };
  143.  
  144. struct rg {
  145.     struct _fsm var st[];  // finite-state machine
  146.     int match_longest,     // zero (false) or nonzero (true)
  147.         match_case,        // zero (false) or nonzero (true)
  148.         align_left,        // 0 - none, 1 - boundary, 2 - boundary or \n
  149.         align_right;       // 0 - none, 1 - boundary, 2 - boundary or \n
  150.  
  151.     // work areas used by strfndr()
  152.     int var m[].resize[0], var start[].resize[0];
  153. };
  154.  
  155. #define LONGEST   1
  156. #define SHORTEST  0
  157.  
  158. strreg(char expression[], int match_longest, int match_case)
  159.        int error, struct rg machine;
  160. strfndr(char search[], size_t from_offset, size_t to_offset,
  161.         struct rg machine) int error, size_t subscript, size_t length;
  162.  
  163.  
  164. /*
  165. * prototypes for associative arrays
  166. *
  167. * the components of structure type ky are for internal use only --
  168. * do not reference or assign values to any of these components
  169. */
  170.  
  171. struct ky {
  172.     int initialized[1];             // true if occurs is nonzero
  173.     int match_case;                 // zero (false) or nonzero (true)
  174.     struct _tx {
  175.         char var text[].resize[0];  // text of key
  176.     } var key[];                    // the keys in added order
  177.     struct _bn {
  178.         int key, red, l, r;         // node of red-black tree
  179.     } var bin[];                    // red-black tree
  180.     int var map[];                  // map to keys in sorted order
  181. };
  182.  
  183. strknew(int match_case) struct ky keys;
  184. strkey(char key[], struct ky keys) size_t subscript;
  185.  
  186. #define MAP_TO_SORTED 1
  187. #define MAP_TO_ADDED  0
  188.  
  189. strkmap(size_t sub, int map_to_sorted, struct ky keys)
  190.    int error, char var key[], size_t subscript;
  191. strkfnd(char key[], struct ky keys) int error, size_t subscript;
  192.  
  193.  
  194. /*
  195. * macros and prototypes for file I/O
  196. */
  197.  
  198. #define FOPEN_MAX        20
  199. #define FILENAME_MAX     260
  200. #define TMP_MAX          32767
  201.  
  202. #define stdin   1
  203. #define stdout  2
  204. #define stderr  3
  205.  
  206. #define SEEK_CUR  1
  207. #define SEEK_END  2
  208. #define SEEK_BGN  3
  209.  
  210.  fopen(char filename[], char mode[]) int error, int file;
  211.  fclose(int file) int error;
  212.  fseek(int file, long offset, int from_where) int error;
  213.  ftell(int file) int error, long current_position;
  214.  fgetc(int file) int error, char character;
  215.  fgets(char out[], size_t count, int file) int error;
  216.  fread(char out[], size_t out_offset,
  217.        size_t read_count, int file) int error, size_t read;
  218.  fputc(char character, int file) int error;
  219.  fputs(char source[], int file) int error;
  220.  fwrite(char source[], size_t source_offset,
  221.         size_t write_count, int file) int error;
  222.  tmpfile() int error, int file;
  223.  tmpnam() char var filename[];
  224.  remove(char filename[]) int error;
  225.  rename(char current_filename[], char new_filename[]) int error;
  226.  
  227. #define TEXT    1
  228. #define BINARY  0
  229.  
  230. fgetall(char filename[], int convert_text) int error, char var data[];
  231. fputall(char filename[], int convert_text, char data[]) int error;
  232.  
  233.  
  234. /*
  235. * macro, structure type, and prototypes for time
  236. */
  237.  
  238. #define CLOCKS_PER_SEC  1000
  239.  
  240. struct tm {
  241.   int tm_sec;   // seconds after the minute  (0 - 61)
  242.   int tm_min;   // minutes after the hour    (0 - 59)
  243.   int tm_hour;  // hours since midnight      (0 - 23)
  244.   int tm_mday;  // day of the month          (1 - 31)
  245.   int tm_mon;   // months since January      (0 - 11)
  246.   int tm_year;  // years since 1900
  247.   int tm_wday;  // days since Sunday         (0 - 6)
  248.   int tm_yday;  // days since January 1st    (0 - 365)
  249.   int tm_isdst; // Daylight Saving Time flag
  250. };
  251.  
  252.  time() time_t current_time;
  253.  difftime(time_t any_time, time_t subtract_time) double seconds;
  254.  localtime(time_t any_time) struct tm time_info;
  255.  gmtime(time_t any_time) struct tm time_info;
  256.  mktime(struct tm time_info) time_t the_time;
  257.  ctime(time_t any_time) char var text[];
  258.  strftime(char format[], struct tm time_info) char var text[];
  259.  clock() clock_t clocks;
  260.  
  261.  
  262. /*
  263. * prototypes for sort and search
  264. */
  265.  
  266.  qsort(any [], fun (any struct, any struct)(int) compare);
  267.  bsearch(any struct, any [],
  268.          fun (any struct, any struct)(int) compare)
  269.          int error, size_t subscript;
  270.  
  271.  
  272. /*
  273. * prototypes for math
  274. */
  275.  
  276.  merr(double x) int error;
  277.  abs(int x) int answer;
  278.  labs(long x) long answer;
  279.  fabs(double x) double answer;
  280.  div(int x, int divide_by) int quotient, int remainder;
  281.  ldiv(long x, long divide_by) long quotient, long remainder;
  282.  rand(int prev) int next;
  283.  fmod(double x, double divide_by) double answer;
  284.  ceil(double x) double answer;
  285.  floor(double x) double answer;
  286.  log(double x) double answer;
  287.  log10(double x) double answer;
  288.  pow(double x, double power) double answer;
  289.  sqrt(double x) double answer;
  290.  exp(double x) double answer;
  291.  sin(double x) double answer;
  292.  cos(double x) double answer;
  293.  tan(double x) double answer;
  294.  asin(double x) double answer;
  295.  acos(double x) double answer;
  296.  atan(double x) double answer;
  297.  atan2(double y, double x) double answer;
  298.  
  299.  
  300. /*
  301. * max and min macros
  302. */
  303.  
  304. #define max(a, b)  (((a) > (b)) ? (a) : (b))
  305. #define min(a, b)  (((a) < (b)) ? (a) : (b))
  306.  
  307.  
  308. /*
  309. * assert macro
  310. */
  311.  
  312. #undef assert
  313. #ifdef NDEBUG
  314. #define assert(test) (1)
  315. #else
  316. #define _STR(x) #x
  317. #define assert(test) ((test) ? 1 : (fprintf(stderr, "Assertion \
  318. failed: " #test ", file " __FILE__ ", line " _STR(__LINE__) "\n"), \
  319. exit(EXIT_FAILURE), 0))
  320. #endif
  321.  
  322.  
  323. /*
  324. * limits for integral types
  325. */
  326.  
  327. // number of bits in a char
  328. #define CHAR_BIT   8
  329.  
  330. // signed char
  331. #define SCHAR_MIN   (-128)
  332. #define SCHAR_MAX     127
  333. #define UCHAR_MAX     255
  334.  
  335. // char (assuming type char is signed)
  336. #define CHAR_MIN   SCHAR_MIN
  337. #define CHAR_MAX   SCHAR_MAX
  338.  
  339. // short
  340. #define SHRT_MIN   (-32768)
  341. #define SHRT_MAX     32767
  342. #define USHRT_MAX    65535
  343.  
  344. // int
  345. #define INT_MIN   (-2147483647 - 1)
  346. #define INT_MAX     2147483647
  347. #define UINT_MAX    4294967295U
  348.  
  349. // long
  350. #define LONG_MIN   (-2147483647L - 1)
  351. #define LONG_MAX     2147483647L
  352. #define ULONG_MAX    4294967295LU
  353.  
  354.  
  355. /*
  356. * limits for floating-point types
  357. */
  358.  
  359. // rounding mode for addition: 1 means rounding is to the nearest value
  360. #define FLT_ROUNDS   1
  361.  
  362. // the base of the exponent
  363. #define FLT_RADIX    2
  364.  
  365. // base-radix digits in mantissa (same as number of bits, since radix is 2)
  366. #define FLT_MANT_DIG   24
  367. #define DBL_MANT_DIG   53
  368.  
  369. // decimal digits of precision
  370. #define FLT_DIG   6
  371. #define DBL_DIG   15
  372.  
  373. // smallest valid base-radix exponent
  374. #define FLT_MIN_EXP   (-125)
  375. #define DBL_MIN_EXP   (-1021)
  376.  
  377. // smallest valid decimal exponent
  378. #define FLT_MIN_10_EXP   (-37)
  379. #define DBL_MIN_10_EXP   (-307)
  380.  
  381. // largest valid base-radix exponent
  382. #define FLT_MAX_EXP   128
  383. #define DBL_MAX_EXP   1024
  384.  
  385. // largest valid decimal exponent
  386. #define FLT_MAX_10_EXP   38
  387. #define DBL_MAX_10_EXP   308
  388.  
  389. // largest valid positive number
  390. #define FLT_MAX   3.402823466e+38
  391. #define DBL_MAX   1.7976931348623158e+308
  392.  
  393. // smallest positive number such that 1.0 + EPSILON != 1.0
  394. #define FLT_EPSILON   1.192092896e-7
  395. #define DBL_EPSILON   2.2204460492503131e-16
  396.  
  397. // smallest valid positive number
  398. #define FLT_MIN   1.175494351e-38
  399. #define DBL_MIN   2.2250738585072014e-308
  400.  
  401. // type long double
  402. #define LDBL_MANT_DIG     DBL_MANT_DIG
  403. #define LDBL_DIG          DBL_DIG
  404. #define LDBL_MIN_EXP      DBL_MIN_EXP
  405. #define LDBL_MIN_10_EXP   DBL_MIN_10_EXP
  406. #define LDBL_MAX_EXP      DBL_MAX_EXP
  407. #define LDBL_MAX_10_EXP   DBL_MAX_10_EXP
  408. #define LDBL_MAX          DBL_MAX
  409. #define LDBL_EPSILON      DBL_EPSILON
  410. #define LDBL_MIN          DBL_MIN
  411.  
  412.  
  413. /*
  414. * common macros
  415. */
  416.  
  417. #define MEMORY_FAILURE  32000  /* MOAL C's one predefined exception */
  418.  
  419. #define TRUE   1
  420. #define FALSE  0
  421.  
  422. #define EOF        (-1)
  423. #define NOT_FOUND  (-2)
  424. #define NaN        (-3)
  425. #define pINF       (-4)
  426. #define nINF       (-5)
  427.  
  428.  
  429. #endif  /* _INC_STD_LIB */
  430.