1// This file is part of SmallBASIC
2//
3// System information
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2000 Nicholas Christopoulos
9
10#if !defined(SB_SYS_H)
11#define SB_SYS_H
12
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#if defined(_Win32)
18#include <windows.h>
19#endif
20
21#if defined(__cplusplus)
22extern "C" {
23#endif
24
25#include <ctype.h>
26#include <fcntl.h>
27#include <limits.h>
28#include <math.h>
29#include <stdarg.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <sys/stat.h>
35#include <time.h>
36#include <unistd.h>
37#include <utime.h>
38
39#if !defined DBL_EPSILON
40#define DBL_EPSILON 0.00000000000001
41#endif
42#define EPSILON DBL_EPSILON
43#define OS_PREC64
44
45#define VAR_MAX_INT LONG_MAX
46#define VAR_NUM_FMT "%f"
47#define VAR_INT_FMT "%lld"
48#define VAR_INT_NUM_FMT "%.0f"
49
50#define OS_PATHNAME_SIZE 1024
51#define OS_FILENAME_SIZE 256
52#define OS_FILEHANDLES 256
53#define OS_DIRSEP '/'
54
55#if defined(_Win32)
56 #define SB_VERSYS "Win"
57 #define OS_LINESEPARATOR "\r\n"
58#else
59 #define SB_VERSYS "Unix"
60 #define OS_LINESEPARATOR "\n"
61#endif
62
63#define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1)
64#define OS_LINESEPARATOR_LEN STRLEN(OS_LINESEPARATOR)
65
66#if UINTPTR_MAX == 0xffffffff
67 #define SB_BIT_SZ "_32 "
68#else
69 #define SB_BIT_SZ "_64 "
70#endif
71
72// SB's constants
73#if defined(_SDL)
74 #define SB_STR_VER VERSION " SDL " SB_VERSYS SB_BIT_SZ BUILD_DATE
75#elif defined (_ANDROID)
76 #define SB_STR_VER VERSION " Android " BUILD_DATE
77#elif defined (_FLTK)
78 #define SB_STR_VER VERSION " FLTK " BUILD_DATE
79#else
80 #define SB_STR_VER VERSION " Console " SB_VERSYS SB_BIT_SZ BUILD_DATE
81#endif
82#define SB_ERRMSG_SIZE 2048
83#define SB_KEYWORD_SIZE 128
84#define SB_SOURCELINE_SIZE 65536 // compiler
85#define SB_TEXTLINE_SIZE 8192 // RTL
86#define SB_EXEC_STACK_SIZE 1024 // executor's stack size
87#define SB_EVAL_STACK_SIZE 16 // evaluation stack size
88#define SB_KW_NONE_STR "Nil"
89
90// STD MACROS
91#define ABS(x) ( ((x) < 0) ? -(x) : (x) ) // absolute value
92#define SGN(a) ( ((a)<0)? -1 : 1 ) // sign
93#define ZSGN(a) ( ((a)<0)? -1 : (((a)>0)? 1 : 0) ) // sign which returns 0 for 0
94#define SWAP(a,b,c) ( (c) = (a), (a) = (b), (b) = (c) ) // swap values
95#define FLOOR(a) ((a)>0 ? (int)(a) : -(int)(-a)) // floor
96#define CEILING(a) ((a)==(int)(a) ? (a) : (a)>0 ? 1+(int)(a) : -(1+(int)(-a)))
97
98#if !defined(NULL)
99#define NULL (void*)0L
100#endif
101
102/*
103 * data-types
104 */
105typedef char *char_p_t;
106typedef uint8_t byte;
107typedef uint8_t code_t;
108typedef int32_t bid_t;
109typedef uint32_t bcip_t;
110
111#define INVALID_ADDR 0xFFFFFFFF
112#define OS_ADDRSZ 4 // size of address pointer (always 4 for 32b addresses)
113#define OS_CODESZ 4 // size of buildin func/proc ptrs (always 4 for 32b mode)
114#define OS_STRLEN 4 // size of strings
115
116#define ADDRSZ OS_ADDRSZ
117#define CODESZ OS_CODESZ
118#define BC_CTRLSZ (ADDRSZ+ADDRSZ)
119
120#include "include/var.h"
121#include "common/str.h"
122
123var_num_t pcg32_rand(void);
124void pcg32_srand(var_int_t seed);
125
126#if !defined(O_BINARY)
127#define O_BINARY 0
128#endif
129
130#if !defined(CMD_PAUSE_DELAY)
131#define CMD_PAUSE_DELAY 50
132#endif
133
134#if defined(__cplusplus)
135}
136#endif
137#endif
138