Skip to content

Commit 0bdcdb6

Browse files
committed
Improved support for Windows 64-bit.
1 parent 7117c72 commit 0bdcdb6

17 files changed

+175
-124
lines changed

Diff for: base.c

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#include <stdio.h>
2-
#include <string.h>
3-
#include <ctype.h>
4-
#include <math.h>
51
#include "citrine.h"
6-
#include "siphash.h"
72

83
ctr_size ctr_program_length;
94
uint64_t ctr_cwlk_subprogram;

Diff for: citrine.c

-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
#include <inttypes.h>
2-
3-
#include <stdlib.h>
4-
#include <stdio.h>
5-
#include <string.h>
6-
#include <inttypes.h>
7-
#include <ctype.h>
8-
#include <stdarg.h>
9-
#include <math.h>
10-
#include <stdint.h>
11-
#include <unistd.h>
121
#include "citrine.h"
13-
#include "siphash.h"
142

153
int ctr_argc;
164
char** ctr_argv;

Diff for: citrine.h

+35-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
1-
21
#include "dictionary.h"
32
#include "msg.h"
4-
53
#include <inttypes.h>
64
#include <stdlib.h>
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <ctype.h>
8+
#include <unistd.h>
9+
#include <stdarg.h>
10+
#include <math.h>
11+
#include <stdint.h>
12+
#include <time.h>
13+
#include <libgen.h>
14+
#include <errno.h>
15+
#include <sys/file.h>
16+
#include <dirent.h>
17+
#include <locale.h>
18+
19+
#ifdef forLinux
20+
#include <bsd/stdlib.h>
21+
#include <bsd/string.h>
22+
#endif
23+
24+
#include "siphash.h"
25+
#include <sys/stat.h>
26+
27+
#ifdef WIN
28+
#include <windows.h>
29+
#include <conio.h>
30+
#define PRId64 "I64d"
31+
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
32+
#define setenv(name,value,o) _putenv_s(name, value);
33+
#define CTR_DIRSEP "\\"
34+
#else
35+
#include <termios.h>
36+
#include <sys/wait.h>
37+
#include <dlfcn.h>
38+
#define CTR_DIRSEP "/"
39+
#endif
740

841
/**
942
* Version information
1043
*/
1144
#define CTR_VERSION "0.9.5"
1245
#define CTR_VERSION_NUM 95
1346

14-
15-
#ifdef DIRSEPBACKSL
16-
#define CTR_DIRSEP "\\"
17-
#else
18-
#define CTR_DIRSEP "/"
19-
#endif
20-
2147
/**
2248
* Define the Citrine tokens
2349
*/

Diff for: collections.c

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#include <string.h>
21
#include "citrine.h"
32

