Reformat code, remove obsolete comments

No effective code changes, i.e. only formatting, indents and comments.
This commit is contained in:
Albrecht Schlosser 2023-08-10 15:40:45 +02:00
parent dbb77b9657
commit 76fb2d5b79

View File

@ -1,7 +1,7 @@
/* /*
* Windows scandir function for the Fast Light Tool Kit (FLTK). * Windows scandir function for the Fast Light Tool Kit (FLTK).
* *
* Copyright 1998-2020 by Bill Spitzak and others. * Copyright 1998-2023 by Bill Spitzak and others.
* *
* This library is free software. Distribution and use rights are outlined in * This library is free software. Distribution and use rights are outlined in
* the file "COPYING" which should have been included with this file. If this * the file "COPYING" which should have been included with this file. If this
@ -88,32 +88,30 @@ int fl_scandir(const char *dirname, struct dirent ***namelist,
} }
strcpy(findIn, dirname); strcpy(findIn, dirname);
for (d = findIn; *d; d++) if (*d=='/') *d='\\'; for (d = findIn; *d; d++) if (*d == '/') *d = '\\';
if (len==0) { strcpy(findIn, ".\\*"); } if (len == 0) { strcpy(findIn, ".\\*"); }
if ((len==2)&&findIn[1]==':'&&isalpha(findIn[0])) { *d++ = '\\'; *d = 0; } if ((len == 2) && (findIn[1] == ':') && isalpha(findIn[0])) { *d++ = '\\'; *d = 0; }
if ((len==1)&& (d[-1]=='.')) { strcpy(findIn, ".\\*"); is_dir = 1; } if ((len == 1) && (d[-1] == '.')) { strcpy(findIn, ".\\*"); is_dir = 1; }
if ((len>0) && (d[-1]=='\\')) { *d++ = '*'; *d = 0; is_dir = 1; } if ((len > 0) && (d[-1] == '\\')) { *d++ = '*'; *d = 0; is_dir = 1; }
if ((len>1) && (d[-1]=='.') && (d[-2]=='\\')) { d[-1] = '*'; is_dir = 1; } if ((len > 1) && (d[-1] == '.') && (d[-2] == '\\')) { d[-1] = '*'; is_dir = 1; }
{ /* Create a block to limit the scope while we find the initial "wide" filename */ { /* Create a block to limit the scope while we find the initial "wide" filename */
/* unsigned short * wbuf = (unsigned short*)malloc(sizeof(short) *(len + 10)); */ unsigned short *wbuf = NULL;
/* wbuf[fl_utf2unicode(findIn, strlen(findIn), wbuf)] = 0; */ unsigned wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), NULL, 0); /* Pass NULL to query length */
unsigned short *wbuf = NULL; wlen++; /* add a little extra for termination etc. */
unsigned wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), NULL, 0); /* Pass NULL to query length */ wbuf = (unsigned short*)malloc(sizeof(unsigned short)*(wlen+2));
wlen++; /* add a little extra for termination etc. */ wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), wbuf, wlen); /* actually convert the filename */
wbuf = (unsigned short*)malloc(sizeof(unsigned short)*(wlen+2)); wbuf[wlen] = 0; /* NULL terminate the resultant string */
wlen = fl_utf8toUtf16(findIn, (unsigned) strlen(findIn), wbuf, wlen); /* actually convert the filename */ if (!is_dir) { /* this file may still be a directory that we need to list */
wbuf[wlen] = 0; /* NULL terminate the resultant string */ DWORD attr = GetFileAttributesW(wbuf);
if (!is_dir) { /* this file may still be a directory that we need to list */ if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) ) {
DWORD attr = GetFileAttributesW(wbuf); wbuf[wlen] = '\\'; wbuf[wlen+1] = '*'; wbuf[wlen+2] = 0;
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) ) { }
wbuf[wlen] = '\\'; wbuf[wlen+1] = '*'; wbuf[wlen+2] = 0; }
} h = FindFirstFileW(wbuf, &findw); /* get a handle to the first filename in the search */
} free(wbuf); /* release the "wide" buffer before the pointer goes out of scope */
h = FindFirstFileW(wbuf, &findw); /* get a handle to the first filename in the search */
free(wbuf); /* release the "wide" buffer before the pointer goes out of scope */
} }
if (h==INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
free(findIn); free(findIn);
ret = GetLastError(); ret = GetLastError();
if (ret != ERROR_NO_MORE_FILES) { if (ret != ERROR_NO_MORE_FILES) {
@ -128,7 +126,6 @@ int fl_scandir(const char *dirname, struct dirent ***namelist,
int dstlen = l * 5 + 1; int dstlen = l * 5 + 1;
selectDir=(struct dirent*)malloc(sizeof(struct dirent)+dstlen); selectDir=(struct dirent*)malloc(sizeof(struct dirent)+dstlen);
/* l = fl_unicode2utf(findw.cFileName, l, selectDir->d_name); */
l = fl_utf8fromwc(selectDir->d_name, dstlen, findw.cFileName, l); l = fl_utf8fromwc(selectDir->d_name, dstlen, findw.cFileName, l);
selectDir->d_name[l] = 0; selectDir->d_name[l] = 0;