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