home *** CD-ROM | disk | FTP | other *** search
- -- $Source: /home/harp/1/proto/monoBANK/winnt/test_stdio.adb,v $
- -- $Revision: 1.4 $ $Date: 95/02/06 11:29:47 $ $Author: mg $
- -------------------------------------------------------------------------------
- --
- -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT
- -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- -- PURPOSE. The user assumes the entire risk as to the accuracy and the
- -- use of this file.
- --
- -- Copyright (c) Intermetrics, Inc. 1995
- -- Royalty-free, unlimited, worldwide, non-exclusive use, modification,
- -- reproduction and further distribution of this file is permitted.
- --
- -------------------------------------------------------------------------------
-
- pragma Linker_Options("-lwin32ada");
-
-
- with Ada.Unchecked_Conversion,
- interfaces.c,
- interfaces.c.strings,
- stdarg,
- Stdarg.Inst,
- Win32,
- Win32.Stdio;
-
- procedure Test_Stdio is
-
- use interfaces.c, interfaces.c.strings, stdarg, Stdarg.Inst, Win32.Stdio;
-
- I1: constant Interfaces.C.Int := 1;
- C : constant Interfaces.C.Char := 'x';
- S1: constant Interfaces.C.Short := 16#2345#;
- F : constant Interfaces.C.Double := 12.345;
-
- type Rec is record
- I1,
- I2,
- I3: Interfaces.C.Int;
- end record;
-
- R: constant Rec := (1, 2, 3);
-
- function "&" is new Stdarg.Concat(Rec);
- function "&" is new Stdarg.Concat(Interfaces.C.Short);
-
- function To_PCSTR is new Ada.Unchecked_Conversion (
- Interfaces.C.Strings.Chars_Ptr, Win32.PCSTR);
-
- function LFS (S: String) return Win32.PCSTR is
- begin
- return To_PCSTR(New_String(S & Ascii.LF));
- end LFS;
-
- function LFS2 (S: String) return Win32.PCSTR is
- begin
- return To_PCSTR(New_String(S));
- end LFS2;
-
- LF: Character renames Ascii.LF;
- F0: Win32.PCSTR := LFS(
- "Answer should be:" & LF &
- " i1=1, c=x, S1=0x00002345, f=12.345000, rec=1 2 3");
- F1: constant String :=
- " i1=%d, c=%c, S1=0x%08hx, f=%f, rec=%d %d %d";
- F2: constant String :=
- " c=%c, S1=0x%08hx, f=%f, rec=%d %d %d";
- F3: constant String :=
- " f=%f, S1=0x%08hx, f=%f, rec=%d %d %d";
-
- type AI is access all Interfaces.C.Int;
- type AS is access all Interfaces.C.Short;
- type AC is access all Interfaces.C.Char;
- type AD is access all Interfaces.C.Double;
-
- I2: aliased Interfaces.C.Int := 1;
- S2: aliased Interfaces.C.Short := 2;
- C2: aliased Interfaces.C.Char := 'a';
- D2: aliased Interfaces.C.Double := 0.0;
-
- function "&" is new Stdarg.Concat(AI);
- function "&" is new Stdarg.Concat(AS);
- function "&" is new Stdarg.Concat(AC);
- function "&" is new Stdarg.Concat(AD);
-
- dummy: Win32.INT;
- begin
- dummy := printf(F0);
- dummy := Printf(LFS("From printf:" & LF & F1),
- Empty & I1 & C & S1 & F & R);
- dummy := VPrintf(LFS("From vprintf:" & LF & F1),
- Empty & I1 & C & S1 & F & R);
- dummy := Printf(LFS("From printf:" & LF & F2),
- Empty & C & S1 & F & R);
- dummy := VPrintf(LFS("From vprintf:" & LF & F2),
- Empty & C & S1 & F & R);
- dummy := Printf(LFS("From printf:" & LF & F3),
- Stdarg.Empty & F & S1 & F & R);
- dummy := VPrintf(LFS("From vprintf:" & LF & F3),
- Empty & F & S1 & F & R);
- dummy := fprintf(stdout, LFS("hello stdout"));
- dummy := fprintf(stderr, LFS("hello stderr"));
- dummy := fprintf(stderr, LFS("input 2 int's, a char, and a float"));
- dummy := fscanf(stdin, LFS2("%d %hd %c %lf"),
- Empty & I2'access & S2'access & C2'access & D2'access);
- dummy := printf(LFS(F1), Empty & I2 & C2 & S2 & D2 & R);
- dummy := VPrintf(LFS("Done"));
- end Test_Stdio;