source: trunk/dll/makelist.c@ 603

Last change on this file since 603 was 603, checked in by Gregg Young, 18 years ago

Work around for PM drag/drop limit; more drag/drop error checking

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: makelist.c 603 2007-04-06 21:57:45Z gyoung $
5
6 Make file lists
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2003, 2006 Steven H.Levine
10
11 12 Feb 03 SHL AddToFileList: standardize EA math
12 22 Jul 06 SHL Use Runtime_Error
13 22 Jul 06 SHL AddToList optimize
14 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
15
16***********************************************************************/
17
18#define INCL_DOS
19#define INCL_WIN
20#include <os2.h>
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <ctype.h>
26
27#include "fm3dll.h"
28#include "fm3str.h"
29
30static PSZ pszSrcFile = __FILE__;
31
32#pragma alloc_text(MAKELIST,AddToList,AddToFileList,BuildList,FreeListInfo,FreeList)
33#pragma alloc_text(MAKELIST,SortList,BuildArcList,RemoveFromList,CombineLists)
34
35VOID SortList(LISTINFO * li)
36{
37 /* bubble-sort entries by size, descending */
38
39 INT x;
40 CHAR *s;
41 ULONG l;
42 BOOL swapped;
43
44 if (li && li->list && li->list[0] && li->cbFile) {
45 do {
46 swapped = FALSE;
47 for (x = 0; li->list[x] && li->list[x + 1]; x++) {
48 if (li->cbFile[x] < li->cbFile[x + 1]) {
49 s = li->list[x];
50 li->list[x] = li->list[x + 1];
51 li->list[x + 1] = s;
52 l = li->cbFile[x];
53 li->cbFile[x] = li->cbFile[x + 1];
54 li->cbFile[x + 1] = l;
55 if (li->ulitemID) {
56 l = li->ulitemID[x];
57 li->ulitemID[x] = li->ulitemID[x + 1];
58 li->ulitemID[x + 1] = l;
59 }
60 swapped = TRUE;
61 }
62 }
63 } while (swapped);
64 }
65}
66
67VOID FreeListInfo(LISTINFO * li)
68{
69 if (li) {
70 if (li->ulitemID)
71 free(li->ulitemID);
72 if (li->cbFile)
73 free(li->cbFile);
74 if (li->list)
75 FreeList(li->list);
76 free(li);
77 fexceedpmdrglimit = FALSE;
78 }
79}
80
81VOID FreeList(CHAR ** list)
82{
83 register INT x;
84
85 if (list) {
86 for (x = 0; list[x]; x++) {
87#ifdef __DEBUG_ALLOC__
88 _heap_check();
89#endif
90 free(list[x]);
91 }
92#ifdef __DEBUG_ALLOC__
93 _heap_check();
94#endif
95 free(list);
96 }
97 DosPostEventSem(CompactSem);
98}
99
100INT AddToFileList(CHAR * string, FILEFINDBUF4 * ffb4, FILELIST *** list,
101 INT * numfiles, INT * numalloced)
102{
103 FILELIST *pfl;
104
105 if (string && ffb4) {
106 if (((*numfiles) + 3) > *numalloced) {
107 FILELIST **pflArray;
108
109 // Use plain realloc for speed
110 pflArray = realloc(*list, (*numalloced + 6) * sizeof(FILELIST *));
111 if (!pflArray) {
112 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
113 return 1;
114 }
115 (*numalloced) += 6;
116 *list = pflArray;
117 }
118 // Use plain malloc for speed
119 pfl = malloc(sizeof(FILELIST) + strlen(string));
120 if (!pfl) {
121 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
122 return 2;
123 }
124 pfl->attrFile = ffb4->attrFile;
125 pfl->date = ffb4->fdateLastWrite;
126 pfl->time = ffb4->ftimeLastWrite;
127 pfl->ladate = ffb4->fdateLastAccess;
128 pfl->latime = ffb4->ftimeLastAccess;
129 pfl->crdate = ffb4->fdateCreation;
130 pfl->crtime = ffb4->ftimeCreation;
131 pfl->cbFile = ffb4->cbFile;
132 pfl->easize = CBLIST_TO_EASIZE(ffb4->cbList);
133 strcpy(pfl->fname, string);
134 (*list)[*numfiles] = pfl;
135 (*numfiles)++;
136 (*list)[*numfiles] = NULL;
137 (*list)[(*numfiles) + 1] = NULL;
138#ifdef __DEBUG_ALLOC__
139 _heap_check();
140#endif
141 }
142 return 0;
143}
144
145INT AddToList(CHAR * string, CHAR *** list, INT * numfiles, INT * numalloced)
146{
147 CHAR **ppsz;
148 PSZ psz;
149
150 if (string) {
151 if (((*numfiles) + 3) > *numalloced) {
152 // Use plain realloc for speed
153 ppsz = realloc(*list, (*numalloced + 6) * sizeof(CHAR *));
154 if (!ppsz) {
155 Runtime_Error(pszSrcFile, __LINE__, "realloc");
156 return 1;
157 }
158 (*numalloced) += 6;
159 *list = ppsz;
160 }
161 // Use plain malloc for speed
162 psz = malloc(strlen(string) + 1);
163 if (!psz) {
164 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
165 return 2;
166 }
167 (*list)[*numfiles] = psz;
168 strcpy((*list)[*numfiles], string);
169 (*numfiles)++;
170 (*list)[*numfiles] = NULL;
171 (*list)[(*numfiles) + 1] = NULL;
172#ifdef __DEBUG_ALLOC__
173 _heap_check();
174#endif
175 }
176 return 0;
177}
178
179CHAR **BuildList(HWND hwndCnr)
180{
181 PCNRITEM pci;
182 CHAR **list = NULL, **test;
183 INT numfiles = 0, numalloc = 0, error = 0, attribute = CRA_CURSORED;
184
185 pci = (PCNRITEM) CurrentRecord(hwndCnr);
186 if (pci && (INT) pci != -1 && !(pci->flags & RECFLAGS_ENV)) {
187 if (pci->rc.flRecordAttr & CRA_SELECTED) {
188 attribute = CRA_SELECTED;
189 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
190 MPFROMSHORT(attribute));
191 }
192 }
193 while (pci && (INT) pci != -1 && !error) {
194 if (!(pci->rc.flRecordAttr & CRA_FILTERED))
195 error = AddToList(pci->szFileName, &list, &numfiles, &numalloc);
196 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
197 MPFROMSHORT(attribute));
198 }
199 if (numalloc > numfiles + 1) {
200 // Use plain realloc for speed
201 test = realloc(list, sizeof(CHAR *) * (numfiles + 1));
202 if (!test)
203 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_OUTOFMEMORY));
204 else
205 list = test;
206 }
207 return list;
208}
209
210CHAR **BuildArcList(HWND hwndCnr)
211{
212 PARCITEM pai;
213 CHAR **list = NULL;
214 INT numfiles = 0, numalloc = 0, error = 0, attribute = CRA_CURSORED;
215
216 pai = (PARCITEM) CurrentRecord(hwndCnr);
217 if (pai && (INT) pai != -1) {
218 if (pai->rc.flRecordAttr & CRA_SELECTED) {
219 attribute = CRA_SELECTED;
220 pai = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
221 MPFROMSHORT(attribute));
222 }
223 }
224 while (pai && (INT) pai != -1 && !error) {
225 if (!(pai->rc.flRecordAttr & CRA_FILTERED))
226 error = AddToList(pai->szFileName, &list, &numfiles, &numalloc);
227 pai = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pai),
228 MPFROMSHORT(attribute));
229 }
230 return list;
231}
232
233CHAR **RemoveFromList(CHAR ** list, CHAR * item)
234{
235 register INT x, y;
236
237 if (list && list[0] && item) {
238 for (x = 0; list[x]; x++) {
239 if (item == list[x]) {
240 free(list[x]);
241 list[x] = NULL;
242 for (y = x;; y++) {
243 if (y != x && !list[y])
244 break;
245 list[y] = list[y + 1];
246 }
247 if (!list[0]) {
248 FreeList(list);
249 list = NULL;
250 }
251 break;
252 }
253 }
254 }
255 return list;
256}
257
258CHAR **CombineLists(CHAR ** prime, CHAR ** add)
259{
260 register INT x;
261 INT numalloc, numfiles = 0;
262
263 if (add && add[0]) {
264 if (prime) {
265 for (x = 0; prime[x]; x++)
266 numfiles++;
267 }
268 numalloc = numfiles;
269 for (x = 0; add[x]; x++) {
270 if (*add[x])
271 AddToList(add[x], &prime, &numfiles, &numalloc);
272 }
273 FreeList(add);
274 }
275 return prime;
276}
Note: See TracBrowser for help on using the repository browser.