source: trunk/dll/subj.c@ 1438

Last change on this file since 1438 was 1438, checked in by Gregg Young, 16 years ago

Improved drivebar changes; Added AddBackslashToPath() to remove repeatative code. replaced "
" with PCSZ variable; ANY_OBJ added the DosAlloc... (experimental)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: subj.c 1438 2009-06-28 20:47:00Z gyoung $
5
6 Edit .subject EAs
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2008 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 08 Mar 09 GKY Additional strings move to PCSZs
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 "fm3dll.h"
30#include "info.h" // Data declaration(s)
31#include "mainwnd.h" // Data declaration(s)
32#include "init.h" // Data declaration(s)
33#include "fm3dlg.h"
34#include "fm3str.h"
35#include "errutil.h" // Dos_Error...
36#include "strutil.h" // GetPString
37#include "input.h" // InputDlgProc
38#include "subj.h"
39#include "wrappers.h" // xDosSetPathInfo
40#include "strips.h" // bstrip
41#include "fortify.h"
42
43// Data definitions
44static PSZ pszSrcFile = __FILE__;
45
46#pragma data_seg(GLOBAL2)
47PCSZ SUBJECT = ".SUBJECT";
48
49INT Subject(HWND hwnd, CHAR * filename)
50{
51 APIRET rc;
52 EAOP2 eaop;
53 PGEA2LIST pgealist;
54 PFEA2LIST pfealist;
55 PGEA2 pgea;
56 PFEA2 pfea;
57 CHAR *value, subject[1024], oldsubject[1024];
58 STRINGINPARMS sip;
59 INT ret = 0;
60
61 *subject = 0;
62 pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
63 if (pgealist) {
64 pgea = &pgealist->list[0];
65 strcpy(pgea->szName, SUBJECT);
66 pgea->cbName = strlen(pgea->szName);
67 pgea->oNextEntryOffset = 0;
68 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
69 pfealist = xmallocz(1024, pszSrcFile, __LINE__);
70 if (pfealist)
71 free(pgealist);
72 else {
73 pfealist->cbList = 1024;
74 eaop.fpGEA2List = pgealist;
75 eaop.fpFEA2List = pfealist;
76 eaop.oError = 0;
77 rc = DosQueryPathInfo(filename, FIL_QUERYEASFROMLIST,
78 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
79 free(pgealist);
80 if (!rc) {
81 pfea = &eaop.fpFEA2List->list[0];
82 value = pfea->szName + pfea->cbName + 1;
83 value[pfea->cbValue] = 0;
84 if (*(USHORT *) value == EAT_ASCII)
85 strncpy(subject, value + (sizeof(USHORT) * 2), 1023);
86 subject[1023] = 0;
87 }
88 free(pfealist);
89 if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED) {
90 saymsg(MB_CANCEL,
91 hwnd,
92 GetPString(IDS_OOPSTEXT),
93 GetPString(IDS_EASBUSYTEXT), filename);
94 return 2; // Error
95 }
96 else if (rc) {
97 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
98 PCSZ_DOSQUERYPATHINFO);
99 return 2; // Error
100 }
101 }
102 }
103 memset(&sip, 0, sizeof(sip));
104 strcpy(oldsubject, subject);
105 sip.help = GetPString(IDS_SUBJECTINPUTHELPTEXT);
106 sip.ret = subject;
107 sip.prompt = GetPString(IDS_SUBJECTINPUTPROMPTTEXT);
108 sip.inputlen = 1024;
109 sip.title = filename;
110 if (WinDlgBox
111 (HWND_DESKTOP, hwnd, InputDlgProc, FM3ModHandle, STR_FRAME, &sip)
112 && isalpha(*filename)
113 && !(driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)) {
114 subject[1023] = 0;
115 bstrip(subject);
116 if (strcmp(oldsubject, subject)) {
117
118 ULONG ealen;
119 USHORT len;
120 CHAR *eaval;
121
122 len = strlen(subject);
123 if (len)
124 ealen = sizeof(FEA2LIST) + 9 + len + 4;
125 else
126 ealen = sizeof(FEALIST) + 9;
127 rc = xDosAllocMem((PPVOID) & pfealist, ealen + 1L,
128 OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE);
129 if (rc)
130 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
131 GetPString(IDS_OUTOFMEMORY));
132 else {
133 memset(pfealist, 0, ealen + 1);
134 pfealist->cbList = ealen;
135 pfealist->list[0].oNextEntryOffset = 0L;
136 pfealist->list[0].fEA = 0;
137 pfealist->list[0].cbName = 8;
138 strcpy(pfealist->list[0].szName, SUBJECT);
139 if (len) {
140 eaval = pfealist->list[0].szName + 9;
141 *(USHORT *) eaval = (USHORT) EAT_ASCII;
142 eaval += sizeof(USHORT);
143 *(USHORT *) eaval = (USHORT) len;
144 eaval += sizeof(USHORT);
145 memcpy(eaval, subject, len);
146 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
147 }
148 else
149 pfealist->list[0].cbValue = 0;
150 eaop.fpGEA2List = (PGEA2LIST) 0;
151 eaop.fpFEA2List = pfealist;
152 eaop.oError = 0;
153 rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
154 &eaop, sizeof(eaop), DSPI_WRTTHRU);
155 DosFreeMem(pfealist);
156 if (rc) {
157 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
158 GetPString(IDS_ERRORSETTINGSUBJECTTEXT), filename);
159 }
160 else
161 ret = 1; // OK
162 }
163 }
164 }
165 return ret; // No change?
166}
167
168#pragma alloc_text(FMINPUT,Subject)
Note: See TracBrowser for help on using the repository browser.