Windows support.
This commit is contained in:
parent
ba274c0371
commit
b666de95af
@ -1,4 +1,8 @@
|
||||
#ifndef _WIN32
|
||||
#include <dlfcn.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -524,16 +528,13 @@ void execute(Stack *stack, Stack *originstack, char *modname)
|
||||
|
||||
// Native
|
||||
|
||||
#ifndef _WIN32
|
||||
if (!strcmp(NAME, "native"))
|
||||
{
|
||||
char *modulename = malloc(strlen(ARG) + 7 * sizeof(char));
|
||||
char *modulename = malloc(strlen(ARG) + 6 * sizeof(char));
|
||||
strcpy(modulename, "./");
|
||||
strcat(modulename, ARG);
|
||||
#ifdef _WIN32
|
||||
strcat(modulename, ".dll");
|
||||
#else
|
||||
strcat(modulename, ".so");
|
||||
#endif
|
||||
void *module = dlopen(modulename, RTLD_NOW);
|
||||
|
||||
if (!module)
|
||||
@ -554,6 +555,34 @@ void execute(Stack *stack, Stack *originstack, char *modname)
|
||||
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
if (!strcmp(NAME, "native"))
|
||||
{
|
||||
char *modulename = malloc(strlen(ARG) + 7 * sizeof(char));
|
||||
strcpy(modulename, "./");
|
||||
strcat(modulename, ARG);
|
||||
strcat(modulename, ".dll");
|
||||
void *module = LoadLibrary(TEXT(modulename));
|
||||
|
||||
if (!module)
|
||||
kms(stack, "UNABLE TO OPEN DYNAMIC LIBRARY");
|
||||
|
||||
int (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void),
|
||||
size_t max_size);
|
||||
labashka = (int (*)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void),
|
||||
size_t max_size))GetProcAddress(module, "labashka");
|
||||
|
||||
stack_init_callback(stack);
|
||||
|
||||
labashka(stack_pop_callback, stack_push_callback, stack_len_callback, stack->stacksize);
|
||||
|
||||
FreeLibrary(module);
|
||||
|
||||
free(modulename);
|
||||
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Self-modifying
|
||||
|
||||
|
@ -6,6 +6,10 @@
|
||||
#include "config.h"
|
||||
#include "stack.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "wincompat.h"
|
||||
#endif
|
||||
|
||||
Stack *program_init(uint16_t stacksize)
|
||||
{
|
||||
Stack *stack = calloc(1,sizeof(&stack) + sizeof(Instruction) * PROGRAM_MAXSIZE + sizeof(int16_t) * MAX_LABELS +
|
||||
|
57
src/wincompat.c
Normal file
57
src/wincompat.c
Normal file
@ -0,0 +1,57 @@
|
||||
#ifdef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wincompat.h"
|
||||
size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
char *bufptr = NULL;
|
||||
char *p = bufptr;
|
||||
size_t size;
|
||||
int c;
|
||||
|
||||
if (lineptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (stream == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (n == NULL) {
|
||||
return -1;
|
||||
}
|
||||
bufptr = *lineptr;
|
||||
size = *n;
|
||||
|
||||
c = fgetc(stream);
|
||||
if (c == EOF) {
|
||||
return -1;
|
||||
}
|
||||
if (bufptr == NULL) {
|
||||
bufptr = malloc(128);
|
||||
if (bufptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
size = 128;
|
||||
}
|
||||
p = bufptr;
|
||||
while(c != EOF) {
|
||||
if ((p - bufptr) > (size - 1)) {
|
||||
size = size + 128;
|
||||
bufptr = realloc(bufptr, size);
|
||||
if (bufptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
c = fgetc(stream);
|
||||
}
|
||||
|
||||
*p++ = '\0';
|
||||
*lineptr = bufptr;
|
||||
*n = size;
|
||||
|
||||
return p - bufptr - 1;
|
||||
}
|
||||
#endif
|
6
src/wincompat.h
Normal file
6
src/wincompat.h
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
size_t getline(char **lineptr, size_t *n, FILE *stream);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user