/
builtins.adb.orig
2484 lines (2381 loc) · 112 KB
/
builtins.adb.orig
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
------------------------------------------------------------------------------
-- Built-in Shell Commands --
-- --
-- Part of SparForte --
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2001-2014 Free Software Foundation --
-- --
-- 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. --
-- --
-- This is maintained at http://www.pegasoft.ca --
-- --
------------------------------------------------------------------------------
with interfaces.c,
ada.text_io,
ada.strings.unbounded.text_io,
ada.strings.fixed,
ada.calendar,
#if POSTGRES
APQ,
#else
#if MYSQL
APQ,
#end if;
#end if;
bush_os,
string_util,
world,
user_io,
script_io,
jobs,
-- scanner_arrays,
compiler,
parser_aux,
parser_db,
parser_mysql,
parser_teams,
parser; -- for pragma annotate
use interfaces.c,
ada.text_io,
ada.strings.unbounded.text_io,
ada.strings.fixed,
ada.calendar,
#if POSTGRES
APQ,
#else
#if MYSQL
APQ,
#end if;
#end if;
bush_os,
string_util,
world,
jobs,
user_io,
script_io,
-- scanner_arrays,
compiler,
parser_aux,
parser_db,
parser_mysql,
parser_teams,
parser; -- for pragma annotate
package body builtins is
-- for help command
HTMLOutput : boolean := false;
MANOutput : boolean := false;
LicenseOutput : boolean := false;
TodoOutput : boolean := false;
CollabOutput : boolean := false;
-----------------------------------------------------------------------------
-- FIND PWD
--
-- Assign the current working directory to the current_working_directory
-- variable.
-- Determine current working directory and assign it to the current_working_
-- directory variable, else assign it a null string.
-- loosely modelled on bash/builtins/cd.def
-----------------------------------------------------------------------------
buffer : string( 1..4096 );
procedure findPwd is
begin
C_reset_errno;
getcwd( buffer, buffer'length );
if C_errno /= 0 then
err( "findPwd: error getting current working directory, errno "
& C_errno'img );
current_working_directory := null_unbounded_string;
end if;
current_working_directory := to_unbounded_string(
buffer( 1..index( buffer, ASCII.NUL & "" ) - 1 ) ) ;
end findPwd;
-----------------------------------------------------------------------------
-- BIND PWD
--
-- Assign the current working directory to the current_working_directory
-- variable.
-- loosely modelled on bash/builtins/cd.def
-----------------------------------------------------------------------------
procedure bindPwd( symlinks : boolean := false ) is
begin
findPwd;
if current_working_directory /= null_unbounded_string then
-- SYMBOLIC LINKS TO BE HANDLED HERE LATER
--findIdent( to_unbounded_string( "PWD" ), pwd );
--findIdent( to_unbounded_string( "OLDPWD" ), oldpwd );
--if identifiers( pwd ).kind = string_t then
-- if identifiers( oldpwd ).kind = string_t then
-- identifiers( oldpwd ).value := identifiers( pwd ).value;
-- end if;
-- identifiers( pwd ).value := current_working_directory;
--end if;
null;
end if;
end bindPwd;
-----------------------------------------------------------------------------
-- OLD_PWD
--
-- Old version of the builtin pwd command used in previous versions of Bush.
-- Syntax: old_pwd
-- loosely modelled on bash/builtins/cd.def
-----------------------------------------------------------------------------
function old_pwd return unbounded_string is
-- pwd: present working directory
begin
bindPwd;
return current_working_directory;
end old_pwd;
-----------------------------------------------------------------------------
-- OLD_CD
--
-- Old version of the builtin cd command used in previous versions of Bush.
-- Syntax: old_cd s
-- loosely modelled on bash/builtins/cd.def
-----------------------------------------------------------------------------
procedure old_cd( s : unbounded_string ) is
pwd, oldpwd : identifier;
path : unbounded_string := s;
showPath : boolean := false;
temp_id : identifier;
begin
if length( path ) = 0 then -- no path?
path := to_unbounded_string( "$HOME" ); -- then go home
elsif Element( path, 1 ) = '~' then -- leading tilda?
Delete( path, 1, 1 ); -- shortform for
Insert( path, 1, "$HOME" ); -- home
elsif path = "-" then -- minus path?
path := to_unbounded_string( "$OLDPWD" ); -- short for OLDPWD
showPath := inputMode = interactive or inputMode = breakout;
end if;
if head( path, 5 ) = "$HOME" then
findIdent( to_unbounded_string( "HOME" ), temp_id );
Delete( path, 1, 5 );
Insert( path, 1, to_string( identifiers( temp_id ).value.all ) );
elsif head( path, 7 ) = "$OLDPWD" then
findIdent( to_unbounded_string( "OLDPWD" ), temp_id );
Delete( path, 1, 7 );
Insert( path, 1, to_string( identifiers( temp_id ).value.all ) );
end if;
-- CDPATH support not yet implmeneted. Should go HERE, but
-- is CDPATH such a good idea anyway? Not usually!
if chdir( to_string( path ) & ASCII.NUL ) = 0 then
bindPwd;
-- it should also not take into account the nesting (should be global)
findIdent( to_unbounded_string( "PWD" ), pwd );
findIdent( to_unbounded_string( "OLDPWD" ), oldpwd );
if pwd /= eof_t then
if oldpwd /= eof_t then
identifiers( oldpwd ).value.all := identifiers( pwd ).value.all;
end if;
identifiers( pwd ).value.all := current_working_directory;
end if;
else
err( "cannot access '" & to_string( path ) & "'" );
end if;
if showPath then
put_line( current_working_directory );
end if;
end old_cd;
-----------------------------------------------------------------------------
-- ENV (POSIX SHELL COMMAND)
--
-- env : show the attributes of an identifier / all identifiers (if eof_t)
-- Syntax: env [id]
-- NOTE: another instance supports argument list params
-----------------------------------------------------------------------------
procedure env( id : identifier := eof_t ) is
perc : integer;
begin
if identifiers( id ).kind = new_t then
discardUnusedIdentifier( id );
err( "identifier not declared" );
return;
end if;
if id /= eof_t then
Put_Identifier( id );
return;
end if;
for i in 1..identifiers_top-1 loop
if identifiers( i ).kind /= keyword_t then
Put_Identifier( i );
end if;
end loop;
perc := integer( ( ( identifiers_top - 1 ) * 100 ) / identifiers'last );
Put( "The symbol table is" );
Put( perc'img );
Put( "% full with" );
Put( identifier'image( identifiers_top-1 ) );
Put_Line( " identifiers." );
end env;
-----------------------------------------------------------------------------
-- ALTER (SQL COMMAND)
--
-- alter : SQL alter - change database configuration
-- Syntax: alter shell_word
-----------------------------------------------------------------------------
procedure alter( ap : argumentListPtr ) is
-- alter : SQL alter
tempStr : unbounded_string;
begin
if ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if not engineOpen then
err( "no database connection open" );
elsif currentEngine = Engine_PostgreSQL then
#if POSTGRES
DoSQLStatement( "alter " & tempStr );
#else
err( "postgresql support not configured" );
#end if;
elsif currentEngine = Engine_MySQL then
#if MYSQL
DoMySQLSQLStatement( "alter " & tempStr );
#else
err( "mysql support not configured" );
#end if;
else
err( "internal error: unrecognized database engine" );
end if;
end if;
end alter;
-----------------------------------------------------------------------------
-- CLEAR (POSIX SHELL COMMAND)
--
-- clear : clear the screen / reset the terminal screen
-- Syntax: clear
-----------------------------------------------------------------------------
procedure clear( ap : argumentListPtr ) is
term_id : identifier;
begin
if ap'length /= 0 then
err( "zero argument expected" );
elsif isExecutingCommand then
findIdent( to_unbounded_string( "TERM" ), term_id );
terminalClear( identifiers( term_id ).value.all );
end if;
end clear;
-----------------------------------------------------------------------------
-- DELETE (SQL COMMAND)
--
-- delete : SQL delete
-- Syntax: delete shell_word
-----------------------------------------------------------------------------
procedure delete( ap : argumentListPtr ) is
tempStr : unbounded_string;
begin
if ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if not engineOpen then
err( "no database connection open" );
elsif currentEngine = Engine_PostgreSQL then
#if POSTGRES
DoSQLStatement( "delete " & tempStr );
#else
err( "postgres support not configured" );
#end if;
elsif currentEngine = Engine_MySQL then
#if MYSQL
DoMySQLSQLStatement( "delete " & tempStr );
#else
err( "mysql support not configured" );
#end if;
else
err( "internal error: unrecognized database engine" );
end if;
end if;
end delete;
-----------------------------------------------------------------------------
-- DO HISTORY (POSIX SHELL COMMAND)
--
-- history: shell history control
-- history [-c | n]
-----------------------------------------------------------------------------
procedure do_history( ap : argumentListPtr ) is
i : integer;
historyMax : natural := 0;
historyFirst : natural := 0;
word : unbounded_string;
pattern : unbounded_string;
mustClearHistory : boolean := false;
showHistory : boolean := false;
tempStr : unbounded_string;
begin
if ap'length = 0 then
null;
elsif ap'length /= 1 then
err( "zero or one argument expected" );
return;
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if tempStr = "-c" then
clearHistory;
return;
end if;
historyMax := natural( to_numeric( tempStr ) );
if historyMax > historyArray'last then
historyMax := historyArray'last;
end if;
end if;
-- If the user has requested a maximum number of lines (historyMax),
-- then calculate the first line (historyFirst) to be shown. If all
-- should be shown, turn on showHistory flag immediately.
if historyMax /= 0 then
if historyNext - historyMax < 1 then
historyFirst := historyArray'last - historyMax + historyNext;
else
historyFirst := historyNext- historyMax;
end if;
end if;
showHistory := historyFirst = 0 or historyFirst = historyNext;
-- Determine the starting point in the history array. The history
-- array wraps around to the first element when it has been filled.
if historyNext = historyArray'last then
i := 1;
else
i := historyNext + 1;
end if;
-- Walk the history array and show the contents. Wrap around when the
-- end of array is reached.
loop
if i = historyArray'last then
i := 1;
end if;
exit when i = historyNext;
if historyFirst = i then
showHistory := true;
end if;
if length( history( i ).line ) > 0 then
if showHistory then
put( i'img );
put( ": " );
put( getDateString( history( i ).time ) );
put( " | " );
put( history( i ).pwd );
put( " | " );
put_line( history( i ).line );
end if;
end if;
i := i + 1;
end loop;
end do_history;
-----------------------------------------------------------------------------
-- INSERT (SQL COMMAND)
--
-- insert: SQL insert - add a row to a database table
-- Syntax: insert shell_word
-----------------------------------------------------------------------------
procedure insert( ap : argumentListPtr ) is
tempStr : unbounded_string;
begin
if ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if not engineOpen then
err( "no database connection open" );
elsif currentEngine = Engine_PostgreSQL then
#if POSTGRES
DoSQLStatement( "insert " & tempStr );
#else
err( "postgres support not configured" );
#end if;
elsif currentEngine = Engine_MySQL then
#if MYSQL
DoMySQLSQLStatement( "insert " & tempStr );
#else
err( "mysql support not configured" );
#end if;
else
err( "internal error: unrecognized database engine" );
end if;
end if;
end insert;
-----------------------------------------------------------------------------
-- CD (POSIX SHELL COMMAND)
--
-- cd: change current directory
-- Syntax: cd - | shell_word
-----------------------------------------------------------------------------
procedure cd( ap : argumentListPtr ) is
tempStr : unbounded_string;
begin
if rshOpt then
err( "cd is not allowed in a " & optional_bold( "restricted shell" ) );
elsif ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
old_cd( tempStr );
end if;
end cd;
-----------------------------------------------------------------------------
-- JOBS (POSIX SHELL COMMAND)
--
-- jobs: show a list of running background jobs
-- Syntax: jobs
-----------------------------------------------------------------------------
procedure jobs( ap : argumentListPtr ) is
-- jobs: list running jobs
begin
if ap'length /= 0 then
err( "no arguments expected" );
elsif isExecutingCommand then
putJobList;
end if;
end jobs;
-----------------------------------------------------------------------------
-- PWD (POSIX SHELL COMMAND)
--
-- pwd: show the present (current) working directory
-- Syntax: pwd
-----------------------------------------------------------------------------
procedure pwd( ap : argumentListPtr ) is
-- pwd: present working directory (also updated current_working_directory)
begin
if ap'length /= 0 then
err( "no arguments expected" );
elsif isExecutingCommand then
put_line( old_pwd );
end if;
end pwd;
-----------------------------------------------------------------------------
-- SELECT (SQL COMMAND)
--
-- select: SQL select - display rows from database tables
-- Syntax: select shell_word
-----------------------------------------------------------------------------
procedure SQLselect( ap : argumentListPtr ) is
-- SQL select: SQL select statement
tempStr : unbounded_string;
begin
-- put_line( "length = " & ap'length'img ); -- DEBUG
-- if ap'length > 0 then
-- put_line( "param = " & ap( 1 ).all );
-- end if;
if ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if not engineOpen then
err( "no database connection open" );
elsif currentEngine = Engine_PostgreSQL then
#if POSTGRES
DoSQLSelect( "select " & tempStr );
#else
err( "postgresql support not supported" );
#end if;
elsif currentEngine = Engine_MySQL then
#if MYSQL
DoMySQLSQLSelect( "select " & tempStr );
#else
err( "mysql support not supported" );
#end if;
else
err( "internal error: unrecognized database engine" );
end if;
end if;
end SQLselect;
-----------------------------------------------------------------------------
-- STEP (SparForte BUILTIN)
--
-- step: in breakout mode, run the next line and show a command prompt
-- Syntax: step
-----------------------------------------------------------------------------
procedure step( ap : argumentListPtr ) is
begin
if ap'length /= 0 then
err( "zero arguments expected" );
elsif inputMode /= breakout then
err( "step can only be used when you break out of a script" );
elsif isExecutingCommand then
done := true;
breakoutContinue := true;
stepFlag1 := true;
put_trace( "stepping" );
end if;
end step;
-----------------------------------------------------------------------------
-- DO TRACE (SparForte BUILTIN)
--
-- trace: turn source line tracing on or off, or show the current setting
-- Syntax: trace [true | false ]
-----------------------------------------------------------------------------
procedure do_trace( ap : argumentListPtr ) is
tempStr : unbounded_string;
begin
if ap'length = 0 then
if isExecutingCommand then
if trace then
put_line( "Trace is currently on" );
else
put_line( "Trace is currently off" );
end if;
end if;
elsif ap'length > 1 then
err( "zero or one argument expected" );
elsif isExecutingCommand then -- or syntax_check then -- when debugging
-- true (boolean) will be a value of 1, but true (shell word) will be
-- "true". This is not ideal since it should really check types.
tempStr := to_unbounded_string( ap( 1 ).all );
if ( tempStr = "true" & ASCII.NUL ) or ( tempStr = "1" & ASCII.NUL ) then
trace := true;
put_line( "Trace is on" );
elsif ( tempStr = "false" & ASCII.NUL ) or ( tempStr = "0" & ASCII.NUL ) then
trace := false;
put_line( "Trace is off" );
else
err( "expected true or false" );
end if;
end if;
end do_trace;
-----------------------------------------------------------------------------
-- UNSET (POSIX SHELL COMMAND)
--
-- unset: remove an identifier from the symbol table
-- Syntax: unset identifier
-- Note: this uses a word, not an identifier token as in older versions of
-- SparForte. If SparForte becomes more complex, this may need to be redesigned.
-----------------------------------------------------------------------------
procedure unset( ap : argumentListPtr ) is
tempStr : unbounded_string;
identToUnset : identifier;
begin
if rshOpt then
err( "unset is not allowed in a " & optional_bold( "restricted shell" ) );
elsif ap'length /= 1 then
err( "one argument expected" );
elsif inputMode /= interactive and inputMode /= breakout then
err( "unset is only allowed in an interactive session" );
elsif onlyAda95 then
err( "unset is not allowed with " & optional_bold( "pragma ada_95" ) );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
findIdent( tempStr, identToUnset );
if identToUnset = eof_t then
err( "identifier not declared" );
elsif boolean(rshOpt) and then identifiers( identToUnset ).name = "PATH" then
err( "unsetting PATH is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToUnset ).name = "HOME" then
err( "unsetting HOME is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToUnset ).name = "PWD" then
err( "unsetting PWD is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToUnset ).name = "OLDPWD" then
err( "unsetting OLDPWD is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif identifiers( identToUnset ).renamed_count > 0 then
err_renaming( identToUnset );
elsif isExecutingCommand then
-- record? delete any fields first (notice not recursive)
if identifiers( identToUnset ).kind = root_record_t then
for i in keywords_top..identifiers_top - 1 loop
if identifiers( i ).field_of = identToUnset and not identifiers( i ).deleted then
if not deleteIdent( i ) then
err( "unable to unset identifier field " & to_string( identifiers( i ).name ) );
end if;
end if;
end loop;
-- single dimensional array. Free dynamic memory. (notice not recursive)
-- Removed 11/03/25 - this already done by delete ident
--elsif identifiers( identToUnset ).list then
-- clearArray( arrayID( to_numeric( identifiers( identToUnset ).value ) ) );
end if;
if not deleteIdent( identToUnset ) then
err( "unable to unset identifier" );
end if;
end if;
end if;
end unset;
-----------------------------------------------------------------------------
-- ENV (POSIX SHELL COMMAND)
--
-- env: show the attributes of one/all identifier(s) from the symbol table
-- Syntax: env [identifier]
-- Note: this uses a word, not an identifier token as in older versions of
-- SparForte. If SparForte becomes more complex, this may need to be redesigned.
-----------------------------------------------------------------------------
procedure env( ap : argumentListPtr ) is
tempStr : unbounded_string;
identToShow : identifier;
begin
if rshOpt then
err( "env is not allowed in a " & optional_bold( "restricted shell" ) );
elsif ap'length > 1 then
err( "zero or one argument expected" );
-- elsif inputMode /= interactive and inputMode /= breakout then
-- err( "env is only allowed in an interactive session" );
elsif isExecutingCommand then
if ap'length = 0 then
put_all_identifiers;
else
tempStr := to_unbounded_string( ap( 1 ).all );
if length( tempStr ) <= 1 then
err( "internal error: name of identifier to find is empty" );
else
-- remove ASCII.NUL from C string
delete( tempStr, length( tempStr ), length( tempStr ) );
findIdent( tempStr, identToShow );
if identToShow = eof_t then
err( "identifier not declared" );
elsif boolean(rshOpt) and then identifiers( identToShow ).name = "PATH" then
err( "env PATH is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToShow ).name = "HOME" then
err( "env HOME is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToShow ).name = "PWD" then
err( "env PWD is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif boolean(rshOpt) and then identifiers( identToShow ).name = "OLDPWD" then
err( "env OLDPWD is not allowed in a " &
optional_bold( "restricted shell" ) );
elsif isExecutingCommand then
Put_Identifier( identToShow );
end if;
end if;
end if;
end if;
end env;
-----------------------------------------------------------------------------
-- UPDATE (SQL COMMAND)
--
-- update: SQL update - update rows in a database table
-- Syntax: update shell_word
-----------------------------------------------------------------------------
procedure update( ap : argumentListPtr ) is
tempStr : unbounded_string;
begin
if ap'length /= 1 then
err( "one argument expected" );
elsif isExecutingCommand then
tempStr := to_unbounded_string( ap( 1 ).all );
delete( tempStr, length( tempStr ), length( tempStr ) );
if not engineOpen then
err( "no database connection open" );
elsif currentEngine = Engine_PostgreSQL then
#if POSTGRES
DoSQLStatement( "update " & tempStr );
#else
err( "postgresql support not supported" );
#end if;
elsif currentEngine = Engine_MySQL then
#if MYSQL
DoMySQLSQLStatement( "update " & tempStr );
#else
err( "mysql support not supported" );
#end if;
else
err( "internal error: unrecognized database engine" );
end if;
end if;
end update;
-----------------------------------------------------------------------------
-- WAIT (POSIX SHELL COMMAND)
--
-- wait: wait for all background jobs to finish running
-- Syntax: wait
-----------------------------------------------------------------------------
procedure wait( ap : argumentListPtr ) is
begin
if ap'length /= 0 then
err( "zero arguments expected" );
elsif isExecutingCommand then
wait4children;
end if;
end wait;
-----------------------------------------------------------------------------
-- VM (SparForte BUILTIN)
--
-- vm: show the interal state of the virtual machine
-- (Not yet implemented)
-- Syntax: vm nr n | sr n | ir n
-----------------------------------------------------------------------------
procedure vm( regtype, regnum : unbounded_string ) is
-- r : aVMRegister;
begin
err( "not yet written" );
-- if to_string( regtype ) = "nr" then
-- r := aVMRegister'value( " " & to_string( regnum ) );
-- put( "numeric register " & r'img & " = " );
-- put_line( VMNR( aVMNRNumber( r ) ) );
-- elsif to_string( regtype ) = "sr" then
-- put( "string register " & r'img & " = " );
-- r := aVMRegister'value( " " & to_string( regnum ) );
-- put_line( VMSR( aVMSRNumber( r ) ) );
-- elsif to_string( regtype ) = "ir" then
-- put( "index register " & r'img & " = " );
-- r := aVMRegister'value( " " & to_string( regnum ) );
-- put_line( VMIR( aVMIRNumber( r ) )'img );
-- Put_Identifier( VMIR( aVMIRNumber( r ) ) );
-- else
-- put_line( "usage: vm nr|sr|ir, n" );
-- end if;
end vm;
-- Scan and script and provide help
procedure DoScriptHelp( helpTopic : unbounded_string ) is
scriptState : aScriptState;
firstLine : aliased unbounded_string;
exprVal : unbounded_string;
info : unbounded_string;
genDate : unbounded_string;
-- not really in another script but we'll be safe...
last_tag : unbounded_string;
closeResult : int;
-- to-do's
todoTotal : natural := 0;
workMeasureCntUnknown : natural := 0;
workMeasureCntHours : natural := 0;
workMeasureCntFpoints : natural := 0;
workMeasureCntSpoints : natural := 0;
workMeasureCntSloc : natural := 0;
workMeasureCntSizeS : natural := 0;
workMeasureCntSizeM : natural := 0;
workMeasureCntSizeL : natural := 0;
workMeasureCntSizeXL : natural := 0;
workPriorityCntUnknown : natural := 0;
workPriorityCntLevelL : natural := 0;
workPriorityCntLevelM : natural := 0;
workPriorityCntLevelH : natural := 0;
workPriorityCntSeverity1 : natural := 0;
workPriorityCntSeverity2 : natural := 0;
workPriorityCntSeverity3 : natural := 0;
workPriorityCntSeverity4 : natural := 0;
workPriorityCntSeverity5 : natural := 0;
workPriorityCntRisk : natural := 0;
workPriorityCntCVSSMinor : natural := 0;
workPriorityCntCVSSMajor : natural := 0;
workPriorityCntCVSSCrit : natural := 0;
workPriorityCompleted : natural := 0;
measure : identifier;
units : unbounded_string;
-- repeatedly used strings, converted to unbounded_strings
advise_str : constant unbounded_string := to_unbounded_string( "advise" );
license_str : constant unbounded_string := to_unbounded_string( "license" );
todo_str : constant unbounded_string := to_unbounded_string( "todo" );
blocked_str : constant unbounded_string := to_unbounded_string( "blocked" );
clarify_str : constant unbounded_string := to_unbounded_string( "clarify" );
dispute_str : constant unbounded_string := to_unbounded_string( "dispute" );
propose_str : constant unbounded_string := to_unbounded_string( "propose" );
annotate_str : constant unbounded_string := to_unbounded_string( "annotate" );
refactor_str : constant unbounded_string := to_unbounded_string( "refactor" );
--authorId : identifier := eof_t;
function ParsePragmaKindAsHelp return unbounded_string is
pragmaKind : unbounded_string;
begin
pragmaKind := identifiers( token ).name;
discardUnusedIdentifier( token );
getNextToken;
return pragmaKind;
end ParsePragmaKindAsHelp;
procedure ParsePragmaStatementAsHelp( pragmaKind : unbounded_string ) is
exprVal : unbounded_string;
exprType : identifier;
begin
if pragmaKind = license_str then
if token = symbol_t and identifiers( token ).value.all = "(" then
getNextToken;
info := identifiers( token ).name;
discardUnusedIdentifier( token );
getNextToken;
if token = symbol_t and identifiers( token ).value.all = "," then
expect( symbol_t, "," );
info := info & ": " & identifiers( token ).value.all;
expect( strlit_t );
end if;
expect( symbol_t, ")" );
if LicenseOutput then
put_line( to_string( info ) );
end if;
end if;
elsif pragmaKind = todo_str then
if token = symbol_t and identifiers( token ).value.all = "(" then
todoTotal := todoTotal + 1;
getNextToken;
info := identifiers( token ).name; -- name
getNextToken;
expect( symbol_t, "," );
ParseStaticExpression( exprVal, exprType );
info := info & "," & ToCSV( exprVal ); -- message
expect( symbol_t, "," );
info := info & "," & identifiers( token ).name; -- measure
measure := token;
getNextToken;
expect( symbol_t, "," );
info := info & "," & identifiers( token ).value.all; -- unit
units := identifiers( token ).value.all;
-- calculate work by measure
if measure = teams_work_measure_unknown_t then
workMeasureCntUnknown := workMeasureCntUnknown + 1;
elsif measure = teams_work_measure_hours_t then
workMeasureCntHours := workMeasureCntHours + natural( to_numeric( units ) );
elsif measure = teams_work_measure_fpoints_t then
workMeasureCntFpoints := workMeasureCntFpoints + natural( to_numeric( units ) );
elsif measure = teams_work_measure_spoints_t then
workMeasureCntSpoints := workMeasureCntSpoints + natural( to_numeric( units ) );
elsif measure = teams_work_measure_sloc_t then
workMeasureCntSloc := workMeasureCntSloc + natural( to_numeric( units ) );
elsif measure = teams_work_measure_size_t and units = "s" then
workMeasureCntSizeS := workMeasureCntSizeS + 1;
elsif measure = teams_work_measure_size_t and units = "m" then
workMeasureCntSizeM := workMeasureCntSizeM + 1;
elsif measure = teams_work_measure_size_t and units = "l" then
workMeasureCntSizeL := workMeasureCntSizeL + 1;
elsif measure = teams_work_measure_size_t and units = "xl" then
workMeasureCntSizeXL := workMeasureCntSizeXL + 1;
else
null; -- DEBUG
end if;
getNextToken;
expect( symbol_t, "," );
info := info & "," & identifiers( token ).name; -- priority
measure := token;
getNextToken;
expect( symbol_t, "," );
info := info & "," & identifiers( token ).value.all; -- unit
units := identifiers( token ).value.all;
if measure = teams_work_priority_unknown_t then
workPriorityCntUnknown := workPriorityCntUnknown + 1;
elsif measure = teams_work_priority_level_t and units = "l" then
workPriorityCntLevelL := workPriorityCntLevelL + 1;
elsif measure = teams_work_priority_level_t and units = "m" then
workPriorityCntLevelM := workPriorityCntLevelM + 1;
elsif measure = teams_work_priority_level_t and units = "h" then
workPriorityCntLevelH := workPriorityCntLevelH + 1;
elsif measure = teams_work_priority_severity_t and units = " 1" then
workPriorityCntSeverity1 := workPriorityCntSeverity1 + 1;
elsif measure = teams_work_priority_severity_t and units = " 2" then
workPriorityCntSeverity2 := workPriorityCntSeverity2 + 1;
elsif measure = teams_work_priority_severity_t and units = " 3" then
workPriorityCntSeverity3 := workPriorityCntSeverity3 + 1;
elsif measure = teams_work_priority_severity_t and units = " 4" then
workPriorityCntSeverity4 := workPriorityCntSeverity4 + 1;
elsif measure = teams_work_priority_severity_t and units = " 5" then
workPriorityCntSeverity5 := workPriorityCntSeverity5 + 1;
elsif measure = teams_work_priority_risk_t then
workPriorityCntRisk := workPriorityCntRisk + natural( to_numeric( units ) );
elsif measure = teams_work_priority_completed_t then
workPriorityCompleted := workPriorityCompleted + 1;
elsif measure = teams_work_priority_cvss_t then
declare
u : long_float;
begin
u := to_numeric( units );
if u < 4.0 then
workPriorityCntCVSSMinor := workPriorityCntCVSSMinor + 1;
elsif u < 7.0 then
workPriorityCntCVSSMajor := workPriorityCntCVSSMajor + 1;
else
workPriorityCntCVSSCrit := workPriorityCntCVSSCrit + 1;
end if;
end;
else
null; -- DEBUG
end if;
getNextToken;
-- ticket is optional
if token = symbol_t and identifiers( token ).value.all = "," then
expect( symbol_t, "," );
info := info & "," & ToCSV( identifiers( token ).value.all );
getNextToken;
end if;
expect( symbol_t, ")" );
if TodoOutput then
put_line( to_string( info ) );
end if;
end if;
elsif pragmaKind = advise_str or
pragmaKind = blocked_str or
pragmaKind = clarify_str or
pragmaKind = dispute_str or
pragmaKind = propose_str or
pragmaKind = refactor_str then
if token = symbol_t and identifiers( token ).value.all = "(" then
getNextToken;
info := pragmaKind & "," & identifiers( token ).name; -- name
getNextToken;
expect( symbol_t, "," );