File: invocation.adb

package info (click to toggle)
topal 0.7.13.3-2
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 636 kB
  • ctags: 57
  • sloc: ada: 6,552; sh: 196; makefile: 125; ansic: 111
file content (163 lines) | stat: -rw-r--r-- 6,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
-- `Topal': GPG/Pine integration
--
-- Copyright (C) 2001,2002  Phillip J. Brooke
--
--     This program is free software; you can redistribute it and/or modify
--     it under the terms of the GNU General Public License as published by
--     the Free Software Foundation; either version 2 of the License, or
--     (at your option) any later version.
--
--     This program is distributed in the hope that it will be useful,
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--     GNU General Public License for more details.
--
--     You should have received a copy of the GNU General Public License
--     along with this program; if not, write to the Free Software
--     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

with Ada.Text_IO;
with Command_Line_Wrapper; use Command_Line_Wrapper;
with Misc;                 use Misc;

package body Invocation is

   procedure Parse_Options (Parse_All : Boolean) is
   begin
      loop exit when not More;
         if Match(UBS_Array'(1 => ToUBS("-debug"),
                             2 => ToUBS("-d"),
                             3 => ToUBS("--debug"),
                             4 => ToUBS("--d"))) then
            Config.Debug := True;
         elsif Match("--simple") then
            Config.FE_Simple := True;
         elsif Match("--rewrite") then
            Config.FE_Simple := False;
         elsif Match("--no-clear") then
            Config.No_Clean := True;
         else
            -- We haven't got an options match.
            if Parse_All then
               Error("Option `" & Current & "' not recognised.");
            else
               -- Don't care.
               exit;
            end if;
         end if;
      end loop;
   end Parse_Options;

   procedure Parse_Command_Line is
   begin
      -- Sort out the command-line.
      Debug("Examining command-line options...");
      -- Eat up some options.
      Parse_Options(Parse_All => False);
      if not More then
         Run_Mode := Help_Text;
      else
         if Match(UBS_Array'(1 => ToUBS("-help"),
                             2 => ToUBS("-h"),
                             3 => ToUBS("--help"),
                             4 => ToUBS("--h"),
                             5 => ToUBS("-?"),
                             6 => ToUBS("--?"))) then
            Run_Mode := Help_Text;
            Parse_Options(Parse_All => True);
         elsif Match(UBS_Array'(1 => ToUBS("-display"),
                                2 => ToUBS("-decrypt"),
                                3 => ToUBS("-verify"))) then
           -- -decrypt and -verify are legacy for release 0.4.5 to 0.5.0.
            if not More(Needed => 2) then
               Error("-display, -decrypt and -verify need two arguments: _TMPFILE_ _RESULTFILE_");
            else
               Run_Mode := Inline_Display;
               Tmpfile := Eat;
               Resultfile := Eat;
            end if;
         elsif Match("-mime") then
            if not More(Needed => 2) then
               Error("-mime needs two arguments: INFILE CONTENT-TYPE");
            else
               Run_Mode := Mime_Display;
               Infile := Eat;
               Content_Type := Eat;
            end if;
         elsif Match("-mimeapgp") then
            if not More(Needed => 2) then
               Error("-mimeapgp needs two arguments: INFILE CONTENT-TYPE");
            else
               Run_Mode := Old_Mime_Display;
               Infile := Eat;
               Content_Type := Eat;
            end if;
         elsif Match("-send") then
            if not More(Needed => 2) then
               Error("-send needs at least two arguments: _TMPFILE_ _RESULTFILE_"
                     & ", then _RECIPIENTS_");
            else
               Run_Mode := Inline_Send;
               Tmpfile := Eat;
               Resultfile := Eat;
               Recipients := Eat_Remaining_Arguments;
            end if;
         elsif Match("-sendmime") then
            if not More(Needed => 3) then
               Error("-sendmime needs at least three arguments: _TMPFILE_ _RESULTFILE_ _MIMETYPE_"
                     & ", then _RECIPIENTS_");
            else
               Run_Mode := Mime_Send;
               Tmpfile := Eat;
               Resultfile := Eat;
               Mimefile := Eat;
               Recipients := Eat_Remaining_Arguments;
            end if;
         elsif Match("-clear") then
            Run_Mode := Clear_Temp;
         elsif Match("-clearc") then
            Run_Mode := Clear_Cache;
         elsif Match("-clearall") then
            Run_Mode := Clear_All;
         elsif Match("-default") then
            Run_Mode := Dump_Default_Config;
         elsif Match("-dump") then
            Run_Mode := Dump_Current_Config;
         elsif Match("-config") then
            Run_Mode := Interactive_Config;
         elsif Match(UBS_Array'(1 => ToUBS("--fix-email"),
                                2 => ToUBS("-fe")))
           or Command_Basename = "topal-fix-email" then
            Run_Mode := Fix_Email;
         elsif Match(UBS_Array'(1 => ToUBS("--fix-folder"),
                                2 => ToUBS("-ff")))
           or Command_Basename = "topal-fix-folder" then
            Run_Mode := Fix_Folders;
            Folders := Eat_Remaining_Arguments;
         elsif Match(UBS_Array'(1 => ToUBS("-nps"),
                                2 => ToUBS("-s"))) then
            if not More then
               Error("-nps (-s) needs at least one argument: _THEFILE_"
                     & ", then _RECIPIENTS_");
            else
               Run_Mode := Nonpine_Send;
               Tmpfile := Eat;
               Recipients := Eat_Remaining_Arguments;
            end if;
         else
            -- Assume we meant topal -s arg1 arg2 ...
            Run_Mode := Nonpine_Send;
            Tmpfile := Eat;
            Recipients := Eat_Remaining_Arguments;
         end if;
      end if;
      -- Eat any remaining arguments; let's hope they're options.
      Parse_Options(Parse_All => True);
   exception
      when others =>
         Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
                              "Exception raised in Invocation.Parse_Command_Line");
         raise;
   end Parse_Command_Line;

end Invocation;