dbcc icon indicating copy to clipboard operation
dbcc copied to clipboard

Fix for getting DBC file base name on Windows.

Open blackboxembedded opened this issue 1 year ago • 6 comments

This changes dbcc_basename to work on Windows as well. I tested on UNIX and Windows with the change and both worked as expected.

blackboxembedded avatar Aug 16 '24 22:08 blackboxembedded

Can you change back the formatting to how it was? I am aware the formatting for this function is different from the rest of the file as well, that's because it was taken from another project.

howerj avatar Aug 18 '24 08:08 howerj

Sorry about that, I think I have the formatting fixed now.

blackboxembedded avatar Aug 18 '24 13:08 blackboxembedded

Won't this fail under Linux if there are any files with a backslash in them?

howerj avatar Aug 18 '24 14:08 howerj

I just tested and you are correct it does fail. The same is true the other way as well. I would guess the use of \ or / in a filename is uncommon. One option might make the behavior a compile time option if building on Windows.

blackboxembedded avatar Aug 18 '24 15:08 blackboxembedded

I would have thought the code would work fine on Windows, as both "/" and "" are not allowed in file names. I'm loathe to put more compile time options and macros in this program, but it looks like there is no other choice.

Perhaps something like:

/* at the top of the file */
#ifdef _WIN32
#define WINDOWS (1)
#else 
#define WINDOWS (0)
#endif

/* ~~~ code ~~~ */

/* near dbcc_basename */
static int is_path_sep(int ch) {
    return WINDOWS ? ch == '\\'  /* || ch == '/' ??? */: ch == '/';
}

howerj avatar Aug 18 '24 15:08 howerj

Sorry for the delay, here is what I came up with. Something about is_path_sep(int ch) is causing a seg fault later in the app and I couldn't track it down.

blackboxembedded avatar Aug 31 '24 15:08 blackboxembedded