mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
a-ztexio.adb
1938 lines (1531 loc) · 51.5 KB
/
a-ztexio.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
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . W I D E _ W I D E _ T E X T _ I O --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
-- --
-- GNAT 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 3, or (at your option) any later ver- --
-- sion. GNAT 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Streams; use Ada.Streams;
with Interfaces.C_Streams; use Interfaces.C_Streams;
with System.CRTL;
with System.File_IO;
with System.WCh_Cnv; use System.WCh_Cnv;
with System.WCh_Con; use System.WCh_Con;
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
pragma Elaborate_All (System.File_IO);
-- Needed because of calls to Chain_File in package body elaboration
package body Ada.Wide_Wide_Text_IO is
package FIO renames System.File_IO;
subtype AP is FCB.AFCB_Ptr;
function To_FCB is new Ada.Unchecked_Conversion (File_Mode, FCB.File_Mode);
function To_TIO is new Ada.Unchecked_Conversion (FCB.File_Mode, File_Mode);
use type FCB.File_Mode;
use type System.CRTL.size_t;
WC_Encoding : constant Character;
pragma Import (C, WC_Encoding, "__gl_wc_encoding");
-- Default wide character encoding
Err_Name : aliased String := "*stderr" & ASCII.NUL;
In_Name : aliased String := "*stdin" & ASCII.NUL;
Out_Name : aliased String := "*stdout" & ASCII.NUL;
-- Names of standard files
--
-- Use "preallocated" strings to avoid calling "new" during the elaboration
-- of the run time. This is needed in the tasking case to avoid calling
-- Task_Lock too early. A filename is expected to end with a null character
-- in the runtime, here the null characters are added just to have a
-- correct filename length.
--
-- Note: the names for these files are bogus, and probably it would be
-- better for these files to have no names, but the ACVC tests insist.
-- We use names that are bound to fail in open etc.
Null_Str : aliased constant String := "";
-- Used as form string for standard files
-----------------------
-- Local Subprograms --
-----------------------
function Get_Wide_Wide_Char_Immed
(C : Character;
File : File_Type) return Wide_Wide_Character;
-- This routine is identical to Get_Wide_Wide_Char, except that the reads
-- are done in Get_Immediate mode (i.e. without waiting for a line return).
function Getc_Immed (File : File_Type) return int;
-- This routine is identical to Getc, except that the read is done in
-- Get_Immediate mode (i.e. without waiting for a line return).
procedure Putc (ch : int; File : File_Type);
-- Outputs the given character to the file, which has already been checked
-- for being in output status. Device_Error is raised if the character
-- cannot be written.
procedure Set_WCEM (File : in out File_Type);
-- Called by Open and Create to set the wide character encoding method for
-- the file, processing a WCEM form parameter if one is present. File is
-- IN OUT because it may be closed in case of an error.
procedure Terminate_Line (File : File_Type);
-- If the file is in Write_File or Append_File mode, and the current line
-- is not terminated, then a line terminator is written using New_Line.
-- Note that there is no Terminate_Page routine, because the page mark at
-- the end of the file is implied if necessary.
procedure Ungetc (ch : int; File : File_Type);
-- Pushes back character into stream, using ungetc. The caller has checked
-- that the file is in read status. Device_Error is raised if the character
-- cannot be pushed back. An attempt to push back and end of file character
-- (EOF) is ignored.
-------------------
-- AFCB_Allocate --
-------------------
function AFCB_Allocate
(Control_Block : Wide_Wide_Text_AFCB) return FCB.AFCB_Ptr
is
pragma Unreferenced (Control_Block);
begin
return new Wide_Wide_Text_AFCB;
end AFCB_Allocate;
----------------
-- AFCB_Close --
----------------
procedure AFCB_Close (File : not null access Wide_Wide_Text_AFCB) is
begin
-- If the file being closed is one of the current files, then close
-- the corresponding current file. It is not clear that this action
-- is required (RM A.10.3(23)) but it seems reasonable, and besides
-- ACVC test CE3208A expects this behavior.
if File = Current_In then
Current_In := null;
elsif File = Current_Out then
Current_Out := null;
elsif File = Current_Err then
Current_Err := null;
end if;
Terminate_Line (File.all'Access);
end AFCB_Close;
---------------
-- AFCB_Free --
---------------
procedure AFCB_Free (File : not null access Wide_Wide_Text_AFCB) is
FT : File_Type := File.all'Access;
procedure Free is new
Ada.Unchecked_Deallocation (Wide_Wide_Text_AFCB, File_Type);
begin
Free (FT);
end AFCB_Free;
-----------
-- Close --
-----------
procedure Close (File : in out File_Type) is
begin
FIO.Close (AP (File)'Unrestricted_Access);
end Close;
---------
-- Col --
---------
-- Note: we assume that it is impossible in practice for the column
-- to exceed the value of Count'Last, i.e. no check is required for
-- overflow raising layout error.
function Col (File : File_Type) return Positive_Count is
begin
FIO.Check_File_Open (AP (File));
return File.Col;
end Col;
function Col return Positive_Count is
begin
return Col (Current_Out);
end Col;
------------
-- Create --
------------
procedure Create
(File : in out File_Type;
Mode : File_Mode := Out_File;
Name : String := "";
Form : String := "")
is
Dummy_File_Control_Block : Wide_Wide_Text_AFCB;
pragma Warnings (Off, Dummy_File_Control_Block);
-- Yes, we know this is never assigned a value, only the tag
-- is used for dispatching purposes, so that's expected.
begin
FIO.Open (File_Ptr => AP (File),
Dummy_FCB => Dummy_File_Control_Block,
Mode => To_FCB (Mode),
Name => Name,
Form => Form,
Amethod => 'W',
Creat => True,
Text => True);
File.Self := File;
Set_WCEM (File);
end Create;
-------------------
-- Current_Error --
-------------------
function Current_Error return File_Type is
begin
return Current_Err;
end Current_Error;
function Current_Error return File_Access is
begin
return Current_Err.Self'Access;
end Current_Error;
-------------------
-- Current_Input --
-------------------
function Current_Input return File_Type is
begin
return Current_In;
end Current_Input;
function Current_Input return File_Access is
begin
return Current_In.Self'Access;
end Current_Input;
--------------------
-- Current_Output --
--------------------
function Current_Output return File_Type is
begin
return Current_Out;
end Current_Output;
function Current_Output return File_Access is
begin
return Current_Out.Self'Access;
end Current_Output;
------------
-- Delete --
------------
procedure Delete (File : in out File_Type) is
begin
FIO.Delete (AP (File)'Unrestricted_Access);
end Delete;
-----------------
-- End_Of_File --
-----------------
function End_Of_File (File : File_Type) return Boolean is
ch : int;
begin
FIO.Check_Read_Status (AP (File));
if File.Before_Wide_Wide_Character then
return False;
elsif File.Before_LM then
if File.Before_LM_PM then
return Nextc (File) = EOF;
end if;
else
ch := Getc (File);
if ch = EOF then
return True;
elsif ch /= LM then
Ungetc (ch, File);
return False;
else -- ch = LM
File.Before_LM := True;
end if;
end if;
-- Here we are just past the line mark with Before_LM set so that we
-- do not have to try to back up past the LM, thus avoiding the need
-- to back up more than one character.
ch := Getc (File);
if ch = EOF then
return True;
elsif ch = PM and then File.Is_Regular_File then
File.Before_LM_PM := True;
return Nextc (File) = EOF;
-- Here if neither EOF nor PM followed end of line
else
Ungetc (ch, File);
return False;
end if;
end End_Of_File;
function End_Of_File return Boolean is
begin
return End_Of_File (Current_In);
end End_Of_File;
-----------------
-- End_Of_Line --
-----------------
function End_Of_Line (File : File_Type) return Boolean is
ch : int;
begin
FIO.Check_Read_Status (AP (File));
if File.Before_Wide_Wide_Character then
return False;
elsif File.Before_LM then
return True;
else
ch := Getc (File);
if ch = EOF then
return True;
else
Ungetc (ch, File);
return (ch = LM);
end if;
end if;
end End_Of_Line;
function End_Of_Line return Boolean is
begin
return End_Of_Line (Current_In);
end End_Of_Line;
-----------------
-- End_Of_Page --
-----------------
function End_Of_Page (File : File_Type) return Boolean is
ch : int;
begin
FIO.Check_Read_Status (AP (File));
if not File.Is_Regular_File then
return False;
elsif File.Before_Wide_Wide_Character then
return False;
elsif File.Before_LM then
if File.Before_LM_PM then
return True;
end if;
else
ch := Getc (File);
if ch = EOF then
return True;
elsif ch /= LM then
Ungetc (ch, File);
return False;
else -- ch = LM
File.Before_LM := True;
end if;
end if;
-- Here we are just past the line mark with Before_LM set so that we
-- do not have to try to back up past the LM, thus avoiding the need
-- to back up more than one character.
ch := Nextc (File);
return ch = PM or else ch = EOF;
end End_Of_Page;
function End_Of_Page return Boolean is
begin
return End_Of_Page (Current_In);
end End_Of_Page;
-----------
-- Flush --
-----------
procedure Flush (File : File_Type) is
begin
FIO.Flush (AP (File));
end Flush;
procedure Flush is
begin
Flush (Current_Out);
end Flush;
----------
-- Form --
----------
function Form (File : File_Type) return String is
begin
return FIO.Form (AP (File));
end Form;
---------
-- Get --
---------
procedure Get
(File : File_Type;
Item : out Wide_Wide_Character)
is
C : Character;
begin
FIO.Check_Read_Status (AP (File));
if File.Before_Wide_Wide_Character then
File.Before_Wide_Wide_Character := False;
Item := File.Saved_Wide_Wide_Character;
-- Ada.Text_IO checks Before_LM_PM here, shouldn't we do the same???
else
Get_Character (File, C);
Item := Get_Wide_Wide_Char (C, File);
end if;
end Get;
procedure Get (Item : out Wide_Wide_Character) is
begin
Get (Current_In, Item);
end Get;
procedure Get
(File : File_Type;
Item : out Wide_Wide_String)
is
begin
for J in Item'Range loop
Get (File, Item (J));
end loop;
end Get;
procedure Get (Item : out Wide_Wide_String) is
begin
Get (Current_In, Item);
end Get;
-------------------
-- Get_Character --
-------------------
procedure Get_Character
(File : File_Type;
Item : out Character)
is
ch : int;
begin
if File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
File.Col := 1;
if File.Before_LM_PM then
File.Line := 1;
File.Page := File.Page + 1;
File.Before_LM_PM := False;
else
File.Line := File.Line + 1;
end if;
end if;
loop
ch := Getc (File);
if ch = EOF then
raise End_Error;
elsif ch = LM then
File.Line := File.Line + 1;
File.Col := 1;
elsif ch = PM and then File.Is_Regular_File then
File.Page := File.Page + 1;
File.Line := 1;
else
Item := Character'Val (ch);
File.Col := File.Col + 1;
return;
end if;
end loop;
end Get_Character;
-------------------
-- Get_Immediate --
-------------------
procedure Get_Immediate
(File : File_Type;
Item : out Wide_Wide_Character)
is
ch : int;
begin
FIO.Check_Read_Status (AP (File));
if File.Before_Wide_Wide_Character then
File.Before_Wide_Wide_Character := False;
Item := File.Saved_Wide_Wide_Character;
elsif File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
Item := Wide_Wide_Character'Val (LM);
else
ch := Getc_Immed (File);
if ch = EOF then
raise End_Error;
else
Item := Get_Wide_Wide_Char_Immed (Character'Val (ch), File);
end if;
end if;
end Get_Immediate;
procedure Get_Immediate
(Item : out Wide_Wide_Character)
is
begin
Get_Immediate (Current_In, Item);
end Get_Immediate;
procedure Get_Immediate
(File : File_Type;
Item : out Wide_Wide_Character;
Available : out Boolean)
is
ch : int;
begin
FIO.Check_Read_Status (AP (File));
Available := True;
if File.Before_Wide_Wide_Character then
File.Before_Wide_Wide_Character := False;
Item := File.Saved_Wide_Wide_Character;
elsif File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
Item := Wide_Wide_Character'Val (LM);
else
-- Shouldn't we use getc_immediate_nowait here, like Text_IO???
ch := Getc_Immed (File);
if ch = EOF then
raise End_Error;
else
Item := Get_Wide_Wide_Char_Immed (Character'Val (ch), File);
end if;
end if;
end Get_Immediate;
procedure Get_Immediate
(Item : out Wide_Wide_Character;
Available : out Boolean)
is
begin
Get_Immediate (Current_In, Item, Available);
end Get_Immediate;
--------------
-- Get_Line --
--------------
procedure Get_Line
(File : File_Type;
Item : out Wide_Wide_String;
Last : out Natural)
is
begin
FIO.Check_Read_Status (AP (File));
Last := Item'First - 1;
-- Immediate exit for null string, this is a case in which we do not
-- need to test for end of file and we do not skip a line mark under
-- any circumstances.
if Last >= Item'Last then
return;
end if;
-- Here we have at least one character, if we are immediately before
-- a line mark, then we will just skip past it storing no characters.
if File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
-- Otherwise we need to read some characters
else
-- If we are at the end of file now, it means we are trying to
-- skip a file terminator and we raise End_Error (RM A.10.7(20))
if Nextc (File) = EOF then
raise End_Error;
end if;
-- Loop through characters in string
loop
-- Exit the loop if read is terminated by encountering line mark
-- Note that the use of Skip_Line here ensures we properly deal
-- with setting the page and line numbers.
if End_Of_Line (File) then
Skip_Line (File);
return;
end if;
-- Otherwise store the character, note that we know that ch is
-- something other than LM or EOF. It could possibly be a page
-- mark if there is a stray page mark in the middle of a line,
-- but this is not an official page mark in any case, since
-- official page marks can only follow a line mark. The whole
-- page business is pretty much nonsense anyway, so we do not
-- want to waste time trying to make sense out of non-standard
-- page marks in the file. This means that the behavior of
-- Get_Line is different from repeated Get of a character, but
-- that's too bad. We only promise that page numbers etc make
-- sense if the file is formatted in a standard manner.
-- Note: we do not adjust the column number because it is quicker
-- to adjust it once at the end of the operation than incrementing
-- it each time around the loop.
Last := Last + 1;
Get (File, Item (Last));
-- All done if the string is full, this is the case in which
-- we do not skip the following line mark. We need to adjust
-- the column number in this case.
if Last = Item'Last then
File.Col := File.Col + Count (Item'Length);
return;
end if;
-- Exit from the loop if we are at the end of file. This happens
-- if we have a last line that is not terminated with a line mark.
-- In this case we consider that there is an implied line mark;
-- this is a non-standard file, but we will treat it nicely.
exit when Nextc (File) = EOF;
end loop;
end if;
end Get_Line;
procedure Get_Line
(Item : out Wide_Wide_String;
Last : out Natural)
is
begin
Get_Line (Current_In, Item, Last);
end Get_Line;
function Get_Line (File : File_Type) return Wide_Wide_String is
Buffer : Wide_Wide_String (1 .. 500);
Last : Natural;
function Get_Rest (S : Wide_Wide_String) return Wide_Wide_String;
-- This is a recursive function that reads the rest of the line and
-- returns it. S is the part read so far.
--------------
-- Get_Rest --
--------------
function Get_Rest (S : Wide_Wide_String) return Wide_Wide_String is
-- Each time we allocate a buffer the same size as what we have
-- read so far. This limits us to a logarithmic number of calls
-- to Get_Rest and also ensures only a linear use of stack space.
Buffer : Wide_Wide_String (1 .. S'Length);
Last : Natural;
begin
Get_Line (File, Buffer, Last);
declare
R : constant Wide_Wide_String := S & Buffer (1 .. Last);
begin
if Last < Buffer'Last then
return R;
else
return Get_Rest (R);
end if;
end;
end Get_Rest;
-- Start of processing for Get_Line
begin
Get_Line (File, Buffer, Last);
if Last < Buffer'Last then
return Buffer (1 .. Last);
else
return Get_Rest (Buffer (1 .. Last));
end if;
end Get_Line;
function Get_Line return Wide_Wide_String is
begin
return Get_Line (Current_In);
end Get_Line;
------------------------
-- Get_Wide_Wide_Char --
------------------------
function Get_Wide_Wide_Char
(C : Character;
File : File_Type) return Wide_Wide_Character
is
function In_Char return Character;
-- Function used to obtain additional characters it the wide character
-- sequence is more than one character long.
function WC_In is new Char_Sequence_To_UTF_32 (In_Char);
-------------
-- In_Char --
-------------
function In_Char return Character is
ch : constant Integer := Getc (File);
begin
if ch = EOF then
raise End_Error;
else
return Character'Val (ch);
end if;
end In_Char;
-- Start of processing for Get_Wide_Wide_Char
begin
FIO.Check_Read_Status (AP (File));
return Wide_Wide_Character'Val (WC_In (C, File.WC_Method));
end Get_Wide_Wide_Char;
------------------------------
-- Get_Wide_Wide_Char_Immed --
------------------------------
function Get_Wide_Wide_Char_Immed
(C : Character;
File : File_Type) return Wide_Wide_Character
is
function In_Char return Character;
-- Function used to obtain additional characters it the wide character
-- sequence is more than one character long.
function WC_In is new Char_Sequence_To_UTF_32 (In_Char);
-------------
-- In_Char --
-------------
function In_Char return Character is
ch : constant Integer := Getc_Immed (File);
begin
if ch = EOF then
raise End_Error;
else
return Character'Val (ch);
end if;
end In_Char;
-- Start of processing for Get_Wide_Wide_Char_Immed
begin
FIO.Check_Read_Status (AP (File));
return Wide_Wide_Character'Val (WC_In (C, File.WC_Method));
end Get_Wide_Wide_Char_Immed;
----------
-- Getc --
----------
function Getc (File : File_Type) return int is
ch : int;
begin
ch := fgetc (File.Stream);
if ch = EOF and then ferror (File.Stream) /= 0 then
raise Device_Error;
else
return ch;
end if;
end Getc;
----------------
-- Getc_Immed --
----------------
function Getc_Immed (File : File_Type) return int is
ch : int;
end_of_file : int;
procedure getc_immediate
(stream : FILEs; ch : out int; end_of_file : out int);
pragma Import (C, getc_immediate, "getc_immediate");
begin
FIO.Check_Read_Status (AP (File));
if File.Before_LM then
File.Before_LM := False;
File.Before_LM_PM := False;
ch := LM;
else
getc_immediate (File.Stream, ch, end_of_file);
if ferror (File.Stream) /= 0 then
raise Device_Error;
elsif end_of_file /= 0 then
return EOF;
end if;
end if;
return ch;
end Getc_Immed;
-------------------------------
-- Initialize_Standard_Files --
-------------------------------
procedure Initialize_Standard_Files is
begin
Standard_Err.Stream := stderr;
Standard_Err.Name := Err_Name'Access;
Standard_Err.Form := Null_Str'Unrestricted_Access;
Standard_Err.Mode := FCB.Out_File;
Standard_Err.Is_Regular_File := is_regular_file (fileno (stderr)) /= 0;
Standard_Err.Is_Temporary_File := False;
Standard_Err.Is_System_File := True;
Standard_Err.Text_Encoding := Default_Text;
Standard_Err.Access_Method := 'T';
Standard_Err.Self := Standard_Err;
Standard_Err.WC_Method := Default_WCEM;
Standard_In.Stream := stdin;
Standard_In.Name := In_Name'Access;
Standard_In.Form := Null_Str'Unrestricted_Access;
Standard_In.Mode := FCB.In_File;
Standard_In.Is_Regular_File := is_regular_file (fileno (stdin)) /= 0;
Standard_In.Is_Temporary_File := False;
Standard_In.Is_System_File := True;
Standard_In.Text_Encoding := Default_Text;
Standard_In.Access_Method := 'T';
Standard_In.Self := Standard_In;
Standard_In.WC_Method := Default_WCEM;
Standard_Out.Stream := stdout;
Standard_Out.Name := Out_Name'Access;
Standard_Out.Form := Null_Str'Unrestricted_Access;
Standard_Out.Mode := FCB.Out_File;
Standard_Out.Is_Regular_File := is_regular_file (fileno (stdout)) /= 0;
Standard_Out.Is_Temporary_File := False;
Standard_Out.Is_System_File := True;
Standard_Out.Text_Encoding := Default_Text;
Standard_Out.Access_Method := 'T';
Standard_Out.Self := Standard_Out;
Standard_Out.WC_Method := Default_WCEM;
FIO.Make_Unbuffered (AP (Standard_Out));
FIO.Make_Unbuffered (AP (Standard_Err));
end Initialize_Standard_Files;
-------------
-- Is_Open --
-------------
function Is_Open (File : File_Type) return Boolean is
begin
return FIO.Is_Open (AP (File));
end Is_Open;
----------
-- Line --
----------
-- Note: we assume that it is impossible in practice for the line
-- to exceed the value of Count'Last, i.e. no check is required for
-- overflow raising layout error.
function Line (File : File_Type) return Positive_Count is
begin
FIO.Check_File_Open (AP (File));
return File.Line;
end Line;
function Line return Positive_Count is
begin
return Line (Current_Out);
end Line;
-----------------
-- Line_Length --
-----------------
function Line_Length (File : File_Type) return Count is
begin
FIO.Check_Write_Status (AP (File));
return File.Line_Length;
end Line_Length;
function Line_Length return Count is
begin
return Line_Length (Current_Out);
end Line_Length;
----------------
-- Look_Ahead --
----------------
procedure Look_Ahead
(File : File_Type;
Item : out Wide_Wide_Character;
End_Of_Line : out Boolean)
is
ch : int;
-- Start of processing for Look_Ahead
begin
FIO.Check_Read_Status (AP (File));
-- If we are logically before a line mark, we can return immediately
if File.Before_LM then
End_Of_Line := True;
Item := Wide_Wide_Character'Val (0);
-- If we are before a wide character, just return it (this can happen
-- if there are two calls to Look_Ahead in a row).
elsif File.Before_Wide_Wide_Character then
End_Of_Line := False;
Item := File.Saved_Wide_Wide_Character;
-- otherwise we must read a character from the input stream