forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdskmain.cpp
More file actions
387 lines (321 loc) · 10.4 KB
/
dskmain.cpp
File metadata and controls
387 lines (321 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include "prefix.h"
#include "globdefs.h"
#include "filedefs.h"
#include "objdefs.h"
#include "parsedef.h"
#include "mcio.h"
#include "mcerror.h"
#include "globals.h"
#include "variable.h"
#include "util.h"
#include "mode.h"
#include "securemode.h"
#include "dispatch.h"
#include "stacklst.h"
#include "stack.h"
#include "debug.h"
#include "card.h"
#include "tooltip.h"
#include "osspec.h"
#include "redraw.h"
#include "font.h"
#include "stacksecurity.h"
#include "system.h"
#include "eventqueue.h"
////////////////////////////////////////////////////////////////////////////////
static uint2 nvars;
static void create_var(MCStringRef p_var)
{
MCAutoStringRef t_vname;
/* UNCHECKED */ MCStringFormat(&t_vname, "$%d", nvars++);
MCVariable *tvar;
MCNewAutoNameRef t_name;
/* UNCHECKED */ MCNameCreate(*t_vname, &t_name);
/* UNCHECKED */ MCVariable::ensureglobal(*t_name, tvar);
tvar->setvalueref(p_var);
MCU_realloc((char **)&MCstacknames, MCnstacks, MCnstacks + 1, sizeof(MCStringRef));
MCstacknames[MCnstacks++] = MCValueRetain(p_var);
}
static void create_var(uint4 p_v)
{
MCVariable *tvar;
/* UNCHECKED */ MCVariable::ensureglobal(MCNAME("$#"), tvar);
tvar->setnvalue(p_v);
}
static Boolean byte_swapped()
{
uint2 test = 1;
return *((uint1 *)&test);
}
////////////////////////////////////////////////////////////////////////////////
static void
X_initialize_mccmd(const X_init_options& p_options)
{
MCSAutoLibraryRef t_self;
MCSLibraryCreateWithAddress(reinterpret_cast<void *>(X_initialize_mccmd),
&t_self);
MCSLibraryCopyPath(*t_self,
MCcmd);
}
static void
X_initialize_mcappcodepath(const X_init_options& p_options)
{
if (p_options.app_code_path != nullptr)
{
MCappcodepath = MCValueRetain(p_options.app_code_path);
return;
}
MCU_path_split(MCcmd,
&MCappcodepath,
nullptr);
}
bool X_init(const X_init_options& p_options)
{
int argc = p_options.argc;
MCStringRef *argv = p_options.argv;
MCStringRef *envp = p_options.envp;
void *t_bottom;
MCstackbottom = (char *)&t_bottom;
MCmainwindowcallback = p_options.main_window_callback;
#ifdef _WINDOWS_DESKTOP
// MW-2011-07-26: Make sure errno pointer is initialized - this won't be
// if the engine is running through the plugin.
extern int *g_mainthread_errno;
if (g_mainthread_errno == nil)
g_mainthread_errno = _errno();
#endif
////
X_clear_globals();
////
#ifndef _WINDOWS_DESKTOP
MCS_init();
#endif
////
X_initialize_names();
////
// MW-2012-02-23: [[ FontRefs ]] Initialize the font module.
MCFontInitialize();
// MW-2012-02-23: [[ FontRefs ]] Initialize the logical font table module.
MCLogicalFontTableInitialize();
// Initialize the event queue
MCEventQueueInitialize();
////
MCswapbytes = byte_swapped();
MCtruemcstring = MCtruestring;
MCfalsemcstring = MCfalsestring;
MCnullmcstring = MCnullmcstring;
#ifdef _WINDOWS_DESKTOP
// Make sure certain things are already created before MCS_init. This is
// required right now because the Windows MCS_init uses MCS_query_registry
// which needs these things.
MCperror = new (nothrow) MCError();
MCeerror = new (nothrow) MCError();
/* UNCHECKED */ MCVariable::create(MCresult);
#endif
#ifdef _WINDOWS_DESKTOP
MCS_init();
#endif
/* Set up MCcmd correctly - this is the path to the loadable object
* containing this folder. */
X_initialize_mccmd(p_options);
/* Set up MCappcodepath correctly if not already set - on desktop this is
* the folder containing MCcmd. */
X_initialize_mcappcodepath(p_options);
#ifdef _WINDOWS_DESKTOP
delete MCperror;
delete MCeerror;
delete MCresult;
#endif
// Create the basic locale and the system locale
if (!MCLocaleCreateWithName(MCSTR("en_US"), kMCBasicLocale))
return false;
kMCSystemLocale = MCS_getsystemlocale();
if (kMCSystemLocale == nil)
return false;
MCSCommandLineSetName (argv[0]);
if (MCModeIsExecutableFirstArgument())
create_var(argv[0]);
/* This list will be used to set the argument list returned by
* MCSCommandLineGetArguments(). */
MCAutoProperListRef t_arguments;
/* UNCHECKED */ MCProperListCreateMutable (&t_arguments);
MCAutoStringRefAsUTF8String t_mccmd_utf8;
/* UNCHECKED */ t_mccmd_utf8 . Lock(MCcmd);
for (int i = 1; i < argc; i++)
{
if (MCStringIsEqualToCString(argv[i], "-d", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-display", kMCCompareExact))
{
if (++i >= argc || MCStringGetCharAtIndex(argv[i], 0) == '-')
{
fprintf(stderr, "%s: bad display name\n", *t_mccmd_utf8);
return False;
}
/* UNCHECKED */ MCStringConvertToCString(argv[i], MCdisplayname);
continue;
}
if (MCStringIsEqualToCString(argv[i], "-f", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-files", kMCCompareExact))
{
MCnofiles = True;
MCsecuremode = MC_SECUREMODE_ALL;
continue;
}
/* TODO Remove -g,-geometry flag because it's not used any more */
if (MCStringIsEqualToCString(argv[i], "-g", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-geometry", kMCCompareExact))
{
if (++i >= argc)
{
fprintf(stderr, "%s: bad geometry\n", *t_mccmd_utf8);
return False;
}
continue;
}
if (MCStringIsEqualToCString(argv[i], "-m", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-mmap", kMCCompareExact))
{
MCmmap = False;
continue;
}
if (MCStringIsEqualToCString(argv[i], "-n", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-nopixmaps", kMCCompareExact))
{
MCnopixmaps = True;
continue;
}
if (MCStringIsEqualToCString(argv[i], "-x", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-xftoff", kMCCompareExact))
{
MCuseXft = False;
continue;
}
#ifdef _MAC_DESKTOP
if (MCStringIsEqualToCString(argv[i], "-psn", kMCCompareExact))
{
// psn passed, skip it
continue;
}
#endif
if (MCStringIsEqualToCString(argv[i], "-s", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-sharedoff", kMCCompareExact))
{
MCshmoff = True;
continue;
}
if (MCStringIsEqualToCString(argv[i], "+s", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "+sharedon", kMCCompareExact))
{
MCshmon = True;
continue;
}
if (MCStringIsEqualToCString(argv[i], "-u", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-ui", kMCCompareExact)) {
MCnoui = True;
continue;
}
if (MCStringIsEqualToCString(argv[i], "-v", kMCCompareExact)
|| MCStringIsEqualToCString(argv[i], "-visualid", kMCCompareExact))
{
uint4 visualid = 0;
if (++i >= argc || MCStringGetCharAtIndex(argv[i], 0) == '-' || !MCU_stoui4(argv[i], visualid))
{
fprintf(stderr, "%s: bad visual id\n", *t_mccmd_utf8);
return False;
}
MCvisualid = visualid;
continue;
}
if (MCStringIsEqualToCString(argv[i], "-h", kMCCompareExact)
&& MCglobals == NULL)
{
MCAutoPointer<char> t_MCN_version;
/* UNCHECKED */ MCStringConvertToCString(MCNameGetString(MCN_version_string), &t_MCN_version);
fprintf(stderr, "LiveCode %s Copyright 2003-2015 LiveCode Ltd\n\
Usage: %s [-d[isplay] displayname] \n\
[-f[iles] (disable access to files and processes)\n\
[-g[eometry] ={+-}<xoffset>{+-}<yoffset>]\n\
[-i[nput] fd] read commands from fd (0 is stdin) or named pipe\n\
[-m[map]] (don't memory map files)\n\
[-n[opixmaps]] (draw direct to screen)\n\
[-p[ointerfocus]] (use active focus)\n\
[-s[haredoff]] (don't use shared memory server extension)\n\
[+s[haredon]] (use shared memory server extension)\n\
[-u[i]] (don't create graphical user interface)\n\
[-v[isualid] n] (use visual id n as listed from xdpyinfo)\n\
[-w[indowid] n] (watch window id n for commands)\n\
[stackname(s) | argument(s)]\n", *t_MCN_version, *t_mccmd_utf8);
return False;
}
create_var(argv[i]);
/* UNCHECKED */ MCProperListPushElementOntoBack (*t_arguments, argv[i]);
}
create_var(nvars);
/* UNCHECKED */ MCSCommandLineSetArguments (*t_arguments);
if (!X_open(argc, argv, envp))
return false;
if (MCstacknames != NULL && MCModeShouldLoadStacksOnStartup())
{
for(int i = 0 ; i < MCnstacks ; i++)
{
MCStack *sptr;
if (MCdispatcher->loadfile(MCstacknames[i], sptr) == IO_NORMAL)
sptr->open();
MCValueRelease(MCstacknames[i]);
}
MCnstacks = 0;
delete[] MCstacknames; /* Allocated with new[] */
MCstacknames = NULL;
MCeerror->clear();
}
return true;
}
// Important: This function is on the emterpreter whitelist. If its
// signature function changes, the mangled name must be updated in
// em-whitelist.json
bool X_main_loop_iteration()
{
void *t_bottom;
MCstackbottom = (char *)&t_bottom;
////
if (MCiconicstacks == 0 && !MCscreen->hasmessages() && MCstacks->isempty() && MCnsockets == 0)
{
// MW-2005-11-01: We want to keep the result here so we call with send=True
// (the result is used by the development environment bootstrap code)
MCdefaultstackptr->getcard()->message(MCM_shut_down, (MCParameter *)NULL, True, True);
MCquit = True;
return false;
}
MCscreen->wait(MCmaxwait, True, True);
MCU_resetprops(True);
// MW-2011-08-19: [[ Redraw ]] Make sure we flush any updates.
MCRedrawUpdateScreen();
MCabortscript = False;
if (MCtracedobject)
{
MCtracedobject->message(MCM_trace_done);
MCtracedobject = nil;
}
if (!MCtodestroy -> isempty())
{
MCtooltip -> cleartip();
MCtodestroy -> destroy();
}
MCU_cleaninserted();
MCscreen->siguser();
MCdefaultstackptr = MCstaticdefaultstackptr;
MCS_alarm(0.0);
return true;
}
////////////////////////////////////////////////////////////////////////////////