File: uconv.adb

package info (click to toggle)
libaws 20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,656 kB
  • sloc: ada: 95,505; python: 2,270; ansic: 1,017; makefile: 829; xml: 235; javascript: 202; java: 112; sh: 106
file content (47 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (3)
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

--  Test availability of the Unchecked_Conversion between
--  Stream_Element_Array and String

with Ada.Unchecked_Conversion;
with Ada.Streams; use Ada.Streams;
with Ada.Text_IO;
with Ada.Command_Line;

procedure Uconv is

   Sample : constant String :=
      "$Author$" & ASCII.LF &
      "$Date$" & ASCII.LF &
      "$Name$" & ASCII.LF &
      "$Locker$" & ASCII.LF &
      "$RCSfile$" & ASCII.LF &
      "$Revision$" & ASCII.LF &
      "$Source$" & ASCII.LF &
      "$State$" & ASCII.LF;

   subtype Fixed_String is String (Sample'First .. Sample'Last);

   subtype Fixed_Array is Stream_Element_Array
     (Stream_Element_Offset (Sample'First)
      .. Stream_Element_Offset (Sample'Last));

   function To_Stream_Elements is
     new Ada.Unchecked_Conversion (Fixed_String, Fixed_Array);

   function To_String is
     new Ada.Unchecked_Conversion (Fixed_Array, Fixed_String);

begin
   if Fixed_Array'Size = Fixed_String'Size
   and then Fixed_Array'Alignment = Fixed_String'Alignment
   and then Sample = To_String (To_Stream_Elements (Sample)) then
      Ada.Text_IO.Put_Line ("Use fast.");
   else
      Ada.Text_IO.Put_Line ("Use portable.");
      declare
         use Ada.Command_Line;
      begin
         Set_Exit_Status (Failure);
      end;
   end if;
end Uconv;