home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / test_stdio.adb < prev    next >
Encoding:
Text File  |  1995-12-07  |  3.8 KB  |  109 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/test_stdio.adb,v $ 
  2. -- $Revision: 1.4 $ $Date: 95/02/06 11:29:47 $ $Author: mg $ 
  3. -------------------------------------------------------------------------------
  4. --
  5. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  6. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  7. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  8. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  9. -- use of this file.
  10. --
  11. -- Copyright (c) Intermetrics, Inc. 1995
  12. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  13. -- reproduction and further distribution of this file is permitted.
  14. --
  15. -------------------------------------------------------------------------------
  16.  
  17. pragma Linker_Options("-lwin32ada");
  18.  
  19.  
  20. with Ada.Unchecked_Conversion,
  21.      interfaces.c, 
  22.      interfaces.c.strings, 
  23.      stdarg, 
  24.      Stdarg.Inst, 
  25.      Win32, 
  26.      Win32.Stdio;
  27.  
  28. procedure Test_Stdio is
  29.  
  30.     use interfaces.c, interfaces.c.strings, stdarg, Stdarg.Inst, Win32.Stdio;
  31.  
  32.     I1: constant Interfaces.C.Int := 1;
  33.     C : constant Interfaces.C.Char := 'x';
  34.     S1: constant Interfaces.C.Short := 16#2345#;
  35.     F : constant Interfaces.C.Double := 12.345;
  36.  
  37.     type Rec is record
  38.        I1, 
  39.        I2, 
  40.        I3: Interfaces.C.Int;
  41.     end record;
  42.  
  43.     R: constant Rec := (1, 2, 3);
  44.  
  45.     function "&" is new Stdarg.Concat(Rec);
  46.     function "&" is new Stdarg.Concat(Interfaces.C.Short);
  47.  
  48.     function To_PCSTR is new Ada.Unchecked_Conversion (
  49.         Interfaces.C.Strings.Chars_Ptr, Win32.PCSTR);
  50.  
  51.     function LFS (S: String) return Win32.PCSTR is
  52.     begin
  53.         return To_PCSTR(New_String(S & Ascii.LF));
  54.     end LFS;
  55.  
  56.     function LFS2 (S: String) return Win32.PCSTR is
  57.     begin
  58.         return To_PCSTR(New_String(S));
  59.     end LFS2;
  60.  
  61.     LF: Character renames Ascii.LF;
  62.     F0: Win32.PCSTR := LFS(
  63.        "Answer should be:" & LF &
  64.        " i1=1, c=x, S1=0x00002345, f=12.345000, rec=1 2 3");
  65.     F1: constant String :=
  66.        " i1=%d, c=%c, S1=0x%08hx, f=%f, rec=%d %d %d";
  67.     F2: constant String :=
  68.        " c=%c, S1=0x%08hx, f=%f, rec=%d %d %d";
  69.     F3: constant String :=
  70.        " f=%f, S1=0x%08hx, f=%f, rec=%d %d %d";
  71.  
  72.     type AI is access all Interfaces.C.Int;
  73.     type AS is access all Interfaces.C.Short;
  74.     type AC is access all Interfaces.C.Char;
  75.     type AD is access all Interfaces.C.Double;
  76.  
  77.     I2: aliased Interfaces.C.Int := 1;      
  78.     S2: aliased Interfaces.C.Short := 2;    
  79.     C2: aliased Interfaces.C.Char := 'a';   
  80.     D2: aliased Interfaces.C.Double := 0.0;
  81.      
  82.     function "&" is new Stdarg.Concat(AI);
  83.     function "&" is new Stdarg.Concat(AS);
  84.     function "&" is new Stdarg.Concat(AC);
  85.     function "&" is new Stdarg.Concat(AD);
  86.  
  87.     dummy: Win32.INT;
  88. begin
  89.     dummy := printf(F0);
  90.     dummy := Printf(LFS("From printf:" & LF & F1),
  91.                 Empty & I1 & C & S1 & F & R);
  92.     dummy := VPrintf(LFS("From vprintf:" & LF & F1),
  93.                 Empty & I1 & C & S1 & F & R);
  94.     dummy := Printf(LFS("From printf:" & LF & F2),
  95.                 Empty & C & S1 & F & R);
  96.     dummy := VPrintf(LFS("From vprintf:" & LF & F2),
  97.                 Empty & C & S1 & F & R);
  98.     dummy := Printf(LFS("From printf:" & LF & F3),
  99.                 Stdarg.Empty & F & S1 & F & R);
  100.     dummy := VPrintf(LFS("From vprintf:" & LF & F3),
  101.                 Empty & F & S1 & F & R);
  102.     dummy := fprintf(stdout, LFS("hello stdout"));
  103.     dummy := fprintf(stderr, LFS("hello stderr"));
  104.     dummy := fprintf(stderr, LFS("input 2 int's, a char, and a float"));
  105.     dummy := fscanf(stdin, LFS2("%d %hd %c %lf"), 
  106.                 Empty & I2'access & S2'access & C2'access & D2'access);
  107.     dummy := printf(LFS(F1), Empty & I2 & C2 & S2 & D2 & R);
  108.     dummy := VPrintf(LFS("Done"));
  109. end Test_Stdio;