4-
53
/**
64
* @def
75
* List

Diff for: file.c

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
#include <stdio.h>
2-
#include <string.h>
3-
#include <errno.h>
4-
#include <sys/file.h>
5-
#include <sys/stat.h>
6-
#include <dirent.h>
71
#include "citrine.h"
82

9-
/**
10-
* Path Separator.
11-
*/
12-
const char* PATH_SEP =
13-
#if defined _WIN32 || defined __CYGWIN__
14-
"\\";
15-
#else
16-
"/";
17-
#endif
18-
193
/**
204
* @def
215
* File
@@ -312,14 +296,17 @@ ctr_object* ctr_file_list(ctr_object* myself, ctr_argument* argumentList) {
312296
putArgumentList->object = ctr_build_string_from_cstring(entry->d_name);
313297
ctr_map_put(fileListItem, putArgumentList);
314298
putArgumentList->next->object = ctr_build_string_from_cstring( CTR_MSG_DSC_TYPE );
315-
if ((strlen(fullPath) + strlen(PATH_SEP) + strlen(entry->d_name)) > PATH_MAX) {
299+
if ((strlen(CTR_DIRSEP) + strlen(CTR_DIRSEP) + strlen(entry->d_name)) > PATH_MAX) {
316300
continue;
317301
}
318302
strcpy( fullPath, pathValue );
319-
strcat( fullPath, PATH_SEP );
303+
strcat( fullPath, CTR_DIRSEP );
320304
strcat( fullPath, entry->d_name);
321305
if (realpath( fullPath, pathBuf )) {
322306
/* lstat is slow, but we have no choice, there is no other way to keep this portable */
307+
#ifdef WIN
308+
putArgumentList->object = ctr_build_string_from_cstring( CTR_MSG_DSC_FILE );
309+
#else
323310
lstat(pathBuf, &st);
324311
if (S_ISREG(st.st_mode))
325312
putArgumentList->object = ctr_build_string_from_cstring( CTR_MSG_DSC_FILE );
@@ -337,6 +324,7 @@ ctr_object* ctr_file_list(ctr_object* myself, ctr_argument* argumentList) {
337324
putArgumentList->object = ctr_build_string_from_cstring( CTR_MSG_DSC_NPIP );
338325
else
339326
putArgumentList->object = ctr_build_string_from_cstring( CTR_MSG_DSC_OTHR );
327+
#endif
340328
ctr_map_put(fileListItem, putArgumentList);
341329
addArgumentList->object = fileListItem;
342330
ctr_array_push(fileList, addArgumentList);

Diff for: lexer.c

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#include <stdio.h>
2-
#include <string.h>
3-
#include <ctype.h>
41
#include "citrine.h"
52

63
int ctr_clex_bflmt = 255;

Diff for: makefile.win64

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#Usage: CC=x86_64-w64-mingw32-gcc-8.3-win32 make -f makefile.win64
2+
CFLAGS = -O2 -g -mtune=native -Wall -D CTRLANG=${ISO} -D INCLUDETESTS -D WIN \
3+
-D REPLACE_PROGRAM_PASSWORD -D WINDOWS_PROGRAM_PASSWORD\
4+
-D REPLACE_PLUGIN_SYSTEM -D WINDOWS_PLUGIN_SYSTEM\
5+
-D REPLACE_CLOCK_WAIT -D WINDOWS_CLOCK_WAIT
6+
OBJS = test.o siphash.o utf8.o memory.o util.o base.o collections.o file.o system.o \
7+
world.o lexer.o parser.o walker.o translator.o citrine.o portability.o
8+
prefix ?= /usr
9+
10+
.SUFFIXES: .o .c
11+
12+
all:ctr
13+
14+
install:
15+
install -d $(DESTDIR)$(prefix)/bin $(DESTDIR)$(prefix)/share/fonts/citrine
16+
install ./bin/$(shell uname -s)/ctr* $(DESTDIR)$(prefix)/bin
17+
install ./fonts/Citrine.ttf $(DESTDIR)$(prefix)/share/fonts/citrine
18+
19+
ctr: $(OBJS)
20+
$(CC) -shared $(OBJS) -g -lm -o bin/Win64/ctr${ISO}.exe
21+
gendef bin/Win64/ctr${ISO}.exe
22+
x86_64-w64-mingw32-dlltool -d ctr${ISO}.def -l ctr${ISO}import.lib -e ctr${ISO}exports.o
23+
$(CC) ctr${ISO}exports.o $(OBJS) -g -lm -o bin/Win64/ctr${ISO}.exe
24+
25+
.c.o:
26+
$(CC) $(CFLAGS) -I i18n/${ISO} -c $<
27+
28+
clean:
29+
rm -rf ${OBJS} ctr
30+
31+
plugin:
32+
cd plugins/${PACKAGE} ; make clean ; make install-${NAME}
33+

Diff for: memory.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
#include <stdlib.h>
2-
#include <stdio.h>
3-
#include <string.h>
4-
#include <ctype.h>
5-
#include <stdarg.h>
6-
#include <math.h>
7-
#include <stdint.h>
81
#include "citrine.h"
92

103
uint64_t ctr_gc_alloc;
@@ -62,13 +55,13 @@ void* ctr_heap_allocate( size_t size ) {
6255
/* Check whether we can afford to allocate this much */
6356
ctr_gc_alloc += size;
6457
if (ctr_gc_memlimit < ctr_gc_alloc) {
65-
printf( CTR_MERR_OOM, size );
58+
printf( CTR_MERR_OOM, (unsigned long) size );
6659
exit(1);
6760
}
6861
/* Perform allocation and check result */
6962
slice_of_memory = ctr_pool_alloc( size );
7063
if ( slice_of_memory == NULL ) {
71-
printf( CTR_MERR_MALLOC, size );
64+
printf( CTR_MERR_MALLOC, (unsigned long) size );
7265
exit(1);
7366
}
7467
/* Store the width of the memory block in the slice itself so we can always find it */

Diff for: mk.sh

+5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/bin/sh
22
OS=$(uname -s)
3+
4+
if [ -z "$MAKEFILE" ]; then
35
if [ "$OS" = "OpenBSD" -o "$OS" = "FreeBSD" -o "$OS" = "Darwin" ]; then
46
MAKEFILE=makefile.bsd
57
elif [ "$OS" = "Haiku" ]; then
68
MAKEFILE=makefile.haiku
79
else
810
MAKEFILE=makefile
911
fi
12+
fi
13+
14+
1015
echo "USING: ${MAKEFILE}"
1116

1217
#Get list of ISO codes to build.

Diff for: plugins/mock/percolator/makefile.win64

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
LDFLAGS= -shared
2+
CFLAGS= -D WIN
3+
4+
all:libctrpercolator.dll
5+
6+
libctrpercolator.dll: percolator.o
7+
$(CC) ${LDFLAGS} percolator.o ../../../ctr${ISO}import.lib -o libctrpercolator.dll
8+
9+
percolator.o:
10+
$(CC) ${CFLAGS} -I . -c percolator.c -Wall -Werror -fPIC -o percolator.o
11+
12+
clean:
13+
rm percolator.o

Diff for: plugins/mock/percolator/percolator.c

-3
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,12 @@ ctr_object* ctr_percolator_new(ctr_object* myself, ctr_argument* argumentList) {
168168
void begin(){
169169
/* Create the Coffee Percolator Object - Use new, because its a prototype, not a class !*/
170170
ctr_object* percolatorObject = ctr_percolator_new(CtrStdObject, NULL);
171-
172171
/* Set the prototype */
173172
percolatorObject->link = CtrStdObject;
174-
175173
/* Add the method 'new' so people can create their percolators */
176174
ctr_internal_create_func(percolatorObject, ctr_build_string_from_cstring( "new" ), &ctr_percolator_new );
177175
ctr_internal_create_func(percolatorObject, ctr_build_string_from_cstring( "brew" ), &ctr_percolator_brew );
178176
ctr_internal_create_func(percolatorObject, ctr_build_string_from_cstring( "coffee:water:" ), &ctr_percolator_add_coffee_water );
179-
180177
/* Make the Percolator accessible to the world */
181178
ctr_internal_object_add_property(CtrStdWorld, ctr_build_string_from_cstring( "Percolator" ), percolatorObject, CTR_CATEGORY_PUBLIC_PROPERTY);
182179
}

Diff for: portability.c

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "citrine.h"
2+
3+
#ifdef WINDOWS_PROGRAM_PASSWORD
4+
ctr_object* ctr_program_waitforpassword(ctr_object* myself, ctr_argument* argumentList) {
5+
ctr_object* answer;
6+
int i = 0;
7+
char ch = NULL;
8+
char* buff;
9+
ctr_size page = 10;
10+
buff = ctr_heap_allocate(page * sizeof(char));
11+
while ((ch = getch()) != '\r') {
12+
buff[i++] = ch;
13+
if (i >= page) {
14+
page *= 2;
15+
buff = (char*) ctr_heap_reallocate(buff, page * sizeof(char));
16+
if (buff == NULL) {
17+
CtrStdFlow = ctr_error( CTR_ERR_OOM, 0 );
18+
return CtrStdNil;
19+
}
20+
}
21+
}
22+
answer = ctr_build_string(buff, i);
23+
ctr_heap_free(buff);
24+
return answer;
25+
}
26+
#endif
27+
28+
29+
#ifdef WINDOWS_PLUGIN_SYSTEM
30+
typedef int (__cdecl *MYPROC)();
31+
void* ctr_internal_plugin_find(ctr_object* key) {
32+
ctr_object* modNameObject = ctr_internal_cast2string(key);
33+
void* handle;
34+
char pathNameMod[1024];
35+
char* modName;
36+
char* modNameLow;
37+
MYPROC init_plugin;
38+
char* realPathModName = NULL;
39+
modName = ctr_heap_allocate_cstring( modNameObject );
40+
modNameLow = modName;
41+
for ( ; *modNameLow; ++modNameLow) *modNameLow = tolower(*modNameLow);
42+
snprintf(pathNameMod, 1024,"mods\\%s\\libctr%s.dll", modName, modName);
43+
ctr_heap_free( modName );
44+
realPathModName = realpath(pathNameMod, NULL);
45+
handle = LoadLibrary(realPathModName);
46+
free(realPathModName);
47+
if ( !handle ) {
48+
printf("%s\n",CTR_ERR_FOPEN);
49+
exit(1);
50+
}
51+
/* the begin() function will add the missing object to the world */
52+
init_plugin = (MYPROC) GetProcAddress(handle, "begin");
53+
if ( !init_plugin ) {
54+
printf("%s\n",CTR_ERR_FOPEN);
55+
FreeLibrary(handle);
56+
exit(1);
57+
}
58+
(void) init_plugin();
59+
return handle;
60+
}
61+
#endif
62+
63+
64+
#ifdef WINDOWS_CLOCK_WAIT
65+
ctr_object* ctr_clock_wait(ctr_object* myself, ctr_argument* argumentList) {
66+
ctr_object* arg = ctr_internal_cast2number(argumentList->object);
67+
int n = (int) arg->value.nvalue;
68+
Sleep(n * 1000);
69+
return myself;
70+
}
71+
#endif

0 commit comments

Comments
 (0)