Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/clipboar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9359 - (hide annotations) (download) (as text)
Sat Aug 14 03:26:30 2021 UTC (2 years, 7 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 8601 byte(s)
UILanguageFile を unicode版(UILanguageFileW)へ切り替え

- SetDlgTexts() -> SetDlgTextsW()
- get_lang_msgW() ->GetI18nStrWW()
- SetI18nList() -> SetI18nListW()
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2006- TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, Clipboard routines */
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include <string.h>
34     #include <stdlib.h>
35     #include <stdio.h>
36 doda 8445 #define _CRTDBG_MAP_ALLOC
37     #include <crtdbg.h>
38     #include <wchar.h>
39 maya 3227
40     #include "ttwinman.h"
41 doda 4769 #include "ttlib.h"
42 doda 8445 #include "codeconv.h"
43 maya 3227
44     #include "clipboar.h"
45 zmatsuo 8586 #include "fileread.h"
46 doda 8445 #include "sendmem.h"
47     #include "clipboarddlg.h"
48 maya 3227
49 doda 8445 static const wchar_t BracketStartW[] = L"\033[200~";
50     static const wchar_t BracketEndW[] = L"\033[201~";
51 doda 6456
52 doda 8445 static void TrimTrailingNLW(wchar_t *src)
53     {
54     wchar_t *tail = src + wcslen(src) - 1;
55     while(tail >= src) {
56     if (*tail != L'\r' && *tail != L'\n') {
57     break;
58     }
59     *tail = L'\0';
60     tail--;
61     }
62     }
63    
64 zmatsuo 8737 /**
65 doda 8445 * �t�@�C�������`���������������Atext���������������������B
66     * ���������� TRUE������
67     */
68     static BOOL search_dictW(char *filename, const wchar_t *text)
69     {
70     BOOL result = FALSE;
71     const wchar_t *buf_top = LoadFileWA(filename, NULL);
72     const wchar_t *buf = buf_top;
73     if (buf == NULL) {
74     return FALSE;
75     }
76    
77     for(;;) {
78     const wchar_t *line_end;
79     size_t len;
80     wchar_t *search_str;
81     if (*buf == 0) {
82     break;
83     }
84     if (*buf == '\r' || *buf == '\n') {
85     buf++;
86     continue;
87     }
88     line_end = wcspbrk(buf, L"\r\n");
89     if (line_end == NULL) {
90     // ���s������
91     len = wcslen(buf);
92     if (len == 0) {
93     // �I��
94     break;
95     }
96     } else {
97     len = line_end - buf;
98     }
99     search_str = (wchar_t *)malloc(sizeof(wchar_t) * (len+1));
100     if (search_str == NULL)
101     continue;
102     memcpy(search_str, buf, sizeof(wchar_t) * len);
103     search_str[len] = 0;
104     buf += len;
105     result = (wcsstr(text, search_str) != NULL);
106     free(search_str);
107     if (result) {
108     result = TRUE;
109     break;
110     }
111     }
112     free((void *)buf_top);
113     return result;
114     }
115    
116 doda 6456 /*
117     * �N���b�v�{�[�h�����e���m�F���A�\���t�����s�����m�F�_�C�A���O���o���B
118     *
119     * �����l:
120     * TRUE -> ���������A�\���t�������{
121     * FALSE -> �\���t�����~
122     */
123 zmatsuo 8736 static BOOL CheckClipboardContentW(HWND HWin, const wchar_t *str_w, BOOL AddCR, wchar_t **out_str_w)
124 doda 6456 {
125 zmatsuo 8736 INT_PTR ret;
126 doda 6456 BOOL confirm = FALSE;
127    
128 zmatsuo 8736 *out_str_w = NULL;
129 doda 6594 if ((ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE) == 0) {
130 doda 6456 return TRUE;
131     }
132    
133     /*
134     * ConfirmChangePasteCR ����������
135     * �����������������������B
136     *
137     * ChangePasteCR !ChangePasteCR
138     * AddCR !AddCR AddCR !AddCR
139     * ���s���� o o x(2) o
140     * ���s���� o(1) x x x
141     *
142     * ChangePasteCR �� AddCR �������m�F���s����(1���m�F����)���������������A
143     * !ChangePasteCR �������l�������AAddCR ���������� CR ����������������
144     * �m�F���s������������ 2 �����������m�F���s�p���������v�\�������������B
145     * 2 ����������������������?
146     */
147     if (AddCR) {
148 doda 6594 if (ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE_CR) {
149 doda 6456 confirm = TRUE;
150     }
151     }
152     else {
153 doda 8445 size_t pos = wcscspn(str_w, L"\r\n"); // ���s����������������
154     if (str_w[pos] != '\0') {
155     confirm = TRUE;
156     }
157     }
158    
159     // �������T�[�`����
160     if (!confirm && search_dictW(ts.ConfirmChangePasteStringFile, str_w)) {
161     confirm = TRUE;
162     }
163    
164     ret = IDOK;
165     if (confirm) {
166     clipboarddlgdata dlg_data;
167     dlg_data.strW_ptr = str_w;
168 zmatsuo 9359 dlg_data.UILanguageFileW = ts.UILanguageFileW;
169 doda 8445 ret = clipboarddlg(hInst, HWin, &dlg_data);
170     *out_str_w = dlg_data.strW_edited_ptr;
171     }
172    
173     if (ret == IDOK) {
174     return TRUE;
175     }
176     else {
177     return FALSE;
178     }
179     }
180    
181     /**
182     * �N���b�v�{�[�h�p�e�L�X�g���M����
183     *
184     * @param str_w �����������|�C���^
185     * malloc()�������o�b�t�@�A���M��������������free()������
186     */
187 zmatsuo 8788 static void CBSendStart(wchar_t *str_w)
188 doda 8445 {
189 zmatsuo 8788 SendMem *sm = SendMemTextW(str_w, 0);
190 zmatsuo 8920 if (sm == NULL) {
191     free(str_w);
192 doda 8445 return;
193 zmatsuo 8920 }
194 zmatsuo 8588 if (ts.PasteDelayPerLine == 0) {
195     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_NO_DELAY, 0, 0);
196 doda 8445 }
197 zmatsuo 8588 else {
198     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_PER_LINE, ts.PasteDelayPerLine, 0);
199     }
200 doda 8445 #if 0
201     SendMemInitDialog(sm, hInst, HVTWin, ts.UILanguageFile);
202     SendMemInitDialogCaption(sm, L"from clipboard");
203     SendMemInitDialogFilename(sm, L"Clipboard");
204     #endif
205     SendMemStart(sm);
206     }
207    
208     void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed)
209     {
210     wchar_t *str_w;
211     wchar_t *str_w_edited;
212    
213     if (! cv.Ready) {
214     return;
215     }
216     if (TalkStatus!=IdTalkKeyb) {
217     return;
218     }
219    
220     str_w = GetClipboardTextW(HWin, FALSE);
221 zmatsuo 8796 if (str_w == NULL || !IsTextW(str_w, 0)) {
222 doda 8445 // �N���b�v�{�[�h����������������������������
223     return;
224     }
225    
226     if (ts.PasteFlag & CPF_TRIM_TRAILING_NL) {
227     // �o�b�t�@���������s������
228     TrimTrailingNLW(str_w);
229     }
230    
231 zmatsuo 8459 {
232 zmatsuo 8919 // ���s�� CR+LF �����K���A�_�C�A���O�����s���������\����������
233     wchar_t *dest = NormalizeLineBreakCRLF(str_w);
234 doda 8445 free(str_w);
235     str_w = dest;
236     }
237    
238     if (!CheckClipboardContentW(HWin, str_w, AddCR, &str_w_edited)) {
239 zmatsuo 8738 free(str_w);
240 doda 8445 return;
241     }
242     if (str_w_edited != NULL) {
243     // �_�C�A���O�����W������
244     free(str_w);
245     str_w = str_w_edited;
246     }
247    
248     if (AddCR) {
249     size_t str_len = wcslen(str_w) + 2;
250     str_w = realloc(str_w, sizeof(wchar_t) * str_len);
251     str_w[str_len-2] = L'\r';
252     str_w[str_len-1] = 0;
253     }
254    
255 zmatsuo 8920 {
256     // ���s�� CR ���������K��
257     wchar_t *dest = NormalizeLineBreakCR(str_w, 0);
258     free(str_w);
259     str_w = dest;
260     }
261    
262 doda 8445 if (Bracketed) {
263     const size_t BracketStartLenW = _countof(BracketStartW) - 1;
264     const size_t BracketEndLenW = _countof(BracketEndW) - 1;
265     size_t str_len = wcslen(str_w);
266     size_t dest_len = str_len + BracketStartLenW + BracketEndLenW;
267     wchar_t *dest = malloc(sizeof(wchar_t) * (dest_len+1));
268     size_t i = 0;
269     wmemcpy(&dest[i], BracketStartW, BracketStartLenW);
270     i += BracketStartLenW;
271     wmemcpy(&dest[i], str_w, str_len);
272     i += str_len;
273     wmemcpy(&dest[i], BracketEndW, BracketEndLenW);
274     i += BracketEndLenW;
275     dest[i] = 0;
276     free(str_w);
277     str_w = dest;
278     }
279    
280 zmatsuo 8788 CBSendStart(str_w);
281 doda 8445 }
282    
283 doda 4769 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
284     {
285 doda 8445 size_t mb_len, b64_len, header_len = 0, footer_len = 0;
286     wchar_t *str_w = NULL;
287     char *str_mb = NULL;
288     char *str_b64 = NULL;
289    
290     if (! cv.Ready) {
291     return;
292     }
293     if (TalkStatus!=IdTalkKeyb) {
294     return;
295     }
296    
297     str_w = GetClipboardTextW(HWin, FALSE);
298 zmatsuo 8796 if (str_w == NULL || !IsTextW(str_w, 0)) {
299 doda 8445 // �N���b�v�{�[�h����������������������������
300     goto error;
301     }
302    
303     if (ts.Language == IdUtf8 || ts.KanjiCodeSend == IdUTF8) {
304     str_mb = ToU8W(str_w);
305     }
306     else {
307     str_mb = ToCharW(str_w);
308     }
309    
310     if (str_mb == NULL) {
311     goto error;
312     }
313    
314     if (header != NULL) {
315     header_len = strlen(header);
316     }
317     if (footer != NULL) {
318     footer_len = strlen(footer);
319     }
320    
321     mb_len = strlen(str_mb);
322     b64_len = (mb_len + 2) / 3 * 4 + header_len + footer_len + 1;
323    
324     if ((str_b64 = malloc(b64_len)) == NULL) {;
325     goto error;
326     }
327    
328     if (header_len > 0) {
329     strncpy_s(str_b64, b64_len, header, _TRUNCATE);
330     }
331    
332     b64encode(str_b64 + header_len, b64_len - header_len, str_mb, mb_len);
333    
334     if (footer_len > 0) {
335     strncat_s(str_b64, b64_len, footer, _TRUNCATE);
336     }
337    
338     free(str_w);
339     if ((str_w = ToWcharA(str_b64)) == NULL) {
340     goto error;
341     }
342    
343     free(str_mb);
344     free(str_b64);
345    
346     // �\���t�����������������o����
347 zmatsuo 8788 CBSendStart(str_w);
348 doda 8445
349     return;
350    
351     error:
352     free(str_w);
353     free(str_mb);
354     free(str_b64);
355     return;
356     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26