source: trunk/dll/subj.c@ 1627

Last change on this file since 1627 was 1627, checked in by Gregg Young, 14 years ago

Add a low mem version of xDosAlloc* wrappers; move error checking into all the xDosAlloc* wrappers. Ticket 471

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