Debian Codegraph @

src/core/util_platforms.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler and Virtual Machine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
24
25 //-----------------------------------------------------------------------------
26 // name: util_platforms.h
27 // desc: platform-specific utilities, e.g., for Android and various
28 //
29 // author: Andriy Kunitsyn ([email protected]) | ChuckAndroid
30 // Ge Wang (https://ccrma.stanford.edu/~ge/)
31 // date: Summer 2021
32 //-----------------------------------------------------------------------------
33 #ifndef __UTIL_PLATFORMS_H__
34 #define __UTIL_PLATFORMS_H__
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string>
39 #include "chuck_def.h"
40
41
42
43
44 // try to open a file by filname, adding extension if needed
45 // filename argument is changed to name of actual opened file
46 FILE * ck_openFileAutoExt( std::string & filenameMutable,
47 const std::string & extension );
48 // platform-abstracted temp file creation
49 FILE * ck_tmpfile();
50
51 // check if is dir
52 t_CKBOOL ck_isdir( const std::string & path );
53 // check if file exists
54 t_CKBOOL ck_fileexists( const std::string & path );
55
56 // do any platform-specific setup to enable ANSI escape codes
57 t_CKBOOL ck_configANSI_ESCcodes();
58
59 // are we output to a TTY (teletype, character by character)
60 // (vs say a file stream; helpful for determining if we should
61 // suppress printing ANSI escapes codes, e.g., color codes
62 // to the output stream
63 t_CKBOOL ck_isatty( int fd );
64 // get a general idea (typically stderr is used here)
65 t_CKBOOL ck_isatty();
66
67 // get TTY terminal width, or a default width (if can't get from TTY)
68 t_CKUINT ck_ttywidth();
69 // set default TTY width
70 void ck_ttywidth_setdefault( t_CKUINT width );
71 // get default TTY width
72 t_CKUINT ck_ttywidth_default();
73
74 // abstraction for getline, c edition
75 size_t ck_getline( char ** lineptr, size_t * n, FILE * stream );
76
77 // sleep
78 void ck_usleep( t_CKUINT microseconds );
79
80 // gettimeofday
81 int ck_gettimeofday( long * tv_sec, long * tv_usec, void * tzp );
82
83
84
85
86 //-----------------------------------------------------------------------------
87 // Chuck platform string | 1.5.5.2 (azaday)
88 //-----------------------------------------------------------------------------
89 // note: this must be placed *after* the platform defines above
90 //-----------------------------------------------------------------------------
91 #if defined( __PLATFORM_MACOS__)
92 #define CHUCK_PLATFORM_STRING "mac"
93 #elif defined(__PLATFORM_LINUX__)
94 #define CHUCK_PLATFORM_STRING "linux"
95 #elif defined(__PLATFORM_WINDOWS__)
96 #define CHUCK_PLATFORM_STRING "windows"
97 #elif defined(__PLATFORM_EMSCRIPTEN__)
98 #define CHUCK_PLATFORM_STRING "web"
99 #elif defined(__PLATFORM_IOS__)
100 #define CHUCK_PLATFORM_STRING "ios"
101 #elif defined(__PLATFORM_ANDROID__)
102 #define CHUCK_PLATFORM_STRING "android"
103 #elif defined(__PLATFORM_CYGWIN__)
104 #define CHUCK_PLATFORM_STRING "cygwin" // not sure if needed, as cygwin implies windows
105 #elif
106 #define CHUCK_PLATFORM_STRING "unknown"
107 #endif
108
109
110
111
112
113 //-----------------------------------------------------------------------------
114 #if defined(__PLATFORM_APPLE__) && !defined(__CHIP_MODE__)
115 //-----------------------------------------------------------------------------
116 #include <CoreFoundation/CoreFoundation.h>
117
118 // struct to hold version number
119 struct ck_OSVersion
120 {
121 short major;
122 short minor;
123 short patch;
124
125 ck_OSVersion() { reset(); }
126 void reset() { major = minor = patch = 0; }
127 std::string str();
128 };
129
130 // get darwin kernel release version
131 ck_OSVersion ck_darwin_version();
132 // get macOS version
133 ck_OSVersion ck_macOS_version();
134 //---------------------------------------------------------
135 // Darwin operating system version to macOS release version
136 // https://en.wikipedia.org/wiki/Darwin_(operating_system)
137 // 25.x.x. macOS 16.x.x Tahoe
138 // 24.x.x. macOS 15.x.x Sequoia
139 // 23.x.x. macOS 14.x.x Sonoma
140 // 22.x.x. macOS 13.x.x Ventura
141 // 21.x.x. macOS 12.x.x Monterey
142 // 20.x.x. macOS 11.x.x Big Sur
143 // 19.x.x. macOS 10.15.x Catalina
144 // 18.x.x. macOS 10.14.x Mojave
145 // 17.x.x. macOS 10.13.x High Sierra
146 // 16.x.x macOS 10.12.x Sierra
147 // 15.x.x OS X 10.11.x El Capitan
148 // 14.x.x OS X 10.10.x Yosemite
149 // 13.x.x OS X 10.9.x Mavericks
150 // 12.x.x OS X 10.8.x Mountain Lion
151 // 11.x.x OS X 10.7.x Lion
152 // 10.x.x OS X 10.6.x Snow Leopard
153 // 9.x.x OS X 10.5.x Leopard
154 // 8.x.x OS X 10.4.x Tiger
155 // 7.x.x OS X 10.3.x Panther
156 // 6.x.x OS X 10.2.x Jaguar
157 // 5.x OS X 10.1.x Puma
158 // 4.x OS X 10.0.x Cheetah
159 //---------------------------------------------------------
160
161 // get up time | replacement for UpTime()
162 AbsoluteTime ck_macOS_uptime();
163
164 #endif // #if defined(__PLATFORM_APPLE__) && !defined(__CHIP_MODE__)
165
166
167
168
169 //-----------------------------------------------------------------------------
170 #ifdef __ANDROID__
171 //-----------------------------------------------------------------------------
172 #include <jni.h>
173 #include <stdio.h>
174
175 //-----------------------------------------------------------------------------
176 // name: namespace ChuckAndroid
177 // desc: android specific ChucK utilities
178 //-----------------------------------------------------------------------------
179 namespace ChuckAndroid
180 {
181 JavaVM * getJVM();
182 FILE * getTemporaryFile() noexcept;
183 bool copyJARURLFileToTemporary(const char * jar_url, int * fd) noexcept;
184 };
185
186 #endif // __ANDROID__
187
188
189
190
191 #endif // __UTIL_PLATFORMS_H__