Mercurial > gftp.yaz
comparison src/text/gftp-text.c @ 675:84d38c525f46
2005-1-24 Brian Masney <masneyb@gftp.org>
* src/text/gftp-text.c (gftp_text_ask_question, gftp_text_write_string)
- convert the string from UTF8 to the users' current locale before it is
displayed
* src/text/gftp-text.c src/text/gftp-text.h - fixed signed/unsigned
mismatch when calculating the window size
* src/gtk/transfer.c (update_file_status) - expanded the maximum length
of the dlstr variable
author | masneyb |
---|---|
date | Tue, 25 Jan 2005 01:11:00 +0000 |
parents | 81b957b00691 |
children | ff091f8e387f |
comparison
equal
deleted
inserted
replaced
674:cecd264e1e40 | 675:84d38c525f46 |
---|---|
18 /*****************************************************************************/ | 18 /*****************************************************************************/ |
19 | 19 |
20 #include "gftp-text.h" | 20 #include "gftp-text.h" |
21 static const char cvsid[] = "$Id$"; | 21 static const char cvsid[] = "$Id$"; |
22 | 22 |
23 int | 23 unsigned int |
24 gftp_text_get_win_size (void) | 24 gftp_text_get_win_size (void) |
25 { | 25 { |
26 struct winsize size; | 26 struct winsize size; |
27 int ret; | 27 unsigned int ret; |
28 | 28 |
29 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0) | 29 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0) |
30 ret = 80; | 30 ret = 80; |
31 else | 31 else |
32 ret = size.ws_col; | 32 ret = size.ws_col; |
34 return (ret); | 34 return (ret); |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 static void | 38 static void |
39 gftp_text_write_string (char *string) | 39 gftp_text_write_string (gftp_request * request, char *string) |
40 { | 40 { |
41 char *stpos, *endpos, savechar; | 41 gchar *stpos, *endpos, *locale_str, savechar; |
42 int sw; | 42 unsigned int sw; |
43 | 43 |
44 sw = gftp_text_get_win_size (); | 44 sw = gftp_text_get_win_size (); |
45 | 45 |
46 stpos = string; | 46 locale_str = gftp_string_from_utf8 (request, string); |
47 if (locale_str == NULL) | |
48 stpos = string; | |
49 else | |
50 stpos = locale_str; | |
51 | |
47 do | 52 do |
48 { | 53 { |
49 if ((endpos = strchr (stpos, '\n')) == NULL) | 54 if ((endpos = strchr (stpos, '\n')) == NULL) |
50 endpos = stpos + strlen (stpos); | 55 endpos = stpos + strlen (stpos); |
51 | 56 |
75 } | 80 } |
76 | 81 |
77 sw = sw; | 82 sw = sw; |
78 } | 83 } |
79 while (stpos != endpos); | 84 while (stpos != endpos); |
85 | |
86 if (locale_str != NULL) | |
87 g_free (locale_str); | |
80 } | 88 } |
81 | 89 |
82 | 90 |
83 static void | 91 static void |
84 gftp_text_log (gftp_logging_level level, gftp_request * request, | 92 gftp_text_log (gftp_logging_level level, gftp_request * request, |
132 } | 140 } |
133 | 141 |
134 if (level == gftp_logging_misc_nolog) | 142 if (level == gftp_logging_misc_nolog) |
135 printf ("%s", outstr); | 143 printf ("%s", outstr); |
136 else | 144 else |
137 gftp_text_write_string (outstr); | 145 gftp_text_write_string (request, outstr); |
138 | 146 |
139 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT); | 147 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT); |
140 | 148 |
141 if (utf8_str != NULL) | 149 if (utf8_str != NULL) |
142 g_free (utf8_str); | 150 g_free (utf8_str); |
145 | 153 |
146 char * | 154 char * |
147 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size) | 155 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size) |
148 { | 156 { |
149 struct termios term, oldterm; | 157 struct termios term, oldterm; |
158 gchar *locale_question; | |
150 sigset_t sig, sigsave; | 159 sigset_t sig, sigsave; |
151 char *pos, *termname; | 160 char *pos, *termname; |
152 int singlechar; | 161 int singlechar; |
153 FILE *infd; | 162 FILE *infd; |
154 | 163 |
174 tcsetattr (fileno (infd), TCSAFLUSH, &term); | 183 tcsetattr (fileno (infd), TCSAFLUSH, &term); |
175 } | 184 } |
176 else | 185 else |
177 infd = stdin; | 186 infd = stdin; |
178 | 187 |
179 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, question, GFTPUI_COMMON_COLOR_DEFAULT); | 188 locale_question = g_locale_from_utf8 (question, -1, NULL, NULL, NULL); |
189 if (locale_question != NULL) | |
190 { | |
191 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, locale_question, | |
192 GFTPUI_COMMON_COLOR_DEFAULT); | |
193 g_free (locale_question); | |
194 } | |
195 else | |
196 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, question, | |
197 GFTPUI_COMMON_COLOR_DEFAULT); | |
180 | 198 |
181 if (size == 1) | 199 if (size == 1) |
182 { | 200 { |
183 singlechar = fgetc (infd); | 201 singlechar = fgetc (infd); |
184 *buf = singlechar; | 202 *buf = singlechar; |