source: trunk/dll/flesh.c@ 731

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

Correct ticket 24 pointer errors for Gregg

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
RevLine 
[145]1
2/***********************************************************************
3
4 $Id: flesh.c 731 2007-07-23 23:18:39Z stevenhl $
5
6 Flesh
7
8 Copyright (c) 1993-98 M. Kimes
[574]9 Copyright (c) 2005-07 Steven H. Levine
[145]10
11 24 May 05 SHL Rework Win_Error usage
[166]12 25 May 05 SHL Rework for ProcessDirectory
[284]13 28 May 05 SHL Clean while reading code
14 24 Oct 05 SHL Delete obsolete code
[340]15 22 Jul 06 SHL Check more run time errors
[515]16 19 Oct 06 SHL Stubby - correct . and .. detect
[574]17 22 Mar 07 GKY Use QWL_USER
[145]18
19***********************************************************************/
20
[2]21#define INCL_DOS
22#define INCL_DOSERRORS
23#define INCL_WIN
[340]24#include <os2.h>
[2]25
26#include <stdarg.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <ctype.h>
[145]31
[2]32#include "fm3dll.h"
33#include "fm3str.h"
34
35#pragma data_seg(DATA1)
[340]36
37static PSZ pszSrcFile = __FILE__;
38
[2]39#pragma alloc_text(FLESH,Flesh,FleshEnv,Unflesh,Stubby)
40
[551]41BOOL FleshEnv(HWND hwndCnr, PCNRITEM pciParent)
[175]42{
[551]43 PCNRITEM pciL;
[2]44 DIRCNRDATA *dcd;
[551]45 CHAR path[CCHMAXPATH + 12],
46 fullpath[CCHMAXPATH + 12], *env, *p, *pp, *var = NULL;
[2]47
[551]48 if (!pciParent || (INT) pciParent == -1 || !hwndCnr)
[2]49 return FALSE;
[574]50 dcd = (DIRCNRDATA *) WinQueryWindowPtr(hwndCnr, QWL_USER);
[551]51 if (!dcd)
[2]52 return FALSE;
53
[730]54 strcpy(path, pciParent->pszFileName + 1);
[551]55 if (stricmp(path, GetPString(IDS_ENVVARSTEXT) + 1))
56 UnFlesh(hwndCnr, pciParent);
57 if (*path) {
[2]58 path[strlen(path) - 1] = 0;
[551]59 if (!stricmp(path, "LIBPATH")) {
60 var = xmalloc(65536, pszSrcFile, __LINE__);
61 if (var)
62 LoadLibPath(var, 65536);
[2]63 env = var;
64 }
65 else
66 env = getenv(path);
[551]67 if (env && *env) {
[2]68 p = env;
[551]69 while (*p) {
70 pp = path;
71 while (*p == ';')
72 p++;
73 while (*p && *p != ';') {
74 *pp = *p;
75 p++;
76 pp++;
77 }
78 *pp = 0;
79 if (*path &&
80 strcmp(path, ".") &&
81 strcmp(path, ".\\") &&
82 strcmp(path, "..") &&
83 strcmp(path, "..\\") &&
84 strncmp(path, ".\\", 2) && strncmp(path, "..\\", 3)) {
85 if (!DosQueryPathInfo(path,
86 FIL_QUERYFULLNAME,
87 fullpath,
88 sizeof(fullpath)) && IsValidDir(fullpath)) {
89 pciL = FindCnrRecord(hwndCnr,
90 fullpath, pciParent, FALSE, FALSE, FALSE);
91 if (pciL) {
92 while (pciL && pciL != (PCNRITEM) - 1 && pciL != pciParent)
93 pciL = WinSendMsg(hwndCnr,
94 CM_QUERYRECORD,
95 MPFROMP(pciL),
96 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
97 }
98 if (!pciL) {
[2]99
[551]100 RECORDINSERT ri;
[2]101
[551]102 pciL = WinSendMsg(hwndCnr,
103 CM_ALLOCRECORD,
104 MPFROMLONG(EXTRA_RECORD_BYTES2),
105 MPFROMLONG(1));
106 if (pciL) {
[730]107 pciL->pszFileName = xstrdup(fullpath, pszSrcFile, __LINE__);
108 pciL->rc.pszIcon = pciL->pszFileName;
[551]109 if (!fNoIconsDirs &&
110 (!isalpha(*fullpath) ||
111 !(driveflags[toupper(*fullpath) - 'A'] &
112 DRIVE_NOLOADICONS)))
113 pciL->rc.hptrIcon = WinLoadFileIcon(fullpath, FALSE);
114 if (!pciL->rc.hptrIcon)
115 pciL->rc.hptrIcon = hptrDir;
116 pciL->attrFile = FILE_DIRECTORY;
117 strcpy(pciL->szDispAttr, "----D-");
118 pciL->pszDispAttr = pciL->szDispAttr;
119 memset(&ri, 0, sizeof(ri));
120 ri.cb = sizeof(ri);
121 ri.pRecordOrder = (PRECORDCORE) CMA_END;
122 ri.pRecordParent = (PRECORDCORE) pciParent;
123 ri.zOrder = (ULONG) CMA_TOP;
124 ri.cRecordsInsert = 1;
125 ri.fInvalidateRecord = FALSE;
126 if (!WinSendMsg(hwndCnr,
127 CM_INSERTRECORD, MPFROMP(pciL), MPFROMP(&ri)))
128 WinSendMsg(hwndCnr,
129 CM_FREERECORD, MPFROMP(&pciL), MPFROMSHORT(1));
130 }
131 }
132 }
133 }
[2]134 }
135 }
[551]136 if (var)
[2]137 free(var);
[551]138 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
139 CM_QUERYRECORD,
140 MPFROMP(pciParent),
141 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
142 while (pciL && (INT) pciL != -1) {
[2]143 pciL->flags |= (RECFLAGS_NODRAG | RECFLAGS_UNDERENV);
144 WinSendMsg(hwndCnr,
[551]145 CM_INVALIDATERECORD, MPFROMP(&pciL), MPFROM2SHORT(1, 0));
[2]146 pciL = WinSendMsg(hwndCnr,
[551]147 CM_QUERYRECORD,
148 MPFROMP(pciL), MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]149 }
150 }
151 return TRUE;
152}
153
[551]154BOOL Flesh(HWND hwndCnr, PCNRITEM pciParent)
[166]155{
[551]156 PCNRITEM pciL;
[2]157 DIRCNRDATA *dcd;
[551]158 BOOL includefiles = fFilesInTree;
[2]159
[551]160 if (!pciParent || (INT) pciParent == -1 || !hwndCnr)
[2]161 return FALSE;
[551]162 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
163 CM_QUERYRECORD,
164 MPFROMP(pciParent),
165 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[730]166 if (!pciL || !*pciL->pszFileName) {
[551]167 if (pciL && (INT) pciL != -1) {
[2]168 WinSendMsg(hwndCnr,
[551]169 CM_REMOVERECORD, MPFROMP(&pciL), MPFROM2SHORT(1, CMA_FREE));
[166]170 }
[2]171 dcd = INSTDATA(hwndCnr);
[166]172 if (dcd && dcd->size != sizeof(DIRCNRDATA))
[2]173 dcd = NULL;
[730]174 if (driveflags[toupper(*pciParent->pszFileName) - 'A'] &
[551]175 DRIVE_INCLUDEFILES)
[2]176 includefiles = TRUE;
177 ProcessDirectory(hwndCnr,
[551]178 pciParent,
[730]179 pciParent->pszFileName,
[551]180 includefiles, TRUE, TRUE, NULL, dcd, NULL, NULL);
[2]181 }
182 return TRUE;
183}
184
[551]185BOOL UnFlesh(HWND hwndCnr, PCNRITEM pciParent)
[175]186{
[551]187 BOOL ret = FALSE;
[2]188 PCNRITEM pciL;
189
[175]190 if (!pciParent || !hwndCnr)
[2]191 return FALSE;
[551]192 for (;;) {
193 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
194 CM_QUERYRECORD,
195 MPFROMP(pciParent),
196 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
197 if (pciL && (INT) pciL != -1) {
[2]198 ret = TRUE;
199 WinSendMsg(hwndCnr,
[551]200 CM_REMOVERECORD, MPFROMP(&pciL), MPFROM2SHORT(1, CMA_FREE));
[2]201 }
202 else
203 break;
204 }
[551]205 if (ret) {
[2]206 WinSendMsg(hwndCnr,
[551]207 CM_INVALIDATERECORD,
208 MPFROMP(&pciParent),
209 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
[175]210 }
[2]211 return ret;
212}
213
214#define DDEPTH 16
215
[551]216BOOL Stubby(HWND hwndCnr, PCNRITEM pciParent)
[175]217{
[2]218 /*
219 * this code is full of workarounds for screwed up LANs.
220 * let's hope all the current LAN programmers fall into
221 * a black hole and make way for people who can get it right...
222 */
223
[551]224 BOOL ret = FALSE;
225 FILEFINDBUF3 ffb[DDEPTH];
[2]226 PFILEFINDBUF3 pffb;
[551]227 HDIR hDir = HDIR_CREATE;
228 ULONG nm, ulM = 1L, total = 0L, fl = MUST_HAVE_DIRECTORY;
229 CHAR str[CCHMAXPATH];
230 register INT len;
231 APIRET rc, prc;
232 BOOL isadir = FALSE, isremote = FALSE, includefiles = fFilesInTree;
233 ULONG ddepth = 3L;
234 static BOOL brokenlan = FALSE, isbroken = FALSE;
[2]235
[730]236 if (!pciParent || !*pciParent->pszFileName || !hwndCnr)
[2]237 return FALSE;
238
[730]239 len = strlen(pciParent->pszFileName);
240 memcpy(str, pciParent->pszFileName, len + 1);
[551]241 if (str[len - 1] != '\\')
[2]242 str[len++] = '\\';
243 str[len++] = '*';
244 str[len] = 0;
245
[551]246 if (!isalpha(*str) || str[1] != ':' || str[2] != '\\')
[2]247 MakeFullName(str);
248
[551]249 if (!isalpha(*str) ||
250 str[1] != ':' ||
251 str[2] != '\\' || ((driveflags[toupper(*str) - 'A'] & DRIVE_IGNORE)))
[2]252 return FALSE;
253
[551]254 if (isalpha(*str) && driveflags[toupper(*str) - 'A'] & DRIVE_INCLUDEFILES)
[2]255 includefiles = TRUE;
256
[551]257 if (!isalpha(*str) ||
258 str[1] != ':' ||
259 str[2] != '\\' || ((driveflags[toupper(*str) - 'A'] & DRIVE_REMOTE)))
[2]260 isremote = TRUE;
261
[551]262 if (isremote) {
[2]263 ddepth = 14;
[551]264 if (fRemoteBug) {
265 if (brokenlan) {
266 ddepth = (ULONG) - 1;
267 ddepth--;
[2]268 }
269 ulM = 1L;
270 }
271 }
[551]272 else if (isbroken)
[2]273 ddepth = 14;
274
[551]275 if (!isremote || !fRemoteBug)
[2]276 ulM = (ddepth < 16L) ? ddepth : 1L;
277
278 nm = ulM;
279
280 DosError(FERR_DISABLEHARDERR);
[551]281 if (includefiles)
[2]282 fl = FILE_DIRECTORY;
283 rc = DosFindFirst(str,
[551]284 &hDir,
285 FILE_NORMAL | fl |
286 FILE_READONLY | FILE_ARCHIVED |
287 FILE_SYSTEM | FILE_HIDDEN,
288 &ffb, ulM * sizeof(FILEFINDBUF3), &nm, FIL_STANDARD);
289 if (ulM == 1L && !rc) {
[2]290 do {
291 pffb = &ffb[0];
[551]292 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY) && !brokenlan) {
293 brokenlan = TRUE;
294 ddepth = (ULONG) - 1L;
295 ddepth--;
296 if (!NoBrokenNotify) {
297 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
298 HWND_DESKTOP,
299 GetPString(IDS_LANERRORTITLETEXT),
300 GetPString(IDS_LANERRORTEXT));
301 if (prc == MBID_NO) {
302 saymsg(MB_ENTER,
303 HWND_DESKTOP,
304 GetPString(IDS_LANERROR2TITLETEXT),
305 GetPString(IDS_LANERROR2TEXT));
306 NoBrokenNotify = 255L;
307 PrfWriteProfileData(fmprof,
308 FM3Str,
309 "NoBrokenNotify",
310 &NoBrokenNotify, sizeof(ULONG));
311 }
312 }
313 else {
314 NoBrokenNotify--;
315 PrfWriteProfileData(fmprof,
316 FM3Str,
317 "NoBrokenNotify",
318 &NoBrokenNotify, sizeof(ULONG));
319 }
[2]320 }
[515]321 if (*pffb->achName &&
[551]322 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
[515]323 // Skip . and ..
[551]324 (pffb->achName[0] != '.' ||
[515]325 (pffb->achName[1] &&
[551]326 (pffb->achName[1] != '.' || pffb->achName[2])))) {
327 DosFindClose(hDir);
328 isadir = TRUE;
329 goto Interruptus;
[2]330 }
331 nm = 1L;
332 DosError(FERR_DISABLEHARDERR);
[551]333 } while (++total < ddepth && !(rc = (DosFindNext(hDir,
334 &ffb,
335 sizeof(FILEFINDBUF3),
336 &nm))));
[2]337 DosFindClose(hDir);
[730]338 if (toupper(*pciParent->pszFileName) > 'B' &&
339 (*(pciParent->pszFileName + 1)) == ':' &&
340 (*(pciParent->pszFileName + 2)) == '\\' && !(*(pciParent->pszFileName + 3))) {
[2]341
342 CHAR s[132];
343
344 sprintf(s,
[551]345 GetPString(IDS_NOSUBDIRSTEXT),
[730]346 total, toupper(*pciParent->pszFileName));
[551]347 if (rc && rc != ERROR_NO_MORE_FILES)
348 sprintf(&s[strlen(s)], GetPString(IDS_SEARCHERRORTEXT), rc, str);
349 else if (ddepth < 16L)
350 brokenlan = TRUE;
[2]351 Notify(s);
352 }
353 goto None;
354 }
355
[551]356 if (!rc) {
[2]357 DosFindClose(hDir);
[551]358 if (nm) {
[2]359
[551]360 register PBYTE fb = (PBYTE) & ffb[0];
[2]361
[551]362 for (len = 0; len < nm; len++) {
363 pffb = (PFILEFINDBUF3) fb;
364 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY)) {
365 if (!isbroken) {
366 isbroken = TRUE;
367 if (!NoBrokenNotify) {
368 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
369 HWND_DESKTOP,
370 GetPString(IDS_FSDERRORTITLETEXT),
371 GetPString(IDS_FSDERRORTEXT),
372 (isremote) ?
373 GetPString(IDS_REMOTETEXT) :
374 GetPString(IDS_LOCALTEXT), *str);
375 if (prc == MBID_NO) {
376 saymsg(MB_ENTER,
377 HWND_DESKTOP,
378 GetPString(IDS_FSDERROR2TITLETEXT),
379 GetPString(IDS_FSDERROR2TEXT));
380 NoBrokenNotify = 255L;
381 PrfWriteProfileData(fmprof,
382 FM3Str,
383 "NoBrokenNotify",
384 &NoBrokenNotify, sizeof(ULONG));
385 }
386 }
387 else {
388 NoBrokenNotify--;
389 PrfWriteProfileData(fmprof,
390 FM3Str,
391 "NoBrokenNotify",
392 &NoBrokenNotify, sizeof(ULONG));
393 }
394 }
395 }
396 if (*pffb->achName &&
397 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
[515]398 // Skip . and ..
[551]399 (pffb->achName[0] != '.' || (pffb->achName[1]
400 && (pffb->achName[1] != '.'
401 || pffb->achName[2])))) {
402 isadir = TRUE;
403 break;
404 }
405 fb += pffb->oNextEntryOffset;
[2]406 }
407
[551]408 Interruptus:
[2]409
[551]410 if (isadir) {
[2]411
[551]412 PCNRITEM pci;
[2]413
[551]414 pci = WinSendMsg(hwndCnr,
415 CM_ALLOCRECORD,
416 MPFROMLONG(EXTRA_RECORD_BYTES2), MPFROMLONG(1L));
417 if (!pci) {
418 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
419 GetPString(IDS_RECORDALLOCFAILEDTEXT));
[340]420 }
421 else {
[551]422 RECORDINSERT ri;
[730]423 //pci->pszFileName = pci->szFileName;
[731]424 pci->pszFileName = xstrdup(NullStr, pszSrcFile, __LINE__);
[551]425 pci->rc.pszIcon = pci->pszFileName;
426 memset(&ri, 0, sizeof(RECORDINSERT));
427 ri.cb = sizeof(RECORDINSERT);
428 ri.pRecordOrder = (PRECORDCORE) CMA_END;
429 ri.pRecordParent = (PRECORDCORE) pciParent;
430 ri.zOrder = (ULONG) CMA_TOP;
431 ri.cRecordsInsert = 1L;
432 ri.fInvalidateRecord = TRUE;
433 if (!WinSendMsg(hwndCnr,
434 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
435 DosSleep(100L);
436 WinSetFocus(HWND_DESKTOP, hwndCnr);
437 if (WinIsWindow((HAB) 0, hwndCnr)) {
438 if (!WinSendMsg(hwndCnr,
439 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
440 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
441 GetPString(IDS_RECORDINSERTFAILEDTEXT));
442 WinSendMsg(hwndCnr,
443 CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(1));
[340]444 }
445 else
[551]446 ret = TRUE;
447 }
448 }
449 else
450 ret = TRUE;
451 }
[2]452 }
[551]453 else if (toupper(*str) > 'B' && str[1] == ':' && str[2] == '\\' &&
454 !str[3]) {
[2]455
[551]456 CHAR s[162];
[2]457
[551]458 sprintf(s,
459 GetPString(IDS_NOSUBDIRS2TEXT),
460 nm,
[730]461 toupper(*pciParent->pszFileName),
[551]462 (isremote) ? GetPString(IDS_NOSUBDIRS3TEXT) : NullStr);
463 Notify(s);
[2]464 }
465 }
466 }
[551]467 else if (toupper(*str) > 'B' && rc != ERROR_NO_MORE_FILES) {
[2]468
469 CHAR s[CCHMAXPATH + 80];
470
[551]471 sprintf(s, GetPString(IDS_SEARCHERRORTEXT), rc, str);
[2]472 Notify(s);
473 }
474
475None:
476
477 DosError(FERR_DISABLEHARDERR);
478 return ret;
479}
Note: See TracBrowser for help on using the repository browser.