Skip to content

Commit

Permalink
Attempt to make bc work on mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Howard committed Oct 12, 2018
1 parent 736de9b commit 10548df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <stdbool.h>
#include <string.h>

#include <unistd.h>

#include <io.h>
#include <parse.h>
#include <program.h>
Expand Down Expand Up @@ -1332,11 +1330,6 @@ BcStatus bc_program_init(BcProgram *p, size_t line_len,

assert(p);

assert((unsigned long) sysconf(_SC_BC_BASE_MAX) <= BC_MAX_OBASE);
assert((unsigned long) sysconf(_SC_BC_DIM_MAX) <= BC_MAX_DIM);
assert((unsigned long) sysconf(_SC_BC_SCALE_MAX) <= BC_MAX_SCALE);
assert((unsigned long) sysconf(_SC_BC_STRING_MAX) <= BC_MAX_STRING);

p->nchars = p->scale = 0;
p->len = line_len;
p->parse_init = init;
Expand Down
27 changes: 26 additions & 1 deletion src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <signal.h>

#ifndef win32

#include <sys/types.h>
#include <unistd.h>

#else // win32

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#endif // win32

#include <status.h>
#include <args.h>
#include <vm.h>
#include <io.h>

#ifndef win32
void bc_vm_sig(int sig) {
if (sig == SIGINT) {
size_t len = strlen(bcg.sig_msg);
Expand All @@ -42,6 +53,15 @@ void bc_vm_sig(int sig) {
}
else bcg.sig_other = 1;
}
#else // win32
BOOL WINAPI bc_vm_sig(DWORD sig) {
if (sig == CTRL_C_EVENT) {
if (fputs(bcg.sig_msg) != EOF)
bcg.sig += (bcg.signe = bcg.sig == bcg.sigc);
}
else bcg.sig_other = 1;
}
#endif // win32

BcStatus bc_vm_info(const char* const help) {
if (printf("%s %s\n", bcg.name, BC_VERSION) < 0) return BC_STATUS_IO_ERR;
Expand Down Expand Up @@ -320,11 +340,16 @@ BcStatus bc_vm_init(BcVm *vm, BcVmExe exe, const char *env_len) {
sa.sa_handler = bc_vm_sig;
sa.sa_flags = 0;

#ifndef win32
if (sigaction(SIGINT, &sa, NULL) < 0 || sigaction(SIGPIPE, &sa, NULL) < 0 ||
sigaction(SIGHUP, &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0)
{
return BC_STATUS_EXEC_SIGACTION_FAIL;
}
#else // win32
if (!SetConsoleCtrlHandler(bc_vm_sig, TRUE))
return BC_STATUS_EXEC_SIGACTION_FAIL;
#endif // win32

vm->exe = exe;
vm->flags = 0;
Expand Down

0 comments on commit 10548df

Please sign in to comment.