Debian Codegraph @

mednafen/general.cpp

raw symbols SCIP
1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/
19
20 #include <string.h>
21 #include <stdarg.h>
22
23 #include <sys/types.h>
24
25 #include <string>
26
27 #include "general.h"cxx . . $ `<file>/mednafen/general.h`/
28 #include "state.h"cxx . . $ `<file>/mednafen/state.h`/
29
30 using namespace std;
31
32 static bool IsAbsolutePathcxx . . $ IsAbsolutePath(c5f7da30cbc0f4e9).(const char *path)
33 {
34 if (path[0] == '\\' || path[0] == '/')
35 return(TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!);
36
37 #if defined(WIN32) || defined(DOS)
38 if((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'))
39 {
40 if(path[1] == ':')
41 return(TRUE);
42 }
43 #endif
44
45 return(FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!);
46 }
47
48 bool MDFN_IsFIROPSafecxx . . $ MDFN_IsFIROPSafe(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path)
49 {
50 // We could make this more OS-specific, but it shouldn't hurt to try to weed out usage of characters that are path
51 // separators in one OS but not in another, and we'd also run more of a risk of missing a special path separator case
52 // in some OS.
53
54 if(!MDFN_GetSettingBcxx . . $ MDFN_GetSettingB(c5f7da30cbc0f4e9).("filesys.untrusted_fip_check"))
55 return(true);
56
57 if(path.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('\0') != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
58 return(false);
59
60 if(path.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).(':') != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
61 return(false);
62
63 if(path.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('\\') != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
64 return(false);
65
66 if(path.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('/') != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
67 return(false);
68
69 return(true);
70 }
71
72 void MDFN_GetFilePathComponentscxx . . $ MDFN_GetFilePathComponents(f608b903cc9a02a6).(const stdcxx . . $ std/::stringcxx . . $ std/string# &file_path,
73 stdcxx . . $ std/::stringcxx . . $ std/string# *dir_path_out, stdcxx . . $ std/::stringcxx . . $ std/string# *file_base_out,
74 stdcxx . . $ std/::stringcxx . . $ std/string# *file_ext_out)
75 {
76 size_t final_ds; // in file_path
77 stringcxx . . $ std/string# file_namecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
78 size_t fn_final_dot; // in local var file_name
79 stringcxx . . $ std/string# dir_pathcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., file_basecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., file_extcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; // Temporary output
80
81 #ifdef _WIN32
82 final_ds = file_path.find_last_of('\\');
83
84 size_t alt_final_ds = file_path.find_last_of('/');
85
86 if(final_ds == string::npos || (alt_final_ds != string::npos && alt_final_ds > final_ds))
87 final_ds = alt_final_ds;
88 #else
89 final_ds = file_path.find_last_ofcxx . . $ std/__cxx11/basic_string#find_last_of(2dda2fc6b78abe68).('/');
90 #endif
91
92 if(final_ds == stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
93 {
94 dir_path =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stringcxx . . $ std/string#(".");
95 file_name =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). file_path;
96 }
97 else
98 {
99 dir_path =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). file_path.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, final_ds);
100 file_name =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). file_path.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(final_ds + 1);
101 }
102
103 fn_final_dot = file_name.find_last_ofcxx . . $ std/__cxx11/basic_string#find_last_of(2dda2fc6b78abe68).('.');
104
105 if(fn_final_dot != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
106 {
107 file_base =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). file_name.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, fn_final_dot);
108 file_ext =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). file_name.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(fn_final_dot);
109 }
110 else
111 {
112 file_base =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). file_name;
113 file_ext =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stringcxx . . $ std/string#("");
114 }
115
116 if(dir_path_out)
117 *dir_path_out =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). dir_path;
118
119 if(file_base_out)
120 *file_base_out =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). file_base;
121
122 if(file_ext_out)
123 *file_ext_out =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). file_ext;
124 }
125
126 stdcxx . . $ std/::stringcxx . . $ std/string# MDFN_EvalFIPcxx . . $ MDFN_EvalFIP(2007729dd81cc85).(const stdcxx . . $ std/::stringcxx . . $ std/string# &dir_path, const stdcxx . . $ std/::stringcxx . . $ std/string# &rel_path, bool skip_safety_check)
127 {
128 char slash;
129 #ifdef _WIN32
130 slash = '\\';
131 #else
132 slash = '/';
133 #endif
134
135 if(!skip_safety_check && !MDFN_IsFIROPSafecxx . . $ MDFN_IsFIROPSafe(7c222eea44a24d43).(rel_path))
136 throw MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(0, _cxx . . $ `mednafen/mednafen.h:9:9`!("Referenced path \"%s\" is potentially unsafe. See \"filesys.untrusted_fip_check\" setting.\n"), rel_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
137
138 if(IsAbsolutePathcxx . . $ IsAbsolutePath(c5f7da30cbc0f4e9).(rel_path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()))
139 return(cxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).rel_path);
140 else
141 return(dir_path +cxx . . $ std/operator+(4f1c09d7d89f005e). slash +cxx . . $ std/operator+(db5dc2ea912c6495). rel_path);
142 }
143
144 const char * GetFNComponentcxx . . $ GetFNComponent(fb58d2e09a2a1ce6).(const char *str)
145 {
146 const char *tp1;
147
148 #ifdef _WIN32
149 tp1 = ((char *)strrchr(str,'\\'));
150
151 const char *tp3;
152
153 tp3 = ((char *)strrchr(str,'/'));
154
155 if (tp1<tp3)
156 tp1 = tp3;
157 #else
158 tp1 = ((char *)strrchr(str,'/'));
159 #endif
160
161 if (tp1)
162 return (tp1+1);
163 else
164 return (str);
165 }
166
167 // Remove whitespace from beginning of string
168 void MDFN_ltrimcxx . . $ MDFN_ltrim(80d0450aec2fd74).(stdcxx . . $ std/::stringcxx . . $ std/string# &string)
169 {
170 size_t len = string.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).();
171 size_t di, si;
172 bool InWhitespace = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!;
173
174 di = si = 0;
175
176 while(si < len)
177 {
178 if(InWhitespace && (string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si] == ' ' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si] == '\r' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si] == '\n' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si] == '\t' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si] == 0x0b))
179 {
180
181 }
182 else
183 {
184 InWhitespace = FALSEcxx . . $ `mednafen/mednafen-types.h:109:9`!;
185 string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).di] = string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).si];
186 di++;
187 }
188 si++;
189 }
190
191 string.resizecxx . . $ std/__cxx11/basic_string#resize(9dac5f4bebd06212).(di);
192 }
193
194 // Remove whitespace from end of string
195 void MDFN_rtrimcxx . . $ MDFN_rtrim(80d0450aec2fd74).(stdcxx . . $ std/::stringcxx . . $ std/string# &string)
196 {
197 size_t len = string.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).();
198
199 if(len)
200 {
201 size_t x = len;
202 size_t new_len = len;
203
204 do
205 {
206 x--;
207
208 if(!(string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] == ' ' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] == '\r' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] == '\n' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] == '\t' || string[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).x] == 0x0b))
209 break;
210
211 new_len--;
212 } while(x);
213
214 string.resizecxx . . $ std/__cxx11/basic_string#resize(9dac5f4bebd06212).(new_len);
215 }
216 }
217
218
219 void MDFN_trimcxx . . $ MDFN_trim(80d0450aec2fd74).(stdcxx . . $ std/::stringcxx . . $ std/string# &string)
220 {
221 MDFN_rtrimcxx . . $ MDFN_rtrim(80d0450aec2fd74).(string);
222 MDFN_ltrimcxx . . $ MDFN_ltrim(80d0450aec2fd74).(string);
223 }
224