source: trunk/dll/subj.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

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