1 /* ---------- direct.c --------- */
13 static char path
[MAX_PATH
];
14 static char drive
[_MAX_DRIVE
] = " :";
15 static char dir
[_MAX_DIR
];
16 static char name
[_MAX_FNAME
];
17 static char ext
[_MAX_EXT
];
19 /* ----- Create unambiguous path from file spec, filling in the
20 drive and directory if incomplete. Optionally change to
21 the new drive and subdirectory ------ */
22 void DfCreatePath(char *path
,char *fspec
,int InclName
,int Change
)
25 char currdir
[MAX_PATH
];
28 /* save the current directory */
30 GetCurrentDirectory (MAX_PATH
, currdir
);
32 *drive
= *dir
= *name
= *ext
= '\0';
33 _splitpath(fspec
, drive
, dir
, name
, ext
);
36 *drive
= toupper(*drive
);
39 if (InclName
&& *name
)
46 _chdrive(*drive
- '@');
54 cp
= dir
+strlen(dir
)-1;
59 getcwd(dir
, sizeof dir
);
60 memmove(dir
, dir
+2, strlen(dir
+1));
64 if (!(cm
& EXTENSION
) && strchr(fspec
, '.') != NULL
)
69 if (dir
[strlen(dir
)-1] != '\\')
71 memset(path
, 0, sizeof path
);
72 _makepath(path
, drive
, dir
, name
, ext
);
75 SetCurrentDirectory (currdir
);
79 static int dircmp(const void *c1
, const void *c2
)
81 return stricmp(*(char **)c1
, *(char **)c2
);
85 BOOL
DfDlgDirList(DFWINDOW wnd
, char *fspec
,
86 enum DfCommands nameid
, enum DfCommands pathid
,
90 struct _finddata_t ff
;
91 DF_CTLWINDOW
*ct
= DfFindCommand(wnd
->extension
,nameid
,DF_LISTBOX
);
93 char **dirlist
= NULL
;
95 DfCreatePath(path
, fspec
, TRUE
, TRUE
);
99 DfSendMessage(ct
->wnd
, DFM_CLEARTEXT
, 0, 0);
105 cd
= GetLogicalDrives ();
106 for (dr
= 0; dr
< 26; dr
++)
112 sprintf(drname
, "[%c:\\]", (char)(dr
+'A'));
114 /* ---- test for network or RAM disk ---- */
115 regs
.x
.ax
= 0x4409; /* IOCTL func 9 */
117 int86(DOS
, ®s
, ®s
);
119 if (regs
.x
.dx
& 0x1000)
120 strcat(drname
, " (Network)");
121 else if (regs
.x
.dx
== 0x0800)
122 strcat(drname
, " (RAMdisk)");
125 DfSendMessage(lwnd
,DFM_ADDTEXT
,(DF_PARAM
)drname
,0);
128 DfSendMessage(lwnd
, DFM_PAINT
, 0, 0);
130 ax
= _findfirst(path
, &ff
);
135 if (!((attrib
& 0x4000) &&
136 (ff
.attrib
& (attrib
& 0x3f)) == 0) &&
137 strcmp(ff
.name
, "."))
139 char fname
[MAX_PATH
+2];
140 sprintf(fname
, (ff
.attrib
& FILE_ATTRIBUTE_DIRECTORY
) ?
141 "[%s]" : "%s" , ff
.name
);
142 dirlist
= DfRealloc(dirlist
,
143 sizeof(char *)*(i
+1));
144 dirlist
[i
] = DfMalloc(strlen(fname
)+1);
145 if (dirlist
[i
] != NULL
)
146 strcpy(dirlist
[i
], fname
);
150 while (_findnext(ax
, &ff
) == 0);
155 /* -- sort file/drive/directory list box data -- */
156 qsort(dirlist
, i
, sizeof(void *), dircmp
);
158 /* ---- send sorted list to list box ---- */
159 for (j
= 0; j
< i
; j
++) {
160 DfSendMessage(lwnd
,DFM_ADDTEXT
,(DF_PARAM
)dirlist
[j
],0);
165 DfSendMessage(lwnd
, DFM_SHOW_WINDOW
, 0, 0);
169 _makepath(path
, drive
, dir
, NULL
, NULL
);
170 DfPutItemText(wnd
, pathid
, path
);