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