1
|
1 /*****************************************************************************/
|
|
2 /* gftp-text.c - text port of gftp */
|
122
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
1
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp-text.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 static gftp_request * gftp_text_locreq = NULL;
|
|
24 static gftp_request * gftp_text_remreq = NULL;
|
|
25 static volatile int cancel = 0;
|
|
26 static int configuration_changed = 0,
|
|
27 number_commands = 30;
|
|
28
|
|
29 struct _gftp_text_methods gftp_text_methods[] = {
|
|
30 {N_("about"), 2, gftp_text_about, NULL,
|
37
|
31 N_("Shows gFTP information"), NULL},
|
1
|
32 {N_("ascii"), 2, gftp_text_ascii, &gftp_text_remreq,
|
37
|
33 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
|
1
|
34 {N_("binary"), 1, gftp_text_binary, &gftp_text_remreq,
|
37
|
35 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
|
1
|
36 {N_("cd"), 2, gftp_text_cd, &gftp_text_remreq,
|
37
|
37 N_("Changes the remote working directory"), NULL},
|
1
|
38 {N_("chdir"), 3, gftp_text_cd, &gftp_text_remreq,
|
37
|
39 N_("Changes the remote working directory"), NULL},
|
1
|
40 {N_("chmod"), 3, gftp_text_chmod, &gftp_text_remreq,
|
37
|
41 N_("Changes the permissions of a remote file"), NULL},
|
|
42 {N_("clear"), 3, gftp_text_clear, NULL,
|
|
43 N_("Available options: cache"), gftp_text_clear_show_subhelp},
|
|
44 {N_("close"), 3, gftp_text_close, &gftp_text_remreq,
|
|
45 N_("Disconnects from the remote site"), NULL},
|
1
|
46 {N_("delete"), 1, gftp_text_delete, &gftp_text_remreq,
|
37
|
47 N_("Removes a remote file"), NULL},
|
1
|
48 {N_("get"), 1, gftp_text_mget_file, NULL,
|
37
|
49 N_("Downloads remote file(s)"), NULL},
|
1
|
50 {N_("help"), 1, gftp_text_help, NULL,
|
37
|
51 N_("Shows this help screen"), NULL},
|
1
|
52 {N_("lcd"), 3, gftp_text_cd, &gftp_text_locreq,
|
37
|
53 N_("Changes the local working directory"), NULL},
|
1
|
54 {N_("lchdir"), 4, gftp_text_cd, &gftp_text_locreq,
|
37
|
55 N_("Changes the local working directory"), NULL},
|
1
|
56 {N_("lchmod"), 4, gftp_text_chmod, &gftp_text_locreq,
|
37
|
57 N_("Changes the permissions of a local file"), NULL},
|
1
|
58 {N_("ldelete"), 2, gftp_text_delete, &gftp_text_locreq,
|
37
|
59 N_("Removes a local file"), NULL},
|
1
|
60 {N_("lls"), 2, gftp_text_ls, &gftp_text_locreq,
|
37
|
61 N_("Shows the directory listing for the current local directory"), NULL},
|
1
|
62 {N_("lmkdir"), 2, gftp_text_mkdir, &gftp_text_locreq,
|
37
|
63 N_("Creates a local directory"), NULL},
|
1
|
64 {N_("lpwd"), 2, gftp_text_pwd, &gftp_text_locreq,
|
37
|
65 N_("Show current local directory"), NULL},
|
1
|
66 {N_("lrename"), 3, gftp_text_rename, &gftp_text_locreq,
|
37
|
67 N_("Rename a local file"), NULL},
|
1
|
68 {N_("lrmdir"), 3, gftp_text_rmdir, &gftp_text_locreq,
|
37
|
69 N_("Remove a local directory"), NULL},
|
1
|
70 {N_("ls"), 2, gftp_text_ls, &gftp_text_remreq,
|
37
|
71 N_("Shows the directory listing for the current remote directory"), NULL},
|
1
|
72 {N_("mget"), 2, gftp_text_mget_file, NULL,
|
37
|
73 N_("Downloads remote file(s)"), NULL},
|
1
|
74 {N_("mkdir"), 2, gftp_text_mkdir, &gftp_text_remreq,
|
37
|
75 N_("Creates a remote directory"), NULL},
|
1
|
76 {N_("mput"), 2, gftp_text_mput_file, NULL,
|
37
|
77 N_("Uploads local file(s)"), NULL},
|
1
|
78 {N_("open"), 1, gftp_text_open, &gftp_text_remreq,
|
37
|
79 N_("Opens a connection to a remote site"), NULL},
|
1
|
80 {N_("put"), 2, gftp_text_mput_file, NULL,
|
37
|
81 N_("Uploads local file(s)"), NULL},
|
1
|
82 {N_("pwd"), 2, gftp_text_pwd, &gftp_text_remreq,
|
37
|
83 N_("Show current remote directory"), NULL},
|
1
|
84 {N_("quit"), 1, gftp_text_quit, NULL,
|
37
|
85 N_("Exit from gFTP"), NULL},
|
1
|
86 {N_("rename"), 2, gftp_text_rename, &gftp_text_remreq,
|
37
|
87 N_("Rename a remote file"), NULL},
|
1
|
88 {N_("rmdir"), 2, gftp_text_rmdir, &gftp_text_remreq,
|
37
|
89 N_("Remove a remote directory"), NULL},
|
1
|
90 {N_("set"), 1, gftp_text_set, NULL,
|
37
|
91 N_("Show configuration file variables. You can also set variables by set var=val"), gftp_text_set_show_subhelp},
|
1
|
92 {NULL, 0, NULL, NULL, NULL}};
|
|
93
|
|
94 int
|
|
95 main (int argc, char **argv)
|
|
96 {
|
122
|
97 char *pos, *stpos, *startup_directory;
|
1
|
98 gftp_request * request;
|
|
99 size_t len, cmdlen;
|
|
100 int i;
|
|
101 #ifdef HAVE_LIBREADLINE
|
|
102 char *tempstr, prompt[20];
|
|
103 #else
|
|
104 char tempstr[512];
|
|
105 #endif
|
|
106
|
|
107 #ifdef HAVE_GETTEXT
|
|
108 setlocale (LC_ALL, "");
|
|
109 bindtextdomain ("gftp", LOCALE_DIR);
|
|
110 textdomain ("gftp");
|
|
111 #endif
|
|
112
|
|
113 signal (SIGCHLD, sig_child);
|
|
114 signal (SIGPIPE, SIG_IGN);
|
|
115
|
124
|
116 gftp_read_config_file (SHARE_DIR);
|
|
117
|
|
118 if (gftp_parse_command_line (&argc, &argv) != 0)
|
|
119 exit (0);
|
1
|
120
|
|
121 /* SSH doesn't support reading the password with askpass via the command
|
|
122 line */
|
|
123
|
|
124 gftp_text_remreq = gftp_request_new ();
|
122
|
125 gftp_set_request_option (gftp_text_remreq, "ssh_use_askpass",
|
|
126 GINT_TO_POINTER(0));
|
|
127 gftp_set_request_option (gftp_text_remreq, "ssh_use_sftp_subsys",
|
|
128 GINT_TO_POINTER(0));
|
1
|
129 gftp_text_remreq->logging_function = gftp_text_log;
|
|
130
|
|
131 gftp_text_locreq = gftp_request_new ();
|
122
|
132 gftp_set_request_option (gftp_text_locreq, "ssh_use_askpass",
|
|
133 GINT_TO_POINTER(0));
|
|
134 gftp_set_request_option (gftp_text_locreq, "ssh_use_sftp_subsys",
|
|
135 GINT_TO_POINTER(0));
|
1
|
136 gftp_text_locreq->logging_function = gftp_text_log;
|
|
137 gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq);
|
122
|
138
|
|
139 gftp_lookup_request_option (gftp_text_locreq, "startup_directory",
|
|
140 &startup_directory);
|
|
141 if (*startup_directory != '\0')
|
1
|
142 gftp_set_directory (gftp_text_locreq, startup_directory);
|
122
|
143
|
1
|
144 gftp_connect (gftp_text_locreq);
|
|
145
|
122
|
146 gftp_text_log (gftp_logging_misc, NULL, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);
|
1
|
147 gftp_text_log (gftp_logging_recv, NULL, "masneyb@gftp.org");
|
|
148 gftp_text_log (gftp_logging_misc, NULL, _(">.\nIf you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n"));
|
|
149 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
150 gftp_text_log (gftp_logging_misc, NULL, _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n"));
|
|
151 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
152
|
|
153 if (argc == 3 && strcmp (argv[1], "-d") == 0)
|
|
154 {
|
|
155 if ((pos = strrchr (argv[2], '/')) != NULL)
|
|
156 *pos = '\0';
|
|
157 gftp_text_open (gftp_text_remreq, argv[2], NULL);
|
|
158
|
|
159 if (pos != NULL)
|
|
160 *pos = '/';
|
|
161
|
|
162 gftp_text_mget_file (gftp_text_remreq, pos + 1, NULL);
|
|
163 exit (0);
|
|
164 }
|
|
165 else if (argc == 2)
|
|
166 gftp_text_open (gftp_text_remreq, argv[1], NULL);
|
|
167
|
|
168 #ifdef HAVE_LIBREADLINE
|
|
169 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
170 while ((tempstr = readline (prompt)))
|
|
171 #else
|
|
172 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
173 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
|
|
174 #endif
|
|
175 {
|
|
176 len = strlen (tempstr);
|
|
177 if (tempstr[len - 1] == '\n')
|
|
178 tempstr[--len] = '\0';
|
|
179 if (tempstr[len - 1] == '\r')
|
|
180 tempstr[--len] = '\0';
|
|
181
|
|
182 for (stpos = tempstr; *stpos == ' '; stpos++);
|
|
183
|
|
184 for (pos = tempstr + len - 1;
|
|
185 (*pos == ' ' || *pos == '\t') && pos > tempstr;
|
|
186 pos--)
|
|
187 *pos = '\0';
|
|
188
|
|
189 if (*stpos == '\0')
|
|
190 {
|
|
191 #ifndef HAVE_LIBREADLINE
|
|
192 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
193 #endif
|
|
194 continue;
|
|
195 }
|
|
196
|
|
197 #ifdef HAVE_LIBREADLINE
|
|
198 add_history (tempstr);
|
|
199 #endif
|
|
200
|
|
201 if ((pos = strchr (stpos, ' ')) != NULL)
|
|
202 *pos = '\0';
|
|
203 cmdlen = strlen (stpos);
|
|
204
|
|
205 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
206 {
|
|
207 if (strcmp (gftp_text_methods[i].command, stpos) == 0)
|
|
208 break;
|
|
209 else if (cmdlen >= gftp_text_methods[i].minlen &&
|
|
210 strncmp (gftp_text_methods[i].command, stpos, cmdlen) == 0)
|
|
211 break;
|
|
212 }
|
|
213
|
|
214 if (pos != NULL)
|
|
215 pos++;
|
|
216 else
|
|
217 pos = "";
|
|
218
|
|
219 if (gftp_text_methods[i].command != NULL)
|
|
220 {
|
|
221 if (gftp_text_methods[i].request != NULL)
|
|
222 request = *gftp_text_methods[i].request;
|
|
223 else
|
|
224 request = NULL;
|
|
225
|
|
226 if (gftp_text_methods[i].func (request, pos, NULL) == 0)
|
|
227 break;
|
|
228 }
|
|
229 else
|
|
230 gftp_text_log (gftp_logging_error, NULL,
|
|
231 _("Error: Command not recognized\n"));
|
|
232
|
|
233 #ifdef HAVE_LIBREADLINE
|
|
234 free (tempstr);
|
|
235 #else
|
|
236 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
237 #endif
|
|
238 }
|
|
239
|
122
|
240 if (gftp_logfd != NULL)
|
|
241 fclose (gftp_logfd);
|
1
|
242 gftp_text_quit (NULL, NULL, NULL);
|
|
243
|
|
244 return (0);
|
|
245 }
|
|
246
|
|
247
|
|
248 void
|
|
249 gftp_text_log (gftp_logging_level level, void *ptr, const char *string, ...)
|
|
250 {
|
|
251 char tempstr[512], *stpos, *endpos;
|
|
252 va_list argp;
|
|
253 int sw;
|
|
254
|
|
255 g_return_if_fail (string != NULL);
|
|
256
|
|
257 switch (level)
|
|
258 {
|
|
259 case gftp_logging_send:
|
|
260 printf ("%s", COLOR_GREEN);
|
|
261 break;
|
|
262 case gftp_logging_recv:
|
|
263 printf ("%s", COLOR_YELLOW);
|
|
264 break;
|
|
265 case gftp_logging_error:
|
|
266 printf ("%s", COLOR_RED);
|
|
267 break;
|
|
268 default:
|
|
269 printf ("%s", COLOR_DEFAULT);
|
|
270 break;
|
|
271 }
|
|
272
|
|
273 va_start (argp, string);
|
|
274 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
|
|
275 va_end (argp);
|
|
276
|
122
|
277 if (gftp_logfd != NULL)
|
1
|
278 {
|
122
|
279 fwrite (tempstr, 1, strlen (tempstr), gftp_logfd);
|
|
280 if (ferror (gftp_logfd))
|
1
|
281 {
|
122
|
282 fclose (gftp_logfd);
|
|
283 gftp_logfd = NULL;
|
1
|
284 }
|
|
285 else
|
122
|
286 fflush (gftp_logfd);
|
1
|
287 }
|
|
288
|
|
289 sw = gftp_text_get_win_size ();
|
|
290 stpos = tempstr;
|
|
291 endpos = tempstr + 1;
|
|
292 do
|
|
293 {
|
|
294 if (strlen (stpos) <= sw)
|
|
295 {
|
|
296 printf ("%s", stpos);
|
|
297 break;
|
|
298 }
|
|
299 for (endpos = stpos + sw - 1; *endpos != ' ' && endpos > stpos; endpos--);
|
|
300 if (endpos != stpos)
|
|
301 {
|
|
302 *endpos = '\0';
|
|
303 }
|
|
304 printf ("%s\n", stpos);
|
|
305 stpos = endpos + 1;
|
|
306 }
|
|
307 while (stpos != endpos);
|
|
308
|
|
309 printf ("%s", COLOR_DEFAULT);
|
|
310 }
|
|
311
|
|
312
|
|
313 int
|
|
314 gftp_text_open (gftp_request * request, char *command, gpointer *data)
|
|
315 {
|
|
316 char tempstr[255], *pos;
|
|
317
|
|
318 if (GFTP_IS_CONNECTED (request))
|
|
319 {
|
|
320 gftp_disconnect (request);
|
|
321 }
|
|
322
|
|
323 if (*command == '\0')
|
|
324 {
|
|
325 gftp_text_log (gftp_logging_error, NULL,
|
|
326 _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n"));
|
|
327 return (1);
|
|
328 }
|
|
329
|
|
330 if (gftp_parse_url (request, command) < 0)
|
|
331 {
|
|
332 gftp_text_log (gftp_logging_error, NULL,
|
|
333 _("Could not parse URL %s\n"), command);
|
|
334 return (1);
|
|
335 }
|
|
336
|
122
|
337 if (request->username == NULL)
|
1
|
338 {
|
|
339 if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr,
|
|
340 sizeof (tempstr))) != NULL)
|
|
341 {
|
|
342 gftp_set_username (request, pos);
|
|
343 if (request->password)
|
|
344 {
|
|
345 g_free (request->password);
|
|
346 request->password = NULL;
|
|
347 }
|
|
348 }
|
67
|
349 else
|
|
350 gftp_set_username (request, "anonymous");
|
1
|
351 }
|
|
352
|
122
|
353 if (strcmp (request->username, "anonymous") != 0 &&
|
1
|
354 (request->password == NULL || *request->password == '\0'))
|
|
355 {
|
|
356 if ((pos = gftp_text_ask_question ("Password", 0, tempstr,
|
|
357 sizeof (tempstr))) == NULL)
|
|
358 return (1);
|
|
359 gftp_set_password (request, pos);
|
|
360 }
|
|
361
|
|
362 gftp_connect (request);
|
|
363 return (1);
|
|
364 }
|
|
365
|
|
366
|
|
367 int
|
|
368 gftp_text_close (gftp_request * request, char *command, gpointer *data)
|
|
369 {
|
|
370 gftp_disconnect (request);
|
|
371 return (1);
|
|
372 }
|
|
373
|
|
374
|
|
375 int
|
|
376 gftp_text_about (gftp_request * request, char *command, gpointer *data)
|
|
377 {
|
|
378 char *str;
|
|
379
|
|
380 gftp_text_log (gftp_logging_misc, NULL,
|
122
|
381 "%s. Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>\n",
|
|
382 gftp_version);
|
1
|
383
|
|
384 str = _("Translated by");
|
|
385 if (strcmp (str, "Translated by") != 0)
|
|
386 gftp_text_log (gftp_logging_misc, NULL, "%s\n", str);
|
|
387 return (1);
|
|
388 }
|
|
389
|
|
390
|
|
391 int
|
|
392 gftp_text_quit (gftp_request * request, char *command, gpointer *data)
|
|
393 {
|
|
394 gftp_clear_cache_files ();
|
|
395 if (configuration_changed)
|
|
396 gftp_write_config_file ();
|
|
397 return (0);
|
|
398 }
|
|
399
|
|
400
|
|
401 int
|
|
402 gftp_text_pwd (gftp_request * request, char *command, gpointer *data)
|
|
403 {
|
|
404 if (!GFTP_IS_CONNECTED (request))
|
|
405 {
|
|
406 gftp_text_log (gftp_logging_error, NULL,
|
|
407 _("Error: Not connected to a remote site\n"));
|
|
408 return (1);
|
|
409 }
|
|
410 gftp_text_log (gftp_logging_misc, NULL, "%s\n", request->directory);
|
|
411 return (1);
|
|
412 }
|
|
413
|
|
414
|
|
415 int
|
|
416 gftp_text_cd (gftp_request * request, char *command, gpointer *data)
|
|
417 {
|
|
418 char *newdir = NULL;
|
|
419
|
|
420 if (!GFTP_IS_CONNECTED (request))
|
|
421 {
|
|
422 gftp_text_log (gftp_logging_error, NULL,
|
|
423 _("Error: Not connected to a remote site\n"));
|
|
424 return (1);
|
|
425 }
|
|
426 else if (*command == '\0')
|
|
427 {
|
|
428 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
|
|
429 return (1);
|
|
430 }
|
|
431 else if (request->protonum == GFTP_LOCAL_NUM &&
|
|
432 (newdir = expand_path (command)) == NULL)
|
|
433 {
|
|
434 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
|
|
435 return (1);
|
|
436 }
|
|
437
|
|
438 gftp_set_directory (request, newdir != NULL ? newdir : command);
|
|
439
|
|
440 if (newdir != NULL)
|
|
441 g_free (newdir);
|
|
442
|
|
443 return (1);
|
|
444 }
|
|
445
|
|
446
|
|
447 int
|
|
448 gftp_text_mkdir (gftp_request * request, char *command, gpointer *data)
|
|
449 {
|
|
450 if (!GFTP_IS_CONNECTED (request))
|
|
451 {
|
|
452 gftp_text_log (gftp_logging_error, NULL,
|
|
453 _("Error: Not connected to a remote site\n"));
|
|
454 return (1);
|
|
455 }
|
|
456
|
|
457 if (*command == '\0')
|
|
458 {
|
|
459 gftp_text_log (gftp_logging_error, NULL,
|
|
460 _("usage: mkdir <new directory>\n"));
|
|
461 }
|
|
462 else
|
|
463 {
|
|
464 gftp_make_directory (request, command);
|
|
465 }
|
|
466 return (1);
|
|
467 }
|
|
468
|
|
469
|
|
470 int
|
|
471 gftp_text_rmdir (gftp_request * request, char *command, gpointer *data)
|
|
472 {
|
|
473 if (!GFTP_IS_CONNECTED (request))
|
|
474 {
|
|
475 gftp_text_log (gftp_logging_error, NULL,
|
|
476 _("Error: Not connected to a remote site\n"));
|
|
477 return (1);
|
|
478 }
|
|
479
|
|
480 if (*command == '\0')
|
|
481 {
|
|
482 gftp_text_log (gftp_logging_error, NULL, _("usage: rmdir <directory>\n"));
|
|
483 }
|
|
484 else
|
|
485 {
|
|
486 gftp_remove_directory (request, command);
|
|
487 }
|
|
488 return (1);
|
|
489 }
|
|
490
|
|
491
|
|
492 int
|
|
493 gftp_text_delete (gftp_request * request, char *command, gpointer *data)
|
|
494 {
|
|
495 if (!GFTP_IS_CONNECTED (request))
|
|
496 {
|
|
497 gftp_text_log (gftp_logging_error, NULL,
|
|
498 _("Error: Not connected to a remote site\n"));
|
|
499 return (1);
|
|
500 }
|
|
501
|
|
502 if (*command == '\0')
|
|
503 {
|
|
504 gftp_text_log (gftp_logging_error, NULL,_("usage: delete <file>\n"));
|
|
505 }
|
|
506 else
|
|
507 {
|
|
508 gftp_remove_file (request, command);
|
|
509 }
|
|
510 return (1);
|
|
511 }
|
|
512
|
|
513
|
|
514 int
|
|
515 gftp_text_rename (gftp_request * request, char *command, gpointer *data)
|
|
516 {
|
|
517 char *pos;
|
|
518
|
|
519 if (!GFTP_IS_CONNECTED (request))
|
|
520 {
|
|
521 gftp_text_log (gftp_logging_error, NULL,
|
|
522 _("Error: Not connected to a remote site\n"));
|
|
523 return (1);
|
|
524 }
|
|
525
|
|
526 if ((pos = strchr (command, ' ')) != NULL)
|
|
527 *pos++ = '\0';
|
|
528
|
|
529 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
530 {
|
|
531 gftp_text_log (gftp_logging_error, NULL,
|
|
532 _("usage: rename <old name> <new name>\n"));
|
|
533 }
|
|
534 else
|
|
535 {
|
|
536 gftp_rename_file (request, command, pos);
|
|
537 }
|
|
538 return (1);
|
|
539 }
|
|
540
|
|
541
|
|
542 int
|
|
543 gftp_text_chmod (gftp_request * request, char *command, gpointer *data)
|
|
544 {
|
|
545 char *pos;
|
|
546
|
|
547 if (!GFTP_IS_CONNECTED (request))
|
|
548 {
|
|
549 gftp_text_log (gftp_logging_error, NULL,
|
|
550 _("Error: Not connected to a remote site\n"));
|
|
551 return (1);
|
|
552 }
|
|
553
|
|
554 if ((pos = strchr (command, ' ')) != NULL)
|
|
555 *pos++ = '\0';
|
|
556
|
|
557 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
558 {
|
|
559 gftp_text_log (gftp_logging_error, NULL,
|
|
560 _("usage: chmod <mode> <file>\n"));
|
|
561 }
|
|
562 else
|
|
563 {
|
|
564 gftp_chmod (request, pos, strtol (command, NULL, 10));
|
|
565 }
|
|
566 return (1);
|
|
567 }
|
|
568
|
|
569
|
|
570 int
|
|
571 gftp_text_ls (gftp_request * request, char *command, gpointer *data)
|
|
572 {
|
37
|
573 GList * files, * templist, * delitem;
|
1
|
574 char *color, buf[20], *filespec;
|
37
|
575 int sortcol, sortasds;
|
|
576 gftp_file * fle;
|
1
|
577 time_t curtime;
|
|
578
|
|
579 time (&curtime);
|
|
580 if (!GFTP_IS_CONNECTED (request))
|
|
581 {
|
|
582 gftp_text_log (gftp_logging_error, NULL,
|
|
583 _("Error: Not connected to a remote site\n"));
|
|
584 return (1);
|
|
585 }
|
|
586
|
|
587 filespec = *command != '\0' ? command : NULL;
|
|
588 if (gftp_list_files (request) != 0)
|
|
589 return (1);
|
|
590
|
37
|
591 files = NULL;
|
|
592 fle = g_malloc0 (sizeof (*fle));
|
|
593 while (gftp_get_next_file (request, NULL, fle) > 0)
|
1
|
594 {
|
37
|
595 if (strcmp (fle->file, ".") == 0)
|
1
|
596 {
|
37
|
597 gftp_file_destroy (fle);
|
1
|
598 continue;
|
|
599 }
|
37
|
600 files = g_list_prepend (files, fle);
|
|
601 fle = g_malloc0 (sizeof (*fle));
|
|
602 }
|
|
603 g_free (fle);
|
1
|
604
|
58
|
605 if (files == NULL)
|
|
606 return (1);
|
|
607
|
37
|
608 if (request == gftp_text_locreq)
|
|
609 {
|
122
|
610 gftp_lookup_request_option (request, "local_sortcol", &sortcol);
|
|
611 gftp_lookup_request_option (request, "local_sortasds", &sortasds);
|
37
|
612 }
|
|
613 else
|
|
614 {
|
122
|
615 gftp_lookup_request_option (request, "remote_sortcol", &sortcol);
|
|
616 gftp_lookup_request_option (request, "remote_sortasds", &sortasds);
|
37
|
617 }
|
|
618
|
|
619 files = gftp_sort_filelist (files, sortcol, sortasds);
|
|
620 delitem = NULL;
|
|
621 for (templist = files; templist != NULL; templist = templist->next)
|
|
622 {
|
|
623 if (delitem != NULL)
|
|
624 {
|
|
625 fle = delitem->data;
|
|
626 gftp_file_destroy (fle);
|
|
627 g_free (fle);
|
|
628 delitem = NULL;
|
|
629 }
|
|
630
|
|
631 fle = templist->data;
|
|
632
|
|
633 if (*fle->attribs == 'd')
|
1
|
634 color = COLOR_BLUE;
|
37
|
635 else if (*fle->attribs == 'l')
|
1
|
636 color = COLOR_WHITE;
|
37
|
637 else if (strchr (fle->attribs, 'x') != NULL)
|
1
|
638 color = COLOR_GREEN;
|
|
639 else
|
|
640 color = COLOR_DEFAULT;
|
|
641
|
37
|
642 if (curtime > fle->datetime + 6 * 30 * 24 * 60 * 60 ||
|
|
643 curtime < fle->datetime - 60 * 60)
|
|
644 strftime (buf, sizeof (buf), "%b %d %Y", localtime (&fle->datetime));
|
1
|
645 else
|
37
|
646 strftime (buf, sizeof (buf), "%b %d %H:%M", localtime (&fle->datetime));
|
1
|
647
|
16
|
648 #if defined (_LARGEFILE_SOURCE)
|
|
649 printf ("%s %8s %8s %10lld %s %s%s%s\n",
|
|
650 #else
|
|
651 printf ("%s %8s %8s %10ld %s %s%s%s\n",
|
|
652 #endif
|
37
|
653 fle->attribs, fle->user, fle->group,
|
|
654 fle->size, buf, color, fle->file, COLOR_DEFAULT);
|
|
655 delitem = templist;
|
1
|
656 }
|
|
657 gftp_end_transfer (request);
|
37
|
658
|
|
659 if (delitem != NULL)
|
|
660 {
|
|
661 fle = delitem->data;
|
|
662 gftp_file_destroy (fle);
|
|
663 g_free (fle);
|
|
664 delitem = NULL;
|
|
665 }
|
|
666
|
|
667 if (files != NULL)
|
|
668 g_list_free (files);
|
|
669
|
1
|
670 return (1);
|
|
671 }
|
|
672
|
|
673
|
|
674 int
|
|
675 gftp_text_binary (gftp_request * request, char *command, gpointer *data)
|
|
676 {
|
|
677 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
678 {
|
|
679 gftp_text_log (gftp_logging_error, NULL,
|
|
680 _("Error: Not connected to a remote site\n"));
|
|
681 return (1);
|
|
682 }
|
|
683
|
122
|
684 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
|
|
685 GINT_TO_POINTER(0));
|
|
686 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
|
|
687 GINT_TO_POINTER(0));
|
1
|
688 return (1);
|
|
689 }
|
|
690
|
|
691
|
|
692 int
|
|
693 gftp_text_ascii (gftp_request * request, char *command, gpointer *data)
|
|
694 {
|
|
695 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
696 {
|
|
697 gftp_text_log (gftp_logging_error, NULL,
|
|
698 _("Error: Not connected to a remote site\n"));
|
|
699 return (1);
|
|
700 }
|
|
701
|
122
|
702 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
|
|
703 GINT_TO_POINTER(1));
|
|
704 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
|
|
705 GINT_TO_POINTER(1));
|
1
|
706 return (1);
|
|
707 }
|
|
708
|
|
709
|
|
710 int
|
|
711 gftp_text_mget_file (gftp_request * request, char *command, gpointer *data)
|
|
712 {
|
|
713 gftp_transfer * transfer;
|
|
714 gftp_file * fle;
|
|
715
|
|
716 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
717 {
|
|
718 gftp_text_log (gftp_logging_error, NULL,
|
|
719 _("Error: Not connected to a remote site\n"));
|
|
720 return (1);
|
|
721 }
|
|
722
|
|
723 if (*command == '\0')
|
|
724 {
|
|
725 gftp_text_log (gftp_logging_error, NULL, _("usage: mget <filespec>\n"));
|
|
726 return (1);
|
|
727 }
|
|
728
|
129
|
729 transfer = gftp_tdata_new ();
|
1
|
730 transfer->fromreq = gftp_text_remreq;
|
|
731 transfer->toreq = gftp_text_locreq;
|
|
732 transfer->transfer_direction = GFTP_DIRECTION_DOWNLOAD;
|
|
733
|
|
734 /* FIXME - ask whether to resume/skip/overwrite */
|
|
735 if (gftp_list_files (transfer->fromreq) != 0)
|
|
736 {
|
|
737 transfer->fromreq = transfer->toreq = NULL;
|
|
738 free_tdata (transfer);
|
|
739 return (1);
|
|
740 }
|
|
741 fle = g_malloc0 (sizeof (*fle));
|
|
742 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
743 {
|
|
744 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
745 {
|
|
746 gftp_file_destroy (fle);
|
|
747 continue;
|
|
748 }
|
|
749 transfer->files = g_list_append (transfer->files, fle);
|
|
750 fle = g_malloc (sizeof (*fle));
|
|
751 }
|
|
752 g_free (fle);
|
|
753 gftp_end_transfer (transfer->fromreq);
|
|
754
|
|
755 if (transfer->files == NULL)
|
|
756 {
|
|
757 transfer->fromreq = transfer->toreq = NULL;
|
|
758 free_tdata (transfer);
|
|
759 return (1);
|
|
760 }
|
|
761
|
|
762 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
763 {
|
|
764 transfer->fromreq = transfer->toreq = NULL;
|
|
765 free_tdata (transfer);
|
|
766 return (1);
|
|
767 }
|
|
768
|
|
769 if (transfer->files == NULL)
|
|
770 {
|
|
771 transfer->fromreq = transfer->toreq = NULL;
|
|
772 free_tdata (transfer);
|
|
773 return (1);
|
|
774 }
|
|
775
|
|
776 gftp_text_transfer_files (transfer);
|
|
777 transfer->fromreq = transfer->toreq = NULL;
|
|
778 free_tdata (transfer);
|
|
779 return (1);
|
|
780 }
|
|
781
|
|
782
|
|
783 int
|
|
784 gftp_text_mput_file (gftp_request * request, char *command, gpointer *data)
|
|
785 {
|
|
786 gftp_transfer * transfer;
|
|
787 gftp_file * fle;
|
|
788
|
|
789 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
790 {
|
|
791 gftp_text_log (gftp_logging_error, NULL,
|
|
792 _("Error: Not connected to a remote site\n"));
|
|
793 return (1);
|
|
794 }
|
|
795
|
|
796 if (*command == '\0')
|
|
797 {
|
|
798 gftp_text_log (gftp_logging_error, NULL, _("usage: mput <filespec>\n"));
|
|
799 return (1);
|
|
800 }
|
|
801
|
129
|
802 transfer = gftp_tdata_new ();
|
1
|
803 transfer->fromreq = gftp_text_locreq;
|
|
804 transfer->toreq = gftp_text_remreq;
|
|
805 transfer->transfer_direction = GFTP_DIRECTION_UPLOAD;
|
|
806
|
|
807 if (gftp_list_files (transfer->fromreq) != 0)
|
|
808 {
|
|
809 transfer->fromreq = transfer->toreq = NULL;
|
|
810 free_tdata (transfer);
|
|
811 return (1);
|
|
812 }
|
|
813 fle = g_malloc (sizeof (*fle));
|
|
814 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
815 {
|
|
816 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
817 {
|
|
818 gftp_file_destroy (fle);
|
|
819 continue;
|
|
820 }
|
|
821 transfer->files = g_list_append (transfer->files, fle);
|
|
822 fle = g_malloc (sizeof (*fle));
|
|
823 }
|
|
824 g_free (fle);
|
|
825 gftp_end_transfer (transfer->fromreq);
|
|
826
|
|
827 if (transfer->files == NULL)
|
|
828 {
|
|
829 transfer->fromreq = transfer->toreq = NULL;
|
|
830 free_tdata (transfer);
|
|
831 return (1);
|
|
832 }
|
|
833
|
|
834 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
835 {
|
|
836 transfer->fromreq = transfer->toreq = NULL;
|
|
837 free_tdata (transfer);
|
|
838 return (1);
|
|
839 }
|
|
840
|
|
841 if (transfer->files == NULL)
|
|
842 {
|
|
843 transfer->fromreq = transfer->toreq = NULL;
|
|
844 free_tdata (transfer);
|
|
845 return (1);
|
|
846 }
|
|
847
|
|
848 gftp_text_transfer_files (transfer);
|
|
849 transfer->fromreq = transfer->toreq = NULL;
|
|
850 free_tdata (transfer);
|
|
851 return (1);
|
|
852 }
|
|
853
|
|
854
|
|
855 int
|
|
856 gftp_text_transfer_files (gftp_transfer * transfer)
|
|
857 {
|
122
|
858 char buf[8192], *progress = "|/-\\";
|
1
|
859 struct timeval updatetime;
|
|
860 long fromsize, total;
|
|
861 gftp_file * curfle;
|
|
862 int i, j, sw, tot;
|
|
863 ssize_t num_read;
|
|
864
|
|
865 for (transfer->curfle = transfer->files;
|
|
866 transfer->curfle != NULL;
|
|
867 transfer->curfle = transfer->curfle->next)
|
|
868 {
|
|
869 curfle = transfer->curfle->data;
|
|
870 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
|
|
871 continue;
|
|
872
|
|
873 if (curfle->isdir && transfer->toreq->mkdir != NULL)
|
|
874 {
|
|
875 transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
|
|
876 continue;
|
|
877 }
|
|
878
|
|
879 transfer->curtrans = curfle->startsize;
|
58
|
880 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, -1,
|
1
|
881 curfle->startsize, transfer->toreq, curfle->destfile,
|
58
|
882 -1, curfle->startsize);
|
1
|
883 if (fromsize < 0)
|
|
884 return (1);
|
|
885
|
|
886 gettimeofday (&transfer->starttime, NULL);
|
|
887 memcpy (&transfer->lasttime, &transfer->starttime,
|
|
888 sizeof (transfer->lasttime));
|
|
889 memset (&updatetime, 0, sizeof (updatetime));
|
|
890
|
|
891 total = 0;
|
|
892 i = 0;
|
122
|
893 num_read = -1;
|
1
|
894 while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq,
|
|
895 buf, sizeof (buf))) > 0)
|
|
896 {
|
|
897 printf ("\r%c ", progress[i++]);
|
|
898 fflush (stdout);
|
|
899 if (progress[i] == '\0')
|
|
900 i = 0;
|
|
901
|
|
902 total += num_read;
|
122
|
903 gftp_calc_kbs (transfer, num_read);
|
1
|
904 if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize)
|
|
905 {
|
|
906 sw = gftp_text_get_win_size () - 20;
|
|
907 tot = (float) total / (float) fromsize * (float) sw;
|
|
908
|
|
909 if (tot > sw)
|
|
910 tot = sw;
|
|
911 printf ("[");
|
|
912 for (j=0; j<tot; j++)
|
|
913 printf ("=");
|
|
914 for (j=0; j<sw-tot; j++)
|
|
915 printf (" ");
|
|
916 printf ("] @ %.2fKB/s", transfer->kbs);
|
|
917 fflush (stdout);
|
|
918 memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime));
|
|
919 }
|
|
920
|
122
|
921 if (gftp_put_next_file_chunk (transfer->toreq, buf, num_read) < 0)
|
1
|
922 {
|
|
923 num_read = -1;
|
|
924 break;
|
|
925 }
|
|
926 }
|
|
927 printf ("\n");
|
|
928
|
|
929 if (num_read < 0)
|
|
930 {
|
|
931 gftp_text_log (gftp_logging_misc, NULL,
|
|
932 _("Could not download %s\n"), curfle->file);
|
|
933 gftp_disconnect (transfer->fromreq);
|
|
934 gftp_disconnect (transfer->toreq);
|
|
935 }
|
|
936 else
|
|
937 {
|
|
938 gftp_text_log (gftp_logging_misc, NULL,
|
|
939 _("Successfully transferred %s\n"), curfle->file);
|
|
940 gftp_end_transfer (transfer->fromreq);
|
|
941 gftp_end_transfer (transfer->toreq);
|
|
942 }
|
|
943
|
|
944 }
|
|
945 return (1);
|
|
946 }
|
|
947
|
|
948
|
|
949 int
|
|
950 gftp_text_help (gftp_request * request, char *command, gpointer *data)
|
|
951 {
|
37
|
952 int i, j, ele, numrows, numcols = 6, handled;
|
|
953 char *pos;
|
1
|
954
|
|
955 if (command != NULL && *command != '\0')
|
|
956 {
|
37
|
957 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
|
|
958 if (*pos == ' ')
|
|
959 {
|
|
960 *pos++ = '\0';
|
|
961 if (*pos == '\0')
|
|
962 pos = NULL;
|
|
963 }
|
|
964 else
|
|
965 pos = NULL;
|
|
966
|
1
|
967 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
968 {
|
|
969 if (strcmp (gftp_text_methods[i].command, command) == 0)
|
|
970 break;
|
|
971 }
|
|
972
|
|
973 if (gftp_text_methods[i].cmd_description != NULL)
|
37
|
974 {
|
|
975 if (pos != NULL && gftp_text_methods[i].subhelp_func != NULL)
|
|
976 handled = gftp_text_methods[i].subhelp_func (pos);
|
|
977 else
|
|
978 handled = 0;
|
|
979
|
|
980 if (!handled)
|
|
981 printf ("%s\n", _(gftp_text_methods[i].cmd_description));
|
|
982 }
|
1
|
983 else
|
|
984 *command = '\0';
|
|
985 }
|
|
986
|
|
987 if (command == NULL || *command == '\0')
|
|
988 {
|
|
989 numrows = number_commands / numcols;
|
|
990 if (number_commands % numcols != 0)
|
|
991 numrows++;
|
|
992
|
|
993 printf (_("Supported commands:\n\n"));
|
|
994 for (i=0; i<numrows; i++)
|
|
995 {
|
|
996 printf (" ");
|
|
997 for (j=0; j<numcols; j++)
|
|
998 {
|
|
999 ele = i + j * numrows;
|
|
1000 if (ele >= number_commands)
|
|
1001 break;
|
|
1002 printf ("%-10s", gftp_text_methods[ele].command);
|
|
1003 }
|
|
1004 printf ("\n");
|
|
1005 }
|
|
1006
|
|
1007 printf ("\n");
|
|
1008 }
|
|
1009 return (1);
|
|
1010 }
|
|
1011
|
|
1012
|
|
1013 int
|
|
1014 gftp_text_set (gftp_request * request, char *command, gpointer *data)
|
|
1015 {
|
122
|
1016 gftp_config_vars * cv;
|
1
|
1017 char *pos, *backpos;
|
122
|
1018 GList * templist;
|
1
|
1019 int i;
|
|
1020
|
|
1021 if (command == NULL || *command == '\0')
|
|
1022 {
|
122
|
1023 for (templist = gftp_options_list;
|
|
1024 templist != NULL;
|
|
1025 templist = templist->next)
|
1
|
1026 {
|
122
|
1027 cv = templist->data;
|
37
|
1028
|
122
|
1029 for (i=0; cv[i].key != NULL; i++)
|
1
|
1030 {
|
122
|
1031 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
|
|
1032 continue;
|
|
1033
|
|
1034 if (*cv[i].key == '\0' ||
|
|
1035 gftp_option_types[cv[i].otype].write_function == NULL)
|
|
1036 continue;
|
|
1037
|
|
1038 printf ("%s = ", cv[i].key);
|
|
1039 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
|
|
1040 printf ("\n");
|
1
|
1041 }
|
|
1042 }
|
|
1043 }
|
|
1044 else
|
|
1045 {
|
|
1046 if ((pos = strchr (command, '=')) == NULL)
|
|
1047 {
|
|
1048 gftp_text_log (gftp_logging_error, NULL,
|
|
1049 _("usage: set [variable = value]\n"));
|
|
1050 return (1);
|
|
1051 }
|
|
1052 *pos = '\0';
|
|
1053
|
|
1054 for (backpos = pos - 1;
|
|
1055 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
1056 backpos--)
|
|
1057 *backpos = '\0';
|
|
1058 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
1059
|
122
|
1060 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
|
1
|
1061 {
|
|
1062 gftp_text_log (gftp_logging_error, NULL,
|
|
1063 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
1064 return (1);
|
|
1065 }
|
|
1066
|
122
|
1067 if (!(cv->ports_shown & GFTP_PORT_TEXT))
|
37
|
1068 {
|
|
1069 gftp_text_log (gftp_logging_error, NULL,
|
|
1070 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
|
|
1071 return (1);
|
|
1072 }
|
|
1073
|
122
|
1074 if (gftp_option_types[cv->otype].read_function != NULL)
|
1
|
1075 {
|
122
|
1076 configuration_changed = 1;
|
|
1077 gftp_option_types[cv->otype].read_function (pos, cv, 1);
|
1
|
1078 }
|
|
1079 }
|
|
1080
|
|
1081 return (1);
|
|
1082 }
|
|
1083
|
|
1084
|
37
|
1085 int
|
|
1086 gftp_text_clear (gftp_request * request, char *command, gpointer *data)
|
|
1087 {
|
|
1088 if (strcasecmp (command, "cache") == 0)
|
|
1089 gftp_clear_cache_files ();
|
|
1090 else
|
|
1091 gftp_text_log (gftp_logging_error, NULL, "Invalid argument\n");
|
|
1092 return (1);
|
|
1093 }
|
|
1094
|
|
1095
|
1
|
1096 char *
|
|
1097 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
|
|
1098 {
|
|
1099 struct termios term, oldterm;
|
|
1100 sigset_t sig, sigsave;
|
|
1101 char *pos, *termname;
|
|
1102 FILE *infd, *outfd;
|
|
1103
|
|
1104 if (!echo)
|
|
1105 {
|
|
1106 sigemptyset (&sig);
|
|
1107 sigaddset (&sig, SIGINT);
|
|
1108 sigaddset (&sig, SIGTSTP);
|
|
1109 sigprocmask (SIG_BLOCK, &sig, &sigsave);
|
|
1110
|
|
1111 termname = ctermid (NULL);
|
|
1112 if ((infd = fopen (termname, "r+")) == NULL)
|
|
1113 {
|
|
1114
|
|
1115 gftp_text_log (gftp_logging_error, NULL,
|
|
1116 "Cannot open controlling terminal %s\n", termname);
|
|
1117 return (NULL);
|
|
1118 }
|
|
1119 outfd = infd;
|
|
1120
|
|
1121 tcgetattr (0, &term);
|
|
1122 oldterm = term;
|
|
1123 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
|
1124 tcsetattr (fileno (infd), TCSAFLUSH, &term);
|
|
1125 }
|
|
1126 else
|
|
1127 {
|
|
1128 infd = stdin;
|
|
1129 outfd = stdout;
|
|
1130 }
|
|
1131
|
|
1132 fprintf (outfd, "%s%s%s: ", COLOR_BLUE, question, COLOR_DEFAULT);
|
|
1133
|
|
1134 if (fgets (buf, size, infd) == NULL)
|
|
1135 return (NULL);
|
|
1136 buf[size - 1] = '\0';
|
|
1137
|
|
1138 if (!echo)
|
|
1139 {
|
|
1140 fprintf (outfd, "\n");
|
|
1141 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
|
|
1142 fclose (outfd);
|
|
1143 sigprocmask (SIG_SETMASK, &sigsave, NULL);
|
|
1144 }
|
|
1145
|
|
1146 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
|
|
1147 *pos == '\n'; pos--);
|
|
1148 *(pos+1) = '\0';
|
|
1149
|
|
1150 for (pos = buf; *pos == ' '; pos++);
|
|
1151 if (*pos == '\0')
|
|
1152 return (NULL);
|
|
1153
|
|
1154 return (pos);
|
|
1155 }
|
|
1156
|
|
1157
|
|
1158 int
|
|
1159 gftp_text_get_win_size (void)
|
|
1160 {
|
|
1161 struct winsize size;
|
|
1162 int ret;
|
|
1163
|
|
1164 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
|
|
1165 ret = 80;
|
|
1166 else
|
|
1167 ret = size.ws_col;
|
|
1168 return (ret);
|
|
1169 }
|
|
1170
|
|
1171
|
|
1172 void
|
|
1173 sig_child (int signo)
|
|
1174 {
|
|
1175 }
|
|
1176
|
|
1177
|
37
|
1178 int
|
|
1179 gftp_text_set_show_subhelp (char *topic)
|
|
1180 {
|
122
|
1181 gftp_config_vars * cv;
|
37
|
1182
|
122
|
1183 if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)
|
37
|
1184 {
|
122
|
1185 printf ("%s\n", cv->comment);
|
|
1186 return (1);
|
37
|
1187 }
|
|
1188
|
|
1189 return (0);
|
|
1190 }
|
|
1191
|
|
1192
|
|
1193 int
|
|
1194 gftp_text_clear_show_subhelp (char *topic)
|
|
1195 {
|
|
1196 if (strcmp (topic, "cache") == 0)
|
|
1197 {
|
|
1198 printf (_("Clear the directory cache\n"));
|
|
1199 return (1);
|
|
1200 }
|
|
1201
|
|
1202 return (0);
|
|
1203 }
|
|
1204
|