home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / adaada.zip / ADAADA.ZIP / SRC / CW_ADA / CW_SMAN_.ADA < prev    next >
Text File  |  1994-10-12  |  8KB  |  273 lines

  1. -- Copyright (c) 1994 ARINC Research Corporation
  2. -- From material copyright (c) 1991, 1992 Premia Corporation
  3. --
  4. -- This material may be reproduced by or for the US Government pursuant 
  5. -- to the copyright license under DFAR Clause 252.227-7013 (1988)
  6. --
  7. -- Developed for US Air Force under contract no. F41608-90-D-0544-0005
  8. --
  9. -- MODIFICATIONS
  10. --   94/06 - J. Neuse, SD/OSE/EA  - Initial code
  11. --   94/10 - O. Sluder, SD/OSE/EA - Cleanup
  12.  
  13. with CW_TYPES;
  14.  
  15. -- *************
  16. -- *           *
  17. -- *  CW_SMAN  *  BODY
  18. -- *           *
  19. -- *************
  20.  
  21. package body CW_SMAN is
  22.  
  23.   -- The following pragmas are required by the Meridian OpenAda for
  24.   -- Windows 2.0 compiler in the package spec and body of code to be
  25.   -- included in a DLL, or an application calling the DLL will 
  26.   -- general protection fault
  27.   pragma SUPPRESS (elaboration_check);
  28.   pragma SUPPRESS (storage_check);
  29.  
  30.   -- ..................
  31.   -- .                        .
  32.   -- .  Addr_Str_Len  .  BODY
  33.   -- .                     .
  34.   -- ..................
  35.   --
  36.   -- NOTES
  37.   --   1. This function returns the length of aa string pointed to by
  38.   --        a system address. It looks for the ASCII.NUL character which
  39.   --        delimits c strings. It is to be used in conjunction with
  40.   --        Addr_To_Str which returns an Ada string indicated by the
  41.   --        system address.
  42.   --   2. This function returns the string length including the nul char
  43.   --   3. This function is not a part of the CodeWright API
  44.  
  45.   function Addr_Str_Len (Address : in SYSTEM.ADDRESS) return INTEGER is
  46.  
  47.     Temp_Addr : SYSTEM.ADDRESS := Address;
  48.     Found_Nul : BOOLEAN        := FALSE;
  49.     Length    : INTEGER        := 1;
  50.  
  51.   begin --  function Addr_Str_Len
  52.  
  53.     Length := 1;
  54.     while not Found_Nul loop
  55.  
  56.     Find_Nul:
  57.       declare
  58.         Temp_Ch : character;
  59.         for Temp_Ch use at Temp_Addr;
  60.       begin
  61.         Found_Nul := (Temp_Ch = ASCII.NUL);
  62.         if not Found_Nul then
  63.           Length    := Length + 1;
  64.           Temp_Addr := SYSTEM."+" (Temp_Addr, 1);
  65.         end if;
  66.       end Find_Nul;
  67.  
  68.     end loop;
  69.  
  70.     return Length;
  71.  
  72.   end Addr_Str_Len;
  73.  
  74.   -- ....................
  75.   -- .                          .
  76.   -- .  Addr_To_String  .  BODY
  77.   -- .                       .
  78.   -- ....................
  79.   --
  80.   -- NOTES
  81.   --   1. This function returns a string pointed to by a system address.
  82.   --        It is to be used in conjunction with Addr_Str_Len which returns
  83.   --        the length of a string pointed to by a system address.
  84.   --        This function returns an Ada string, that is, a string without
  85.   --        the ending nul character.
  86.   --   2. The function bases the length of the returned string on the length
  87.   --        passed.  Therefore, it is the responsibility of the caller to
  88.   --        include the proper length and determine whether to include a nul
  89.   --        character from a c string.
  90.   --   3. This function is not a part of the CodeWright API.
  91.  
  92.   function Addr_To_String (Address : in SYSTEM.ADDRESS;
  93.                            Length  : in INTEGER) return STRING is
  94.  
  95.     Return_Str : STRING (1 .. Length);
  96.  
  97.   begin --  function Addr_To_String
  98.  
  99.   Assign_Str:
  100.     declare
  101.       Temp_Str : string (1 .. Length);
  102.       for Temp_Str use at Address;
  103.     begin -- Assign_Str
  104.       Return_Str (1 .. Length) := temp_str (1 .. Length);
  105.     end Assign_Str;
  106.  
  107.     return Return_Str;
  108.  
  109.   end Addr_To_String;
  110.  
  111.   -- ..............
  112.   -- .                    .
  113.   -- .  FindChar  .  BODY
  114.   -- .                 .
  115.   -- ..............
  116.   --
  117.   -- NOTES
  118.   --   1. This function is not a part of the CodeWright API.  This is provided
  119.   --        for Ada string manipulation.  The function returns the string
  120.   --        position of a specific character of a string based on a starting
  121.   --        position.
  122.  
  123.   function FindChar (Start : in INTEGER;
  124.                      Char  : in CHARACTER;
  125.                      Str   : in STRING) return INTEGER is
  126.  
  127.     i : integer := Start;
  128.  
  129.   begin --  function FindChar
  130.  
  131.     while Str (i) /= Char loop
  132.       i := i + 1;
  133.     end loop;
  134.  
  135.     return i;
  136.  
  137.   end FindChar;
  138.  
  139.   -- .............
  140.   -- .           .
  141.   -- .  StrFree  .  BODY
  142.   -- .           .
  143.   -- .............
  144.  
  145.   procedure StrFree (Str_Address : in SYSTEM.ADDRESS) is
  146.  
  147.  
  148.     -- ................
  149.     -- .              .
  150.     -- .  CW_StrFree  .  SPEC
  151.     -- .              .
  152.     -- ................
  153.  
  154.     procedure CW_StrFree (Str_Address : in SYSTEM.ADDRESS);
  155.     pragma INTERFACE (windows, CW_StrFree, "StrFree");
  156.  
  157.   begin --  procedure StrFree
  158.  
  159.     CW_StrFree (Str_Address);
  160.  
  161.   end StrFree;
  162.  
  163.   -- ..............
  164.   -- .            .
  165.   -- .  StrMatch  .  BODY
  166.   -- .            .
  167.   -- ..............
  168.  
  169.   function StrMatch (pattern : in STRING;
  170.                      str     : in STRING;
  171.                      flags   : in INTEGER;
  172.                      len     : in LONG_INTEGER) return LONG_INTEGER is
  173.  
  174.     Return_Long  : LONG_INTEGER;
  175.     Pass_Pattern : CW_TYPES.LPSTR;
  176.     Pass_Str     : CW_TYPES.LPSTR;
  177.  
  178.     -- .................
  179.     -- .               .
  180.     -- .  CW_StrMatch  .  SPEC
  181.     -- .               .
  182.     -- .................
  183.  
  184.     function CW_StrMatch (pattern : in SYSTEM.ADDRESS;
  185.                           str     : in SYSTEM.ADDRESS;
  186.                           flags   : in INTEGER;
  187.                           len     : in SYSTEM.ADDRESS) return LONG_INTEGER;
  188.     pragma INTERFACE (windows, CW_StrMatch, "StrMatch");
  189.  
  190.   begin --  function StrMatch
  191.  
  192.     Pass_Pattern := new STRING'(pattern & ASCII.NUL);
  193.     Pass_Str     := new STRING'(str & ASCII.NUL);
  194.  
  195.     Return_Long :=
  196.       CW_StrMatch (Pass_Pattern.all (Pass_Pattern.all'FIRST)'ADDRESS,
  197.                    Pass_Str.all (Pass_Str.all'FIRST)'ADDRESS, flags,
  198.                    len'ADDRESS);
  199.  
  200.     return Return_Long;
  201.  
  202.   end StrMatch;
  203.  
  204.   -- ............
  205.   -- .          .
  206.   -- .  StrNew  .  BODY
  207.   -- .          .
  208.   -- ............
  209.  
  210.   function StrNew (str : in STRING) return SYSTEM.ADDRESS is
  211.  
  212.     Pass_LPSTR     : CW_TYPES.LPSTR;
  213.     Return_Address : SYSTEM.ADDRESS;
  214.  
  215.     -- ...............
  216.     -- .             .
  217.     -- .  CW_StrNew  .  SPEC
  218.     -- .             .
  219.     -- ...............
  220.  
  221.     function CW_StrNew (str : in SYSTEM.ADDRESS) return SYSTEM.ADDRESS;
  222.     pragma INTERFACE (windows, CW_StrNew, "StrNew");
  223.  
  224.   begin
  225.  
  226.     Pass_LPSTR     := new STRING'(str & ascii.nul);
  227.     Return_Address := CW_StrNew (Pass_LPSTR.all (Pass_LPSTR.all'FIRST)'ADDRESS);
  228.     return (Return_Address);
  229.  
  230.   end StrNew;
  231.  
  232.   -- .............
  233.   -- .           .
  234.   -- .  StrTrim  .  BODY
  235.   -- .           .
  236.   -- .............
  237.  
  238.   function StrTrim (Str  : in STRING;
  239.                     cset : in STRING) return STRING is
  240.  
  241.     Length     : INTEGER;
  242.     Pass_Str   : CW_TYPES.LPSTR;
  243.     Return_Str : CW_TYPES.LPSTR;
  244.     Pass_Cset  : CW_TYPES.LPSTR;
  245.     Addr       : SYSTEM.ADDRESS;
  246.  
  247.     -- ................
  248.     -- .              .
  249.     -- .  CW_StrTrim  .  SPEC
  250.     -- .              .
  251.     -- ................
  252.  
  253.     function CW_StrTrim (string : in SYSTEM.ADDRESS;
  254.                          cset   : in SYSTEM.ADDRESS) return SYSTEM.ADDRESS;
  255.     pragma INTERFACE (windows, CW_StrTrim, "StrTrim");
  256.  
  257.   begin --  function StrTrim
  258.  
  259.     Pass_Str  := new STRING'(str & ASCII.NUL);
  260.     Pass_Cset := new STRING'(cset & ASCII.NUL);
  261.  
  262.     Addr := CW_StrTrim (Pass_Str.all (Pass_Str.all'FIRST)'ADDRESS,
  263.                         Pass_Cset.all (Pass_Cset.all'FIRST)'ADDRESS);
  264.  
  265.     Length     := Addr_Str_Len (Addr);
  266.     Return_Str := new STRING'(Addr_To_String (Addr, (Length - 1)));
  267.  
  268.     return Return_Str.all;
  269.  
  270.   end StrTrim;
  271.  
  272. end CW_SMAN;
  273.