source: trunk/dll/saveclip.c@ 1226

Last change on this file since 1226 was 1226, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: saveclip.c 1226 2008-09-13 23:12:40Z jbs $
5
6 Save file list to clipboard
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2008 Steven H. Levine
10
11 12 Feb 03 SHL SaveListDlgProc: standardize EA math
12 01 Aug 04 SHL Rework lstrip/rstrip usage
13 01 Aug 04 SHL Rework fixup usage
14 24 May 05 SHL Rework for CNRITEM.szSubject
15 17 Jul 06 SHL Use Runtime_Error
16 29 Jul 06 SHL Use xfgets
17 22 Mar 07 GKY Use QWL_USER
18 06 Aug 07 GKY Increase Subject EA to 1024
19 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
20 27 Sep 07 SHL Correct ULONGLONG size formatting
21 16 Nov 07 SHL Ensure fixup buffer sufficiently large
22 30 Dec 07 GKY Use CommaFmtULL
23 16 Feb 08 GKY Changed _fsopen flag so a new list file can be created
24 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
25 20 Jul 08 GKY Modify ListtoClipHab to provide either fullpath name or filename for save to clipboard
26 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
27
28***********************************************************************/
29
30#include <stdlib.h>
31#include <string.h>
32#include <share.h>
33
34#define INCL_WIN
35#define INCL_LONGLONG
36
37#include "fm3dll.h"
38#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
39#include "arccnrs.h" // Data declaration(s)
40#include "notebook.h" // Data declaration(s)
41#include "init.h" // Data declaration(s)
42#include "fm3dlg.h"
43#include "fm3str.h"
44#include "saveclip.h"
45#include "makelist.h" // AddToList
46#include "errutil.h" // Dos_Error...
47#include "strutil.h" // GetPString
48#include "pathutil.h" // BldFullPathName
49#include "literal.h" // fixup
50#include "subj.h" // Subject
51#include "getnames.h" // export_filename
52#include "copyf.h" // unlinkf
53#include "wrappers.h" // xfgets
54#include "strips.h" // bstrip
55#include "misc.h" // CheckDriveSpaceAvail
56#include "commafmt.h" // CommaFmtULL
57#include "valid.h" // IsRoot
58#include "dirs.h" // save_dir2
59#include "fortify.h"
60
61static PSZ pszSrcFile = __FILE__;
62
63//static VOID ListToClipboard(HWND hwnd, CHAR ** list, ULONG append);
64
65static CHAR **ListFromClipboardHab(HAB hab);
66static BOOL SaveToClipHab(HAB hab, CHAR * text, BOOL append);
67
68#define MAX_PATTERN_BYTES 80
69
70BOOL SaveToClip(HWND hwnd, CHAR * text, BOOL append)
71{
72 HAB hab = WinQueryAnchorBlock(hwnd);
73
74 return SaveToClipHab(hab, text, append);
75}
76
77BOOL SaveToClipHab(HAB hab, CHAR * text, BOOL append)
78{
79 CHAR *clip = NULL, *hold = NULL, *p;
80 ULONG len;
81 BOOL ret = FALSE;
82
83 if (text) {
84 len = strlen(text);
85 p = text;
86 while (*p) {
87 if (*p == '\n' && (p == text || *(p - 1) != '\r'))
88 len++;
89 p++;
90 }
91 if (len) {
92 if (WinOpenClipbrd(hab)) {
93 if (append)
94 clip = (CHAR *)WinQueryClipbrdData(hab, CF_TEXT);
95 if (clip)
96 len += strlen(clip) + 1;
97 if (!DosAllocSharedMem((PPVOID) & hold, (PSZ) NULL, len, PAG_COMMIT |
98 OBJ_GIVEABLE | PAG_READ | PAG_WRITE)) {
99 *hold = 0;
100 if (clip)
101 strcpy(hold, clip);
102 p = hold + strlen(hold);
103 strcpy(p, text);
104 while (*p) {
105 if (*p == '\n' && (p == hold || *(p - 1) != '\r')) {
106 memmove(p + 1, p, strlen(p) + 1);
107 *p = '\r';
108 }
109 p++;
110 }
111 WinEmptyClipbrd(hab);
112 if (!WinSetClipbrdData(hab, (ULONG) hold, CF_TEXT, CFI_POINTER))
113 DosFreeMem(hold);
114 else
115 ret = TRUE;
116 }
117 WinCloseClipbrd(hab);
118 }
119 }
120 }
121 return ret;
122}
123
124#if 0 // JBS 11 Sep 08
125VOID ListToClipboard(HWND hwnd, CHAR ** list, ULONG append)
126{
127 HAB hab = WinQueryAnchorBlock(hwnd);
128
129 ListToClipboardHab(hab, list, append);
130}
131#endif
132
133VOID ListToClipboardHab(HAB hab, CHAR ** list, ULONG append)
134{
135 CHAR *text = NULL, **clip = NULL, *p = NULL, temp[CCHMAXPATH];
136 INT x;
137 ULONG len = 0;
138
139 if (list && list[0]) {
140 for (x = 0; list[x]; x++) {
141 if (append == IDM_SAVETOCLIPFILENAME ||
142 append == IDM_APPENDTOCLIPFILENAME) {
143 p = strrchr(list[x], '\\');
144 if (p) {
145 p++;
146 strcpy(temp, p);
147 free(list[x]);
148 list[x] = xstrdup(temp, __FILE__, __LINE__);
149 }
150 }
151 len += strlen(list[x]) + 2;
152 }
153 if (len)
154 len++;
155 if (len) {
156 if (append == IDM_APPENDTOCLIP ||
157 append == IDM_APPENDTOCLIP2 ||
158 append == IDM_APPENDTOCLIPFILENAME)
159 clip = ListFromClipboardHab(hab);
160 if (clip && clip[0]) {
161 for (x = 0; clip[x]; x++)
162 len += strlen(clip[x]) + 2;
163 len++;
164 }
165 if (WinOpenClipbrd(hab)) {
166 if (!DosAllocSharedMem((PPVOID) & text, (PSZ) NULL, len, PAG_COMMIT |
167 OBJ_GIVEABLE | PAG_READ | PAG_WRITE)) {
168 *text = 0;
169 if (clip && clip[0]) {
170 for (x = 0; clip[x]; x++) {
171 strcat(text, clip[x]);
172 strcat(text, "\r\n");
173 }
174 }
175 for (x = 0; list[x]; x++) {
176 strcat(text, list[x]);
177 strcat(text, "\r\n");
178 }
179 text[strlen(text) - 2] = 0;
180 WinEmptyClipbrd(hab);
181 if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
182 DosFreeMem(text);
183 }
184 WinCloseClipbrd(hab);
185 }
186 if (clip)
187 FreeList(clip);
188 }
189 }
190}
191
192CHAR **ListFromClipboard(HWND hwnd)
193{
194 HAB hab = WinQueryAnchorBlock(hwnd);
195
196 return ListFromClipboardHab(hab);
197}
198
199CHAR **ListFromClipboardHab(HAB hab)
200{
201 CHAR *p, *pp, *text = NULL, **list = NULL;
202 UINT numfiles = 0, numalloced = 0;
203
204 if (WinOpenClipbrd(hab)) {
205 p = (CHAR *)WinQueryClipbrdData(hab, CF_TEXT);
206 if (p && *p)
207 text = xstrdup(p, pszSrcFile, __LINE__);
208 WinCloseClipbrd(hab);
209 if (text) {
210 bstrip(text);
211 pp = text;
212 p = strchr(pp, '\r');
213 if (!p)
214 p = strchr(pp, '\n');
215 while (p && *p) {
216 *p = 0;
217 p++;
218 while (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t')
219 p++;
220 rstrip(pp);
221 if (*pp) {
222 if (AddToList(pp, &list, &numfiles, &numalloced))
223 break;
224 }
225 pp = p;
226 p = strchr(pp, '\r');
227 if (!p)
228 p = strchr(pp, '\n');
229 }
230 free(text);
231 }
232 }
233 return list;
234}
235
236MRESULT EXPENTRY SaveListDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
237{
238 HWND hwndCnr;
239 CHAR savename[CCHMAXPATH] = "", pattern[81];
240
241 switch (msg) {
242 case WM_INITDLG:
243 if (!mp2) {
244 Runtime_Error(pszSrcFile, __LINE__, "no data");
245 WinDismissDlg(hwnd, 0);
246 }
247 else {
248 WinSetWindowPtr(hwnd, QWL_USER, mp2);
249 hwndCnr = *(HWND *) mp2;
250 WinSendDlgItemMsg(hwnd,
251 SAV_FILENAME,
252 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
253 WinSendDlgItemMsg(hwnd,
254 SAV_PATTERN,
255 EM_SETTEXTLIMIT, MPFROM2SHORT(80, 0), MPVOID);
256 *savename = *pattern = 0;
257 {
258 ULONG size;
259
260 size = CCHMAXPATH;
261 PrfQueryProfileData(fmprof,
262 appname, "SaveToListName", savename, &size);
263 size = MAX_PATTERN_BYTES + 1;
264 PrfQueryProfileData(fmprof,
265 appname, "SaveToListPattern", pattern, &size);
266 }
267 WinSetDlgItemText(hwnd, SAV_FILENAME, savename);
268 if (!*pattern)
269 strcpy(pattern, "%F %s");
270 {
271 CHAR temp[MAX_PATTERN_BYTES * 4 + 1];
272
273 fixup(pattern, temp, sizeof(temp), strlen(pattern));
274 WinSetDlgItemText(hwnd, SAV_PATTERN, temp);
275 }
276 {
277 FILE *fp;
278 CHAR s[CCHMAXPATH + 14];
279
280 BldFullPathName(s, pFM2SaveDirectory, "PATTERNS.DAT");
281 fp = _fsopen(s, "r", SH_DENYWR);
282 if (fp) {
283 while (xfgets(s, 81, fp, pszSrcFile, __LINE__)) {
284 stripcr(s);
285 if (*s && *s != ';')
286 WinSendMsg(WinWindowFromID(hwnd, SAV_LISTBOX), LM_INSERTITEM,
287 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
288 }
289 fclose(fp);
290 }
291 if (!WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_QUERYITEMCOUNT,
292 MPVOID, MPVOID))
293 WinEnableWindow(WinWindowFromID(hwnd, SAV_LISTBOX), FALSE);
294 }
295 }
296 break;
297
298 case UM_SETDIR:
299 {
300 SHORT sSelect, sMax;
301 CHAR szBuffer[CCHMAXPATH + 14];
302 FILE *fp;
303
304 sMax = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
305 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
306 if (sMax > 0) {
307 BldFullPathName(szBuffer, pFM2SaveDirectory, "PATTERNS.DAT");
308 if (CheckDriveSpaceAvail(szBuffer, ullDATFileSpaceNeeded, 1) == 2)
309 break; //already gave error msg
310 fp = xfopen(szBuffer, "w", pszSrcFile, __LINE__);
311 if (fp) {
312 fputs(GetPString(IDS_LISTPATTERNTEXT), fp);
313 for (sSelect = 0; sSelect < sMax; sSelect++) {
314 *szBuffer = 0;
315 WinSendDlgItemMsg(hwnd,
316 SAV_LISTBOX,
317 LM_QUERYITEMTEXT,
318 MPFROM2SHORT(sSelect, 81), MPFROMP(szBuffer));
319 if (*szBuffer)
320 fprintf(fp, "%s\n", szBuffer);
321 }
322 fclose(fp);
323 }
324 }
325 else if (!sMax) {
326 BldFullPathName(szBuffer, pFM2SaveDirectory, "PATTERNS.DAT");
327 unlinkf("%s", szBuffer);
328 }
329 }
330 return 0;
331
332 case WM_CONTROL:
333 if (SHORT1FROMMP(mp1) == SAV_LISTBOX) {
334
335 SHORT sSelect;
336 CHAR szBuffer[81];
337
338 switch (SHORT2FROMMP(mp1)) {
339 case LN_SELECT:
340 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
341 LM_QUERYSELECTION,
342 MPFROMSHORT(LIT_FIRST), MPVOID);
343 if (sSelect >= 0) {
344 *szBuffer = 0;
345 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_QUERYITEMTEXT,
346 MPFROM2SHORT(sSelect, 81), MPFROMP(szBuffer));
347 if (*szBuffer)
348 WinSetDlgItemText(hwnd, SAV_PATTERN, szBuffer);
349 }
350 break;
351
352 case LN_ENTER:
353 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
354 break;
355 }
356 }
357 return 0;
358
359 case WM_COMMAND:
360 hwndCnr = *(HWND *) INSTDATA(hwnd);
361 switch (SHORT1FROMMP(mp1)) {
362 case DID_CANCEL:
363 WinDismissDlg(hwnd, 0);
364 break;
365
366 case IDM_HELP:
367 if (hwndHelp)
368 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
369 MPFROM2SHORT(HELP_SAVETOLIST, 0),
370 MPFROMSHORT(HM_RESOURCEID));
371 break;
372
373 case SAV_FIND:
374 {
375 *savename = 0;
376 WinQueryDlgItemText(hwnd, SAV_FILENAME, CCHMAXPATH, savename);
377 if (!*savename)
378 strcpy(savename, "*.LST");
379 if (export_filename(hwnd, savename, 1) && *savename) {
380 if (!strchr(savename, '.'))
381 strcat(savename, ".LST");
382 WinSetDlgItemText(hwnd, SAV_FILENAME, savename);
383 }
384 }
385 break;
386
387 case SAV_ADD:
388 case SAV_DEL:
389 case DID_OK:
390 WinEnableWindow(hwnd, FALSE);
391 {
392 PCNRITEM pci;
393 FILE *fp;
394 CHAR *p, *pp, temp;
395 CHAR szCmmaFmtFileSize[81];
396 INT attribute = CRA_CURSORED;
397 SHORT sSelect;
398
399 *pattern = 0;
400 WinQueryDlgItemText(hwnd, SAV_PATTERN, 80, pattern);
401 if (!*pattern) {
402 WinEnableWindow(hwnd, TRUE);
403 DosBeep(150, 100);
404 break;
405 }
406 {
407 switch (SHORT1FROMMP(mp1)) {
408 case SAV_ADD:
409 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
410 LM_SEARCHSTRING,
411 MPFROM2SHORT(0, LIT_FIRST),
412 MPFROMP(pattern));
413 if (sSelect < 0) {
414 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_INSERTITEM,
415 MPFROM2SHORT(LIT_SORTASCENDING, 0),
416 MPFROMP(pattern));
417 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
418 }
419 WinEnableWindow(hwnd, TRUE);
420 return 0;
421
422 case SAV_DEL:
423 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
424 LM_QUERYSELECTION,
425 MPFROM2SHORT(LIT_FIRST, 0),
426 MPVOID);
427 if (sSelect >= 0) {
428 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_DELETEITEM,
429 MPFROM2SHORT(sSelect, 0), MPVOID);
430 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
431 }
432 WinEnableWindow(hwnd, TRUE);
433 return 0;
434 }
435 }
436 literal(pattern);
437 if (!*pattern) {
438 WinEnableWindow(hwnd, TRUE);
439 DosBeep(250, 100);
440 break;
441 }
442 PrfWriteProfileString(fmprof, appname, "SaveToListPattern", pattern);
443 *savename = 0;
444 WinQueryDlgItemText(hwnd, SAV_FILENAME, CCHMAXPATH, savename);
445 bstrip(savename);
446 if (!*savename) {
447 WinEnableWindow(hwnd, TRUE);
448 DosBeep(100, 100);
449 break;
450 }
451 if (stricmp(savename, "PRN") &&
452 strnicmp(savename, "\\DEV\\LPT", 8) && !strchr(savename, '.'))
453 strcat(savename, ".LST");
454 PrfWriteProfileString(fmprof, appname, "SaveToListName", savename);
455 pci = (PCNRITEM) WinSendMsg(hwndCnr,
456 CM_QUERYRECORDEMPHASIS,
457 MPFROMLONG(CMA_FIRST),
458 MPFROMSHORT(attribute));
459 if (pci && (INT) pci != -1) {
460 if (pci->rc.flRecordAttr & CRA_SELECTED) {
461 attribute = CRA_SELECTED;
462 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
463 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
464 }
465 }
466 if (!pci || (INT) pci == -1)
467 Runtime_Error(pszSrcFile, __LINE__, "no data");
468 else {
469 fp = _fsopen(savename, "w+", SH_DENYWR);
470 if (!fp)
471 Runtime_Error(pszSrcFile, __LINE__, "_fsopen");
472 else {
473 fseek(fp, 0, SEEK_SET);
474 if (WinQueryButtonCheckstate(hwnd, SAV_APPEND) == 0)
475 DosSetFileSize((HFILE) fileno(fp), 0);
476 else
477 fseek(fp, 0, SEEK_END);
478 while (pci && (INT) pci != -1) {
479 if (!(pci->rc.flRecordAttr & CRA_FILTERED)) {
480 p = pattern;
481 while (*p) {
482 if (*p == '%') {
483 p++;
484 switch (*p) {
485 case 's':
486 fputs(pci->pszSubject, fp);
487 break;
488 case 'S':
489 fprintf(fp, "%-40s", pci->pszSubject);
490 break;
491 case 'Z':
492 CommaFmtULL(szCmmaFmtFileSize,
493 sizeof(szCmmaFmtFileSize), pci->cbFile, ' ');
494 fprintf(fp, "%-13s", szCmmaFmtFileSize);
495 break;
496 case 'z':
497 CommaFmtULL(szCmmaFmtFileSize,
498 sizeof(szCmmaFmtFileSize), pci->cbFile, ' ');
499 fprintf(fp, "%s", szCmmaFmtFileSize);
500 break;
501 case 'E':
502 fprintf(fp, "%-5u", pci->easize);
503 break;
504 case 'e':
505 fprintf(fp, "%u", pci->easize);
506 break;
507 case 'd':
508 case 'D':
509 fprintf(fp,
510 "%04u/%02u/%02u",
511 pci->date.year, pci->date.month, pci->date.day);
512 break;
513 case 't':
514 case 'T':
515 fprintf(fp,
516 "%02u:%02u:%02u",
517 pci->time.hours,
518 pci->time.minutes, pci->time.seconds);
519 break;
520 case 'l':
521 fputs(pci->pszLongName, fp);
522 break;
523 case 'L':
524 fprintf(fp, "%-40s", pci->pszLongName);
525 break;
526 case 'F':
527 case 'f':
528 if (IsRoot(pci->pszFileName))
529 pp = pci->pszFileName;
530 else {
531 pp = strrchr(pci->pszFileName, '\\');
532 if (pp)
533 pp++;
534 else
535 pp = pci->pszFileName;
536 }
537 if (*p == 'F')
538 fprintf(fp, "%-13s", pp);
539 else
540 fputs(pp, fp);
541 break;
542 case 'p':
543 fputs(pci->pszFileName, fp);
544 break;
545 case 'P':
546 temp = 0;
547 if (!IsRoot(pci->pszFileName)) {
548 pp = strrchr(pci->pszFileName, '\\');
549 if (pp) {
550 temp = *pp;
551 *pp = 0;
552 }
553 }
554 fputs(pci->pszFileName, fp);
555 if (temp)
556 *pp = temp;
557 break;
558 case '$':
559 fputc(*pci->pszFileName, fp);
560 break;
561 case '%':
562 fputc('%', fp);
563 break;
564 }
565 }
566 else
567 fputc(*p, fp);
568 p++;
569 }
570 fputs("\n", fp);
571 }
572 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
573 MPFROMSHORT(attribute));
574 }
575 fclose(fp);
576 }
577 }
578 }
579 WinEnableWindow(hwnd, TRUE);
580 WinDismissDlg(hwnd, 1);
581 break;
582 }
583 return 0;
584 }
585 return WinDefDlgProc(hwnd, msg, mp1, mp2);
586}
587
588MRESULT EXPENTRY SaveAllListDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
589 MPARAM mp2)
590{
591
592 CHAR **list;
593 CHAR savename[CCHMAXPATH] = "", pattern[81];
594
595 switch (msg) {
596 case WM_INITDLG:
597 if (!mp2) {
598 Runtime_Error(pszSrcFile, __LINE__, "no data");
599 WinDismissDlg(hwnd, 0);
600 }
601 else {
602 WinSetWindowPtr(hwnd, QWL_USER, mp2);
603 list = (CHAR **) mp2;
604 WinSendDlgItemMsg(hwnd,
605 SAV_FILENAME,
606 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
607 WinSendDlgItemMsg(hwnd,
608 SAV_PATTERN,
609 EM_SETTEXTLIMIT, MPFROM2SHORT(80, 0), MPVOID);
610 *savename = *pattern = 0;
611 {
612 ULONG size;
613
614 size = CCHMAXPATH;
615 PrfQueryProfileData(fmprof,
616 appname, "SaveToListName", savename, &size);
617 size = MAX_PATTERN_BYTES + 1;
618 PrfQueryProfileData(fmprof,
619 appname, "SaveToListPattern", pattern, &size);
620 }
621 WinSetDlgItemText(hwnd, SAV_FILENAME, savename);
622 if (!*pattern)
623 strcpy(pattern, "%F %s");
624 {
625 CHAR temp[MAX_PATTERN_BYTES * 4 + 1];
626
627 fixup(pattern, temp, sizeof(temp), strlen(pattern));
628 WinSetDlgItemText(hwnd, SAV_PATTERN, temp);
629 }
630 {
631 FILE *fp;
632 CHAR s[CCHMAXPATH + 14];
633
634 BldFullPathName(s, pFM2SaveDirectory, "PATTERNS.DAT");
635 fp = _fsopen(s, "r", SH_DENYWR);
636 if (fp) {
637 while (xfgets(s, 81, fp, pszSrcFile, __LINE__)) {
638 stripcr(s);
639 if (*s && *s != ';')
640 WinSendMsg(WinWindowFromID(hwnd, SAV_LISTBOX), LM_INSERTITEM,
641 MPFROM2SHORT(LIT_SORTASCENDING, 0), MPFROMP(s));
642 }
643 fclose(fp);
644 }
645 if (!WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_QUERYITEMCOUNT,
646 MPVOID, MPVOID))
647 WinEnableWindow(WinWindowFromID(hwnd, SAV_LISTBOX), FALSE);
648 }
649 }
650 break;
651
652 case UM_SETDIR:
653 {
654 SHORT sSelect, sMax;
655 CHAR szBuffer[CCHMAXPATH + 14];
656 FILE *fp;
657
658 sMax = (SHORT) WinSendDlgItemMsg(hwnd,
659 SAV_LISTBOX,
660 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
661 if (sMax > 0) {
662 BldFullPathName(szBuffer, pFM2SaveDirectory, "PATTERNS.DAT");
663 if (CheckDriveSpaceAvail(szBuffer, ullDATFileSpaceNeeded, 1) == 2)
664 break; //already gave error msg
665 fp = xfopen(szBuffer, "w", pszSrcFile, __LINE__);
666 if (fp) {
667 fputs(GetPString(IDS_LISTPATTERNTEXT), fp);
668 for (sSelect = 0; sSelect < sMax; sSelect++) {
669 *szBuffer = 0;
670 WinSendDlgItemMsg(hwnd,
671 SAV_LISTBOX,
672 LM_QUERYITEMTEXT,
673 MPFROM2SHORT(sSelect, 81), MPFROMP(szBuffer));
674 if (*szBuffer)
675 fprintf(fp, "%s\n", szBuffer);
676 }
677 fclose(fp);
678 }
679 }
680 else if (!sMax) {
681 BldFullPathName(szBuffer, pFM2SaveDirectory, "PATTERNS.DAT");
682 unlinkf("%s", szBuffer);
683 }
684 }
685 return 0;
686
687 case WM_CONTROL:
688 if (SHORT1FROMMP(mp1) == SAV_LISTBOX) {
689
690 SHORT sSelect;
691 CHAR szBuffer[81];
692
693 switch (SHORT2FROMMP(mp1)) {
694 case LN_SELECT:
695 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
696 LM_QUERYSELECTION,
697 MPFROMSHORT(LIT_FIRST), MPVOID);
698 if (sSelect >= 0) {
699 *szBuffer = 0;
700 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_QUERYITEMTEXT,
701 MPFROM2SHORT(sSelect, 81), MPFROMP(szBuffer));
702 if (*szBuffer)
703 WinSetDlgItemText(hwnd, SAV_PATTERN, szBuffer);
704 }
705 break;
706
707 case LN_ENTER:
708 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
709 break;
710 }
711 }
712 return 0;
713
714 case WM_COMMAND:
715 list = (CHAR **) INSTDATA(hwnd);
716 switch (SHORT1FROMMP(mp1)) {
717 case DID_CANCEL:
718 WinDismissDlg(hwnd, 0);
719 break;
720
721 case IDM_HELP:
722 if (hwndHelp)
723 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
724 MPFROM2SHORT(HELP_SAVETOLIST, 0),
725 MPFROMSHORT(HM_RESOURCEID));
726 break;
727
728 case SAV_FIND:
729 {
730 *savename = 0;
731 WinQueryDlgItemText(hwnd, SAV_FILENAME, CCHMAXPATH, savename);
732 if (!*savename)
733 strcpy(savename, "*.LST");
734 if (export_filename(hwnd, savename, 1) && *savename) {
735 if (!strchr(savename, '.'))
736 strcat(savename, ".LST");
737 WinSetDlgItemText(hwnd, SAV_FILENAME, savename);
738 }
739 }
740 break;
741
742 case SAV_ADD:
743 case SAV_DEL:
744 case DID_OK:
745 WinEnableWindow(hwnd, FALSE);
746 {
747 FILE *fp;
748 CHAR *p, *pp, temp;
749 INT x = 0;
750 SHORT sSelect;
751 FILEFINDBUF4L ffb4;
752 ULONG nm;
753 HDIR hdir;
754 CHAR longname[CCHMAXPATH], subject[1024];
755
756 *pattern = 0;
757 WinQueryDlgItemText(hwnd, SAV_PATTERN, 80, pattern);
758 if (!*pattern) {
759 WinEnableWindow(hwnd, TRUE);
760 DosBeep(150, 100);
761 break;
762 }
763 {
764 switch (SHORT1FROMMP(mp1)) {
765 case SAV_ADD:
766 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
767 LM_SEARCHSTRING,
768 MPFROM2SHORT(0, LIT_FIRST),
769 MPFROMP(pattern));
770 if (sSelect < 0) {
771 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_INSERTITEM,
772 MPFROM2SHORT(LIT_SORTASCENDING, 0),
773 MPFROMP(pattern));
774 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
775 }
776 WinEnableWindow(hwnd, TRUE);
777 return 0;
778
779 case SAV_DEL:
780 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, SAV_LISTBOX,
781 LM_QUERYSELECTION,
782 MPFROM2SHORT(LIT_FIRST, 0),
783 MPVOID);
784 if (sSelect >= 0) {
785 WinSendDlgItemMsg(hwnd, SAV_LISTBOX, LM_DELETEITEM,
786 MPFROM2SHORT(sSelect, 0), MPVOID);
787 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
788 }
789 WinEnableWindow(hwnd, TRUE);
790 return 0;
791 }
792 }
793 literal(pattern);
794 if (!*pattern) {
795 WinEnableWindow(hwnd, TRUE);
796 DosBeep(250, 100);
797 break;
798 }
799 PrfWriteProfileString(fmprof, appname, "SaveToListPattern", pattern);
800 *savename = 0;
801 WinQueryDlgItemText(hwnd, SAV_FILENAME, CCHMAXPATH, savename);
802 bstrip(savename);
803 if (!*savename) {
804 WinEnableWindow(hwnd, TRUE);
805 DosBeep(100, 100);
806 break;
807 }
808 if (stricmp(savename, "PRN") &&
809 strnicmp(savename, "\\DEV\\LPT", 8) && !strchr(savename, '.'))
810 strcat(savename, ".LST");
811 PrfWriteProfileString(fmprof, appname, "SaveToListName", savename);
812 if (!list || !list[0])
813 Runtime_Error(pszSrcFile, __LINE__, "no data");
814 else {
815 fp = _fsopen(savename, "r+", SH_DENYWR);
816 if (!fp)
817 Runtime_Error(pszSrcFile, __LINE__, "_fsopen");
818 else {
819 fseek(fp, 0, SEEK_SET);
820 if (WinQueryButtonCheckstate(hwnd, SAV_APPEND) == 0)
821 DosSetFileSize((HFILE) fileno(fp), 0);
822 else
823 fseek(fp, 0, SEEK_END);
824 while (list[x]) {
825 hdir = HDIR_CREATE;
826 nm = 1;
827 *subject = *longname = 0;
828 if (!xDosFindFirst(list[x], &hdir,
829 FILE_NORMAL | FILE_DIRECTORY |
830 FILE_READONLY | FILE_ARCHIVED |
831 FILE_HIDDEN | FILE_SYSTEM,
832 &ffb4, sizeof(ffb4), &nm, FIL_QUERYEASIZEL)) {
833 /* load the object's Subject, if required */
834 if (ffb4.cbList > 4) {
835 APIRET rc;
836 EAOP2 eaop;
837 PGEA2LIST pgealist;
838 PFEA2LIST pfealist;
839 PGEA2 pgea;
840 PFEA2 pfea;
841 CHAR *value;
842
843 pgealist =
844 xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
845 if (pgealist) {
846 pgea = &pgealist->list[0];
847 strcpy(pgea->szName, SUBJECT);
848 pgea->cbName = strlen(pgea->szName);
849 pgea->oNextEntryOffset = 0;
850 pgealist->cbList = sizeof(GEA2LIST) + pgea->cbName;
851 pfealist = xmallocz(1024, pszSrcFile, __LINE__);
852 if (pfealist) {
853 pfealist->cbList = 1024;
854 eaop.fpGEA2List = pgealist;
855 eaop.fpFEA2List = pfealist;
856 eaop.oError = 0;
857 rc = DosQueryPathInfo(list[x],
858 FIL_QUERYEASFROMLIST,
859 (PVOID) & eaop,
860 (ULONG) sizeof(EAOP2));
861 if (!rc) {
862 pfea = &eaop.fpFEA2List->list[0];
863 value = pfea->szName + pfea->cbName + 1;
864 value[pfea->cbValue] = 0;
865 if (*(USHORT *) value == EAT_ASCII)
866 strncpy(subject, value + (sizeof(USHORT) * 2), 1023);
867 subject[1023] = 0;
868 }
869 free(pfealist);
870 }
871 free(pgealist);
872 }
873 }
874 /* load the object's longname */
875 if (ffb4.cbList > 4) {
876 APIRET rc;
877 EAOP2 eaop;
878 PGEA2LIST pgealist;
879 PFEA2LIST pfealist;
880 PGEA2 pgea;
881 PFEA2 pfea;
882 CHAR *value;
883
884
885 pgealist =
886 xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
887 if (pgealist) {
888 pgea = &pgealist->list[0];
889 strcpy(pgea->szName, LONGNAME);
890 pgea->cbName = strlen(pgea->szName);
891 pgea->oNextEntryOffset = 0;
892 pgealist->cbList = sizeof(GEA2LIST) + pgea->cbName;
893 pfealist = xmallocz(1024, pszSrcFile, __LINE__);
894 if (pfealist) {
895 pfealist->cbList = 1024;
896 eaop.fpGEA2List = pgealist;
897 eaop.fpFEA2List = pfealist;
898 eaop.oError = 0L;
899 rc = DosQueryPathInfo(list[x],
900 FIL_QUERYEASFROMLIST,
901 (PVOID) & eaop,
902 (ULONG) sizeof(EAOP2));
903 if (!rc) {
904 pfea = &eaop.fpFEA2List->list[0];
905 value = pfea->szName + pfea->cbName + 1;
906 value[pfea->cbValue] = 0;
907 if (*(USHORT *) value == EAT_ASCII)
908 strncpy(longname, value +
909 (sizeof(USHORT) * 2), CCHMAXPATHCOMP);
910 longname[CCHMAXPATHCOMP - 1] = 0;
911 }
912 free(pfealist);
913 }
914 free(pgealist);
915 }
916 }
917
918 p = pattern;
919 while (*p) {
920 if (*p == '%') {
921 p++;
922 switch (*p) {
923 CHAR szCmmaFmtFileSize[81];
924 case 's':
925 fputs(subject, fp);
926 break;
927 case 'S':
928 fprintf(fp, "%-40s", subject);
929 break;
930 case 'Z':
931 CommaFmtULL(szCmmaFmtFileSize,
932 sizeof(szCmmaFmtFileSize), ffb4.cbFile, ' ');
933 fprintf(fp, "%-13s", szCmmaFmtFileSize);
934 break;
935 case 'z':
936 CommaFmtULL(szCmmaFmtFileSize,
937 sizeof(szCmmaFmtFileSize), ffb4.cbFile, ' ');
938 fprintf(fp, "%s", szCmmaFmtFileSize);
939 break;
940 case 'E':
941 fprintf(fp, "%-5u", CBLIST_TO_EASIZE(ffb4.cbList));
942 break;
943 case 'e':
944 fprintf(fp, "%u", CBLIST_TO_EASIZE(ffb4.cbList));
945 break;
946 case 'd':
947 case 'D':
948 fprintf(fp,
949 "%04u/%02u/%02u",
950 ffb4.fdateLastWrite.year + 1980,
951 ffb4.fdateLastWrite.month,
952 ffb4.fdateLastWrite.day);
953 break;
954 case 't':
955 case 'T':
956 fprintf(fp,
957 "%02u:%02u:%02u",
958 ffb4.ftimeLastWrite.hours,
959 ffb4.ftimeLastWrite.minutes,
960 ffb4.ftimeLastWrite.twosecs * 2);
961 break;
962 case 'l':
963 fputs(longname, fp);
964 break;
965 case 'L':
966 fprintf(fp, "%-40s", longname);
967 break;
968 case 'F':
969 case 'f':
970 if (IsRoot(list[x]))
971 pp = list[x];
972 else {
973 pp = strrchr(list[x], '\\');
974 if (pp)
975 pp++;
976 else
977 pp = list[x];
978 }
979 if (*p == 'F')
980 fprintf(fp, "%-13s", pp);
981 else
982 fputs(pp, fp);
983 break;
984 case 'p':
985 fputs(list[x], fp);
986 break;
987 case 'P':
988 temp = 0;
989 if (!IsRoot(list[x])) {
990 pp = strrchr(list[x], '\\');
991 if (pp) {
992 temp = *pp;
993 *pp = 0;
994 }
995 }
996 fputs(list[x], fp);
997 if (temp)
998 *pp = temp;
999 break;
1000 case '$':
1001 fputc(*list[x], fp);
1002 break;
1003 case '%':
1004 fputc('%', fp);
1005 break;
1006 }
1007 }
1008 else
1009 fputc(*p, fp);
1010 p++;
1011 }
1012 fputs("\n", fp);
1013 DosFindClose(hdir);
1014 }
1015 x++;
1016 }
1017 fclose(fp);
1018 }
1019 }
1020 }
1021 WinEnableWindow(hwnd, TRUE);
1022 WinDismissDlg(hwnd, 1);
1023 break;
1024 }
1025 return 0;
1026 }
1027 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1028}
1029
1030#pragma alloc_text(FMCLIPBOARDIN,SaveToClip,SaveToClipHab)
1031#pragma alloc_text(FMCLIPBOARDOUT,ListToClipboardHab)
1032#pragma alloc_text(FMCLIPBOARDOUT,ListFromClipboard,ListFromClipboardHab)
1033#pragma alloc_text(SAVELIST,SaveListDlgProc,SaveAllListDlgProc)
Note: See TracBrowser for help on using the repository browser.