Fix short extensions handling.

This commit is contained in:
sorgelig
2018-08-30 00:16:32 +08:00
parent 43cbd37976
commit a3c67d2605
2 changed files with 28 additions and 9 deletions

View File

@@ -206,6 +206,7 @@ char* GetExt(char *ext)
while (*ext) {
strcpy(p, ",");
strncat(p, ext, 3);
while (*(p + strlen(p) - 1) == ' ') *(p + strlen(p) - 1) = 0;
if (strlen(ext) <= 3) break;
ext += 3;
p += strlen(p);

View File

@@ -2062,22 +2062,40 @@ void user_io_kbd(uint16_t key, int press)
unsigned char user_io_ext_idx(char *name, char* ext)
{
unsigned char idx = 0;
int len = strlen(ext);
printf("Subindex of \"%s\" in \"%s\": ", name, ext);
while ((len>3) && *ext)
char *p = strrchr(name, '.');
if (p)
{
if (!strncasecmp(name + strlen(name) - 3, ext, 3))
p++;
char e[4] = " ";
for (int i = 0; i < 3; i++)
{
printf("%d\n", idx);
return idx;
if (!*p) break;
e[i] = *p++;
}
while (*ext)
{
int found = 1;
for (int i = 0; i < 3; i++)
{
if (ext[i] != '?' && (toupper(ext[i]) != toupper(e[i]))) found = 0;
}
if (found)
{
printf("%d\n", idx);
return idx;
}
if (strlen(ext) <= 3) break;
idx++;
ext += 3;
}
if (strlen(ext) <= 3) break;
idx++;
ext += 3;
}
printf("0\n", name, ext, 0);
printf("not found! use 0\n", name, ext, 0);
return 0;
}