Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite example 2 to not use Windows splitpath function #66

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ else()
set_cxx_flag("-g3" DEBUG)
set_cxx_flag("-g3" RELWITHDEBINFO)

set_cxx_flag("-pthread")
set_linker_flag("-pthread")

if (USE_EXTRA_OPTIMIZATION)
# CMake already sets the -O3 flag on Release build and -O[1-3s] already sets the -fomit-frame-pointer flag.
set_cxx_flag("-Og" DEBUG)
Expand All @@ -122,8 +125,6 @@ else()
endif()

if (BUILD_SHARED_LIBCRN OR BUILD_STATIC_LIBCRN OR BUILD_CRUNCH OR BUILD_EXAMPLES)
set_cxx_flag("-pthread")
set_linker_flag("-pthread")
add_subdirectory(crnlib crnlib)
endif()

Expand Down
33 changes: 15 additions & 18 deletions example2/example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@ int main(int argc, char* argv[]) {
return error("Invalid option: %s\n", argv[i]);
}

// Split the source filename into its various components.
#if defined(_WIN32)
char drive_buf[_MAX_DRIVE], dir_buf[_MAX_DIR], fname_buf[_MAX_FNAME], ext_buf[_MAX_EXT];
if (_splitpath_s(pSrc_filename, drive_buf, _MAX_DRIVE, dir_buf, _MAX_DIR, fname_buf, _MAX_FNAME, ext_buf, _MAX_EXT))
return error("Invalid source filename!\n");
#else
char in_filename[FILENAME_MAX];
strncpy(in_filename, pSrc_filename, FILENAME_MAX);
const char drive_buf[] = "";
char *dir_buf = dirname(in_filename);
char *fname_buf = basename(in_filename);
char *dot = strrchr(fname_buf, '.');
if (dot && dot != fname_buf)
*dot = '\0';
#endif

// Load the source file into memory.
printf("Loading source file: %s\n", pSrc_filename);
crn_uint32 src_file_size;
Expand Down Expand Up @@ -152,9 +136,22 @@ int main(int argc, char* argv[]) {

// Now create the DDS file.
char dst_filename[FILENAME_MAX];
crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf);
if (out_filename[0])
if (out_filename[0]) {
strcpy(dst_filename, out_filename);
} else {
unsigned int stripped_length = UINT32_MAX;
const char* ext_begin = strrchr(pSrc_filename, '.');
if (ext_begin) {
#ifdef _WIN32
const char* sep = strpbrk(ext_begin, "/\\");
#else
const char* sep = strpbrk(ext_begin, "/");
#endif
if (!sep)
stripped_length = ext_begin - pSrc_filename;
}
crnlib_snprintf(dst_filename, sizeof(dst_filename), "%-*s.dds", stripped_length, pSrc_filename);
}

printf("Writing DDS file: %s\n", dst_filename);

Expand Down