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

update to fix win build with sheet #229

Merged
merged 2 commits into from
Oct 17, 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
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