~ubuntu-branches/debian/experimental/lftp/experimental

« back to all changes in this revision

Viewing changes to src/CmdExec.h

  • Committer: Package Import Robot
  • Author(s): Noël Köthe
  • Date: 2015-08-21 16:06:22 UTC
  • mfrom: (1.1.20) (24.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20150821160622-lckdmbiqx16wefgy
Tags: 4.6.4-1
new upstream release 2015-08-21

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * lftp and utils
 
2
 * lftp - file transfer program
3
3
 *
4
 
 * Copyright (c) 1996-2007 by Alexander V. Lukyanov (lav@yars.free.net)
 
4
 * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net)
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
 
/* $Id: CmdExec.h,v 1.70 2009/07/17 12:48:41 lav Exp $ */
22
 
 
23
20
#ifndef CMDEXEC_H
24
21
#define CMDEXEC_H
25
22
 
55
52
 
56
53
   virtual void Fg() {}
57
54
   virtual void Bg() {}
 
55
 
 
56
   virtual bool IsInteractive() const { return false; }
58
57
};
59
58
 
60
59
extern CmdFeeder *lftp_feeder;   // feeder to use after 'lftp' command
61
60
 
62
 
class CmdExec : public SessionJob
 
61
class CmdExec : public SessionJob, public ResClient
63
62
{
64
63
public:
65
64
// current command data
70
69
   int   prev_exit_code;
71
70
 
72
71
private:
 
72
   CmdExec *parent_exec;
73
73
   Buffer cmd_buf;
74
74
   bool partial_cmd;
75
75
   int alias_field; // length of expanded alias (and ttl for used_aliases)
 
76
   int failed_exit_code;
76
77
 
77
78
   TouchedAlias *used_aliases;
78
79
   void free_used_aliases();
115
116
   CmdFeeder *feeder;
116
117
   bool feeder_called;
117
118
 
 
119
   bool fed_at_finish;
 
120
   void AtFinish();
 
121
 
118
122
   enum builtins
119
123
   {
120
124
      BUILTIN_NONE=0,
146
150
   void ReuseSavedSession();
147
151
   void RevertToSavedSession();
148
152
 
 
153
   void init(LocalDirectory *c);
 
154
 
149
155
public:
150
156
   void FeedCmd(const char *c);
151
157
   void FeedArgV(const ArgV *,int start=0);
152
158
   void PrependCmd(const char *c);
153
159
   void ExecParsed(ArgV *a,FDStream *o=0,bool b=false);
154
 
   static int unquote(char *buf,const char *str);  // returns buf length
155
 
   static const char *unquote(const char *str);
156
 
   static bool needs_quotation(const char *buf);
 
160
   static bool needs_quotation(const char *buf,int len);
 
161
   static bool needs_quotation(const char *buf) { return needs_quotation(buf,strlen(buf)); }
157
162
   static bool quotable(char c,char in_quotes);
158
163
   static bool is_space(char c) { return c==' ' || c=='\t'; }
159
164
   static bool is_quote(char c) { return c=='"' || c=='\''; }
160
165
   void FeedQuoted(const char *c);
161
166
   void Exit(int);
162
167
   void AtExit();
 
168
   void AtExitBg();
 
169
   void AtExitFg();
 
170
   void AtBackground();
 
171
   void AtTerminate();
163
172
   void EmptyCmds();
164
173
   bool WriteCmds(int fd) const;
165
174
   bool ReadCmds(int fd); // does not clear queue before reading (appends)
166
175
 
 
176
   void AddNewJob(Job *new_job);
167
177
   void SuspendJob(Job *j);
168
178
 
169
179
   CmdExec(FileAccess *s,LocalDirectory *c);
 
180
   CmdExec(CmdExec *parent);
170
181
   ~CmdExec();
171
182
 
172
183
   bool Idle(); // when we have no command running and command buffer is empty
173
184
   int Done();
174
 
   int ExitCode() { return exit_code; }
 
185
   int ExitCode() { return failed_exit_code ? failed_exit_code : exit_code; }
175
186
   int Do();
176
 
   void PrintStatus(int,const char *prefix="\t");
 
187
   xstring& FormatStatus(xstring&,int,const char *prefix="\t");
177
188
   void ShowRunStatus(const SMTaskRef<StatusLine>& s);
178
189
   int AcceptSig(int sig);
179
190
 
181
192
   const char *MakePrompt();
182
193
 
183
194
   bool interactive;
 
195
   bool show_status;
184
196
   bool top_level;
185
197
   bool verbose;
186
198
   bool auto_terminate_in_bg;
213
225
   void top_vfprintf(FILE *file,const char *f,va_list v);
214
226
 
215
227
   void SetInteractive(bool i);
 
228
   void SetInteractive();
216
229
   void SetTopLevel()
217
230
      {
218
231
         top_level=true;
219
232
         Reconfig(0);
 
233
         SetInteractive();
220
234
      }
221
235
   void SetStatusLine(StatusLine *s) { status_line=s; }
222
236
   void SetAutoTerminateInBackground(bool b) { auto_terminate_in_bg=b; }
233
247
   Job *builtin_glob();
234
248
   Job *builtin_queue();
235
249
   Job *builtin_queue_edit();
 
250
   Job *builtin_local();
236
251
 
 
252
   bool load_cmd_module(const char *op);
237
253
   Job *default_cmd();
238
254
 
239
255
   void ChangeSession(FileAccess *new_session);
240
256
 
241
 
   void print_cmd_help(const char *cmd);
 
257
   bool print_cmd_help(const char *cmd);
242
258
   void print_cmd_index();
243
259
 
244
260
   static const char *CmdByIndex(int i);