1
|
#include "ide.h"
|
2
|
|
3
|
#define IMAGECLASS IdeImg
|
4
|
#define IMAGEFILE <ide/ide.iml>
|
5
|
#include <Draw/iml_source.h>
|
6
|
|
7
|
#include <art/BlueBar/BlueBar.h>
|
8
|
|
9
|
void ChStdSkinBlue()
|
10
|
{
|
11
|
ChStdSkin();
|
12
|
InstallBlueBar();
|
13
|
}
|
14
|
|
15
|
void ChHostSkinBlue()
|
16
|
{
|
17
|
ChHostSkin();
|
18
|
InstallBlueBar();
|
19
|
}
|
20
|
|
21
|
void ChClassicSkinBlue()
|
22
|
{
|
23
|
ChClassicSkin();
|
24
|
InstallBlueBar();
|
25
|
}
|
26
|
|
27
|
void Ide::SyncCh()
|
28
|
{
|
29
|
switch(chstyle) {
|
30
|
case 0:
|
31
|
SetSkin(ChHostSkin);
|
32
|
break;
|
33
|
case 1:
|
34
|
SetSkin(ChStdSkin);
|
35
|
break;
|
36
|
case 2:
|
37
|
SetSkin(ChClassicSkin);
|
38
|
break;
|
39
|
case 3:
|
40
|
SetSkin(ChHostSkinBlue);
|
41
|
break;
|
42
|
case 4:
|
43
|
SetSkin(ChStdSkinBlue);
|
44
|
break;
|
45
|
}
|
46
|
}
|
47
|
|
48
|
void Ide::ToggleVerboseBuild() {
|
49
|
console.verbosebuild = !console.verbosebuild;
|
50
|
}
|
51
|
|
52
|
void Ide::ToggleStopOnErrors() {
|
53
|
stoponerrors = !stoponerrors;
|
54
|
}
|
55
|
|
56
|
void Ide::SwapPackagesFiles()
|
57
|
{
|
58
|
wesplit.Zoom(wesplit.GetZoom() == 1 ? -1 : 1);
|
59
|
}
|
60
|
|
61
|
void Ide::ConsoleClear()
|
62
|
{
|
63
|
GetConsole() <<= Null;
|
64
|
}
|
65
|
|
66
|
void Ide::ConsoleCopy()
|
67
|
{
|
68
|
GetConsole().Copy();
|
69
|
}
|
70
|
|
71
|
void Ide::ConsolePaste()
|
72
|
{
|
73
|
String s = ReadClipboardText();
|
74
|
if(!IsNull(s)) {
|
75
|
s.Insert(0, '\n');
|
76
|
int len = console.GetLength();
|
77
|
GetConsole().Insert(len, s.ToWString());
|
78
|
GetConsole().SetCursor(len + 1);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
void Ide::PutConsole(const char *s)
|
83
|
{
|
84
|
console << s << "\n";
|
85
|
}
|
86
|
|
87
|
void Ide::PutVerbose(const char *s)
|
88
|
{
|
89
|
if(console.verbosebuild) {
|
90
|
PutConsole(s);
|
91
|
console.Sync();
|
92
|
}
|
93
|
}
|
94
|
|
95
|
bool Ide::IdeIsBuilding() const
|
96
|
{
|
97
|
return idestate == Ide::BUILDING;
|
98
|
}
|
99
|
|
100
|
String Ide::IdeGetOneFile() const
|
101
|
{
|
102
|
return onefile;
|
103
|
}
|
104
|
|
105
|
int Ide::IdeConsoleExecute(const char *cmdline, Stream *out, const char *envptr, bool quiet)
|
106
|
{
|
107
|
return console.Execute(cmdline, out, envptr, quiet);
|
108
|
}
|
109
|
|
110
|
int Ide::IdeConsoleExecuteWithInput(const char *cmdline, Stream *out, const char *envptr, bool quiet)
|
111
|
{
|
112
|
ShowConsole();
|
113
|
console.Input(true);
|
114
|
int r = console.Execute(cmdline, out, envptr, quiet);
|
115
|
console.Input(false);
|
116
|
return r;
|
117
|
}
|
118
|
|
119
|
int Ide::IdeConsoleExecute(One<AProcess> pick_ process, const char *cmdline, Stream *out, bool quiet)
|
120
|
{
|
121
|
return console.Execute(pick(process), cmdline, out, quiet);
|
122
|
}
|
123
|
|
124
|
int Ide::IdeConsoleAllocSlot()
|
125
|
{
|
126
|
return console.AllocSlot();
|
127
|
}
|
128
|
|
129
|
bool Ide::IdeConsoleRun(const char *cmdline, Stream *out, const char *envptr, bool quiet, int slot, String key, int blitz_count)
|
130
|
{
|
131
|
return console.Run(cmdline, out, envptr, quiet, slot, key, blitz_count);
|
132
|
}
|
133
|
|
134
|
bool Ide::IdeConsoleRun(One<AProcess> pick_ process, const char *cmdline, Stream *out, bool quiet, int slot, String key, int blitz_count)
|
135
|
{
|
136
|
return console.Run(pick(process), cmdline, out, quiet, slot, key, blitz_count);
|
137
|
}
|
138
|
|
139
|
void Ide::IdeConsoleFlush()
|
140
|
{
|
141
|
console.Flush();
|
142
|
}
|
143
|
|
144
|
void Ide::IdeConsoleBeginGroup(String group)
|
145
|
{
|
146
|
console.BeginGroup(group);
|
147
|
}
|
148
|
|
149
|
void Ide::IdeConsoleEndGroup()
|
150
|
{
|
151
|
console.EndGroup();
|
152
|
}
|
153
|
|
154
|
bool Ide::IdeConsoleWait()
|
155
|
{
|
156
|
return console.Wait();
|
157
|
}
|
158
|
|
159
|
void Ide::IdeSetRight(Ctrl& ctrl)
|
160
|
{
|
161
|
right.Add(ctrl.SizePos());
|
162
|
right_split.Zoom(-1);
|
163
|
}
|
164
|
|
165
|
void Ide::IdeRemoveRight(Ctrl& ctrl)
|
166
|
{
|
167
|
ctrl.Remove();
|
168
|
if(!right.GetFirstChild())
|
169
|
right_split.Zoom(0);
|
170
|
}
|
171
|
|
172
|
bool Ide::IdeIsDebug() const
|
173
|
{
|
174
|
return debugger;
|
175
|
}
|
176
|
|
177
|
void Ide::IdeEndDebug()
|
178
|
{
|
179
|
console.Kill();
|
180
|
debugger.Clear();
|
181
|
debuglock = 0;
|
182
|
MakeTitle();
|
183
|
editor.EnableBreakpointing();
|
184
|
SetBar();
|
185
|
editor.HidePtr();
|
186
|
for(int i = 0; i < 2; i++)
|
187
|
posfile[i].Clear();
|
188
|
PosSync();
|
189
|
const Workspace& wspc = IdeWorkspace();
|
190
|
for(int i = 0; i < wspc.GetCount(); i++) {
|
191
|
const Package& pk = wspc.GetPackage(i);
|
192
|
String n = wspc[i];
|
193
|
for(int i = 0; i < pk.file.GetCount(); i++) {
|
194
|
String file = SourcePath(n, pk.file[i]);
|
195
|
ValidateBreakpoints(Filedata(file).lineinfo);
|
196
|
}
|
197
|
}
|
198
|
editor.ValidateBreakpoints();
|
199
|
}
|
200
|
|
201
|
void Ide::IdeSetDebugPos(const String& file, int line, const Image& img, int i)
|
202
|
{
|
203
|
posfile[i] = file;
|
204
|
posline[i] = line;
|
205
|
posimg[i] = img;
|
206
|
EditFile(file);
|
207
|
editor.GotoLine(line);
|
208
|
PosSync();
|
209
|
Size sz = editor.GetPageSize();
|
210
|
Point p = editor.GetScrollPos();
|
211
|
int l = editor.GetCursorLine();
|
212
|
if(sz.cy > 8 && l - p.y > sz.cy - 4)
|
213
|
editor.SetScrollPos(Point(p.x, max(0, l - 4)));
|
214
|
SetForeground();
|
215
|
editor.SetFocus();
|
216
|
}
|
217
|
|
218
|
void Ide::IdeHidePtr()
|
219
|
{
|
220
|
editor.HidePtr();
|
221
|
}
|
222
|
|
223
|
bool Ide::IdeDebugLock()
|
224
|
{
|
225
|
if(debuglock == 0) {
|
226
|
editor.DisableBreakpointing();
|
227
|
MakeTitle();
|
228
|
SetBar();
|
229
|
Sync();
|
230
|
debuglock = 1;
|
231
|
return true;
|
232
|
}
|
233
|
debuglock++;
|
234
|
return false;
|
235
|
}
|
236
|
|
237
|
bool Ide::IdeDebugUnLock()
|
238
|
{
|
239
|
debuglock--;
|
240
|
ASSERT(debuglock >= 0);
|
241
|
if(debuglock == 0) {
|
242
|
MakeTitle();
|
243
|
editor.EnableBreakpointing();
|
244
|
SetBar();
|
245
|
return true;
|
246
|
}
|
247
|
return false;
|
248
|
}
|
249
|
|
250
|
bool Ide::IdeIsDebugLock() const
|
251
|
{
|
252
|
return debuglock;
|
253
|
}
|
254
|
|
255
|
String Ide::IdeGetFileName() const
|
256
|
{
|
257
|
return !designer ? editfile : Null;
|
258
|
}
|
259
|
|
260
|
int Ide::IdeGetFileLine()
|
261
|
{
|
262
|
return !designer ? editor.GetNoLine(editor.GetCursorLine()) : 0;
|
263
|
}
|
264
|
|
265
|
String Ide::IdeGetLine(int i) const
|
266
|
{
|
267
|
if(i >= 0 && i < editor.GetLineCount())
|
268
|
return editor.GetUtf8Line(i);
|
269
|
else
|
270
|
return Null;
|
271
|
}
|
272
|
|
273
|
void Ide::IdeSetBar()
|
274
|
{
|
275
|
SetBar();
|
276
|
}
|
277
|
|
278
|
void Ide::SetupBars()
|
279
|
{
|
280
|
ClearFrames();
|
281
|
int r = HorzLayoutZoom(100);
|
282
|
int l = HorzLayoutZoom(320);
|
283
|
menubar.Transparent();
|
284
|
if(toolbar_in_row) {
|
285
|
toolbar.SetFrame(NullFrame());
|
286
|
bararea.Add(menubar.LeftPos(0, l).VCenterPos(menubar.GetStdHeight()));
|
287
|
bararea.Add(toolbar.HSizePos(l, r).VCenterPos(toolbar.GetStdHeight()));
|
288
|
bararea.Add(display.RightPos(4, r).VSizePos(2, 3));
|
289
|
bararea.Height(max(menubar.GetStdHeight(), toolbar.GetStdHeight()));
|
290
|
AddFrame(bararea);
|
291
|
toolbar.Transparent();
|
292
|
}
|
293
|
else {
|
294
|
bararea.Add(menubar.LeftPos(0, l).VCenterPos(menubar.GetStdHeight()));
|
295
|
bararea.Add(display.RightPos(4, r).VSizePos(2, 3));
|
296
|
bararea.Height(menubar.GetStdHeight());
|
297
|
AddFrame(bararea);
|
298
|
AddFrame(TopSeparatorFrame());
|
299
|
AddFrame(toolbar);
|
300
|
toolbar.NoTransparent();
|
301
|
}
|
302
|
AddFrame(statusbar);
|
303
|
SetBar();
|
304
|
}
|
305
|
|
306
|
Ide::Ide()
|
307
|
{
|
308
|
editor.theide = this;
|
309
|
editor.WhenSel = THISBACK(SetToolBar);
|
310
|
|
311
|
start_time = GetSysTime();
|
312
|
stat_build_time = 0;
|
313
|
build_start_time = Null;
|
314
|
hydra1_threads = CPU_Cores();
|
315
|
|
316
|
gdbSelector = 1;
|
317
|
|
318
|
chstyle = 0;
|
319
|
|
320
|
Sizeable().Zoomable();
|
321
|
|
322
|
display.SetFrame(ThinInsetFrame());
|
323
|
display.SetAlign(ALIGN_CENTER);
|
324
|
|
325
|
filelist.Columns(2);
|
326
|
package.Columns(2);
|
327
|
|
328
|
filetabs = AlignedFrame::TOP;
|
329
|
auto_enclose = false;
|
330
|
mark_lines = true;
|
331
|
|
332
|
persistent_find_replace = false;
|
333
|
|
334
|
idestate = EDITING;
|
335
|
debuglock = 0;
|
336
|
|
337
|
menubar.WhenHelp = statusbar;
|
338
|
menubar.AreaLook(1);
|
339
|
toolbar.WhenHelp = statusbar;
|
340
|
toolbar.AreaLook(1);
|
341
|
toolbar_in_row = false;
|
342
|
SetupBars();
|
343
|
SetBar();
|
344
|
WhenClose = THISBACK(Exit);
|
345
|
|
346
|
editorsplit.Vert(editor, editor2);
|
347
|
editorsplit.Zoom(0);
|
348
|
SyncEditorSplit();
|
349
|
|
350
|
right_split.Horz(editpane, right);
|
351
|
right_split.SetPos(7000);
|
352
|
right_split.Zoom(0);
|
353
|
|
354
|
editor_bottom.Vert(right_split, bottom);
|
355
|
console2.WhenBar = console.WhenBar = THISBACK(ConsoleMenu);
|
356
|
editor_bottom.SetPos(8000);
|
357
|
bottom.SetFrame(btabs);
|
358
|
bottom.Add(console.SizePos().SetFrame(NullFrame()));
|
359
|
bottom.Add(console2.SizePos().SetFrame(NullFrame()));
|
360
|
bottom.Add(calc.SizePos().SetFrame(NullFrame()));
|
361
|
btabs <<= THISBACK(SyncBottom);
|
362
|
BTabs();
|
363
|
|
364
|
pfsplit.SetPos(2000);
|
365
|
pfsplit.Vert(package, filelist);
|
366
|
wesplit.Horz(pfsplit, editor_bottom);
|
367
|
wesplit.SetPos(2000);
|
368
|
Add(wesplit);
|
369
|
|
370
|
editor.topsbbutton.ScrollStyle().NoWantFocus().Show();
|
371
|
editor.topsbbutton1.ScrollStyle().NoWantFocus().Show();
|
372
|
tabs <<= THISBACK(TabFile);
|
373
|
|
374
|
editor2.SetFrame(NullFrame());
|
375
|
editor2.topsbbutton.ScrollStyle().NoWantFocus().Show();
|
376
|
editor2.topsbbutton1.ScrollStyle().NoWantFocus().Show();
|
377
|
editor2.WhenLeftDown = THISBACK(SwapEditors);
|
378
|
editor.WhenAction = THISBACK(AddHistory);
|
379
|
editor.WhenBar = THISBACK(EditorMenu);
|
380
|
editor.WhenFontScroll = THISBACK(EditorFontScroll);
|
381
|
|
382
|
macro_api = MacroEditor();
|
383
|
|
384
|
mainconfiglist.WhenClick = THISBACK(MainConfig);
|
385
|
mainconfiglist <<= THISBACK(OnMainConfigList);
|
386
|
mainconfiglist.NoDropFocus();
|
387
|
mainconfiglist.NoWantFocus();
|
388
|
|
389
|
buildmode.WhenClick = THISBACK(SetupOutputMode);
|
390
|
buildmode.NoWantFocus();
|
391
|
buildmode.Tip("Output mode");
|
392
|
buildmode.AddButton().Tip("Build method").Left() <<= THISBACK(DropMethodList);
|
393
|
buildmode.AddButton().Tip("Build mode") <<= THISBACK(DropModeList);
|
394
|
methodlist.Normal();
|
395
|
methodlist.WhenSelect = THISBACK(SelectMethod);
|
396
|
modelist.Normal();
|
397
|
modelist.WhenSelect = THISBACK(SelectMode);
|
398
|
modelist.Add("Debug");
|
399
|
modelist.Add("Optimal");
|
400
|
modelist.Add("Speed");
|
401
|
modelist.Add("Size");
|
402
|
|
403
|
tabi = 0;
|
404
|
blocktabs = false;
|
405
|
|
406
|
package.WhenBar = THISBACK(PackageMenu);
|
407
|
editor.WhenState = THISBACK(MakeTitle);
|
408
|
|
409
|
package.NoWantFocus();
|
410
|
filelist.NoWantFocus();
|
411
|
filelist.WhenLeftDouble = THISBACK(Group);
|
412
|
|
413
|
Icon(IdeImg::Package(), IdeImg::Package());
|
414
|
|
415
|
tfont = editorfont = font2 = Courier(13);
|
416
|
veditorfont = consolefont = font1 = Courier(11);
|
417
|
editortabsize = 4;
|
418
|
indent_amount = 4;
|
419
|
indent_spaces = false;
|
420
|
show_status_bar = false;
|
421
|
show_tabs = false;
|
422
|
tabs_icons = false;
|
423
|
tabs_crosses = AlignedFrame::RIGHT;
|
424
|
tabs_grouping = true;
|
425
|
tabs_stacking = false;
|
426
|
tabs_serialize = true;
|
427
|
no_parenthesis_indent = false;
|
428
|
#ifdef PLATFORM_POSIX
|
429
|
line_endings = DETECT_LF;
|
430
|
#else
|
431
|
line_endings = DETECT_CRLF;
|
432
|
#endif
|
433
|
|
434
|
|
435
|
|
436
|
|
437
|
astyle_BracketIndent = false;
|
438
|
astyle_NamespaceIndent = true;
|
439
|
astyle_BlockIndent = false;
|
440
|
astyle_CaseIndent = true;
|
441
|
astyle_ClassIndent = true;
|
442
|
astyle_LabelIndent = true;
|
443
|
astyle_SwitchIndent = true;
|
444
|
astyle_PreprocessorIndent = false;
|
445
|
astyle_MinInStatementIndentLength = 2;
|
446
|
astyle_MaxInStatementIndentLength = 20;
|
447
|
astyle_BreakClosingHeaderBracketsMode = true;
|
448
|
astyle_BreakElseIfsMode = true;
|
449
|
astyle_BreakOneLineBlocksMode = true;
|
450
|
astyle_SingleStatementsMode = true;
|
451
|
astyle_BreakBlocksMode = true;
|
452
|
astyle_BreakClosingHeaderBlocksMode = true;
|
453
|
astyle_BracketFormatMode = astyle::BREAK_MODE;
|
454
|
astyle_ParensPaddingMode = astyle::PAD_BOTH;
|
455
|
astyle_ParensUnPaddingMode = true;
|
456
|
astyle_OperatorPaddingMode = true;
|
457
|
astyle_EmptyLineFill = false;
|
458
|
astyle_TabSpaceConversionMode = false;
|
459
|
astyle_TestBox = "#include <stdio.h>\n#ifndef __abcd_h\n#include <abcd.h>\n#endif\n\nvoid test(int a, int b)\n{\n /* this is a switch */\n switch(a)\n\n {\n case 1:\n b = 2;\n break;\n case 2:\n b = 4;\n break;\n default:\n break;\n }\n\n /* this are more statements on one line */\n a = 2*a;b=-5;a=2*(b+2)*(a+3)/4;\n\n /* single line blocks */\n {int z;z = 2*a+b;}\n\n /* loop */\n for(int i = 0;i< 10;i++) { a = b+2*i;}\n\n}\n";
|
460
|
|
461
|
console.WhenSelect = THISBACK(FindError);
|
462
|
console.SetSlots(hydra1_threads);
|
463
|
|
464
|
console2.WhenSelect = THISBACK(FindError);
|
465
|
|
466
|
editor.WhenSelection = THISBACK(Display);
|
467
|
stoponerrors = true;
|
468
|
hilite_scope = 1;
|
469
|
hilite_bracket = 1;
|
470
|
hilite_ifdef = 1;
|
471
|
barline = true;
|
472
|
qtfsel = true;
|
473
|
hilite_if_endif = false;
|
474
|
thousands_separator = true;
|
475
|
wrap_console_text = true;
|
476
|
mute_sounds = false;
|
477
|
line_numbers = false;
|
478
|
|
479
|
use_target = true;
|
480
|
|
481
|
runmode = RUN_WINDOW;
|
482
|
runexternal = false;
|
483
|
forceconsole = false;
|
484
|
|
485
|
browser_closeesc = true;
|
486
|
|
487
|
bookmark_pos = true;
|
488
|
|
489
|
header_guards = true;
|
490
|
insert_include = 1;
|
491
|
|
492
|
SetTimeCallback(-20, THISBACK(Periodic), TIMEID_PERIODIC);
|
493
|
|
494
|
editor.WhenBreakpoint = THISBACK(OnBreakpoint);
|
495
|
|
496
|
ConstructFindInFiles();
|
497
|
|
498
|
ff.style <<= STYLE_NO_REPLACE;
|
499
|
|
500
|
default_charset = CHARSET_UTF8;
|
501
|
|
502
|
HideBottom();
|
503
|
TheIde(this);
|
504
|
|
505
|
targetmode = 0;
|
506
|
|
507
|
doc.WhenTopic = THISBACK(OpenATopic);
|
508
|
|
509
|
editor.NoCutLine();
|
510
|
|
511
|
bordercolumn = 96;
|
512
|
bordercolor = SColorFace();
|
513
|
|
514
|
state_icon = -1;
|
515
|
|
516
|
histi = 0;
|
517
|
|
518
|
doc_serial = -1;
|
519
|
|
520
|
showtime = true;
|
521
|
|
522
|
editor.WhenTip = THISBACK(EditorTip);
|
523
|
editor.WhenCtrlClick = THISBACK(CtrlClick);
|
524
|
|
525
|
find_pick_sel = true;
|
526
|
find_pick_text = false;
|
527
|
|
528
|
deactivate_save = true;
|
529
|
|
530
|
debug_console_apps_in_console = true;
|
531
|
output_per_assembly = true;
|
532
|
|
533
|
issaving = 0;
|
534
|
isscanning = 0;
|
535
|
}
|
536
|
|
537
|
Ide::~Ide()
|
538
|
{
|
539
|
TheIde(NULL);
|
540
|
}
|
541
|
|
542
|
void DelTemps() {
|
543
|
FindFile ff(ConfigFile("*.tmp"));
|
544
|
while(ff) {
|
545
|
DeleteFile(ConfigFile(ff.GetName()));
|
546
|
ff.Next();
|
547
|
}
|
548
|
}
|
549
|
|
550
|
#ifdef PLATFORM_WIN32
|
551
|
#include <mmsystem.h>
|
552
|
#pragma comment( lib, "winmm.lib" )
|
553
|
#endif
|
554
|
|
555
|
void Ide::Paint(Draw&) {}
|
556
|
|
557
|
extern int MemoryProbeFlags;
|
558
|
|
559
|
void Uninstall();
|
560
|
|
561
|
bool SilentMode;
|
562
|
|
563
|
#ifdef PLATFORM_WIN32
|
564
|
#include <Wincon.h>
|
565
|
|
566
|
void Puts(const char *s)
|
567
|
{
|
568
|
dword dummy;
|
569
|
if(!SilentMode)
|
570
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), s, (int)strlen(s), &dummy, NULL);
|
571
|
}
|
572
|
#endif
|
573
|
|
574
|
|
575
|
#ifdef PLATFORM_POSIX
|
576
|
void Puts(const char *s)
|
577
|
{
|
578
|
if(!SilentMode)
|
579
|
puts(s);
|
580
|
}
|
581
|
#endif
|
582
|
|
583
|
bool splash_screen;
|
584
|
|
585
|
int CommaSpace(int c)
|
586
|
{
|
587
|
return c == ',' ? ' ' : c;
|
588
|
}
|
589
|
|
590
|
void ReduceCache()
|
591
|
{
|
592
|
String cfgdir = ConfigFile("cfg");
|
593
|
FindFile ff(AppendFileName(cfgdir, "*.*"));
|
594
|
while(ff) {
|
595
|
if(ff.IsFile()) {
|
596
|
String fn = ff.GetName();
|
597
|
String ext = GetFileExt(fn);
|
598
|
if(ext != ".aux" && ext != ".cfg")
|
599
|
if((Date)Time(ff.GetLastAccessTime()) < GetSysDate() - 14)
|
600
|
DeleteFile(AppendFileName(cfgdir, fn));
|
601
|
}
|
602
|
ff.Next();
|
603
|
}
|
604
|
}
|
605
|
|
606
|
#ifdef flagMAIN
|
607
|
GUI_APP_MAIN
|
608
|
#else
|
609
|
void AppMain___()
|
610
|
#endif
|
611
|
{
|
612
|
SetLanguage(LNG_ENGLISH);
|
613
|
SetDefaultCharset(CHARSET_UTF8);
|
614
|
|
615
|
const Vector<String>& arg = CommandLine();
|
616
|
|
617
|
bool firstinstall = false;
|
618
|
|
619
|
#ifdef PLATFORM_POSIX
|
620
|
LoadUpdaterCfg();
|
621
|
|
622
|
String home = Environment().Get("UPP_HOME", Null);
|
623
|
if(!IsNull(home))
|
624
|
SetHomeDirectory(home);
|
625
|
FindFile ff(ConfigFile("*.var"));
|
626
|
if(!ff) {
|
627
|
if(!Install())
|
628
|
return;
|
629
|
SaveFile(ConfigFile("version"), IDE_VERSION);
|
630
|
firstinstall = true;
|
631
|
}
|
632
|
#endif
|
633
|
|
634
|
#ifdef _DEBUG
|
635
|
|
636
|
#endif
|
637
|
|
638
|
#ifdef PLATFORM_WIN32
|
639
|
if(!CheckLicense())
|
640
|
return;
|
641
|
firstinstall = !IsNull(LoadFile(GetExeDirFile("install.upp")));
|
642
|
#ifdef flagTESTINSTALL
|
643
|
firstinstall = true;
|
644
|
#endif
|
645
|
if(firstinstall) {
|
646
|
if(!Install())
|
647
|
return;
|
648
|
SaveFile(ConfigFile("version"), IDE_VERSION);
|
649
|
}
|
650
|
#endif
|
651
|
|
652
|
for(int i = 0; i < arg.GetCount(); i++) {
|
653
|
if(arg[i] == "-uninstall") {
|
654
|
Uninstall();
|
655
|
return;
|
656
|
}
|
657
|
if(!firstinstall && arg[i] == "-install" && !Install()) return;
|
658
|
|
659
|
#ifdef PLATFORM_WIN32
|
660
|
if(arg[i] == "!") {
|
661
|
String cmdline;
|
662
|
for(++i; i < arg.GetCount(); i++) {
|
663
|
if(!IsNull(cmdline))
|
664
|
cmdline << ' ';
|
665
|
cmdline << arg[i];
|
666
|
}
|
667
|
int n = cmdline.GetLength() + 1;
|
668
|
Buffer<char> cmd(n);
|
669
|
memcpy(cmd, cmdline, n);
|
670
|
SECURITY_ATTRIBUTES sa;
|
671
|
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
|
672
|
sa.lpSecurityDescriptor = NULL;
|
673
|
sa.bInheritHandle = TRUE;
|
674
|
PROCESS_INFORMATION pi;
|
675
|
STARTUPINFO si;
|
676
|
ZeroMemory(&si, sizeof(STARTUPINFO));
|
677
|
si.cb = sizeof(STARTUPINFO);
|
678
|
AllocConsole();
|
679
|
SetConsoleTitle(cmdline);
|
680
|
int time = msecs();
|
681
|
if(CreateProcess(NULL, cmd, &sa, &sa, TRUE,
|
682
|
NORMAL_PRIORITY_CLASS,
|
683
|
NULL, NULL, &si, &pi)) {
|
684
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
685
|
dword exitcode = 255;
|
686
|
GetExitCodeProcess(pi.hProcess, &exitcode);
|
687
|
CloseHandle(pi.hProcess);
|
688
|
CloseHandle(pi.hThread);
|
689
|
Puts("<--- Finished in " + GetPrintTime(time) + ", exitcode: " + AsString(exitcode) + " --->");
|
690
|
}
|
691
|
else
|
692
|
Puts("Unable to launch " + cmdline);
|
693
|
char h[1];
|
694
|
dword dummy;
|
695
|
ReadFile(GetStdHandle(STD_INPUT_HANDLE), h, 1, &dummy, NULL);
|
696
|
return;
|
697
|
}
|
698
|
#endif
|
699
|
}
|
700
|
|
701
|
#ifndef _DEBUG
|
702
|
try {
|
703
|
#endif
|
704
|
void RegisterLayDes(); RegisterLayDes();
|
705
|
void RegisterIconDes(); RegisterIconDes();
|
706
|
|
707
|
splash_screen = true;
|
708
|
|
709
|
Ide ide;
|
710
|
ide.Maximize();
|
711
|
bool clset = false;
|
712
|
if(arg.GetCount() >= 2 && IsAlpha(arg[0][0]) && IsAlpha(arg[1][0])) {
|
713
|
bool build = arg.GetCount() >= 3 && IsAlpha(arg[2][0]);
|
714
|
#ifdef PLATFORM_WIN32
|
715
|
if(build) {
|
716
|
HMODULE hDLL = LoadLibrary ("kernel32");
|
717
|
bool attach = false;
|
718
|
if(hDLL) {
|
719
|
typedef BOOL (WINAPI *AttachConsoleType)(DWORD dwProcessId);
|
720
|
AttachConsoleType AttachConsole;
|
721
|
AttachConsole = (AttachConsoleType) GetProcAddress(hDLL, "AttachConsole");
|
722
|
if(AttachConsole)
|
723
|
attach = AttachConsole((DWORD)-1);
|
724
|
}
|
725
|
if(!attach)
|
726
|
AllocConsole();
|
727
|
}
|
728
|
#endif
|
729
|
for(int i = 3; i < arg.GetCount(); i++)
|
730
|
if(arg[i][0] == '-') {
|
731
|
String x = arg[i];
|
732
|
for(int i = 1; i < x.GetCount(); i++)
|
733
|
if(x[i] == 'l')
|
734
|
SilentMode = true;
|
735
|
}
|
736
|
if(!LoadVars(arg[0])) {
|
737
|
if(build)
|
738
|
Puts("TheIDE: Invalid assembly\n");
|
739
|
else
|
740
|
Exclamation("Invalid assembly!");
|
741
|
SetExitCode(2);
|
742
|
return;
|
743
|
}
|
744
|
if(!FileExists(SourcePath(arg[1], GetFileTitle(arg[1]) + ".upp"))) {
|
745
|
if(build)
|
746
|
Puts("TheIDE: Package does not exist\n");
|
747
|
else
|
748
|
Exclamation("Package does not exist!");
|
749
|
SetExitCode(2);
|
750
|
return;
|
751
|
}
|
752
|
if(build) {
|
753
|
ide.SetMain(arg[1]);
|
754
|
clset = true;
|
755
|
bool stoponerror = false;
|
756
|
const Workspace& wspc = ide.IdeWorkspace();
|
757
|
if(!wspc.GetCount())
|
758
|
return;
|
759
|
const Array<Package::Config>& f = wspc.GetPackage(0).config;
|
760
|
if(f.GetCount())
|
761
|
ide.mainconfigparam = f[0].param;
|
762
|
String m = arg[2];
|
763
|
if(!FileExists(ConfigFile((String)m + ".bm"))) {
|
764
|
SilentMode = false;
|
765
|
Puts("TheIDE: Invalid build method\n");
|
766
|
SetExitCode(3);
|
767
|
return;
|
768
|
}
|
769
|
ide.method <<= m;
|
770
|
ide.debug.def.blitz = ide.release.def.blitz = 0;
|
771
|
ide.debug.def.debug = 2;
|
772
|
ide.release.def.debug = 0;
|
773
|
ide.debug.package.Clear();
|
774
|
ide.release.package.Clear();
|
775
|
ide.debug.linkmode = ide.release.linkmode = 0;
|
776
|
ide.release.createmap = ide.debug.createmap = false;
|
777
|
ide.targetmode = 0;
|
778
|
ide.console.console = true;
|
779
|
bool clean = false;
|
780
|
bool makefile = false;
|
781
|
bool deletedir = false;
|
782
|
int exporting = 0;
|
783
|
String mkf;
|
784
|
for(int i = 3; i < arg.GetCount(); i++)
|
785
|
if(arg[i][0] == '>')
|
786
|
ide.mainconfigparam = Filter(~arg[i] + 1, CommaSpace);
|
787
|
else
|
788
|
if(arg[i][0] == '-') {
|
789
|
String x = arg[i];
|
790
|
for(int i = 1; i < x.GetCount(); i++)
|
791
|
switch(x[i]) {
|
792
|
case 'a':
|
793
|
clean = true;
|
794
|
break;
|
795
|
case 'r':
|
796
|
ide.targetmode = 1;
|
797
|
break;
|
798
|
case '1':
|
799
|
ide.targetmode = 2;
|
800
|
break;
|
801
|
case '2':
|
802
|
ide.targetmode = 3;
|
803
|
break;
|
804
|
case 'm':
|
805
|
ide.release.createmap = ide.debug.createmap = true;
|
806
|
break;
|
807
|
case 'b':
|
808
|
ide.release.def.blitz = ide.debug.def.blitz = 1;
|
809
|
break;
|
810
|
case 's':
|
811
|
ide.debug.linkmode = ide.release.linkmode = 1;
|
812
|
break;
|
813
|
case 'd':
|
814
|
ide.debug.def.debug = 0;
|
815
|
break;
|
816
|
case 'S':
|
817
|
ide.debug.linkmode = ide.release.linkmode = 2;
|
818
|
break;
|
819
|
case 'e':
|
820
|
stoponerror = true;
|
821
|
break;
|
822
|
case 'M':
|
823
|
makefile = true;
|
824
|
break;
|
825
|
case 'v':
|
826
|
ide.console.verbosebuild = true;
|
827
|
break;
|
828
|
case 'l':
|
829
|
break;
|
830
|
case 'x':
|
831
|
exporting = 1;
|
832
|
break;
|
833
|
case 'X':
|
834
|
exporting = 2;
|
835
|
break;
|
836
|
case 'k':
|
837
|
deletedir = false;
|
838
|
break;
|
839
|
default:
|
840
|
SilentMode = false;
|
841
|
Puts("Invalid build option(s)");
|
842
|
SetExitCode(3);
|
843
|
return;
|
844
|
}
|
845
|
}
|
846
|
else {
|
847
|
ide.debug.target_override = ide.release.target_override = true;
|
848
|
ide.debug.target = ide.release.target = mkf = arg[i];
|
849
|
}
|
850
|
if(clean)
|
851
|
ide.Clean();
|
852
|
if(exporting) {
|
853
|
mkf = GetFullPath(mkf);
|
854
|
Cout() << mkf << '\n';
|
855
|
RealizeDirectory(mkf);
|
856
|
if(makefile)
|
857
|
ide.ExportMakefile(mkf);
|
858
|
else
|
859
|
ide.ExportProject(mkf, exporting == 2, false, deletedir);
|
860
|
}
|
861
|
else
|
862
|
if(makefile) {
|
863
|
ide.SaveMakeFile(IsNull(mkf) ? "Makefile" : mkf, false);
|
864
|
SetExitCode(0);
|
865
|
}
|
866
|
else
|
867
|
if(ide.Build())
|
868
|
SetExitCode(0);
|
869
|
else {
|
870
|
if(stoponerror)
|
871
|
PromptOK("TheIDE: Error while building " + DeQtf(arg[1]) + "!");
|
872
|
SetExitCode(1);
|
873
|
}
|
874
|
return;
|
875
|
}
|
876
|
}
|
877
|
|
878
|
ide.LoadConfig();
|
879
|
if(arg.GetCount()==2){
|
880
|
LoadVars(arg[0]);
|
881
|
ide.SetMain(arg[1]);
|
882
|
clset=true;
|
883
|
}
|
884
|
ide.LoadAbbr();
|
885
|
|
886
|
ide.SyncCh();
|
887
|
|
888
|
DelTemps();
|
889
|
if(splash_screen) {
|
890
|
ShowSplash();
|
891
|
Ctrl::ProcessEvents();
|
892
|
}
|
893
|
|
894
|
#ifdef PLATFORM_POSIX
|
895
|
int p=UpdaterCfg().period;
|
896
|
if(!IsNull(p)) {
|
897
|
int next=GetUtcTime()-UpdaterCfg().last+abs(p)*60;
|
898
|
if(p <= 0 || next <= 0)
|
899
|
ide.PostCallback(callback1(&ide,&Ide::CheckUpdates,false),0);
|
900
|
if(p != 0)
|
901
|
ide.SetTimeCallback(max(0, next),callback1(&ide,&Ide::SetUpdateTimer,abs(p)));
|
902
|
}
|
903
|
#endif
|
904
|
|
905
|
ide.editor_bottom.Zoom(0);
|
906
|
ide.right_split.Zoom(0);
|
907
|
if(FileExists(ConfigFile("developide"))) {
|
908
|
#ifdef PLATFORM_WIN32
|
909
|
InstallCrashDump();
|
910
|
#endif
|
911
|
Ini::user_log = true;
|
912
|
}
|
913
|
ide.LoadLastMain();
|
914
|
if(clset || ide.OpenMainPackage()) {
|
915
|
ide.SaveLastMain();
|
916
|
ide.isscanning++;
|
917
|
ide.MakeTitle();
|
918
|
SyncRefs();
|
919
|
ide.FileSelected();
|
920
|
ide.isscanning--;
|
921
|
ide.MakeTitle();
|
922
|
if(!IdeExit)
|
923
|
ide.Run();
|
924
|
ide.SaveConfigOnTime();
|
925
|
ide.SaveLastMain();
|
926
|
}
|
927
|
#ifdef PLATFORM_POSIX
|
928
|
StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml"));
|
929
|
#endif
|
930
|
SaveCodeBase();
|
931
|
DelTemps();
|
932
|
ReduceCache();
|
933
|
#ifndef _DEBUG
|
934
|
}
|
935
|
catch(const CParser::Error& e) {
|
936
|
Exclamation("Parser error " + e);
|
937
|
LOG("!!!!! Parser error " + e);
|
938
|
}
|
939
|
catch(const Exc& e) {
|
940
|
Exclamation("Exception " + e);
|
941
|
LOG("!!!!! Exception " << e);
|
942
|
}
|
943
|
#ifdef PLATFORM_POSIX
|
944
|
catch(...) {
|
945
|
Exclamation("Unknown exception !");
|
946
|
LOG("!!!!! Unknown exception");
|
947
|
}
|
948
|
#endif
|
949
|
#endif
|
950
|
}
|