1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: subj.c 1009 2008-05-10 07:51:58Z stevenhl $
|
---|
5 |
|
---|
6 | Edit .subject EAs
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2004, 2006 Steven H.Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
12 | 17 Jul 06 SHL Use Runtime_Error
|
---|
13 | 06 Aug 07 GKY Increase Subject EA to 1024
|
---|
14 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
15 | 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
|
---|
16 | 29 Feb 08 GKY Use xfree where appropriate
|
---|
17 |
|
---|
18 | ***********************************************************************/
|
---|
19 |
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <string.h>
|
---|
22 | #include <ctype.h>
|
---|
23 |
|
---|
24 | #define INCL_WIN
|
---|
25 | #define INCL_DOS
|
---|
26 | #define INCL_DOSERRORS
|
---|
27 | #define INCL_LONGLONG
|
---|
28 |
|
---|
29 | #include "fm3dlg.h"
|
---|
30 | #include "fm3str.h"
|
---|
31 | #include "errutil.h" // Dos_Error...
|
---|
32 | #include "strutil.h" // GetPString
|
---|
33 | #include "fm3dll.h"
|
---|
34 |
|
---|
35 | static PSZ pszSrcFile = __FILE__;
|
---|
36 |
|
---|
37 | INT Subject(HWND hwnd, CHAR * filename)
|
---|
38 | {
|
---|
39 | APIRET rc;
|
---|
40 | EAOP2 eaop;
|
---|
41 | PGEA2LIST pgealist;
|
---|
42 | PFEA2LIST pfealist;
|
---|
43 | PGEA2 pgea;
|
---|
44 | PFEA2 pfea;
|
---|
45 | CHAR *value, subject[1024], oldsubject[1024];
|
---|
46 | STRINGINPARMS sip;
|
---|
47 | INT ret = 0;
|
---|
48 |
|
---|
49 | *subject = 0;
|
---|
50 | pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
|
---|
51 | if (pgealist) {
|
---|
52 | pgea = &pgealist->list[0];
|
---|
53 | strcpy(pgea->szName, SUBJECT);
|
---|
54 | pgea->cbName = strlen(pgea->szName);
|
---|
55 | pgea->oNextEntryOffset = 0;
|
---|
56 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
---|
57 | pfealist = xmallocz(1024, pszSrcFile, __LINE__);
|
---|
58 | if (pfealist)
|
---|
59 | xfree(pgealist, pszSrcFile, __LINE__);
|
---|
60 | else {
|
---|
61 | pfealist->cbList = 1024;
|
---|
62 | eaop.fpGEA2List = pgealist;
|
---|
63 | eaop.fpFEA2List = pfealist;
|
---|
64 | eaop.oError = 0;
|
---|
65 | rc = DosQueryPathInfo(filename, FIL_QUERYEASFROMLIST,
|
---|
66 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
---|
67 | xfree(pgealist, pszSrcFile, __LINE__);
|
---|
68 | if (!rc) {
|
---|
69 | pfea = &eaop.fpFEA2List->list[0];
|
---|
70 | value = pfea->szName + pfea->cbName + 1;
|
---|
71 | value[pfea->cbValue] = 0;
|
---|
72 | if (*(USHORT *) value == EAT_ASCII)
|
---|
73 | strncpy(subject, value + (sizeof(USHORT) * 2), 1023);
|
---|
74 | subject[1023] = 0;
|
---|
75 | }
|
---|
76 | xfree(pfealist, pszSrcFile, __LINE__);
|
---|
77 | if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED) {
|
---|
78 | saymsg(MB_CANCEL,
|
---|
79 | hwnd,
|
---|
80 | GetPString(IDS_OOPSTEXT),
|
---|
81 | GetPString(IDS_EASBUSYTEXT), filename);
|
---|
82 | return 2; // Error
|
---|
83 | }
|
---|
84 | else if (rc) {
|
---|
85 | Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
|
---|
86 | "DosQueryPathInfo");
|
---|
87 | return 2; // Error
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | memset(&sip, 0, sizeof(sip));
|
---|
92 | strcpy(oldsubject, subject);
|
---|
93 | sip.help = GetPString(IDS_SUBJECTINPUTHELPTEXT);
|
---|
94 | sip.ret = subject;
|
---|
95 | sip.prompt = GetPString(IDS_SUBJECTINPUTPROMPTTEXT);
|
---|
96 | sip.inputlen = 1024;
|
---|
97 | sip.title = filename;
|
---|
98 | if (WinDlgBox
|
---|
99 | (HWND_DESKTOP, hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip)
|
---|
100 | && isalpha(*filename)
|
---|
101 | && !(driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)) {
|
---|
102 | subject[1023] = 0;
|
---|
103 | bstrip(subject);
|
---|
104 | if (strcmp(oldsubject, subject)) {
|
---|
105 |
|
---|
106 | ULONG ealen;
|
---|
107 | USHORT len;
|
---|
108 | CHAR *eaval;
|
---|
109 |
|
---|
110 | len = strlen(subject);
|
---|
111 | if (len)
|
---|
112 | ealen = sizeof(FEA2LIST) + 9 + len + 4;
|
---|
113 | else
|
---|
114 | ealen = sizeof(FEALIST) + 9;
|
---|
115 | rc = DosAllocMem((PPVOID) & pfealist, ealen + 1L,
|
---|
116 | OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
|
---|
117 | if (rc)
|
---|
118 | Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
|
---|
119 | GetPString(IDS_OUTOFMEMORY));
|
---|
120 | else {
|
---|
121 | memset(pfealist, 0, ealen + 1);
|
---|
122 | pfealist->cbList = ealen;
|
---|
123 | pfealist->list[0].oNextEntryOffset = 0L;
|
---|
124 | pfealist->list[0].fEA = 0;
|
---|
125 | pfealist->list[0].cbName = 8;
|
---|
126 | strcpy(pfealist->list[0].szName, SUBJECT);
|
---|
127 | if (len) {
|
---|
128 | eaval = pfealist->list[0].szName + 9;
|
---|
129 | *(USHORT *) eaval = (USHORT) EAT_ASCII;
|
---|
130 | eaval += sizeof(USHORT);
|
---|
131 | *(USHORT *) eaval = (USHORT) len;
|
---|
132 | eaval += sizeof(USHORT);
|
---|
133 | memcpy(eaval, subject, len);
|
---|
134 | pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
|
---|
135 | }
|
---|
136 | else
|
---|
137 | pfealist->list[0].cbValue = 0;
|
---|
138 | eaop.fpGEA2List = (PGEA2LIST) 0;
|
---|
139 | eaop.fpFEA2List = pfealist;
|
---|
140 | eaop.oError = 0;
|
---|
141 | rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
|
---|
142 | &eaop, sizeof(eaop), DSPI_WRTTHRU);
|
---|
143 | DosFreeMem(pfealist);
|
---|
144 | if (rc) {
|
---|
145 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
146 | GetPString(IDS_ERRORSETTINGSUBJECTTEXT), filename);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | ret = 1; // OK
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|
153 | return ret; // No change?
|
---|
154 | }
|
---|
155 |
|
---|
156 | #pragma alloc_text(FMINPUT,Subject)
|
---|