-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiacommon.adb
1787 lines (1599 loc) · 63.3 KB
/
tiacommon.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 COMMON (package body) --
-- --
-- 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 --
-- --
------------------------------------------------------------------------------
with System;
with ada.text_io, ada.strings.unbounded.text_io;
use ada.text_io,
ada.strings.unbounded,
ada.strings.unbounded.text_io;
package body tiacommon is
------------------------------------------------------------------------------
-- O/S BINDINGS
------------------------------------------------------------------------------
---> Pipe Stuff -------------------------------------
type AStdioFileID is new System.Address;
-- a C standard IO (stdio) file id
function popen( command, mode : string ) return AStdioFileID;
pragma import( C, popen, "popen" );
-- opens a pipe to command
procedure pclose( result : out integer; fid : AStdioFileID );
pragma import( C, pclose, "pclose" );
pragma import_valued_procedure( pclose );
-- closes a pipe
function fgetc( fid : AStdioFileID ) return integer;
pragma import( C, fgetc, "fgetc" );
-- part of standard C library. Reads one character from a file.
-- File Stuff
-- GCC 3.x / GNAT 5.x doesn't like this. We'll use Texttools'
-- function as a workaround.
--errno : integer;
--pragma import( C, errno );
-- standard kernel error number
function C_errno return integer;
pragma import( C, C_errno, "C_errno" );
procedure C_reset_errno;
pragma import( C, C_reset_errno, "C_reset_errno" );
type aFileID is new integer;
function Open( path : string; flags, mode : integer ) return aFileID;
pragma import( C, open );
-- kernel call to open a file
procedure Close( f : aFileID );
pragma import( C, close );
-- kernel call to close a file
type writeLock_lockStruct is record
l_type : short_integer := 1; -- write lock
l_whence : short_integer := 0;
l_start : integer := 0;
l_len : integer := 0;
l_pid : integer := 0;
end record;
myLock : writeLock_lockStruct;
procedure fcntl( result : out integer; f : aFileID;
operation : integer; lock : in out writeLock_lockStruct );
pragma import( C, fcntl );
pragma import_valued_procedure( fcntl );
------------------------------------------------------------------------------
-- DECLARATIONS
------------------------------------------------------------------------------
ProjectLockFile : aFileID := 0; -- 0 if project is unlocked
PipeID : AStdioFileID; -- File ID for lpr pipe
EndOfPipe : boolean; -- true of EOF on input pipe
------------------------------------------------------------------------------
-- BACKGROUND PROCESSING
--
-- TIA compiles recently edited files in the background each time the user
-- loads another file. Although parallel compiling isn't supported yet, I've
-- defined the data structures for up to 4 machines, which are cycled through.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- INIT BACKGROUND
--
-- Setup the background processing system.
------------------------------------------------------------------------------
procedure InitBackground is
ID : str255;
begin
NextBackgroundLock := 1;
ID := To255( MyID'img );
FixSpacing( ID );
for i in ABackgroundProcessNumber'range loop
RemoteHosts( i ) := NullStr255;
BackgroundLock( i ) := BackgroundLockPrefix & ID;
end loop;
RemoteHosts( 1 ) := To255( "unused" ); -- always this host
end InitBackground;
------------------------------------------------------------------------------
-- BACKGROUND UPDATE
--
-- Perform a background update. Attempt to compile a file as a separate
-- process, ignoring compiling errors if any.
------------------------------------------------------------------------------
procedure BackgroundUpdate( source : str255 ) is
-- attempt to update object file of source in the background
Cmd : str255;
begin
-- for now, NextBackgroundLock is always '1' for a single machine
if not Opt_Quiet then
return; -- don't bother if quiet updates turned off
end if;
if SourceLanguage = Bush or SourceLanguage = Shell or SourceLanguage = Perl or SourceLanguage = PHP then
return;
end if;
if IsFile( BackgroundLock( 1 ) ) then
SessionLog( "BackgroundUpdate: last update hasn't finished it--skipping" );
else
SessionLog( "BackgroundUpdate: quietly compiling " & source );
Cmd := "touch " & BackgroundLock( 1 );
SessionLog( cmd );
UNIX( cmd );
-- (nice gcc -c opts source > /dev/null 2>/dev/null ; rm -f lock) &
if SourceLanguage = Java then
if Proj_GCJ then
Cmd := To255( "(nice gcj -c -C " );
else
Cmd := To255( "(nice javac " );
end if;
else
if Proj_Alt then
Cmd := To255( "(nice gnatgcc -c " );
else
Cmd := To255( "(nice gcc -c " );
end if;
if Proj_Opt = 1 then
null; -- nothing special for no optimize
elsif Proj_Opt = 2 then
Cmd := Cmd & "-O ";
elsif Proj_Opt = 3 then
Cmd := Cmd & "-O2 ";
else
Cmd := Cmd & "-O3 ";
end if;
if Proj_CPU = 1 then
Cmd := Cmd & "-mno-486 ";
elsif Proj_CPU = 2 then
Cmd := Cmd & "-m486 ";
else -- Pentium or P2
Cmd := Cmd & "-m486 -malign-loops=2 -malign-jumps=2"
& " -malign-functions=2 -fno-strength-reduce ";
end if;
-- debug
-- gnat 3.11 -gnatwu omitted for rebuild
if Proj_Debug = 1 then
Cmd := Cmd & "-gnatp ";
elsif Proj_Debug = 2 then
Cmd := Cmd & "-gnata ";
elsif Proj_Debug = 3 then
Cmd := Cmd & "-gnata -gnato -gnatE ";
end if;
if Proj_Kind = 4 then -- shared library
Cmd := Cmd & "-fPIC -shared ";
end if;
Cmd := Cmd & ToString( Proj_GCCOptions );
end if;
Cmd := Cmd & " " & ToString( source ) &
" > /dev/null 2> /dev/null ; rm -f " &
ToString( BackgroundLock( 1 ) ) & " ) &";
SessionLog( cmd );
UNIX( cmd );
end if;
end BackgroundUpdate;
------------------------------------------------------------------------------
-- IS BACKGROUND UPDATE
--
-- True if a background update is underway.
------------------------------------------------------------------------------
function IsBackgroundUpdate return boolean is
-- is there a background update running on this machine?
begin
return IsFile( BackgroundLock( 1 ) );
end IsBackgroundUpdate;
------------------------------------------------------------------------------
-- UPDATE QUICK OPEN
--
-- Update the quick open list for a new file.
------------------------------------------------------------------------------
procedure UpdateQuickOpen( quickpath : str255; line : Str255List.AListIndex;
posn : integer ) is
base, file : str255;
begin
-- if current directory, discard absolute path if there is one
SplitPath( quickpath, base, file );
if length( base ) > 0 then
if Element( base, length( base ) ) = '/' then
Delete( base, length(base), length(base) );
end if;
end if;
if base /= GetPath then -- not current directory?
file := QuickPath; -- use path as given
end if;
if QuickOpen1.path = file then
QuickOpen1.line := line;
QuickOpen1.posn := posn;
elsif QuickOpen2.path = file then
QuickOpen2.line := line;
QuickOpen2.posn := posn;
elsif QuickOpen3.path = file then
QuickOpen3.line := line;
QuickOpen3.posn := posn;
elsif QuickOpen4.path = file then
QuickOpen4.line := line;
QuickOpen4.posn := posn;
elsif QuickOpen5.path = file then
QuickOpen5.line := line;
QuickOpen5.posn := posn;
else
QuickOpen5 := QuickOpen4;
QuickOpen4 := QuickOpen3;
QuickOpen3 := QuickOpen2;
QuickOpen2 := QuickOpen1;
QuickOpen1 := ASourceReference'( file, line, posn );
end if;
end UpdateQuickOpen;
------------------------------------------------------------------------------
-- NEW SOURCE
--
-- Show the new source dialog box and create a new source file based on the
-- type of source chosen.
------------------------------------------------------------------------------
procedure NewSource is
AdaProcButton : aliased ARadioButton;
AdaSpecButton : aliased ARadioButton;
AdaBodyButton : aliased ARadioButton;
ShellButton : aliased ARadioButton;
CHeaderButton : aliased ARadioButton;
CSourceButton : aliased ARadioButton;
CPPHdrButton : aliased ARadioButton;
CPPSrcButton : aliased ARadioButton;
JavaSrcButton : aliased ARadioButton;
BushSrcButton : aliased ARadioButton;
PerlSrcButton : aliased ARadioButton;
PerlModButton : aliased ARadioButton;
PHPSrcButton : aliased ARadioButton;
PHPButton : aliased ARadioButton;
WebPageButton : aliased ARadioButton;
OKButton : aliased ASimpleButton;
DT : aDialogTaskRecord;
begin
OpenWindow( To255( "New Source" ), 1, 1, 60, 20 );
Init( AdaProcButton, 1, 2, 58, 2, 1, 'a' );
SetText( AdaProcButton, To255( "Ada Procedure (.adb)" ) );
AddControl( AdaProcButton'unchecked_access, false );
SetCheck( AdaProcButton, True );
Init( AdaSpecButton, 1, 3, 58, 3, 1, 's' );
SetText( AdaSpecButton, To255( "Ada Package Specification (.ads)" ) );
AddControl( AdaSpecButton'unchecked_access, false );
SetCheck( AdaSpecButton, False );
Init( AdaBodyButton, 1, 4, 58, 4, 1, 'b' );
SetText( AdaBodyButton, To255( "Ada Package Body (.adb)" ) );
AddControl( AdaBodyButton'unchecked_access, false );
SetCheck( AdaBodyButton, False );
Init( ShellButton, 1, 5, 58, 5, 1, 'l' );
SetText( ShellButton, To255( "Shell Script (.sh)" ) );
AddControl( ShellButton'unchecked_access, false );
SetCheck( ShellButton, False );
Init( CHeaderButton, 1, 6, 58, 6, 1, 'h' );
SetText( CHeaderButton, To255( "C Header (.h)" ) );
AddControl( CHeaderButton'unchecked_access, false );
SetCheck( CHeaderButton, False );
Init( CSourceButton, 1, 7, 58, 7, 1, 'c' );
SetText( CSourceButton, To255( "C Source (.c)" ) );
AddControl( CSourceButton'unchecked_access, false );
SetCheck( CSourceButton, False );
Init( CPPHdrButton, 1, 8, 58, 8, 1, '+' );
SetText( CPPHdrButton, To255( "C++ Header (.h)" ) );
AddControl( CPPHdrButton'unchecked_access, false );
SetCheck( CPPHdrButton, False );
Init( CPPSrcButton, 1, 9, 58, 9, 1, 'r' );
SetText( CPPSrcButton, To255( "C++ Source (.cc)" ) );
AddControl( CPPSrcButton'unchecked_access, false );
SetCheck( CPPSrcButton, False );
Init( JavaSrcButton, 1, 10, 58, 10, 1, 'j' );
SetText( JavaSrcButton, To255( "Java Source (.java)" ) );
AddControl( JavaSrcButton'unchecked_access, false );
SetCheck( JavaSrcButton, False );
Init( BushSrcButton, 1, 11, 58, 11, 1, 'u' );
SetText( BushSrcButton, To255( "BUSH Source (.bush)" ) );
AddControl( BushSrcButton'unchecked_access, false );
SetCheck( BushSrcButton, False );
Init( PerlSrcButton, 1, 12, 58, 12, 1, 'p' );
SetText( PerlSrcButton, To255( "Perl Source (.pl)" ) );
AddControl( PerlSrcButton'unchecked_access, false );
SetCheck( PerlSrcButton, False );
Init( PerlModButton, 1, 13, 58, 13, 1, 'm' );
SetText( PerlModButton, To255( "Perl Module (.pm)" ) );
AddControl( PerlModButton'unchecked_access, false );
SetCheck( PerlModButton, False );
Init( WebPageButton, 1, 14, 58, 14, 1, 'w' );
SetText( WebPageButton, To255( "Web Page (.html)" ) );
AddControl( WebPageButton'unchecked_access, false );
SetCheck( WebPageButton, False );
Init( PHPSrcButton, 1, 15, 58, 15, 1, 'e' );
SetText( PHPSrcButton, To255( "PHP Source (.php)" ) );
AddControl( PHPSrcButton'unchecked_access, false );
SetCheck( PHPSrcButton, False );
Init( OKButton, 27, 17, 32, 17, 'o' );
SetText( OKButton, To255( "OK" ) );
AddControl( OKButton'unchecked_access, false );
DoDialog( DT );
CloseWindow;
-- No source path. Clear source text
SourcePath := NullStr255;
Str255List.Clear( SourceText );
-- Record the source type
if GetCheck( AdaProcButton ) then
sourceType := AdaBody;
elsif GetCheck( AdaSpecButton ) then
sourceType := AdaSpec;
elsif GetCheck( AdaBodyButton ) then
sourceType := AdaBody;
elsif GetCheck( ShellButton ) then
sourceType := ShellScript;
elsif GetCheck( CHeaderButton ) then
sourceType := CHeader;
elsif GetCheck( CSourceButton ) then
sourceType := CSource;
elsif GetCheck( CPPHdrButton ) then
sourceType := CPPHeader;
elsif GetCheck( CPPSrcButton ) then
sourceType := CPPSource;
elsif GetCheck( JavaSrcButton ) then
sourceType := JavaSource;
elsif GetCheck( BushSrcButton ) then
sourceType := BushSource;
elsif GetCheck( PerlSrcButton ) then
sourceType := PerlSource;
elsif GetCheck( PerlModButton ) then
sourceType := PerlModule;
elsif GetCheck( PHPSrcButton ) then
sourceType := PHPSource;
elsif GetCheck( WebPageButton ) then
sourceType := WebPage;
else
sourceType := unknownType;
end if;
-- Create a blank source and record language
if GetCheck( AdaProcButton ) or GetCheck( AdaSpecButton ) or
GetCheck( AdaBodyButton ) then
Str255List.Queue( SourceText,
To255( "-------------------------------------------------" ) );
Str255List.Queue( SourceText,
To255( "-- UNTITLED --" ) );
Str255List.Queue( SourceText,
To255( "-- --" ) );
Str255List.Queue( SourceText,
To255( "-- Descripton: --" ) );
Str255List.Queue( SourceText,
To255( "-- --" ) );
Str255List.Queue( SourceText,
To255( "-- Written by --" ) );
Str255List.Queue( SourceText,
To255( "-- Copyright (c) Company. All rights reserved --" ) );
Str255List.Queue( SourceText,
To255( "-------------------------------------------------" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "-- $Id$" ) );
end if;
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "pragma Optimize( Space );" ) );
if GetCheck( AdaProcButton ) then
Str255List.Queue( SourceText, To255( "procedure untitled is" ) );
elsif GetCheck( AdaSpecButton ) then
Str255List.Queue( SourceText, To255( "package untitled is" ) );
else
Str255List.Queue( SourceText, To255( "package body untitled is" ) );
end if;
Str255List.Queue( SourceText, To255( "" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "-- $Log$" ) );
end if;
Str255List.Queue( SourceText, To255( "end untitled;" ) );
SourceLanguage := Ada_Language;
elsif GetCheck( ShellButton ) then
Str255List.Queue( SourceText, To255( "#!/bin/bash" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# UNTITLED" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# Descripton:" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# Written by" ) );
Str255List.Queue( SourceText,
To255( "# Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "# $Id$" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "# $Log$" ) );
end if;
Str255List.Queue( SourceText, To255( "shopt -s -o nounset" ) );
SourceLanguage := Shell;
elsif GetCheck( CHeaderButton ) or GetCheck( CPPHdrButton ) then
Str255List.Queue( SourceText, To255( "/*" ) );
Str255List.Queue( SourceText, To255( " * UNTITLED" ) );
Str255List.Queue( SourceText, To255( " *" ) );
Str255List.Queue( SourceText, To255( " * Descripton:" ) );
Str255List.Queue( SourceText, To255( " *" ) );
Str255List.Queue( SourceText, To255( " * Written by" ) );
Str255List.Queue( SourceText,
To255( " * Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( " */" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "/* $Id$ */" ) );
end if;
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "#ifdef UNTITLED_H" ) );
Str255List.Queue( SourceText, To255( "#define UNTITLED_H" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "#endif" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "/*" ) );
Str255List.Queue( SourceText, To255( " * $Log$" ) );
Str255List.Queue( SourceText, To255( " */" ) );
end if;
SourceLanguage := C;
elsif GetCheck( CSourceButton ) then
Str255List.Queue( SourceText, To255( "/*" ) );
Str255List.Queue( SourceText, To255( " * UNTITLED" ) );
Str255List.Queue( SourceText, To255( " *" ) );
Str255List.Queue( SourceText, To255( " * Descripton:" ) );
Str255List.Queue( SourceText, To255( " *" ) );
Str255List.Queue( SourceText, To255( " * Written by" ) );
Str255List.Queue( SourceText,
To255( " * Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( " */" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "/* $Id$ */" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "/*" ) );
Str255List.Queue( SourceText, To255( " * $Log$" ) );
Str255List.Queue( SourceText, To255( " */" ) );
end if;
SourceLanguage := C;
elsif GetCheck( BushSrcButton ) then
Str255List.Queue( SourceText, To255( "#!bush_path_here" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText,
To255( "-------------------------------------------------" ) );
Str255List.Queue( SourceText,
To255( "-- UNTITLED --" ) );
Str255List.Queue( SourceText,
To255( "-- --" ) );
Str255List.Queue( SourceText,
To255( "-- Descripton: --" ) );
Str255List.Queue( SourceText,
To255( "-- --" ) );
Str255List.Queue( SourceText,
To255( "-- Written by --" ) );
Str255List.Queue( SourceText,
To255( "-- Copyright (c) Company. All rights reserved --" ) );
Str255List.Queue( SourceText,
To255( "-------------------------------------------------" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "-- $Id$" ) );
end if;
Str255List.Queue( SourceText, To255( "pragma ada_95;" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "procedure untitled is" ) );
Str255List.Queue( SourceText, To255( "begin" ) );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "-- $Log$" ) );
end if;
Str255List.Queue( SourceText, To255( "end untitled;" ) );
SourceLanguage := Bush;
elsif GetCheck( PerlSrcButton ) or GetCheck( PerlModButton ) then
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# UNTITLED" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# Descripton:" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, To255( "# Written by" ) );
Str255List.Queue( SourceText,
To255( "# Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( "#" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "# $Id$" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "# $Log$" ) );
end if;
SourceLanguage := Perl;
elsif GetCheck( PHPSrcButton ) then
Str255List.Queue( SourceText, To255( "<?php" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// UNTITLED" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// Descripton:" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// Written by" ) );
Str255List.Queue( SourceText,
To255( "// Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "// $Id$" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "// $Log$" ) );
end if;
Str255List.Queue( SourceText, To255( "?>" ) );
SourceLanguage := PHP;
elsif GetCheck( WebPageButton ) then
Str255List.Queue( SourceText, To255( "<!-- UNTITLED -->" ) );
Str255List.Queue( SourceText, To255( "<!-- -->" ) );
Str255List.Queue( SourceText, To255( "<!-- Descripton: -->" ) );
Str255List.Queue( SourceText, To255( "<!-- -->" ) );
Str255List.Queue( SourceText, To255( "<!-- Written by -->" ) );
Str255List.Queue( SourceText,
To255( "<!-- Copyright (c) Company. All rights reserved -->" ) );
Str255List.Queue( SourceText, To255( "<!-- -->" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "<!-- $Id$ -->" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "<!-- $Log$ -->" ) );
end if;
SourceLanguage := HTML;
else
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// UNTITLED" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// Descripton:" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, To255( "// Written by" ) );
Str255List.Queue( SourceText,
To255( "// Copyright (c) Company. All rights reserved" ) );
Str255List.Queue( SourceText, To255( "//" ) );
Str255List.Queue( SourceText, NullStr255 );
if HasCVS and Opt_CVS then
Str255List.Queue( SourceText, To255( "// $Id$" ) );
Str255List.Queue( SourceText, NullStr255 );
Str255List.Queue( SourceText, To255( "// $Log$" ) );
end if;
if GetCheck( CPPSrcButton ) then
SourceLanguage := CPP;
else
SourceLanguage := Java;
end if;
end if;
end NewSource;
------------------------------------------------------------------------------
-- CLEAR GNAT ERRORS
--
-- Clear the error list returned by the compiler.
------------------------------------------------------------------------------
procedure ClearGnatErrors is
begin
Str255List.Clear( GnatErrors );
NextGnatError := 1;
end ClearGnatErrors;
------------------------------------------------------------------------------
-- NORMALIZE GNAT ERRORS
--
-- Check for non-standard error formats (ie. Perl's "...line x") and convert
-- to GCC format so Next Error operation works properly.
------------------------------------------------------------------------------
procedure NormalizeGnatErrors is
-- Handle non-standard Perl errors
p : integer;
p2 : integer;
blankCnt : integer;
error : str255;
errorLocation : str255;
errorLine : str255;
errorFile : str255;
errorMessage : str255;
temp : Str255;
begin
if SourceLanguage = Perl then
for i in 1..Str255List.Length( GnatErrors ) loop
Str255List.Find( GnatErrors, i, Error );
ErrorMessage := Error;
<<retry>>
p := length( Error );
blankCnt := 0;
errorLocation := nullStr255;
while p > 1 loop
p := p - 1;
if element( Error, p ) = ' ' then
blankCnt := blankCnt + 1;
if blankCnt = 2 then
if Slice( Error, p+1, p+4 ) = "near" then -- should really length check
-- some perl errors end in "line xyz, near token" Move the "near"
-- part to the front of the error and retry
Temp := To255( Slice( Error, p+1, length( Error ) ) );
p := p - 2; -- skip ", near"
Error := Temp & ", " & To255( Slice( Error, 1, p ) );
goto retry;
else
errorLocation := To255( Slice( Error, p+1, length( Error ) ) );
-- some perl errors have trailing period. But not all. Go fig.
if element( errorLocation, length( errorLocation ) ) = '.' then
Delete( errorLocation, length( errorLocation ), length( errorLocation ) );
end if;
exit;
end if;
end if;
end if;
end loop;
if length( errorLocation ) > 4 then
if Slice( errorLocation, 1, 5 ) = "line " then
errorLine := To255( Slice( errorLocation, 5, length( errorLocation ) ) );
ErrorFile := SourcePath;
p2 := p;
while p > 1 loop
p := p - 1;
if element( Error, p ) = ' ' then
blankCnt := blankCnt + 1;
if blankCnt = 3 then
errorFile := To255( Slice( Error, p+1, p2-1 ) );
if Slice( Error, p-4, p-1 ) = " at" then
errorMessage := To255( Slice( Error, 1, p-4 ) );
else
errorMessage := To255( Slice( Error, 1, p-4 ) );
end if;
exit;
end if;
end if;
end loop;
Error := ErrorFile & ":" & errorLine & ": " & ErrorMessage;
Str255List.Replace( GnatErrors, i, Error );
end if;
end if;
end loop;
elsif SourceLanguage = HTML then
-- Apache will do this
if Str255List.Length( GnatErrors ) > 0 then
Str255List.Find( GnatErrors, Str255List.length( GnatErrors ), Error );
if Error = "Syntax OK" then
Str255List.Clear( GnatErrors, Str255List.length( GnatErrors ) );
end if;
end if;
elsif SourceLanguage = Java then
-- SUN Java: "1. ERROR in untitled.java (at line 10)"
for i in 1..Str255List.Length( GnatErrors ) loop
Str255List.Find( GnatErrors, i, Error );
p := index( Error, "ERROR in" );
if p > 0 then
p := p + 9;
p2 := index( Error, "(at line" );
if p2 > 0 then
errorFile := To255( slice( Error, p, p2-2 ) );
p2 := p2 + 9;
errorLine := NullStr255;
while element( Error, p2 ) /= ')' loop
errorLine := errorLine & element( Error, p2 );
p2 := p2 + 1;
exit when p2 = length( Error );
end loop;
Error := ErrorFile & ":" & errorLine & ": error in this line";
Str255List.Replace( GnatErrors, i, Error );
end if;
end if;
end loop;
end if;
end NormalizeGnatErrors;
------------------------------------------------------------------------------
-- CLEAR LOAD EXCEPTIONS
--
-- Erase the load exceptions list
------------------------------------------------------------------------------
procedure ClearLoadExceptions is
begin
Str255List.Clear( LoadExceptions );
end ClearLoadExceptions;
------------------------------------------------------------------------------
-- CLEAR LOAD EXCEPTIONS
--
-- Add a filename to the list of files that won't be loaded
-- when mentioned in an erro rmessage
------------------------------------------------------------------------------
procedure AddLoadException( current, newfile : str255 ) is
Key : Str255;
begin
Key := current & "~" & newfile;
Str255List.Push( LoadExceptions, Key );
end AddLoadException;
------------------------------------------------------------------------------
-- CLEAR LOAD EXCEPTIONS
--
-- true if in load exception list
------------------------------------------------------------------------------
function IsLoadException( current, newfile : str255 ) return boolean is
Key : Str255;
Location : Str255List.AListIndex;
begin
Key := current & "~" & newfile;
Str255List.Find( LoadExceptions, Key, foundAt => Location );
return location /= 0;
end IsLoadException;
------------------------------------------------------------------------------
-- GET WINDOW TITLE FROM PATH
--
-- Determine an appropriate window title from the source file path. If there
-- is no path, create an "untitled" name based on the sourceType.
------------------------------------------------------------------------------
function GetWindowTitleFromPath( path : Str255 ) return Str255 is
Base, File : Str255;
WindowTitle : str255;
begin
if length( path ) = 0 then
if sourceType = AdaBody then
windowTitle := To255( "untitled.adb" );
elsif sourceType = AdaSpec then
windowTitle := To255( "untitled.ads" );
elsif sourceType = CHeader or sourceType = CPPHeader then
windowTitle := To255( "untitled.h" );
elsif sourceType = CSource then
windowTitle := To255( "untitled.c" );
elsif sourceType = CPPSource then
windowTitle := To255( "untitled.cc" );
elsif sourceType = JavaSource then
windowTitle := To255( "untitled.java" );
elsif sourceType = BushSource then
windowTitle := To255( "untitled.bush" );
elsif sourceType = PerlSource then
windowTitle := To255( "untitled.pl" );
elsif sourceType = PerlModule then
windowTitle := To255( "untitled.pm" );
elsif sourceType = WebPage then
windowTitle := To255( "untitled.html" );
elsif sourceType = ShellScript then
windowTitle := To255( "untitled.sh" );
elsif sourceType = PHPSource then
windowTitle := To255( "untitled.php" );
else
windowTitle := To255( "untitled" );
end if;
else
SplitPath( path, base, file );
if length( base ) > 0 then
if Element( base, length( base ) ) = '/' then
Delete( base, length(base), length(base) );
end if;
end if;
if base = GetPath then
WindowTitle := file;
else
WindowTitle := path;
end if;
end if;
return WindowTitle;
end GetWindowTitleFromPath;
------------------------------------------------------------------------------
-- UPDATE MARGIN STATS
--
-- Update the stats display in the right-hand margin in wide displays. If the
-- display is narrow, nothing is updated.
------------------------------------------------------------------------------
procedure UpdateMarginStats is
X : integer;
Y,L : long_integer;
begin
if ShowingMarginStats then -- wide display?
X := GetPosition( SourceBox ); -- cursor x
if X /= LastCursorPosX then -- change?
SetText( CursorPosX, "Column:" & integer'image( X ) ); -- update X=
Draw( CursorPosX );
LastCursorPosX := X;
end if;
Y := GetCurrent( SourceBox ); -- cursor y
if Y /= LastCursorPosY then -- change?
SetText( CursorPosY, " Row:" & long_integer'image( Y ) );-- update Y=
Draw( CursorPosY );
LastCursorPosY := Y;
end if;
L := GetLength( SourceBox ); -- file len
if L /= LastDocLength then -- change?
LastDocLength := L;
SetText( DocLength, " Size:" & long_integer'image( L ) ); -- update L=
Draw( DocLength );
end if;
end if;
end UpdateMarginStats;
function GetLastWord return str255 is
ch : character;
posn : positive;
i : natural;
first : natural;
last : natural;
text : str255;
function isIdentChar( ch : character ) return boolean is
begin
return (ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z') or
(ch = '_' ) or (ch = '.' );
end isIdentChar;
begin
posn := GetPosition( SourceBox );
if posn = 1 then
return nullstr255;
end if;
posn := posn - 1;
CopyLine( SourceBox, text );
ch := element( text, posn );
if not isIdentChar( ch ) then
return nullstr255;
end if;
i := natural( posn );
while i > 1 loop
ch := element( text, i-1 );
if isIdentChar( ch ) then
i := i - 1;
else
exit;
end if;
end loop;
first := i;
i := i + 1;
if i > length( text ) then
i := i - 1;
else
while i < length( text ) loop
ch := element( text, i );
if isIdentChar( ch ) then
i := i + 1;
else
i := i - 1;
exit;
end if;
end loop;
end if;
last := i;
return to255( Slice( text, first, last ) );
end GetLastWord;
procedure ShowAutoHelp is
text : str255;
word : str255;
fp : functionDataPtr;
begin
if AutoHelpStyle = none then
return;
end if;
word := GetLastWord;
if length( word ) = 0 then
return;
end if;
fp := findFunctionData( languageData, sourceLanguage, word );
if fp /= null then
if AutoHelpStyle = Info or AutoHelpStyle = both then
text := text & unpack( fp.functionInfo.all );
end if;
if fp.functionProto'length > 0 then
if AutoHelpStyle = both and fp.FunctionInfo.all'length > 0 then
text := text & " / ";
end if;
if AutoHelpStyle = proto or AutoHelpStyle = both then
declare
unpacked : string := unpack( fp.functionProto.all );
begin
if length( text ) + unpacked'length < 255 then
text := text & unpacked;
end if;
end;
end if;
end if;
if length( text ) = 0 then
text := to255( "No help" );
end if;
text := fp.functionName.all & ": " & text;
SetInfoText( text );
end if;
end ShowAutoHelp;
------------------------------------------------------------------------------
-- DIALOG CALLBACKS
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- OUTPUT FILTER
--
-- This callback is executed after the Window Manager has allowed a window
-- control to act on an input event. In this case, check to see if the
-- cursor position has changed in the source edit box and update the
-- location information in the right margin.
------------------------------------------------------------------------------
procedure OutputFilter( DT : in out ADialogTaskRecord ) is
begin
if ShowingMarginStats then
if DT.InputRec.InputType = KeyInput or DT.InputRec.InputType = ButtonUpInput then
UpdateMarginStats;
end if;
end if;
end OutputFilter;