Skip to content

added WIN32 implementation of prepare_dirs#58

Open
LowLevelMahn wants to merge 3 commits into
Henne:masterfrom
LowLevelMahn:llm/win32_prepare_dirs
Open

added WIN32 implementation of prepare_dirs#58
LowLevelMahn wants to merge 3 commits into
Henne:masterfrom
LowLevelMahn:llm/win32_prepare_dirs

Conversation

@LowLevelMahn

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/schick/seg120.cpp Outdated
Comment thread src/schick/seg120.cpp Outdated
Comment thread src/schick/seg120.cpp Outdated
Comment thread src/schick/seg120.cpp Outdated
Comment thread src/schick/seg120.cpp Outdated
@Henne

Henne commented Dec 19, 2025

Copy link
Copy Markdown
Owner

Hab noch einen Commit rausgehauen, damit das auch so funktioniert wie ich es mir vorstelle.

@LowLevelMahn

LowLevelMahn commented Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

mir würde es gefallen wenn wir das Dateisuchen ein wenig entkoppeln z.B. so

dann kann man die find_files routine an 4-9 Stellen verwenden

static bool valid_filename(const char* filename, const char* ext)
{
    return (filename[0] != '.') && strstr(filename, ext);
}

void find_files(const char* search_path, const char* ext, void (*file_found_callback)(const char* filename))
{
#if defined(__BORLANDC__)
// ...
#elif defined(_WIN32)
    char path[_MAX_PATH];
    snprintf(path, sizeof(path), "%s/*", search_path);
    struct _finddata_t fileinfo;
    intptr_t handle = _findfirst(path, &fileinfo);
    while (handle != -1) {
        if (valid_filename(fileinfo.name, ext)) {
            file_found_callback(fileinfo.name);
        }
        if (_findnext(handle, &fileinfo) != 0)
        {
            break;
        }
    }
    _findclose(handle);
#else
    DIR* dir = opendir(search_path);
    if (dir != NULL) {
        const struct dirent* ent = readdir(dir);
        while (ent != NULL) {
            if (valid_filename(fileinfo.name, ext)) {
                file_found_callback(fileinfo.name);
            }
            ent = readdir(dir);
        }
        closedir(dir);
    }
#endif
}

// wird aufgerufen wenn find_files eine passende Datei gefunden hat
// hier kann man auch kopieren, loeschen etc.
void print_file_name(const char* filename)
{
	printf("filename: %s\n", filename);
}

int main(int argc, char** argv)
{
	printf("find all *.chr\n");
	find_files("./",".CHR", print_file_name);
	printf("find all *.*\n");
	find_files("./","", print_file_name);
}

dabei kommt das Ergebnis raus

find all *.chr
filename: ARBOSH.CHR
filename: HJALDIS.CHR
filename: RHENAYA.CHR
filename: TALIMEE.CHR
filename: TAMION.CHR
filename: YARANO.CHR
find all *.*
filename: ARBOSH.CHR
filename: GAMES.NAM
filename: HJALDIS.CHR
filename: RHENAYA.CHR
filename: SCHICK.DAT
filename: schick_MSVC.exe
filename: schick_MSVC.pdb
filename: SDL2d.dll
filename: TALIMEE.CHR
filename: TAMION.CHR
filename: TEMP
filename: YARANO.CHR

@LowLevelMahn

Copy link
Copy Markdown
Contributor Author

ist die Implementierung so ok - magst du mal pullen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants