annotate src/text/gftp-text.c @ 951:99f8858bbf02

Updated Occitan translation
author ymarcheg
date Sat, 08 Mar 2008 11:36:14 +0000
parents 1808cebed602
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* gftp-text.c - text port of gftp */
885
1808cebed602 2007-3-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 846
diff changeset
3 /* Copyright (C) 1998-2007 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp-text.h"
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 16
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
23 unsigned int
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
24 gftp_text_get_win_size (void)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 {
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
26 struct winsize size;
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
27 unsigned int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
29 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
30 ret = 80;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
31 else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
32 ret = size.ws_col;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
33
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
34 return (ret);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
35 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
38 static void
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
39 gftp_text_write_string (gftp_request * request, char *string)
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
40 {
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
41 gchar *stpos, *endpos, *locale_str, savechar;
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
42 unsigned int sw;
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
43 size_t destlen;
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
44
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
45 sw = gftp_text_get_win_size ();
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
46
846
77660334b282 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
47 locale_str = gftp_string_from_utf8 (request, 1, string, &destlen);
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
48 if (locale_str == NULL)
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
49 stpos = string;
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
50 else
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
51 stpos = locale_str;
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
52
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
53 do
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
54 {
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
55 if ((endpos = strchr (stpos, '\n')) == NULL)
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
56 endpos = stpos + strlen (stpos);
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
57
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
58 savechar = *endpos;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
59 *endpos = '\0';
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
60
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
61 if (strlen (stpos) <= sw)
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
62 {
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
63 printf ("%s%c", stpos, savechar);
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
64 *endpos = savechar;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
65 if (savechar == '\0')
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
66 break;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
67 stpos = endpos + 1;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
68 }
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
69 else
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
70 {
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
71 *endpos = savechar;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
72 for (endpos = stpos + sw - 1;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
73 *endpos != ' ' && endpos > stpos;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
74 endpos--);
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
75
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
76 if (endpos != stpos)
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
77 *endpos = '\0';
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
78
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
79 printf ("%s\n", stpos);
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
80 stpos = endpos + 1;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
81 }
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
82
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
83 sw = sw;
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
84 }
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
85 while (stpos != endpos);
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
86
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
87 if (locale_str != NULL)
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
88 g_free (locale_str);
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
89 }
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
90
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
91
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
92 static void
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
93 gftp_text_log (gftp_logging_level level, gftp_request * request,
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
94 const char *string, ...)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 {
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
96 char tempstr[512];
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 va_list argp;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 g_return_if_fail (string != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 switch (level)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 case gftp_logging_send:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
104 printf ("%s", GFTPUI_COMMON_COLOR_GREEN);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106 case gftp_logging_recv:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
107 printf ("%s", GFTPUI_COMMON_COLOR_YELLOW);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 case gftp_logging_error:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
110 printf ("%s", GFTPUI_COMMON_COLOR_RED);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112 default:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
113 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
116
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 va_start (argp, string);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119 va_end (argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120
354
2ea37b3c0158 2003-1-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
121 if (gftp_logfd != NULL && level != gftp_logging_misc_nolog)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 {
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
123 fwrite (tempstr, 1, strlen (tempstr), gftp_logfd);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
124 if (ferror (gftp_logfd))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
125 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
126 fclose (gftp_logfd);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
127 gftp_logfd = NULL;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
130 fflush (gftp_logfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
133 if (level == gftp_logging_misc_nolog)
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
134 printf ("%s", tempstr);
387
2f5ce7fb5aad 2003-2-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 380
diff changeset
135 else
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
136 gftp_text_write_string (request, tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
138 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
142 char *
846
77660334b282 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
143 gftp_text_ask_question (gftp_request * request, const char *question, int echo,
77660334b282 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
144 char *buf, size_t size)
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
145 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
146 struct termios term, oldterm;
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
147 gchar *locale_question;
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
148 sigset_t sig, sigsave;
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
149 char *pos, *termname;
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 792
diff changeset
150 size_t destlen;
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
151 int singlechar;
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
152 FILE *infd;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
153
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
154 if (!echo)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
155 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
156 sigemptyset (&sig);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
157 sigaddset (&sig, SIGINT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
158 sigaddset (&sig, SIGTSTP);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
159 sigprocmask (SIG_BLOCK, &sig, &sigsave);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
160
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
161 termname = ctermid (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
162 if ((infd = fopen (termname, "r+")) == NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
163 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
164
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
165 gftp_text_log (gftp_logging_error, NULL,
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
166 _("Cannot open controlling terminal %s\n"), termname);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
167 return (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
168 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
169
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
170 tcgetattr (0, &term);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
171 oldterm = term;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
172 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
173 tcsetattr (fileno (infd), TCSAFLUSH, &term);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
174 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
175 else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
176 infd = stdin;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
177
846
77660334b282 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
178 locale_question = gftp_string_from_utf8 (request, 1, question, &destlen);
675
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
179 if (locale_question != NULL)
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
180 {
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
181 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, locale_question,
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
182 GFTPUI_COMMON_COLOR_DEFAULT);
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
183 g_free (locale_question);
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
184 }
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
185 else
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
186 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, question,
84d38c525f46 2005-1-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 574
diff changeset
187 GFTPUI_COMMON_COLOR_DEFAULT);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
188
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
189 if (size == 1)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
190 {
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
191 singlechar = fgetc (infd);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
192 *buf = singlechar;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
193 }
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
194 else
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
195 {
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
196 if (fgets (buf, size, infd) == NULL)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
197 return (NULL);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
198
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
199 if (size > 1)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
200 buf[size - 1] = '\0';
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
201 }
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
202
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
203 if (!echo)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
204 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
205 printf ("\n");
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
206 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
207 fclose (infd);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
208 sigprocmask (SIG_SETMASK, &sigsave, NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
209 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
210
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
211 if (size > 1)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
212 {
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
213 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
214 *pos == '\n'; pos--);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
215 *(pos+1) = '\0';
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
216
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
217 for (pos = buf; *pos == ' '; pos++);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
218
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
219 if (*pos == '\0')
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
220 return (NULL);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
221
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
222 return (pos);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
223 }
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
224 else
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
225 return (buf);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
226 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
227
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
228
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
229 int
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
230 main (int argc, char **argv)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
231 {
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 458
diff changeset
232 gftp_request * gftp_text_locreq, * gftp_text_remreq;
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
233 void *locuidata, *remuidata;
422
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 399
diff changeset
234 char *pos;
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
235 #if HAVE_LIBREADLINE
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
236 char *tempstr, prompt[20];
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
237 #else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
238 char tempstr[512];
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
239 #endif
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
240
374
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
241 gftpui_common_init (&argc, &argv, gftp_text_log);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
242
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
243 /* SSH doesn't support reading the password with askpass via the command
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
244 line */
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
245
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
246 gftp_text_remreq = gftp_request_new ();
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
247 remuidata = gftp_text_remreq;
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
248 gftp_text_remreq->logging_function = gftp_text_log;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
249
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
250 gftp_text_locreq = gftp_request_new ();
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
251 locuidata = gftp_text_locreq;
458
656a0b3d1403 2004-4-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
252 gftp_text_locreq->logging_function = gftp_text_log;
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
253
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
254 if (gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq) == 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
255 {
792
37bc51131e2d 2006-7-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 702
diff changeset
256 gftp_setup_startup_directory (gftp_text_locreq,
37bc51131e2d 2006-7-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 702
diff changeset
257 "local_startup_directory");
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
258 gftp_connect (gftp_text_locreq);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
259 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
260
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
261 gftpui_common_about (gftp_text_log, NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
262 gftp_text_log (gftp_logging_misc, NULL, "\n");
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
263
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
264 if (argc == 3 && strcmp (argv[1], "-d") == 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
265 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
266 if ((pos = strrchr (argv[2], '/')) != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
267 *pos = '\0';
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
268
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
269 gftpui_common_cmd_open (remuidata, gftp_text_remreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
270 locuidata, gftp_text_locreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
271 argv[2]);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
272
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
273 if (pos != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
274 *pos = '/';
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
275
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
276 gftpui_common_cmd_mget_file (remuidata, gftp_text_remreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
277 locuidata, gftp_text_locreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
278 pos + 1);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
279 exit (0);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
280 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
281 else if (argc == 2)
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
282 {
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
283 gftpui_common_cmd_open (remuidata, gftp_text_remreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
284 locuidata, gftp_text_locreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
285 argv[1]);
792
37bc51131e2d 2006-7-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 702
diff changeset
286
37bc51131e2d 2006-7-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 702
diff changeset
287 gftp_setup_startup_directory (gftp_text_remreq,
37bc51131e2d 2006-7-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 702
diff changeset
288 "remote_startup_directory");
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
289 }
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
290
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
291 #if HAVE_LIBREADLINE
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
292 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
293 while ((tempstr = readline (prompt)))
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
294 {
380
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
295 if (gftpui_common_process_command (locuidata, gftp_text_locreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
296 remuidata, gftp_text_remreq,
05ee37a5558b 2003-1-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
297 tempstr) == 0)
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
298 break;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
299
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
300 add_history (tempstr);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
301 free (tempstr);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
302 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
303 #else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
304 printf ("%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
305 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
306 {
399
e97f1fb92539 2004-2-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 387
diff changeset
307 if (gftpui_common_process_command (locuidata, gftp_text_locreq,
e97f1fb92539 2004-2-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 387
diff changeset
308 remuidata, gftp_text_remreq,
e97f1fb92539 2004-2-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 387
diff changeset
309 tempstr) == 0)
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
310 break;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
311
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
312 printf ("%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
313 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
314 #endif
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
315
574
81b957b00691 2004-9-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 573
diff changeset
316 gftp_shutdown ();
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
317 return (0);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
318 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
319