1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
/* ---------- direct.c --------- */
#include "dflat.h"
#ifndef FA_DIREC
#define FA_DIREC 0x10
#endif
static char path[MAXPATH];
static char drive[MAXDRIVE] = " :";
static char dir[MAXDIR];
static char name[MAXFILE];
static char ext[MAXEXT];
/* ----- Create unambiguous path from file spec, filling in the
drive and directory if incomplete. Optionally change to
the new drive and subdirectory ------ */
void CreatePath(char *spath,char *fspec,int InclName,int Change)
{
int cm = 0;
unsigned currdrive;
char currdir[MAXPATH+1],*cp;
if (!Change)
{
/* ---- save the current drive and subdirectory ---- */
currdrive = getdisk();
getcwd(currdir, sizeof currdir);
memmove(currdir, currdir+2, strlen(currdir+1));
cp = currdir+strlen(currdir)-1;
if ((*cp == '\\') && (strlen(dir) > 1)) /* save "\\" - Eric */
*cp = '\0';
}
*drive = *dir = *name = *ext = '\0';
fnsplit(fspec, drive, dir, name, ext);
if (!InclName)
*name = *ext = '\0';
*drive = toupper(*drive);
if (*ext)
cm |= EXTENSION;
if (InclName && *name)
cm |= FILENAME;
if (*dir)
cm |= DIRECTORY;
if (*drive)
cm |= DRIVE;
if (cm & DRIVE)
setdisk(*drive - 'A');
else
{
*drive = getdisk();
*drive += 'A';
}
if (cm & DIRECTORY)
{
cp = dir+strlen(dir)-1;
if ((*cp == '\\') && (strlen(dir) > 1)) /* save "\\" - Eric */
*cp = '\0';
chdir(dir);
}
getcwd(dir, sizeof dir);
memmove(dir, dir+2, strlen(dir+1));
if (InclName)
{
if (!(cm & FILENAME))
strcpy(name, "*");
if (!(cm & EXTENSION) && strchr(fspec, '.') != NULL)
strcpy(ext, ".*");
}
else
*name = *ext = '\0';
if (dir[strlen(dir)-1] != '\\')
strcat(dir, "\\");
if (spath != NULL)
fnmerge(spath, drive, dir, name, ext);
if (!Change)
{
setdisk(currdrive);
chdir(currdir);
}
}
static int dircmp(const void *c1, const void *c2)
{
return stricmp(*(char **)c1, *(char **)c2);
}
static BOOL BuildList(WINDOW wnd, char *fspec, BOOL dirs)
{
int ax, i = 0, criterr = 1;
struct ffblk ff;
CTLWINDOW *ct = FindCommand(wnd->extension, dirs ? ID_DIRECTORY : ID_FILES,LISTBOX);
WINDOW lwnd;
char **dirlist = NULL;
if (ct != NULL)
{
lwnd = ct->wnd;
SendMessage(lwnd, CLEARTEXT, 0, 0);
while (criterr == 1)
{
ax = findfirst(fspec, &ff, dirs ? FA_DIREC : 0);
criterr = TestCriticalError();
}
if (criterr)
return FALSE;
while (ax == 0)
{
if (!dirs || (ff.ff_attrib & FA_DIREC) && strcmp(ff.ff_name, "."))
{
dirlist = DFrealloc(dirlist, sizeof(char *)*(i+1));
dirlist[i] = DFmalloc(strlen(ff.ff_name)+1);
strcpy(dirlist[i++], ff.ff_name);
}
ax = findnext(&ff);
}
if (dirlist != NULL)
{
int j;
/* -- sort file or directory list box data -- */
qsort(dirlist, i, sizeof(void *), dircmp);
/* ---- send sorted list to list box ---- */
for (j=0;j<i;j++)
{
SendMessage(lwnd,ADDTEXT,(PARAM)dirlist[j],0);
free(dirlist[j]);
}
free(dirlist);
}
SendMessage(lwnd, SHOW_WINDOW, 0, 0);
}
return TRUE;
}
BOOL BuildFileList(WINDOW wnd, char *fspec)
{
return BuildList(wnd, fspec, FALSE);
}
void BuildDirectoryList(WINDOW wnd)
{
BuildList(wnd, "*.*", TRUE);
}
void BuildDriveList(WINDOW wnd)
{
CTLWINDOW *ct = FindCommand(wnd->extension, ID_DRIVE,LISTBOX);
if (ct != NULL)
{
union REGS regs;
char drname[15];
unsigned int cd, dr;
WINDOW lwnd = ct->wnd;
SendMessage(lwnd, CLEARTEXT, 0, 0);
cd = getdisk();
for (dr=0;dr<26;dr++)
{
unsigned ndr;
setdisk(dr);
ndr = getdisk();
if (ndr == dr)
{
/* Test for remapped B drive */
if (dr == 1)
{
regs.x.ax = 0x440e; /* IOCTL func 14 */
regs.h.bl = dr+1;
int86(DOS, ®s, ®s);
if (regs.h.al != 0)
continue;
}
sprintf(drname, "[-%c-]", dr+'A');
/* Test for network or RAM disk */
/*
-- Commented out for now...don't really like or need this
as of right now -- Joe
regs.x.ax = 0x4409; // IOCTL func 9
regs.h.bl = dr+1;
int86(DOS, ®s, ®s);
if (!regs.x.cflag)
{
if (regs.x.dx & 0x1000)
{
drname[0]='<';
drname[4]='>';
};
}
*/
SendMessage(lwnd,ADDTEXT,(PARAM)drname,0);
}
}
SendMessage(lwnd, SHOW_WINDOW, 0, 0);
setdisk(cd);
}
}
void BuildPathDisplay(WINDOW wnd)
{
CTLWINDOW *ct = FindCommand(wnd->extension, ID_PATH,TEXT);
if (ct != NULL)
{
int len;
WINDOW lwnd = ct->wnd;
CreatePath(path, "*.*", FALSE, FALSE);
len = strlen(path);
if (len > 3)
path[len-1] = '\0';
SendMessage(lwnd,SETTEXT,(PARAM)path,0);
SendMessage(lwnd, PAINT, 0, 0);
}
}
|