Skip to content

Commit

Permalink
update to fix win build with sheet (#229)
Browse files Browse the repository at this point in the history
* update to fix win build
* on win, skip the check for literal UTF-8
* TO DO: find a way to add win `sheet` automated tests
  • Loading branch information
liquidaty authored Oct 17, 2024
1 parent a9f2a6d commit 0bdbc83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/sheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
const char *locale = setlocale(LC_ALL, "C.UTF-8");
if (!locale || strstr(locale, "UTF-8") == NULL)
locale = setlocale(LC_ALL, "");
#if !defined(WIN32) && !defined(_WIN32)
if (!locale || strstr(locale, "UTF-8") == NULL) {
fprintf(stderr, "Unable to set locale to UTF-8\n");
return 1; // TO DO: option to continue
}
#endif

if (!terminfo_ok()) {
fprintf(stderr, "Warning: unable to set or detect TERMINFO\n");
Expand All @@ -225,7 +227,7 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
size_t header_span = 0; // number of rows that comprise the header
int err;
{
struct zsvsheet_ui_buffer *tmp_ui_buffer;
struct zsvsheet_ui_buffer *tmp_ui_buffer = NULL;
zsvsheet_ui_buffer_new_blank(&tmp_ui_buffer);
if (!tmp_ui_buffer) {
fprintf(stderr, "Out of memory!\n");
Expand Down Expand Up @@ -440,8 +442,17 @@ const char *display_cell(struct zsvsheet_buffer *buff, size_t data_row, size_t d

// convert the substring to wide characters
wchar_t wsubstring[256]; // Ensure this buffer is large enough
#if defined(WIN32) || defined(_WIN32)
// windows does not have mbsnrtowcs
char *p = (char *)str;
char tmp_ch = p[nbytes];
p[nbytes] = '\0';
size_t wlen = mbstowcs(wsubstring, p, sizeof(wsubstring) / sizeof(wchar_t));
p[nbytes] = tmp_ch;
#else
const char *p = str;
size_t wlen = mbsnrtowcs(wsubstring, &p, nbytes, sizeof(wsubstring) / sizeof(wchar_t), NULL);
#endif
if (wlen == (size_t)-1) {
fprintf(stderr, "Unable to convert to wide chars: %s\n", str);
return str;
Expand Down
11 changes: 6 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,18 @@ if [ "$TRY_SHEET" != "no" ]; then
if tryldflag LDFLAGS_NCURSESW -lncursesw -L${PREFIX}/lib ; then
LDFLAGS_NCURSES=-lncursesw
NCLIB=ncursesw
if [ "$NCURSES_DYNAMIC" != "" ] ; then
if [ "$NCURSES_DYNAMIC" == "" ] ; then
CFLAGS_NCURSES="-DHAVE_NCURSESW -DNCURSESW_STATIC"
else
CFLAGS_NCURSES="-DHAVE_NCURSESW"
fi
elif tryldflag LDFLAGS_NCURSES -lncurses -L${PREFIX}/lib ; then
fi
if tryldflag LDFLAGS_NCURSES -lncurses -L${PREFIX}/lib ; then
NCLIB=ncurses
if [ "$NCURSES_DYNAMIC" != "" ] ; then
CFLAGS_NCURSES="-DHAVE_NCURSES -DNCURSES_STATIC"
if [ "$NCURSES_DYNAMIC" == "" ] ; then
CFLAGS_NCURSES+="-DHAVE_NCURSES -DNCURSES_STATIC"
else
CFLAGS_NCURSES=-DHAVE_NCURSES
CFLAGS_NCURSES+=-DHAVE_NCURSES
fi
fi
ZSVSHEET_BUILD=1
Expand Down

0 comments on commit 0bdbc83

Please sign in to comment.