-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtia.adb
4922 lines (4288 loc) · 174 KB
/
tia.adb
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
------------------------------------------------------------------------------
-- TIA (Tiny IDE for Ada/Anything) --
-- --
-- Developed by Ken O. Burtch --
------------------------------------------------------------------------------
-- --
-- Copyright (C) 1999-2007 PegaSoft Canada --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. This is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 distributed with this; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- This is maintained at http://www.pegasoft.ca/tia.html --
-- --
------------------------------------------------------------------------------
pragma warnings(off); -- don't care that it's non-portable unit
with ada.command_line.environment; -- for return result code, etc.
pragma warnings(on);
with ada.text_io, -- for printing results in non-interactive modes
common, -- texttools' root package
os, -- clock and O/S stuff for Ken's windows
strings, -- Ken's string functions
userio, -- Ken's ASCII drawing stuff
controls, -- controls/widgets for Ken's windows
windows, -- Ken's windows
english, -- common English words
tiacommon, -- tia common definitions
tiatips, -- tia startup help tips
printer, -- line printer support
tiadebug, -- TIA debugger
tiacvs, -- TIA CVS support
tiasvn, -- TIA SVN support
tiagcc, -- TIA GNAT/GCC definitions
gen_list; -- texttools' generic linked list package
use common, os, strings, userio, controls, windows, english,
tiacommon, tiatips, printer, tiadebug, tiacvs, tiasvn;
Pragma Optimize( Space );
-- make program as small as possible
procedure tia is ---------------------------------------------------
-------------------------------------------------------------------------------
-- O/S BINDINGS
-------------------------------------------------------------------------------
procedure sync;
pragma import( C, sync );
-- sync syscall: flush disks
function getuid return integer;
pragma import( C, getuid );
-- determine who we are
-------------------------------------------------------------------------------
-- STR255 INDEX LIST
--
-- A list of indexes into a linked list of 255 character strings.
-------------------------------------------------------------------------------
package Str255IndexList is new gen_list( Str255List.AListIndex,
">", "=" );
-- list of Str255List indexes
-------------------------------------------------------------------------------
-- DECLARATIONS
-------------------------------------------------------------------------------
Done : boolean := false; -- quitting program
Text2Find : str255 := NullStr255; -- last find dialog string
Text2Replace : str255 := NullStr255; -- last find dialog replace string
FindBackwards : boolean := false; -- true if find backwards selected
FindRegExp : boolean := false; -- true if find regexp selected
Replacing : boolean := false; -- true if replacing text
-------------------------------------------------------------------------------
-- UTILITIES
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- UPDATE SOURCE DISPLAY
--
-- Update scroll bar and screen statistics after a major change to the
-- source box (i.e. a Edit/Goto or File/Open)
-------------------------------------------------------------------------------
procedure UpdateSourceDisplay is
begin
SetThumb( SourceBar, GetCurrent( SourceBox ) );
UpdateMarginStats;
end UpdateSourceDisplay;
-------------------------------------------------------------------------------
-- LOADING / SAVING
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- LOAD PROJECT
--
-- Load a project file and set our global vars accordinly. If the path isn't
-- known, this is a new project and initialize global vars to defaults. --
-------------------------------------------------------------------------------
procedure LoadProject is
function RebuildAlert return boolean is
Desc1Line : aliased AStaticLine;
Desc2LIne : aliased AStaticLine;
Desc3LIne : aliased AStaticLine;
YesButton : aliased ASimpleButton;
NoButton : aliased ASimpleButton;
DT : aDialogTaskRecord;
begin
OpenWindow( To255( "Platform Change" ), 1, 1, 78, 9 );
Init( Desc1Line, 1, 2, 76, 2 );
SetText( Desc1Line, "The development environment of the project has changed. A full rebuild" );
AddControl( Desc1Line'unchecked_access, false );
Init( Desc2Line, 1, 3, 76, 3 );
SetText( Desc2Line, "will ensure that all files are consistent with the new platform." );
AddControl( Desc2Line'unchecked_access, false );
Init( Desc3Line, 1, 5, 76, 5 );
SetText( Desc3Line, "Do you want to fully rebuild the project on the next build?" );
AddControl( Desc3Line'unchecked_access, false );
Init( YesButton, 15, 7, 35, 7, 'r' );
SetText( YesButton, To255( "Rebuild" ) );
AddControl( YesButton'unchecked_access, false );
Init( NoButton, 50, 7, 65, 7, 'n' );
SetText( NoButton, To255( "No" ) );
AddControl( NoButton'unchecked_access, false );
DoDialog( DT );
CloseWindow;
return DT.control /= 4;
end RebuildAlert;
TempList : Str255List.List;
TempStr : Str255;
i : integer;
begin
SourcePath := NullStr255;
NeedsFullRecompile := false;
ClearLoadExceptions;
if not IsFile( ProjectPath ) then
NoteAlert( "Starting new project" );
return;
end if;
LoadList( ProjectPath, TempList );
if LastError /= 0 then
StopAlert( "Couldn't load " & ToString( ProjectPath ) );
return;
end if;
Str255List.Pull( TempList, Proj_GCCOptions );
Str255List.Pull( TempList, Proj_LinkOptions );
Str255List.Pull( TempList, Proj_Main );
Str255List.Pull( TempList, Proj_GUI );
Str255List.Pull( TempList, TempStr );
Proj_Opt := Short_Short_Integer( ToInteger( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_CPU := Short_Short_Integer( ToInteger( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_Debug := Short_Short_Integer( ToInteger( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_Kind := Short_Short_Integer( ToInteger( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_Builder := Short_Short_Integer( ToInteger( TempStr ) );
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Proj_Static := i = 1;
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Proj_Egcs := i = 1;
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Proj_Alt := i = 1;
Str255List.Pull( TempList, SourcePath );
if Str255List.Length( TempList ) > 0 then -- not in version 0.6
SessionLog( "LoadProject: version 0.6.1 project file" );
Str255List.Pull( TempList, TempStr );
Proj_BackupTime := ATimeStamp'value( ToString( TempStr ) );
if Str255List.Length( TempList ) > 0 then -- not in version 0.6.1
Str255List.Pull( TempList, Proj_PlatSig );
if Str255List.Length( TempList ) > 0 then -- not in version 0.7.0
Str255List.Pull( TempList, TempStr );
Proj_KeyCount := long_integer'value( ToString( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_BuildCount := long_integer'value( ToString( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_BuildTime := ATimeStamp'value( ToString( TempStr ) );
Str255List.Pull( TempList, TempStr );
Proj_LineCount := long_integer'value( ToString( TempStr ) );
if Str255List.Length( TempList ) > 0 then -- 0.7.3
Str255List.Pull( TempList, Proj_BuildTimeStr );
if Str255List.Length( TempList ) > 0 then -- 1.0.0
Str255List.Pull( TempList, TempStr );
Proj_UpdateTime := ATimeStamp'value( ToString( TempStr ) );
if Str255List.Length( TempList ) > 0 then -- 1.0.3
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Proj_GCJ := i = 1;
Str255List.Pull( TempList, Proj_Repository );
end if;
end if;
end if;
end if;
end if;
else
SessionLog( "LoadProject: version 0.6 project file" );
end if;
Str255List.Clear( TempList );
IsCVSProject := IsDirectory( To255( "./CVS" ) );
IsSVNProject := IsDirectory( To255( "./.svn" ) );
if IsFile( SourcePath ) then
UpdateQuickOpen( SourcePath, 1, 1 );
else
SourcePath := NullStr255;
end if;
-- project signature check
SessionLog( "LoadProject: Old Platform Signature: " & Proj_PlatSig );
SessionLog( "LoadProject: New Platform Signature: " & PlatformSig );
if Proj_PlatSig /= PlatformSig then
NeedsFullRecompile := RebuildAlert;
end if;
-- Lock the Project
if length( SourcePath ) > 0 then
LockProject;
else
ProjectLocked := true;
-- new project? Pretend it's locked.
end if;
if not ProjectLocked then
NoteAlert( "Project in use: read-only session" );
end if;
if Proj_Builder = 1 then -- gnatmake?
if not UNIX( "gnatmake 2>/dev/null ; [ $? -eq 4 ] && exit 0" ) then
CautionAlert( "I can't find gnatmake with your PATH variable" );
end if;
elsif Proj_Builder = 4 then -- jgnatmake?
if not UNIX( "jgnatmake 2>/dev/null ; [ $? -eq 4 ] && exit 0" ) then
CautionAlert( "I can't find jgnatmake with your PATH variable" );
end if;
end if;
UpdateSourceDisplay;
end LoadProject;
-------------------------------------------------------------------------------
-- SAVE PROJECT
--
-- Save the current project. If the project has no pathname, assume it is a
-- new project and prompt for a pathname.
-------------------------------------------------------------------------------
procedure SaveProject is
TempList : Str255List.List;
TempStr : Str255;
ThisPath : Str255;
ImportPath : Str255;
TempFile : Str255;
ssf : ASelectSaveFileRec;
WasNew : boolean := length( ProjectPath ) = 0;
begin
UnlockProject;
if WasNew then
ssf.Prompt := To255( "Save project as ..." );
ssf.Default := To255( "untitled.adp" );
SelectSaveFile( ssf );
if ssf.replied then
ProjectPath := ssf.path & "/" & ssf.fname;
else
NoteAlert( "User Cancelled: project not saved" );
SessionLog( "User Cancelled: project not saved" );
end if;
end if;
if length( ProjectPath ) > 0 then
Str255List.Queue( TempList, Proj_GCCOptions );
Str255List.Queue( TempList, Proj_LinkOptions );
Str255List.Queue( TempList, Proj_Main );
Str255List.Queue( TempList, Proj_GUI );
TempStr := To255( short_short_integer'image( Proj_Opt ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( short_short_integer'image( Proj_CPU ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( short_short_integer'image( Proj_Debug ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( short_short_integer'image( Proj_Kind ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( short_short_integer'image( Proj_Builder ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Proj_Static ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Proj_Egcs ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Proj_Alt ) ) );
Str255List.Queue( TempList, TempStr );
Str255List.Queue( TempList, SourcePath );
TempStr := To255( ATimeStamp'image( Proj_BackupTime ) );
Str255List.Queue( TempList, TempStr );
Str255List.Queue( TempList, Proj_PlatSig );
TempStr := To255( long_integer'image( Proj_KeyCount ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( long_integer'image( Proj_BuildCount ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( ATimeStamp'image( Proj_BuildTime ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( long_integer'image( Proj_LineCount ) );
Str255List.Queue( TempList, TempStr );
Str255List.Queue( TempList, Proj_BuildTimeStr );
TempStr := To255( ATimeStamp'image( Proj_UpdateTime ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Proj_GCJ ) ) );
Str255List.Queue( TempList, TempStr );
Str255List.Queue( TempList, Proj_Repository );
SaveList( ProjectPath, TempList );
if LastError = TT_OK then
SessionLog( "Project saved as " & ProjectPath );
if HasCVS and Opt_CVS and WasNew then
CVSImport;
end if;
if HasSVN and Opt_SVN and WasNew then
SVNImport;
end if;
else
SessionLog( "SaveProject: Error saving file", LastError );
StopAlert( "Error saving file: # " & AnErrorCode'image(
LastError ) );
end if;
end if;
Str255List.Clear( TempList );
end SaveProject;
-------------------------------------------------------------------------------
-- LOAD OPTIONS
--
-- Load the global options from the options file (usually at startup).
-------------------------------------------------------------------------------
procedure LoadOptions is
TempList : Str255List.List;
TempStr : Str255;
i : integer;
begin
if not IsFile( OptionsPath ) then
return; -- no file, use defaults
end if;
LoadList( OptionsPath, TempList );
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Opt_Quiet := i = 1;
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Opt_Blue := i = 1;
if Str255List.length( TempList ) > 0 then -- TIA 0.6 file won't have this
Str255List.Pull( TempList, Opt_Backup );
end if;
if Str255List.length( TempList ) > 0 then -- TIA 0.6.1 file won't have this
Str255List.Pull( TempList, TempStr );
Opt_TipNumber := ToInteger( TempStr );
end if;
if Str255List.length( TempList ) > 0 then -- TIA 0.7.0 file won't have this
Str255List.Pull( TempList, TempStr );
Opt_KeyCount := long_integer'value( ToString( TempStr ) );
end if;
if Str255List.length( TempList ) > 0 then -- old TIA won't have this
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Opt_CVS := i = 1;
end if;
if Str255List.length( TempList ) > 0 then -- old TIA won't have this
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
Opt_SVN := i = 1;
end if;
if Str255List.length( TempList ) > 0 then -- old TIA won't have this
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
KeywordHilight := aPenColourName'val( i );
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
FunctionHilight := aPenColourName'val( i );
Str255List.Pull( TempList, TempStr );
i := ToInteger( TempStr );
AutoHelpStyle := anAutoHelpStyle'val( i );
else
KeywordHilight := yellow;
FunctionHilight := purple;
AutoHelpStyle := both;
end if;
Str255List.Clear( TempList );
BlueBackground( Opt_Blue );
end LoadOptions;
-------------------------------------------------------------------------------
-- SAVE OPTIONS
--
-- Save the global options to the options file (usually at shutdown).
-------------------------------------------------------------------------------
procedure SaveOptions is
TempList : Str255List.List;
TempStr : Str255;
begin
TempStr := To255( integer'image( boolean'pos( Opt_Quiet ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Opt_Blue ) ) );
Str255List.Queue( TempList, TempStr );
Str255List.Queue( TempList, Opt_Backup );
TempStr := To255( Opt_TipNumber'img );
Str255List.Queue( TempList, TempStr );
TempStr := To255( Opt_KeyCount'img );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Opt_CVS ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( boolean'pos( Opt_SVN ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( aPenColourName'pos( KeywordHilight ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( aPenColourName'pos( FunctionHilight ) ) );
Str255List.Queue( TempList, TempStr );
TempStr := To255( integer'image( anAutoHelpStyle'pos( AutoHelpStyle ) ) );
Str255List.Queue( TempList, TempStr );
SaveList( OptionsPath, TempList );
if LastError /= TT_OK then
SessionLog( "SaveOptions: Error saving file", LastError );
StopAlert( "Error saving options: # " & AnErrorCode'image(
LastError ) );
end if;
Str255List.Clear( TempList );
end SaveOptions;
-------------------------------------------------------------------------------
-- SET KEYWORDS
--
-- Set the appropriate keyword hilighting based on the specified pathname
-- (usually the global variable SourcePath).
-------------------------------------------------------------------------------
procedure SetKeywords( SourcePath : str255 ) is
begin
-- Set main window's SourceEditBox to the appropriate
-- language.
SetSourceLanguage( SourceBox, SourceLanguage );
SetHTMLTagsStyle( SourceBox, hilight => false ); -- default
if SourceLanguage = PHP then
SetHTMLTagsStyle( SourceBox, hilight => true );
elsif SourceLanguage = HTML then
SetHTMLTagsStyle( SourceBox, hilight => true );
end if;
if SourceLanguage = UnknownLanguage then
NoteAlert( "I'm treating this unknown file as plain text" );
--ClearKeywords( SourceBox );
end if;
Invalid( SourceBox ); -- force redraw
end SetKeywords;
-------------------------------------------------------------------------------
-- REFERSH SOURCE
--
-- Reload the source file because an outside program (e.g. CVS) has updated it.
-------------------------------------------------------------------------------
procedure RefreshSource is
CursorX : integer;
CursorY : Str255List.AListIndex;
begin
CursorX := GetPosition( SourceBox );
CursorY := GetCurrent( SourceBox );
Str255List.Clear( SourceText ); -- discard old source
LoadSourceFile( SourcePath, SourceText ); -- load new source
SetList( SourceBox, SourceText ); -- put in window
Str255List.Clear( SourceText ); -- no longer used
SetCursor( SourceBox, CursorX, CursorY ); -- restore cursor
UpdateSourceDisplay;
end RefreshSource;
-------------------------------------------------------------------------------
-- DIALOGS
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- EDIT MACROS
--
-- Open a window and allow the user to edit the contents of the TextTools
-- keyboard macro file.
-------------------------------------------------------------------------------
procedure EditMacros is
MacroList : Str255List.List;
MacrosToSave : Str255List.List;
WasChanges : boolean;
s : str255;
begin
if NotEmpty( To255( "$SYS/macro_file" ) ) then
LoadList( To255( "$SYS/macro_file" ), MacroList );
end if;
Str255List.Queue( MacroList, NullStr255 );
EditListInfo( "Macro List", 0, 0, 79, 24, MacroList, WasChanges );
if WasChanges then
while Str255List.length( MacroList ) > 0 loop
Str255List.Pull( MacroList, s );
if length( s ) > 0 then
Str255List.Push( MacrosToSave, s );
end if;
end loop;
SaveList( To255( "$SYS/macro_file" ), MacrosToSave );
if LastError = TT_OK then
NoteAlert( "Restart the program to see changes." );
else
SessionLog( "EditMacros: Error saving file", LastError );
StopAlert( "Error saving file: # " & AnErrorCode'image(
LastError ) );
end if;
Str255List.Clear( MacrosToSave );
end if;
Str255List.Clear( MacroList );
end EditMacros;
-------------------------------------------------------------------------------
-- DO GDB
--
-- Run the gdb (or gnatgdb for ALT version) debugger. --
-------------------------------------------------------------------------------
procedure DoGDB is
begin
if Proj_Debug /= 3 then
NoteAlert( "Project Debug must be set to Prerelease" );
return;
end if;
if Proj_ALT then
UNIX( "gnatgdb " & Proj_Main );
else
UNIX( "gdb " & Proj_Main );
end if;
end DoGDB;
-------------------------------------------------------------------------------
-- DO GUI
--
-- Run the user's GUI builder as selected in proect/parameters.
-------------------------------------------------------------------------------
procedure DoGUI is
begin
UNIX( Proj_GUI );
end DoGUI;
-------------------------------------------------------------------------------
-- FIND SUBPROGRAM
--
-- Create a list of all the subprogram headers in the current source file.
-- Allow the user to chose one and move to that line.
-------------------------------------------------------------------------------
procedure FindSubprogram is
SubBox : aliased ARadioList;
SubBar : aliased AScrollBar;
GotoButton : aliased ASimpleButton;
CancelButton : aliased ASimpleButton;
TheList : Str255List.List;
TheButtons : BooleanList.List;
ThePositions : Str255IndexList.List;
SourceText : Str255List.List;
-- this is a reference. Do not clear().
First : integer;
TempStr : Str255;
Move2Line : Str255List.AListIndex := 0;
DT : ADialogTaskRecord;
begin
SourceText := GetList( SourceBox );
for i in 1..Str255List.Length( SourceText ) loop
Str255List.Find( SourceText, i, TempStr );
TempStr := ToLower( TempStr );
if length( TempStr ) > 0 then
First := Index_Non_Blank( TempStr );
-- should not be case sensitive
begin
if SourceLanguage = Perl then
if Slice( TempStr, First, First+3 ) = "sub " then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
end if;
else
if Slice( TempStr, First, First+9 ) = "procedure " then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
elsif Slice( TempStr, First, First+8 ) = "function " then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
SessionLog( TempStr );
end if;
end if;
exception when others => null;
-- string exception could be raised on short strings
end;
end if;
end loop;
if Str255List.Length( TheList ) = 0 then
NoteAlert( "There are no subprograms" );
goto Done;
end if;
OpenWindow( To255( "Find Subprogram" ), 1, 1, DisplayInfo.H_Res-2, DisplayInfo.V_Res-1,
Normal );
BooleanList.Replace( TheButtons, 1, True );
Init( SubBox, 1, 2, DisplayInfo.H_Res-4, DisplayInfo.V_Res-4 );
SetList( SubBox, TheList );
SetChecks( SubBox, TheButtons );
AddControl( SubBox'unchecked_access, false );
Init( SubBar, DisplayInfo.H_Res-3, 1, DisplayInfo.H_Res-3,
DisplayInfo.V_Res-4 );
AddControl( SubBar'unchecked_access, false );
Init( GotoButton, 2, DisplayInfo.V_Res-3, 11, DisplayInfo.V_Res-3, 'g' );
SetText( GotoButton, To255( "Goto" ) );
SetInstant( GotoButton );
AddControl( GotoButton'unchecked_access, false );
Init( CancelButton, 22, DisplayInfo.V_Res-3, 31, DisplayInfo.V_Res-3, 'l' );
SetText( CancelButton, To255( "Cancel" ) );
SetInstant( CancelButton );
AddControl( CancelButton'unchecked_access, false );
DoDialog( DT );
if DT.control = 3 then -- goto pressed?
Str255IndexList.Find( ThePositions, GetCheck( SubBox ), Move2Line );
MoveCursor( SourceBox, 0,
Move2Line - GetCurrent( SourceBox ) );
end if;
CloseWindow;
<<Done>>
Str255List.Clear( TheList );
BooleanList.Clear( TheButtons );
Str255IndexList.Clear( ThePositions );
UpdateSourceDisplay;
end FindSubprogram;
-------------------------------------------------------------------------------
-- FIND TAGGED RECORD
--
-- Create a list of all tagged record (Ada object) headers in the current
-- program. Allow the user to chose one and move to that line.
-------------------------------------------------------------------------------
procedure FindTaggedRecord is
TagBox : aliased ARadioList;
TagBar : aliased AScrollBar;
GotoButton : aliased ASimpleButton;
CancelButton : aliased ASimpleButton;
TheList : Str255List.List;
TheButtons : BooleanList.List;
ThePositions : Str255IndexList.List;
SourceText : Str255List.List;
-- this is a reference. Do not clear().
TempStr : Str255;
Move2Line : Str255List.AListIndex := 0;
DT : ADialogTaskRecord;
begin
SourceText := GetList( SourceBox );
for i in 1..Str255List.Length( SourceText ) loop
Str255List.Find( SourceText, i, TempStr );
if length( TempStr ) > 0 then
-- should not be case sensitive
if SourceLanguage = Ada_Language then
TempStr := ToLower( TempStr );
if Index( TempStr, "tagged record" ) > 0 then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
elsif Index( TempStr, "with record" ) > 0 then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
elsif Index( TempStr, "with private" ) > 0 then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
end if;
elsif SourceLanguage = Java or SourceLanguage = PHP then
TempStr := ToLower( TempStr );
if Index( TempStr, "class " ) > 0 then
Str255List.Queue( TheList, TempStr );
BooleanList.Queue( TheButtons, False );
Str255IndexList.Queue( ThePositions, i );
end if;
end if;
end if;
end loop;
if Str255List.Length( TheList ) = 0 then
NoteAlert( "There are no tagged records" );
goto Done;
end if;
OpenWindow( To255( "Find Class / Tagged Record" ), 1, 1, DisplayInfo.H_Res-2, DisplayInfo.V_Res-1,
Normal );
BooleanList.Replace( TheButtons, 1, True );
Init( TagBox, 1, 2, DisplayInfo.H_Res-4, DisplayInfo.V_Res-4 );
SetList( TagBox, TheList );
SetChecks( TagBox, TheButtons );
AddControl( TagBox'unchecked_access, false );
Init( TagBar, DisplayInfo.H_Res-3, 1, DisplayInfo.H_Res-3,
DisplayInfo.V_Res-4 );
AddControl( TagBar'unchecked_access, false );
Init( GotoButton, 2, DisplayInfo.V_Res-3, 11, DisplayInfo.V_Res-3, 'g' );
SetText( GotoButton, To255( "Goto" ) );
SetInstant( GotoButton );
AddControl( GotoButton'unchecked_access, false );
Init( CancelButton, 22, DisplayInfo.V_Res-3, 31, DisplayInfo.V_Res-3, 'l' );
SetText( CancelButton, To255( "Cancel" ) );
SetInstant( CancelButton );
AddControl( CancelButton'unchecked_access, false );
DoDialog( DT );
if DT.control = 3 then -- goto pressed?
Str255IndexList.Find( ThePositions, GetCheck( TagBox ), Move2Line );
MoveCursor( SourceBox, 0,
Move2Line - GetCurrent( SourceBox ) );
end if;
CloseWindow;
<<Done>>
Str255List.Clear( TheList );
BooleanList.Clear( TheButtons );
Str255IndexList.Clear( ThePositions );
UpdateSourceDisplay;
end FindTaggedRecord;
-------------------------------------------------------------------------------
-- FIND DIALOG
--
-- Find menu/Find/Replace
--
-- Open a window and prompt the user for text to find, with appropriate
-- checkbox options.
-------------------------------------------------------------------------------
function FindDialog return boolean is
TextLine : aliased AnEditLine;
FindButton : aliased ASimpleButton;
CancelButton : aliased ASimpleButton;
BackwardsButton : aliased ACheckBox;
RegExpButton : aliased ACheckBox;
ReplaceButton : aliased ASimpleButton;
ReplaceLabel : aliased AStaticLine;
ReplaceLine : aliased AnEditLine;
DT : ADialogTaskRecord;
FindNotCancelled : boolean := true;
-- Text2Find is defined in encompasing procedure
begin
OpenWindow( To255( "Find/Replace Text" ), 10, 9, 70, 17, Normal );
Init( TextLine, 1, 2, 58, 2 );
SetText( TextLine, Text2Find );
AddControl( TextLine'unchecked_access, false );
Init( ReplaceLabel, 1, 4, 9, 4 );
SetText( Replacelabel, To255( "Replace:" ) );
AddControl( ReplaceLabel'unchecked_access, false );
Init( ReplaceLine, 10, 4, 58, 4 );
SetText( ReplaceLine, Text2Replace );
AddControl( ReplaceLine'unchecked_access, false );
Init( FindButton, 2, 6, 11, 6, s_Find_Hot );
SetText( FindButton, s_Find );
SetInstant( FindButton );
AddControl( FindButton'unchecked_access, false );
Init( CancelButton, 12, 6, 22, 6, s_Cancel_Hot );
SetText( CancelButton, s_Cancel );
SetInstant( CancelButton );
AddControl( CancelButton'unchecked_access, false );
Init( BackwardsButton, 24, 6, 32, 6, 'b' );
SetText( BackwardsButton, To255( "Back" ) );
SetCheck( BackwardsButton, FindBackwards );
AddControl( BackwardsButton'unchecked_access, false );
Init( RegExpButton, 35, 6, 46, 6, 'x' );
SetText( RegExpButton, To255( "RegExp" ) );
SetCheck( RegExpButton, FindRegExp );
AddControl( RegExpButton'unchecked_access, false );
Init( ReplaceButton, 47, 6, 59, 6, 'r' );
SetText( ReplaceButton, To255( "Replace" ) );
SetInstant( ReplaceButton );
AddControl( ReplaceButton'unchecked_access, false );
loop
DoDialog( DT );
case DT.control is
when 4 => Text2Find := GetText( TextLine );
Text2Replace := NullStr255;
FindBackwards := GetCheck( BackwardsButton );
FindRegExp := GetCheck( RegExpButton );
Replacing := false;
exit;
when 5 => FindNotCancelled := false; -- find cancelled
Text2Find := NullStr255;
Text2Replace := NullStr255;
Replacing := false;
exit;
when 7 => if GetCheck( RegExpButton ) then
SetStatus( ReplaceButton, Off );
else
SetStatus( ReplaceButton, On );
end if;
when 8 => Text2Find := GetText( TextLine );
Text2Replace := GetText( ReplaceLine );
FindBackwards := GetCheck( BackwardsButton );
FindRegExp := GetCheck( RegExpButton );
Replacing := true;
exit;
when others => null;
end case;
end loop;
CloseWindow;
if FindNotCancelled then
UpdateSourceDisplay;
end if;
return FindNotCancelled;
end FindDialog;
-------------------------------------------------------------------------------
-- SAVE SOURCE
--
-- File menu/Save
--
-- Save the current source file. If DoBackgroundUpdate is true, compile
-- quietly after saving. If ForcePrompt is true, prompt for pathname,
-- otherwise only prompt if the path is not known. --
-------------------------------------------------------------------------------
procedure SaveSource( DoBackgroundUpdate : boolean := true;
ForcePrompt : boolean := false ) is
ProjectDir : str255;
TempHeader : str255list.list;
ssf : ASelectSaveFileRec;
SaveAs : boolean := false;
begin
-- no saving if read-only session
if not ProjectLocked then
return;
end if;
TempHeader := GetList( SourceBox );
if Str255List.length( TempHeader ) = 0 then
if length( SourcePath ) > 0 then -- if untitled, don't bother
NoteAlert( "Blank source file not saved" );
end if;
SessionLog( "Blank source file not saved" );
return;
elsif not WasTouched( SourceBox ) and not ForcePrompt then
SessionLog( "SaveSource: save skipped--no source changes" );
return;
elsif length( SourcePath ) = 0 or ForcePrompt then
SaveAs := true;
ProjectDir := GetPath;
ssf.Prompt := To255( "Save as ..." );
if sourceType = AdaBody then
ssf.Default := To255( "untitled.adb" );
elsif sourceType = AdaSpec then
ssf.Default := To255( "untitled.ads" );
elsif sourceType = ShellScript then
ssf.Default := To255( "untitled.sh" );
elsif sourceType = CHeader then
ssf.Default := To255( "untitled.h" );
elsif sourceType = CSource then
ssf.Default := To255( "untitled.c" );
elsif sourceType = CPPheader then
ssf.Default := To255( "untitled.h" );
elsif sourceType = CPPSource then
ssf.Default := To255( "untitled.cc" );
elsif sourceType = JavaSource then
ssf.Default := To255( "untitled.java" );
elsif sourceType = BushSource then
ssf.Default := To255( "untitled.bush" );
elsif sourceType = PerlSource then
ssf.Default := To255( "untitled.pl" );
elsif sourceType = PerlModule then
ssf.Default := To255( "untitled.pm" );
elsif sourceType = PHPSource then
ssf.Default := To255( "untitled.php" );
elsif sourceType = WebPage then
ssf.Default := To255( "untitled.html" );
else
ssf.Default := To255( "untitled.adb" );
end if;
SelectSaveFile( ssf );
-- ssf changes current path, but we want to stick to the
-- project directory by default. Get..Title will show
-- absolute path if source not in current (project) directory.
if ssf.replied then
SourcePath := ssf.path & "/" & ssf.fname;
SetPath( ProjectDir ); -- restore old path
end if;
if (not ssf.replied) or (length( SourcePath ) = 0) then
SessionLog( ssf.Prompt & " was cancelled" );
SetPath( ProjectDir ); -- restore old path
return;
end if;
end if;
--TempHeader := GetList( SourceBox );
if SaveAs and IsFile( SourcePath ) then -- overwrite?
SaveSourceFile( SourcePath, TempHeader ); -- save source
SetSourceLanguage( SourcePath ); -- determine the language
SetKeywords( SourcePath ); -- check hilighting
MoveCursor( SourceBox, 0, 0 ); -- save deletes spaces
elsif SaveAs then -- new file?
SaveSourceFile( SourcePath, TempHeader ); -- save source
if HasCVS and Opt_CVS and IsCVSProject then
CVSAdd; -- add to CVS
end if;
if HasSVN and Opt_SVN and IsSVNProject then
SVNAdd; -- add to CVS
end if;
SetSourceLanguage( SourcePath ); -- determine the language
SetKeywords( SourcePath ); -- check hilighting
MoveCursor( SourceBox, 0, 0 ); -- save deletes spaces
else -- simple save?
SaveSourceFile( SourcePath, TempHeader ); -- just save
end if;
if LastError = TT_OK then
SessionLog( "Saved as " & SourcePath );
else
SessionLog( "SaveSource: Error saving file", LastError );