1
-- Topal: GPG/GnuPG and Alpine/Pine integration
2
-- Copyright (C) 2001--2008 Phillip J. Brooke
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.
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.
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/>.
6
16
with Ada.IO_Exceptions;
147
144
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
148
"Exception raised in Externals.Simple.Cat_Append");
145
"Exception raised in Externals.Simple.Cat_Append("&D1&","&D2&")");
152
149
procedure Chmod (P : in String;
153
150
D : in String) is
155
if ForkExec(Misc.Value_Nonempty(Config.Chmod_Binary),
152
if ForkExec(Misc.Value_Nonempty(Config.Binary(Chmod)),
156
153
UBS_Array'(0 => ToUBS("chmod"),
158
155
2 => ToUBS(D))) /= 0 then
192
procedure Date_1_Append (A, D : in String) is
194
if ForkExec_Append(Misc.Value_Nonempty(Config.Binary(Date)),
195
UBS_Array'(0 => ToUBS("date"),
198
Misc.Error("`date " & A & " >> " & D & "' failed.");
202
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
203
"Exception raised in Externals.Simple.Date_1_Append");
195
207
function Date_String return String is
198
Target : String := Temp_File_Name("thedate");
210
Target : constant String := Temp_File_Name("thedate");
202
if ForkExec_Out(Misc.Value_Nonempty(Config.Date_Binary),
214
if ForkExec_Out(Misc.Value_Nonempty(Config.Binary(Date)),
203
215
UBS_Array'(0 => ToUBS("date"),
204
216
1 => ToUBS("+%Y%m%d%H%M%S")),
205
217
Target) /= 0 then
602
function Test_P (D : in String) return Boolean is
604
return ForkExec(Misc.Value_Nonempty(Config.Binary(Test)),
605
UBS_Array'(0 => ToUBS("test"),
610
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
611
"Exception raised in Externals.Simple.Test_P");
562
615
function Test_S (D : in String) return Boolean is
564
return ForkExec(Misc.Value_Nonempty(Config.Test_Binary),
617
return ForkExec(Misc.Value_Nonempty(Config.Binary(Test)),
565
618
UBS_Array'(0 => ToUBS("test"),
566
619
1 => ToUBS("-S"),
567
620
2 => ToUBS(D))) = 0;
576
procedure View_MIME (F : String) is
578
if ForkExec(Misc.Value_Nonempty(Config.Metamail_Binary),
579
UBS_Array'(0 => ToUBS("metamail"),
580
1 => ToUBS(F))) /= 0 then
581
Misc.Error("metamail failed! (ff5)");
585
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
586
"Exception raised in Externals.Simple.View_MIME");
628
-- Guess content type of F using `file'.
629
function Guess_Content_Type (F : in String) return String is
632
GCT : constant String := Temp_File_Name("gct");
633
H : Ada.Text_IO.File_Type;
636
ForkExec2_Out(File1 => Value_Nonempty(Config.Binary(File)),
637
Argv1 => ToUBS("file "
638
& ToStr(Config.Gpg_Options)
642
File2 => Value_Nonempty(Config.Binary(Sed)),
643
Argv2 => UBS_Array'(0 => ToUBS("sed"),
644
1 => ToUBS("s/,.*//")),
648
Error("Problem generating keylist, GPG barfed (ff7a)");
651
Error("Problem generating keylist, grep barfed (ff7b)");
653
Ada.Text_IO.Open(File => H,
654
Mode => Ada.Text_IO.In_File,
656
First_Line := Unbounded_Get_Line(H);
657
Ada.Text_IO.Close(H);
658
return ToStr(First_Line);
661
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
662
"Exception raised in Externals.Simple.Guess_Content_Type");
664
end Guess_Content_Type;
668
-- Use locale charmap to get the current keymap.
669
function Get_Charmap return String is
672
GCM : constant String := Temp_File_Name("gcm");
673
H : Ada.Text_IO.File_Type;
676
E := ForkExec_Out(File => Value_Nonempty(Config.Binary(Locale)),
677
Argv => ToUBS("locale charmap"),
680
Error("Problem extracting charmap from locale (ff10)");
682
Ada.Text_IO.Open(File => H,
683
Mode => Ada.Text_IO.In_File,
685
First_Line := Unbounded_Get_Line(H);
686
Ada.Text_IO.Close(H);
687
return ToStr(First_Line);
690
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
691
"Exception raised in Externals.Simple.Get_Charmap");
695
-- Convert charmaps within a single file (F) from charset CF to
697
procedure Convert_Charmap (F, CF, CT : in String) is
700
CCM : constant String := Temp_File_Name("ccm");
702
Misc.Debug("Convert_Charmap: attempt conversion of file `"
709
E := ForkExec_InOut(File => Value_Nonempty(Config.Binary(Iconv)),
710
Argv => ToUBS("iconv -f " & CF & " -t " & CT),
714
Error("Problem converting file charmap (ff15)");
720
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
721
"Exception raised in Externals.Simple.Convert_Charmap");
725
-- Equivalent of `system'.
726
function System (Argv : in UBS) return Integer is
727
A : UBS_Array := Misc.Split_Arguments(Argv);
729
return ForkExec(ToStr(A(A'First)), Argv);
732
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
733
"Exception raised in Externals.Simple.System (Argv=`" & ToStr(Argv) & "'");
737
function System (Argv : in String) return Integer is
739
return System(ToUBS(Argv));
742
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
743
"Exception raised in Externals.Simple.System (B)");
590
747
end Externals.Simple;