idewin.cpp

Zbigniew Rebacz, 01/05/2014 01:36 AM

Download (20.2 KB)

 
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> process, const char *cmdline, Stream *out, bool quiet)
120
{
121
        return console.Execute(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> process, const char *cmdline, Stream *out, bool quiet, int slot, String key, int blitz_count)
135
{
136
        return console.Run(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
//        tabs.WhenCloseRest = THISBACK1(CloseRest, &tabs);
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
                astyle code formatter control vars
435
                added 2008.01.27 by Massimo Del Fedele
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
        output_per_assembly = true;
531
        
532
        issaving = 0;
533
        isscanning = 0;
534
}
535

    
536
Ide::~Ide()
537
{
538
        TheIde(NULL);
539
}
540

    
541
void DelTemps() {
542
        FindFile ff(ConfigFile("*.tmp"));
543
        while(ff) {
544
                DeleteFile(ConfigFile(ff.GetName()));
545
                ff.Next();
546
        }
547
}
548

    
549
#ifdef PLATFORM_WIN32
550
#include <mmsystem.h>
551
#pragma comment( lib, "winmm.lib" )
552
#endif
553

    
554
void Ide::Paint(Draw&) {}
555

    
556
extern int MemoryProbeFlags;
557

    
558
void Uninstall();
559

    
560
bool SilentMode;
561

    
562
#ifdef PLATFORM_WIN32
563
#include <Wincon.h>
564

    
565
void Puts(const char *s)
566
{
567
        dword dummy;
568
        if(!SilentMode)
569
                WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), s, (int)strlen(s), &dummy, NULL);
570
}
571
#endif
572

    
573

    
574
#ifdef PLATFORM_POSIX
575
void Puts(const char *s)
576
{
577
        if(!SilentMode)
578
                puts(s);
579
}
580
#endif
581

    
582
bool splash_screen;
583

    
584
int CommaSpace(int c)
585
{
586
        return c == ',' ? ' ' : c;
587
}
588

    
589
void ReduceCache()
590
{
591
        String cfgdir = ConfigFile("cfg");
592
        FindFile ff(AppendFileName(cfgdir, "*.*"));
593
        while(ff) {
594
                if(ff.IsFile()) {
595
                        String fn = ff.GetName();
596
                        String ext = GetFileExt(fn);
597
                        if(ext != ".aux" && ext != ".cfg")
598
                                if((Date)Time(ff.GetLastAccessTime()) < GetSysDate() - 14)
599
                                        DeleteFile(AppendFileName(cfgdir, fn));
600
                }
601
                ff.Next();
602
        }
603
}
604

    
605
#ifdef flagMAIN
606
GUI_APP_MAIN
607
#else
608
void AppMain___()
609
#endif
610
{
611
        SetLanguage(LNG_ENGLISH);
612
        SetDefaultCharset(CHARSET_UTF8);
613

    
614
        const Vector<String>& arg = CommandLine();
615

    
616
        bool firstinstall = false;
617

    
618
#ifdef PLATFORM_POSIX
619
        LoadUpdaterCfg();
620

    
621
        String home = Environment().Get("UPP_HOME", Null);
622
        if(!IsNull(home))
623
                SetHomeDirectory(home);
624
        FindFile ff(ConfigFile("*.var"));
625
        if(!ff) {
626
                if(!Install())
627
                        return;
628
                SaveFile(ConfigFile("version"), IDE_VERSION);
629
                firstinstall = true;
630
        }
631
#endif
632

    
633
#ifdef _DEBUG
634
//        Ctrl::ShowRepaint(50);
635
#endif
636

    
637
#ifdef PLATFORM_WIN32
638
        if(!CheckLicense())
639
                return;
640
        firstinstall = !IsNull(LoadFile(GetExeDirFile("install.upp")));
641
#ifdef flagTESTINSTALL
642
        firstinstall = true;
643
#endif
644
        if(firstinstall) {
645
                if(!Install())
646
                        return;
647
                SaveFile(ConfigFile("version"), IDE_VERSION);
648
        }
649
#endif
650

    
651
        for(int i = 0; i < arg.GetCount(); i++) {
652
                if(arg[i] == "-uninstall") {
653
                        Uninstall();
654
                        return;
655
                }
656
                if(!firstinstall && arg[i] == "-install" && !Install()) return;
657

    
658
        #ifdef PLATFORM_WIN32
659
                if(arg[i] == "!") {
660
                        String cmdline;
661
                        for(++i; i < arg.GetCount(); i++) {
662
                                if(!IsNull(cmdline))
663
                                        cmdline << ' ';
664
                                cmdline << arg[i];
665
                        }
666
                        int n = cmdline.GetLength() + 1;
667
                        Buffer<char> cmd(n);
668
                        memcpy(cmd, cmdline, n);
669
                        SECURITY_ATTRIBUTES sa;
670
                        sa.nLength = sizeof(SECURITY_ATTRIBUTES);
671
                        sa.lpSecurityDescriptor = NULL;
672
                        sa.bInheritHandle = TRUE;
673
                        PROCESS_INFORMATION pi;
674
                        STARTUPINFO si;
675
                        ZeroMemory(&si, sizeof(STARTUPINFO));
676
                        si.cb = sizeof(STARTUPINFO);
677
                        AllocConsole();
678
                        SetConsoleTitle(cmdline);
679
                        int time = msecs();
680
                        if(CreateProcess(NULL, cmd, &sa, &sa, TRUE,
681
                                             NORMAL_PRIORITY_CLASS,
682
                                         NULL, NULL, &si, &pi)) {
683
                                WaitForSingleObject(pi.hProcess, INFINITE);
684
                                dword exitcode = 255;
685
                                GetExitCodeProcess(pi.hProcess, &exitcode);
686
                                CloseHandle(pi.hProcess);
687
                                CloseHandle(pi.hThread);
688
                                Puts("<--- Finished in " + GetPrintTime(time) + ", exitcode: " + AsString(exitcode) + " --->");
689
                        }
690
                        else
691
                                Puts("Unable to launch " + cmdline);
692
                        char h[1];
693
                        dword dummy;
694
                        ReadFile(GetStdHandle(STD_INPUT_HANDLE), h, 1, &dummy, NULL);
695
                        return;
696
                }
697
        #endif
698
        }
699

    
700
        try {
701
                void RegisterLayDes(); RegisterLayDes();
702
                void RegisterIconDes(); RegisterIconDes();
703

    
704
                splash_screen = true;
705

    
706
                Ide ide;
707
                ide.Maximize();
708
                bool clset = false;
709
                if(arg.GetCount() >= 2 && IsAlpha(arg[0][0]) && IsAlpha(arg[1][0])) {
710
                        bool build = arg.GetCount() >= 3 && IsAlpha(arg[2][0]);
711
                #ifdef PLATFORM_WIN32
712
                        if(build) {
713
                                HMODULE hDLL = LoadLibrary ("kernel32");
714
                                bool attach = false;
715
                                if(hDLL) {
716
                                        typedef BOOL (WINAPI *AttachConsoleType)(DWORD dwProcessId);
717
                                        AttachConsoleType AttachConsole;
718
                                        AttachConsole = (AttachConsoleType) GetProcAddress(hDLL, "AttachConsole");
719
                                        if(AttachConsole)
720
                                                attach = AttachConsole((DWORD)-1);
721
                                }
722
                                if(!attach)
723
                                        AllocConsole();
724
                        }
725
                #endif
726
                        for(int i = 3; i < arg.GetCount(); i++)
727
                                if(arg[i][0] == '-') {
728
                                        String x = arg[i];
729
                                        for(int i = 1; i < x.GetCount(); i++)
730
                                                if(x[i] == 'l')
731
                                                        SilentMode = true;
732
                                }
733
                        if(!LoadVars(arg[0])) {
734
                                if(build)
735
                                        Puts("TheIDE: Invalid assembly\n");
736
                                else
737
                                        Exclamation("Invalid assembly!");
738
                                SetExitCode(2);
739
                                return;
740
                        }
741
                        if(!FileExists(SourcePath(arg[1], GetFileTitle(arg[1]) + ".upp"))) {
742
                                if(build)
743
                                        Puts("TheIDE: Package does not exist\n");
744
                                else
745
                                        Exclamation("Package does not exist!");
746
                                SetExitCode(2);
747
                                return;
748
                        }
749
                        if(build) {
750
                                ide.SetMain(arg[1]);
751
                                clset = true;
752
                                bool stoponerror = false;
753
                                const Workspace& wspc = ide.IdeWorkspace();
754
                                if(!wspc.GetCount())
755
                                        return;
756
                                const Array<Package::Config>& f = wspc.GetPackage(0).config;
757
                                if(f.GetCount())
758
                                        ide.mainconfigparam = f[0].param;
759
                                String m = arg[2];
760
                                if(!FileExists(ConfigFile((String)m + ".bm"))) {
761
                                        SilentMode = false;
762
                                        Puts("TheIDE: Invalid build method\n");
763
                                        SetExitCode(3);
764
                                        return;
765
                                }
766
                                ide.method <<= m;
767
                                ide.debug.def.blitz = ide.release.def.blitz = 0;
768
                                ide.debug.def.debug = 2;
769
                                ide.release.def.debug = 0;
770
                                ide.debug.package.Clear();
771
                                ide.release.package.Clear();
772
                                ide.debug.linkmode = ide.release.linkmode = 0;
773
                                ide.release.createmap = ide.debug.createmap = false;
774
                                ide.targetmode = 0;
775
                                ide.console.console = true;
776
                                bool clean = false;
777
                                bool makefile = false;
778
                                bool deletedir = false;
779
                                int  exporting = 0;
780
                                String mkf;
781
                                for(int i = 3; i < arg.GetCount(); i++)
782
                                        if(arg[i][0] == '>')
783
                                                ide.mainconfigparam = Filter(~arg[i] + 1, CommaSpace);
784
                                        else
785
                                        if(arg[i][0] == '-') {
786
                                                String x = arg[i];
787
                                                for(int i = 1; i < x.GetCount(); i++)
788
                                                        switch(x[i]) {
789
                                                        case 'a':
790
                                                                clean = true;
791
                                                                break;
792
                                                        case 'r':
793
                                                                ide.targetmode = 1;
794
                                                                break;
795
                                                        case '1':
796
                                                                ide.targetmode = 2;
797
                                                                break;
798
                                                        case '2':
799
                                                                ide.targetmode = 3;
800
                                                                break;
801
                                                        case 'm':
802
                                                                ide.release.createmap = ide.debug.createmap = true;
803
                                                                break;
804
                                                        case 'b':
805
                                                                ide.release.def.blitz = ide.debug.def.blitz = 1;
806
                                                                break;
807
                                                        case 's':
808
                                                                ide.debug.linkmode = ide.release.linkmode = 1;
809
                                                                break;
810
                                                        case 'd':
811
                                                                ide.debug.def.debug = 0;
812
                                                                break;
813
                                                        case 'S':
814
                                                                ide.debug.linkmode = ide.release.linkmode = 2;
815
                                                                break;
816
                                                        case 'e':
817
                                                                stoponerror = true;
818
                                                                break;
819
                                                        case 'M':
820
                                                                makefile = true;
821
                                                                break;
822
                                                        case 'v':
823
                                                                ide.console.verbosebuild = true;
824
                                                                break;
825
                                                        case 'l':
826
                                                                break;
827
                                                        case 'x':
828
                                                                exporting = 1;
829
                                                                break;
830
                                                        case 'X':
831
                                                                exporting = 2;
832
                                                                break;
833
                                                        case 'k':
834
                                                                deletedir = false;
835
                                                                break;
836
                                                        default:
837
                                                                SilentMode = false;
838
                                                                Puts("Invalid build option(s)");
839
                                                                SetExitCode(3);
840
                                                                return;
841
                                                        }
842
                                        }
843
                                        else {
844
                                                ide.debug.target_override = ide.release.target_override = true;
845
                                                ide.debug.target = ide.release.target = mkf = arg[i];
846
                                        }
847
                                if(clean)
848
                                        ide.Clean();
849
                                if(exporting) {
850
                                        mkf = GetFullPath(mkf);
851
                                        Cout() << mkf << '\n';
852
                                        RealizeDirectory(mkf);
853
                                        if(makefile)
854
                                                ide.ExportMakefile(mkf);
855
                                        else
856
                                                ide.ExportProject(mkf, exporting == 2, false, deletedir);
857
                                }
858
                                else
859
                                if(makefile) {
860
                                        ide.SaveMakeFile(IsNull(mkf) ? "Makefile" : mkf, false);
861
                                        SetExitCode(0);
862
                                }
863
                                else
864
                                if(ide.Build())
865
                                        SetExitCode(0);
866
                                else {
867
                                        if(stoponerror)
868
                                                PromptOK("TheIDE: Error while building " + DeQtf(arg[1]) + "!");
869
                                        SetExitCode(1);
870
                                }
871
                                return;
872
                        }
873
                }
874

    
875
                ide.LoadConfig();
876
                if(arg.GetCount()==2){
877
                        LoadVars(arg[0]);
878
                        ide.SetMain(arg[1]);
879
                        clset=true;
880
                }
881
                ide.LoadAbbr();
882

    
883
                ide.SyncCh();
884

    
885
                DelTemps();
886
                if(splash_screen) {
887
                        ShowSplash();
888
                        Ctrl::ProcessEvents();
889
                }
890

    
891
        #ifdef PLATFORM_POSIX
892
                int p=UpdaterCfg().period;
893
                if(!IsNull(p)) {
894
                        int next=GetUtcTime()-UpdaterCfg().last+abs(p)*60;
895
                        if(p <= 0 || next <= 0)
896
                                ide.PostCallback(callback1(&ide,&Ide::CheckUpdates,false),0);
897
                        if(p != 0)
898
                                ide.SetTimeCallback(max(0, next),callback1(&ide,&Ide::SetUpdateTimer,abs(p)));
899
                }
900
        #endif
901

    
902
                ide.editor_bottom.Zoom(0);
903
                ide.right_split.Zoom(0);
904
                if(FileExists(ConfigFile("developide"))) {
905
        #ifdef PLATFORM_WIN32
906
                        InstallCrashDump();
907
        #endif
908
                        Ini::user_log = true;
909
                }
910
                ide.LoadLastMain();
911
                if(clset || ide.OpenMainPackage()) {
912
                        ide.SaveLastMain();
913
                        ide.isscanning++;
914
                        ide.MakeTitle();
915
                        SyncRefs();
916
                        ide.FileSelected();
917
                        ide.isscanning--;
918
                        ide.MakeTitle();
919
                        if(!IdeExit)
920
                                ide.Run();
921
                        ide.SaveConfigOnTime();
922
                        ide.SaveLastMain();
923
                }
924
        #ifdef PLATFORM_POSIX
925
                StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml"));
926
        #endif
927
                SaveCodeBase();
928
                DelTemps();
929
                ReduceCache();
930
        }
931
        catch(const CParser::Error& e) {
932
                Exclamation("Parser error " + e);
933
                LOG("!!!!! Parser error " + e);
934
        }
935
        catch(const Exc& e) {
936
                Exclamation("Exception " + e);
937
                LOG("!!!!! Exception " << e);
938
        }
939
#ifdef PLATFORM_POSIX
940
        catch(...) {
941
                Exclamation("Unknown exception !");
942
                LOG("!!!!! Unknown exception");
943
        }
944
#endif
945
}