~ubuntu-branches/ubuntu/precise/topal/precise

« back to all changes in this revision

Viewing changes to externals.adb

  • Committer: Bazaar Package Importer
  • Author(s): Phil Brooke
  • Date: 2008-07-18 07:57:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080718075738-i1szqvmxz0evz32p
Tags: upstream-62
ImportĀ upstreamĀ versionĀ 62

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--
2
 
--
3
 
--
4
 
--
 
1
-- Topal: GPG/GnuPG and Alpine/Pine integration
 
2
-- Copyright (C) 2001--2008  Phillip J. Brooke
 
3
--
 
4
-- This program is free software: you can redistribute it and/or modify
 
5
-- it under the terms of the GNU General Public License version 3 as
 
6
-- published by the Free Software Foundation.
 
7
--
 
8
-- This program is distributed in the hope that it will be useful,
 
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
-- GNU General Public License for more details.
 
12
--
 
13
-- You should have received a copy of the GNU General Public License
 
14
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
5
15
 
6
16
with Ada.Strings.Unbounded;
7
17
with Ada.Text_IO;
31
28
                       return Interfaces.C.Strings.Chars_Ptr;
32
29
   pragma Import(C, C_Get_Env, "getenv");
33
30
 
 
31
   procedure C_Set_Env (Name      : Interfaces.C.Char_Array;
 
32
                        Value     : Interfaces.C.Char_Array;
 
33
                        Overwrite : Interfaces.C.Int);
 
34
   pragma Import(C, C_Set_Env, "setenv");
 
35
   pragma Unreferenced(C_Set_Env);
 
36
 
34
37
   procedure C_Perror (S : in Interfaces.C.char_array);
35
38
   pragma Import(C, C_Perror, "perror");
36
39
 
37
 
   C_Errno : Interfaces.C.Int;
38
 
   pragma Import(C, C_Errno, "errno");
 
40
   function C_Errno return Interfaces.C.Int;
 
41
   pragma Import(C, C_Errno, "errno_wrapper");
39
42
 
40
43
   -- Get an environment variable.
41
44
   function Get_Env (Name : String) return String is
42
 
      C_Result : Interfaces.C.Strings.Chars_Ptr
 
45
      C_Result : constant Interfaces.C.Strings.Chars_Ptr
43
46
               := C_Get_Env(Interfaces.C.To_C(Name));
44
47
      Result   : UBS;
45
48
   begin
122
125
   procedure Execvp (File : in String;
123
126
                     Argv : in UBS_Array) is
124
127
      use type Interfaces.C.Size_T;
125
 
      LI  : Interfaces.C.Size_T := Interfaces.C.Size_T(Argv'Last);
 
128
      use type Interfaces.C.Strings.Chars_Ptr;
 
129
      use type UBS;
 
130
      LI  : constant Interfaces.C.Size_T := Interfaces.C.Size_T(Argv'Last);
126
131
      AVC : Interfaces.C.Strings.Chars_Ptr_Array(0..LI+1);
127
132
      -- Last item should be NULL!
128
133
      RV  : Integer;
142
147
      end loop;
143
148
      -- Last item should be null!
144
149
      AVC(LI+1) := Interfaces.C.Strings.Null_Ptr;
 
150
      -- Actually do the exec.
145
151
      RV := Integer(C_Execvp(Interfaces.C.To_C(File), AVC));
146
152
      if RV = -1 then
147
153
         Misc.Debug("Errno is "
156
162
   exception
157
163
      when others =>
158
164
         Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
159
 
                              "Exception raised in Externals.Execvp (B)");
 
165
                              "Exception raised in Externals.Execvp (B), File=`" & File &"'");
160
166
         raise;
161
167
   end Execvp;
162
168
 
608
614
         raise;
609
615
   end ForkExec2_Out;
610
616
 
 
617
   procedure ForkExec2_Out (File1  : in  String;
 
618
                            Argv1  : in  UBS;
 
619
                            Exit1  : out Integer;
 
620
                            File2  : in  String;
 
621
                            Argv2  : in  UBS_Array;
 
622
                            Exit2  : out Integer;
 
623
                            Target : in  String) is
 
624
      AVA1 : UBS_Array := Misc.Split_Arguments(Argv1);
 
625
   begin
 
626
      ForkExec2_Out(File1, AVA1, Exit1,
 
627
                    File2, Argv2, Exit2,
 
628
                    Target);
 
629
   exception
 
630
      when others =>
 
631
         Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
 
632
                              "Exception raised in Externals.ForkExec2_Out(B)");
 
633
         raise;
 
634
   end ForkExec2_Out;
 
635
 
 
636
 
 
637
 
611
638
   procedure ForkExec2_InOut (File1  : in  String;
612
639
                              Argv1  : in  UBS_Array;
613
640
                              Exit1  : out Integer;