| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * WCMD - Wine-compatible command line interface - Directory functions. |
| 3 | * |
| Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999 D A Pickles |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 5 | * |
| Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NOTES: |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 23 | * On entry, global variables quals, param1, param2 contain |
| 24 | * the qualifiers (uppercased and concatenated) and parameters entered, with |
| 25 | * environment-variable and batch parameter substitution already done. |
| 26 | */ |
| 27 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 28 | #include "wcmd.h" |
| 29 | |
| 30 | int WCMD_dir_sort (const void *a, const void *b); |
| 31 | void WCMD_list_directory (char *path, int level); |
| Alexandre Julliard | dd0bdbe | 2002-09-12 17:29:12 +0000 | [diff] [blame] | 32 | char * WCMD_filesize64 (ULONGLONG free); |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 33 | char * WCMD_strrev (char *buff); |
| 34 | |
| 35 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 36 | extern char nyi[]; |
| 37 | extern char newline[]; |
| 38 | extern char version_string[]; |
| 39 | extern char anykey[]; |
| 40 | extern int echo_mode; |
| 41 | extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH]; |
| Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 42 | extern DWORD errorlevel; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 43 | |
| Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 44 | int file_total, dir_total, line_count, page_mode, recurse, wide, bare, |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 45 | max_width; |
| Alexandre Julliard | dd0bdbe | 2002-09-12 17:29:12 +0000 | [diff] [blame] | 46 | ULONGLONG byte_total; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 47 | |
| 48 | /***************************************************************************** |
| 49 | * WCMD_directory |
| 50 | * |
| 51 | * List a file directory. |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 52 | * |
| 53 | */ |
| 54 | |
| 55 | void WCMD_directory () { |
| 56 | |
| 57 | char path[MAX_PATH], drive[8]; |
| 58 | int status; |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 59 | ULARGE_INTEGER avail, total, free; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 60 | CONSOLE_SCREEN_BUFFER_INFO consoleInfo; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 61 | |
| 62 | line_count = 5; |
| Dave Pickles | a9d0209 | 2001-06-20 22:52:12 +0000 | [diff] [blame] | 63 | byte_total = 0; |
| 64 | file_total = dir_total = 0; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 65 | |
| 66 | /* Handle args */ |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 67 | page_mode = (strstr(quals, "/P") != NULL); |
| 68 | recurse = (strstr(quals, "/S") != NULL); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 69 | wide = (strstr(quals, "/W") != NULL); |
| 70 | bare = (strstr(quals, "/B") != NULL); |
| 71 | |
| 72 | /* Handle conflicting args and initialization */ |
| 73 | if (bare) wide = FALSE; |
| 74 | |
| 75 | if (wide) { |
| 76 | GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo); |
| 77 | max_width = consoleInfo.dwSize.X; |
| 78 | } |
| 79 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 80 | if (param1[0] == '\0') strcpy (param1, "."); |
| Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 81 | status = GetFullPathName (param1, sizeof(path), path, NULL); |
| 82 | if (!status) { |
| 83 | WCMD_print_error(); |
| 84 | return; |
| 85 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 86 | lstrcpyn (drive, path, 3); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 87 | |
| 88 | if (!bare) { |
| 89 | status = WCMD_volume (0, drive); |
| 90 | if (!status) { |
| 91 | return; |
| 92 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 93 | } |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 94 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 95 | WCMD_list_directory (path, 0); |
| 96 | lstrcpyn (drive, path, 4); |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 97 | GetDiskFreeSpaceEx (drive, &avail, &total, &free); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 98 | |
| 99 | if (!bare) { |
| 100 | if (recurse) { |
| 101 | WCMD_output ("\n\n Total files listed:\n%8d files%25s bytes\n", |
| 102 | file_total, WCMD_filesize64 (byte_total)); |
| Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 103 | WCMD_output ("%8d directories %18s bytes free\n\n", |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 104 | dir_total, WCMD_filesize64 (free.QuadPart)); |
| 105 | } else { |
| 106 | WCMD_output (" %18s bytes free\n\n", WCMD_filesize64 (free.QuadPart)); |
| 107 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | /***************************************************************************** |
| 112 | * WCMD_list_directory |
| 113 | * |
| 114 | * List a single file directory. This function (and those below it) can be called |
| 115 | * recursively when the /S switch is used. |
| 116 | * |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 117 | * FIXME: Entries sorted by name only. Should we support DIRCMD?? |
| 118 | * FIXME: Assumes 24-line display for the /P qualifier. |
| 119 | * FIXME: Other command qualifiers not supported. |
| Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 120 | * FIXME: DIR /S FILENAME fails if at least one matching file is not found in the top level. |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 121 | */ |
| 122 | |
| 123 | void WCMD_list_directory (char *search_path, int level) { |
| 124 | |
| 125 | char string[1024], datestring[32], timestring[32]; |
| 126 | char mem_err[] = "Memory Allocation Error"; |
| 127 | char *p; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 128 | char real_path[MAX_PATH]; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 129 | DWORD count; |
| 130 | WIN32_FIND_DATA *fd; |
| 131 | FILETIME ft; |
| 132 | SYSTEMTIME st; |
| 133 | HANDLE hff; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 134 | int status, dir_count, file_count, entry_count, i, widest, linesout, cur_width, tmp_width; |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 135 | ULARGE_INTEGER byte_count, file_size; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 136 | |
| 137 | dir_count = 0; |
| 138 | file_count = 0; |
| 139 | entry_count = 0; |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 140 | byte_count.QuadPart = 0; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 141 | widest = 0; |
| 142 | linesout = 0; |
| 143 | cur_width = 0; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * If the path supplied does not include a wildcard, and the endpoint of the |
| 147 | * path references a directory, we need to list the *contents* of that |
| 148 | * directory not the directory file itself. |
| 149 | */ |
| 150 | |
| 151 | if ((strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) { |
| 152 | status = GetFileAttributes (search_path); |
| 153 | if ((status != -1) && (status & FILE_ATTRIBUTE_DIRECTORY)) { |
| 154 | if (search_path[strlen(search_path)-1] == '\\') { |
| 155 | strcat (search_path, "*"); |
| 156 | } |
| 157 | else { |
| 158 | strcat (search_path, "\\*"); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 163 | /* Work out the actual current directory name */ |
| 164 | p = strrchr (search_path, '\\'); |
| 165 | memset(real_path, 0x00, sizeof(real_path)); |
| 166 | lstrcpyn (real_path, search_path, (p-search_path+2)); |
| 167 | |
| 168 | /* Load all files into an in memory structure */ |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 169 | fd = malloc (sizeof(WIN32_FIND_DATA)); |
| 170 | hff = FindFirstFile (search_path, fd); |
| 171 | if (hff == INVALID_HANDLE_VALUE) { |
| Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 172 | SetLastError (ERROR_FILE_NOT_FOUND); |
| 173 | WCMD_print_error (); |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 174 | free (fd); |
| 175 | return; |
| 176 | } |
| 177 | do { |
| 178 | entry_count++; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 179 | |
| 180 | /* Keep running track of longest filename for wide output */ |
| 181 | if (wide) { |
| 182 | int tmpLen = strlen((fd+(entry_count-1))->cFileName) + 3; |
| 183 | if ((fd+(entry_count-1))->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) tmpLen = tmpLen + 2; |
| 184 | if (tmpLen > widest) widest = tmpLen; |
| 185 | } |
| 186 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 187 | fd = realloc (fd, (entry_count+1)*sizeof(WIN32_FIND_DATA)); |
| 188 | if (fd == NULL) { |
| 189 | FindClose (hff); |
| 190 | WCMD_output (mem_err); |
| 191 | return; |
| 192 | } |
| 193 | } while (FindNextFile(hff, (fd+entry_count)) != 0); |
| 194 | FindClose (hff); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 195 | |
| 196 | /* Sort the list of files */ |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 197 | qsort (fd, entry_count, sizeof(WIN32_FIND_DATA), WCMD_dir_sort); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 198 | |
| 199 | /* Output the results */ |
| 200 | if (!bare) { |
| 201 | if (level != 0) WCMD_output ("\n\n"); |
| 202 | WCMD_output ("Directory of %s\n\n", real_path); |
| 203 | if (page_mode) { |
| 204 | line_count += 2; |
| 205 | if (line_count > 23) { |
| 206 | line_count = 0; |
| 207 | WCMD_output (anykey); |
| 208 | ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL); |
| 209 | } |
| 210 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 211 | } |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 212 | |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 213 | for (i=0; i<entry_count; i++) { |
| 214 | FileTimeToLocalFileTime (&(fd+i)->ftLastWriteTime, &ft); |
| 215 | FileTimeToSystemTime (&ft, &st); |
| 216 | GetDateFormat (0, DATE_SHORTDATE, &st, NULL, datestring, |
| 217 | sizeof(datestring)); |
| 218 | GetTimeFormat (0, TIME_NOSECONDS, &st, |
| 219 | NULL, timestring, sizeof(timestring)); |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 220 | |
| 221 | if (wide) { |
| 222 | |
| 223 | tmp_width = cur_width; |
| 224 | if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 225 | WCMD_output ("["); |
| 226 | WCMD_output ("%s", (fd+i)->cFileName); |
| 227 | WCMD_output ("]"); |
| 228 | dir_count++; |
| 229 | tmp_width = tmp_width + strlen((fd+i)->cFileName) + 2; |
| 230 | } else { |
| 231 | WCMD_output ("%s", (fd+i)->cFileName); |
| 232 | tmp_width = tmp_width + strlen((fd+i)->cFileName) ; |
| 233 | file_count++; |
| 234 | #ifndef NONAMELESSSTRUCT |
| 235 | file_size.LowPart = (fd+i)->nFileSizeLow; |
| 236 | file_size.HighPart = (fd+i)->nFileSizeHigh; |
| 237 | #else |
| 238 | file_size.s.LowPart = (fd+i)->nFileSizeLow; |
| 239 | file_size.s.HighPart = (fd+i)->nFileSizeHigh; |
| 240 | #endif |
| 241 | byte_count.QuadPart += file_size.QuadPart; |
| 242 | } |
| 243 | cur_width = cur_width + widest; |
| 244 | |
| 245 | if ((cur_width + widest) > max_width) { |
| 246 | WCMD_output ("\n"); |
| 247 | cur_width = 0; |
| 248 | linesout++; |
| 249 | } else { |
| 250 | WCMD_output ("%*.s", (tmp_width - cur_width) ,""); |
| 251 | } |
| 252 | |
| 253 | } else if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 254 | dir_count++; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 255 | |
| 256 | if (!bare) { |
| 257 | WCMD_output ("%8s %8s <DIR> %s\n", |
| 258 | datestring, timestring, (fd+i)->cFileName); |
| 259 | linesout++; |
| 260 | } else { |
| Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 261 | if (!((strcmp((fd+i)->cFileName, ".") == 0) || |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 262 | (strcmp((fd+i)->cFileName, "..") == 0))) { |
| 263 | WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName); |
| 264 | linesout++; |
| 265 | } |
| 266 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 267 | } |
| 268 | else { |
| 269 | file_count++; |
| Francois Gouget | f860ded | 2001-06-08 18:59:03 +0000 | [diff] [blame] | 270 | #ifndef NONAMELESSSTRUCT |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 271 | file_size.LowPart = (fd+i)->nFileSizeLow; |
| 272 | file_size.HighPart = (fd+i)->nFileSizeHigh; |
| Francois Gouget | f860ded | 2001-06-08 18:59:03 +0000 | [diff] [blame] | 273 | #else |
| 274 | file_size.s.LowPart = (fd+i)->nFileSizeLow; |
| 275 | file_size.s.HighPart = (fd+i)->nFileSizeHigh; |
| 276 | #endif |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 277 | byte_count.QuadPart += file_size.QuadPart; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 278 | if (!bare) { |
| 279 | WCMD_output ("%8s %8s %10s %s\n", |
| 280 | datestring, timestring, |
| 281 | WCMD_filesize64(file_size.QuadPart), (fd+i)->cFileName); |
| 282 | linesout++; |
| 283 | } else { |
| 284 | WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName); |
| 285 | linesout++; |
| 286 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 287 | } |
| 288 | if (page_mode) { |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 289 | line_count = line_count + linesout; |
| 290 | linesout = 0; |
| 291 | if (line_count > 23) { |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 292 | line_count = 0; |
| 293 | WCMD_output (anykey); |
| Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 294 | ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL); |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | } |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 298 | |
| 299 | if (wide && cur_width>0) { |
| 300 | WCMD_output ("\n"); |
| 301 | if (page_mode) { |
| 302 | if (++line_count > 23) { |
| 303 | line_count = 0; |
| 304 | WCMD_output (anykey); |
| 305 | ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL); |
| 306 | } |
| 307 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 308 | } |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 309 | |
| 310 | if (!bare) { |
| 311 | if (file_count == 1) { |
| 312 | WCMD_output (" 1 file %25s bytes\n", WCMD_filesize64 (byte_count.QuadPart)); |
| 313 | } |
| 314 | else { |
| 315 | WCMD_output ("%8d files %24s bytes\n", file_count, WCMD_filesize64 (byte_count.QuadPart)); |
| 316 | } |
| 317 | if (page_mode) { |
| 318 | if (++line_count > 23) { |
| 319 | line_count = 0; |
| 320 | WCMD_output (anykey); |
| 321 | ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL); |
| 322 | } |
| 323 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 324 | } |
| Dave Pickles | 64fba1c | 2001-06-04 02:55:38 +0000 | [diff] [blame] | 325 | byte_total = byte_total + byte_count.QuadPart; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 326 | file_total = file_total + file_count; |
| 327 | dir_total = dir_total + dir_count; |
| Jason Edmeades | a882895 | 2002-04-29 23:33:09 +0000 | [diff] [blame] | 328 | |
| 329 | if (!bare) { |
| 330 | if (dir_count == 1) WCMD_output ("1 directory "); |
| 331 | else WCMD_output ("%8d directories", dir_count); |
| 332 | if (page_mode) { |
| 333 | if (++line_count > 23) { |
| 334 | line_count = 0; |
| 335 | WCMD_output (anykey); |
| 336 | ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL); |
| 337 | } |
| 338 | } |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 339 | } |
| 340 | for (i=0; i<entry_count; i++) { |
| 341 | if ((recurse) && |
| 342 | ((fd+i)->cFileName[0] != '.') && |
| 343 | ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
| Patrik Stridvall | 205721e | 2000-03-24 20:40:41 +0000 | [diff] [blame] | 344 | #if 0 |
| 345 | GetFullPathName ((fd+i)->cFileName, sizeof(string), string, NULL); |
| 346 | #endif |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 347 | p = strrchr (search_path, '\\'); |
| 348 | lstrcpyn (string, search_path, (p-search_path+2)); |
| 349 | lstrcat (string, (fd+i)->cFileName); |
| 350 | lstrcat (string, p); |
| 351 | WCMD_list_directory (string, 1); |
| 352 | } |
| 353 | } |
| 354 | free (fd); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | /***************************************************************************** |
| 359 | * WCMD_filesize64 |
| 360 | * |
| 361 | * Convert a 64-bit number into a character string, with commas every three digits. |
| 362 | * Result is returned in a static string overwritten with each call. |
| 363 | * FIXME: There must be a better algorithm! |
| 364 | */ |
| 365 | |
| Alexandre Julliard | dd0bdbe | 2002-09-12 17:29:12 +0000 | [diff] [blame] | 366 | char * WCMD_filesize64 (ULONGLONG n) { |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 367 | |
| Alexandre Julliard | dd0bdbe | 2002-09-12 17:29:12 +0000 | [diff] [blame] | 368 | ULONGLONG q; |
| Gregg Mattinson | d0f8bf3 | 2002-07-05 22:47:56 +0000 | [diff] [blame] | 369 | uint r, i; |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 370 | char *p; |
| 371 | static char buff[32]; |
| 372 | |
| 373 | p = buff; |
| 374 | i = -3; |
| 375 | do { |
| 376 | if ((++i)%3 == 1) *p++ = ','; |
| 377 | q = n / 10; |
| 378 | r = n - (q * 10); |
| 379 | *p++ = r + '0'; |
| 380 | *p = '\0'; |
| 381 | n = q; |
| 382 | } while (n != 0); |
| 383 | WCMD_strrev (buff); |
| 384 | return buff; |
| 385 | } |
| 386 | |
| 387 | /***************************************************************************** |
| Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 388 | * WCMD_strrev |
| 389 | * |
| 390 | * Reverse a character string in-place (strrev() is not available under unixen :-( ). |
| 391 | */ |
| 392 | |
| 393 | char * WCMD_strrev (char *buff) { |
| 394 | |
| 395 | int r, i; |
| 396 | char b; |
| 397 | |
| 398 | r = lstrlen (buff); |
| 399 | for (i=0; i<r/2; i++) { |
| 400 | b = buff[i]; |
| 401 | buff[i] = buff[r-i-1]; |
| 402 | buff[r-i-1] = b; |
| 403 | } |
| 404 | return (buff); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | int WCMD_dir_sort (const void *a, const void *b) { |
| 409 | |
| 410 | return (lstrcmpi(((WIN32_FIND_DATA *)a)->cFileName, |
| 411 | ((WIN32_FIND_DATA *)b)->cFileName)); |
| 412 | } |