source: trunk/dll/subj.c@ 1184

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

Ticket 187: Draft 2: Move remaining function declarations

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