source: trunk/dll/subj.c@ 1213

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

Ticket 187: Move data declarations/definitions out of fm3dll.h

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