Commit 1ef1cb97 authored by bzt's avatar bzt

MinGW support for sfnedit

parent b88fd362
......@@ -352,7 +352,7 @@ int main(int argc, char **argv)
" -dddd: dump only the kerning table\n"
" -D: dump everything without integrity checks\n"
" in: input SSFN font filename\n out: output ASC filename (if no -r or -d given)\n\n"
"* - don't use if your text editor removes or replaces replaces spaces with tabs\n");
"* - don't use if your text editor removes or replaces spaces with tabs\n");
return 1;
}
infile = argv[i+1];
......
TARGET = sfnedit
MINGWSDL = ../..
SRCS = $(filter-out tinflate.c $(wildcard ui_*.c),$(wildcard *.c))
ifneq ("$(wildcard unifont.sfn.gz)","")
......@@ -27,16 +28,27 @@ endif
# SDL driver
ifeq ("$(FORCEX11)","")
ifeq ("$(DRIVER)","")
# MacOSX
ifneq ("$(wildcard /Library/Frameworks/SDL*)","")
SRCS += ui_sdl.c
LIBS += -framework SDL
DRIVER = sdl
else
# Linux
ifneq ("$(wildcard /usr/include/SDL2/SDL.h)","")
SRCS += ui_sdl.c
CFLAGS += -I/usr/include/SDL2
LIBS += -lSDL2
DRIVER = sdl
else
# Windows MinGW
ifneq ("$(wildcard $(MINGWSDL)/i686-w64-mingw32/include/SDL2/SDL.h)","")
SRCS += ui_sdl.c
CFLAGS += -I$(MINGWSDL)/i686-w64-mingw32/include/SDL2
LIBDIRS = -static-libgcc -L$(MINGWSDL)/i686-w64-mingw32/lib
LIBS += -lSDL2 -lcomdlg32
DRIVER = sdl
endif
endif
endif
endif
......@@ -60,7 +72,7 @@ endif
endif
OBJS = $(SRCS:.c=.o) logofont.o font.o uninames.o
OBJS = logofont.o font.o uninames.o $(SRCS:.c=.o)
all: configure $(OBJS) $(TARGET)
......@@ -85,7 +97,7 @@ uninames.o: unicode.h unicode.dat
$(CC) $(CFLAGS) $< -c $@
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET) $(LIBS)
$(CC) $(LIBDIRS) $(OBJS) -o $(TARGET) $(LIBS)
clean:
@rm config.h $(TARGET) *.o 2>/dev/null || true
@rm config.h $(TARGET) $(TARGET).exe *.o 2>/dev/null || true
......@@ -14,3 +14,16 @@ autodetects zlib too. If found, then the editor can read and write gzip compress
then decompression will be still available by a built-in tiny inflate library (also used for
several internal data), but no gzip compression will be possible for writes. Other than those,
requires libc only.
### Under Windows
You'll need a couple of tools, here's a step-by-step how to:
1. install [MinGW](https://osdn.net/projects/mingw/releases), this will give you gcc and zlib under Windows
2. download [SDL2-devel-X-mingw.tar.gz](http://libsdl.org/download-2.0.php) under the section Development Libraries
3. extract SDL2 into a directory under MinGW's home directory
4. open Makefile in Notepad, and edit MINGWSDL to the path where you've extracted the tarball, add the last SDL2-X part too
5. copy $(MINGWSDL)/i686-w64-mingw32/bin/SDL2.dll into C:\Windows
6. run `make`
On Windows, if command line argument is not specified, the editor will fire up an Open File dialog. There'll be no Save File
dialog when you press \[Ctrl\]+\[S\], sfnedit will save the font to that file.
......@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include "lang.h"
#include "ui.h"
......@@ -61,7 +62,12 @@ void copypaste_init()
}
} else {
sprintf(clipboardfn, "%s/.cache", home);
mdir: mkdir(clipboardfn, 0700);
mdir:
#ifdef __WIN32__
mkdir(clipboardfn);
#else
mkdir(clipboardfn, 0700);
#endif
strcat(clipboardfn, "/sfnclipbrd");
}
}
......
......@@ -38,6 +38,11 @@
#if HAS_ZLIB
#include <zlib.h>
#endif
#ifndef va_start
#define va_start __builtin_va_start
#define va_list __builtin_va_list
#define va_end(x)
#endif
extern char gz;
ssfn_font_t *font = NULL;
......@@ -46,7 +51,9 @@ char *strtable[6];
uint32_t cmap[241];
uint8_t *cpal = (uint8_t*)&cmap, cpalidx[241], cpalrev[241];
int modified = 0;
#if HAS_ZLIB
gzFile sg;
#endif
FILE *sf;
int numchars[SSFN_NUMVARIANTS] = {0};
......@@ -853,7 +860,7 @@ void file_savesfn(int idx)
memcpy(fontfileext, "sfn", 3);
file_sortcmap();
ui_saving(idx, 1000);
sleep(1);
/*sleep(1);*/
ui_saving(idx, -1);
modified = 0;
}
......@@ -865,9 +872,11 @@ void file_printf(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
#ifdef HAS_ZLIB
if(gzipped)
gzvprintf(sg,fmt,ap);
else
#endif
vfprintf(sf,fmt,ap);
va_end(ap);
}
......@@ -913,10 +922,13 @@ void file_saveasc(int idx)
if(chars[0][i].klen && chars[0][i].unicode > 32) savingmax++;
}
#ifdef HAS_ZLIB
if(gzipped) {
sg = gzopen(fontfile,"w9");
if(!sg) { ui_saving(idx, -1); return; }
} else {
} else
#endif
{
sf = fopen(fontfile,"w");
if(!sf) { ui_saving(idx, -1); return; }
}
......@@ -1046,9 +1058,11 @@ void file_saveasc(int idx)
}
file_printf("\n+@----End---\n\n");
#ifdef HAS_ZLIB
if(gzipped)
gzclose(sg);
else
#endif
fclose(sf);
ui_saving(idx, 0);
......
......@@ -38,6 +38,125 @@
#include "file.h"
#include "render.h"
/*
* wrapper for Windows SDL support. This partialy came from SDL_windows_main.c
*/
#ifdef __WIN32__
#include <SDL.h>
#include <windows.h>
static void UnEscapeQuotes(char *arg)
{
char *last = NULL;
while (*arg) {
if (*arg == '"' && (last != NULL && *last == '\\')) {
char *c_curr = arg;
char *c_last = last;
while (*c_curr) {
*c_last = *c_curr;
c_last = c_curr;
c_curr++;
}
*c_last = '\0';
}
last = arg;
arg++;
}
}
/* Parse a command line buffer into arguments */
static int ParseCommandLine(char *cmdline, char **argv)
{
char *bufp;
char *lastp = NULL;
int argc, last_argc;
argc = last_argc = 0;
for (bufp = cmdline; *bufp;) {
/* Skip leading whitespace */
while (SDL_isspace(*bufp)) {
++bufp;
}
/* Skip over argument */
if (*bufp == '"') {
++bufp;
if (*bufp) {
if (argv) {
argv[argc] = bufp;
}
++argc;
}
/* Skip over word */
lastp = bufp;
while (*bufp && (*bufp != '"' || *lastp == '\\')) {
lastp = bufp;
++bufp;
}
} else {
if (*bufp) {
if (argv) {
argv[argc] = bufp;
}
++argc;
}
/* Skip over word */
while (*bufp && !SDL_isspace(*bufp)) {
++bufp;
}
}
if (*bufp) {
if (argv) {
*bufp = '\0';
}
++bufp;
}
/* Strip out \ from \" sequences */
if (argv && last_argc != argc) {
UnEscapeQuotes(argv[last_argc]);
}
last_argc = argc;
}
if (argv) {
argv[argc] = NULL;
}
return (argc);
}
int APIENTRY WinMain(__attribute__((unused)) HINSTANCE hInstance, __attribute__((unused)) HINSTANCE hPrevInstance,
__attribute__((unused)) LPSTR lpCmdLine, __attribute__((unused)) int nCmdShow)
{
OPENFILENAME ofn;
char *cmdline = GetCommandLine();
int ret, argc = ParseCommandLine(cmdline, NULL);
char **argv = SDL_stack_alloc(char*, argc+2);
char fn[1024];
ParseCommandLine(cmdline, argv);
if(!argv[1]) {
memset(&fn,0,sizeof(fn));
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.hInstance = hInstance;
ofn.lpstrFilter = "Font Files (*.sfn, *.asc)\0*.sfn;*.sfn.gz;*.asc;*.asc.gz\0All Files\0*\0\0";
ofn.lpstrFile = fn;
ofn.nMaxFile = sizeof(fn)-1;
ofn.lpstrTitle = "Please Enter a File Name";
if (GetOpenFileName(&ofn)) {
argc++;
argv[1] = fn;
}
}
SDL_SetMainReady();
ret = main(argc, argv);
SDL_stack_free(argv);
exit(ret);
return ret;
}
#endif
/**
* Main sfnedit function
*/
......@@ -54,8 +173,10 @@ int main(int argc, char **argv)
exit(1);
}
#ifndef __WIN32__
signal(SIGQUIT, ui_forcequit);
signal(SIGINT, ui_forcequit);
#endif
memset(nchr, 0, 256);
memset(search, 0, 256);
memset(gsearch, 0, 256);
......
......@@ -217,27 +217,27 @@ do3: switch(active) {
switch(a) {
case 0:
active = 0;
if(evt->x >= nmaxx && evt->x < nmaxx+12) goto do3;
if(evt->x >= nmaxx+128+16 && evt->x < nmaxx+128+32) goto do2;
if(evt->x >= (int)nmaxx && evt->x < (int)nmaxx+12) goto do3;
if(evt->x >= (int)nmaxx+128+16 && evt->x < (int)nmaxx+128+32) goto do2;
return 1;
case 1:
if(evt->x >= nmaxx && evt->x < nmaxx+128) active = 1; else active = 2;
if(evt->x >= (int)nmaxx && evt->x < (int)nmaxx+128) active = 1; else active = 2;
goto do2;
case 2:
active = 3;
if(evt->x >= nmaxx && evt->x < nmaxx+12) goto do3;
if(evt->x >= nmaxx+88+16 && evt->x < nmaxx+88+32) goto do2;
if(evt->x >= (int)nmaxx && evt->x < (int)nmaxx+12) goto do3;
if(evt->x >= (int)nmaxx+88+16 && evt->x < (int)nmaxx+88+32) goto do2;
return 1;
case 3:
active = 4;
if(evt->x >= nmaxx && evt->x < nmaxx+12) goto do3;
if(evt->x >= nmaxx+32+16 && evt->x < nmaxx+32+28) goto do2;
if(evt->x >= nmaxx+32+28+8 && evt->x < nmaxx+32+28+8+128+8) { active = 5; goto do1; }
if(evt->x >= (int)nmaxx && evt->x < (int)nmaxx+12) goto do3;
if(evt->x >= (int)nmaxx+32+16 && evt->x < (int)nmaxx+32+28) goto do2;
if(evt->x >= (int)nmaxx+32+28+8 && evt->x < (int)nmaxx+32+28+8+128+8) { active = 5; goto do1; }
return 1;
case 4:
active = 6;
if(evt->x >= nmaxx && evt->x < nmaxx+12) goto do3;
if(evt->x >= nmaxx+32+16 && evt->x < nmaxx+32+28) goto do2;
if(evt->x >= (int)nmaxx && evt->x < (int)nmaxx+12) goto do3;
if(evt->x >= (int)nmaxx+32+16 && evt->x < (int)nmaxx+32+28) goto do2;
return 1;
case 12:
active = 13;
......
......@@ -44,7 +44,13 @@
#include "unicode.h"
#include "copypaste.h"
#ifdef __WIN32__
extern unsigned char binary_logofont_sfn_start;
#define logofont binary_logofont_sfn_start
#else
extern unsigned char _binary_logofont_sfn_start;
#define logofont _binary_logofont_sfn_start
#endif
extern int glyphra, gmax, selall, kernactive;
ssfn_font_t *ui_font = NULL;
int saving = 0, savingmax = 0, saveact = 2, mainloop = 1;
......@@ -681,7 +687,7 @@ void ui_tabs(ui_win_t *win, int idx)
for(i=0;i<win->w;i++)
win->data[p+i] = theme[THEME_TABBG];
if(!idx) {
ssfn_font = (ssfn_font_t*)&_binary_logofont_sfn_start;
ssfn_font = (ssfn_font_t*)&logofont;
ssfn_x = ssfn_y = 2;
ssfn_fg = theme[THEME_INPUT];
ssfn_bg = theme[THEME_TABBG];
......@@ -703,7 +709,12 @@ void ui_tabs(ui_win_t *win, int idx)
ssfn_x += 16;
s = (char*)win->uniname;
} else {
s = fontfilebn;
s = strrchr(fontfilebn, '/');
if(s) s++; else {
s = strrchr(fontfilebn, '\\');
if(s) s++;
else s = fontfilebn;
}
}
if((int)ssfn_x >= win->w) goto end;
while(*s) {
......@@ -908,7 +919,7 @@ void ui_main(char *fn)
int m;
/* get user interface font */
ui_font = (ssfn_font_t*)load_file((char*)&_binary_font_start, &m);
ui_font = (ssfn_font_t*)load_file((char*)&font_start, &m);
if(!ui_font) error("ui_main", ERR_MEM);
/* get UNICODE names database */
uniname_init();
......
......@@ -169,8 +169,17 @@ typedef struct {
extern uint32_t ssfn_fg, ssfn_bg, ssfn_x, ssfn_y;
extern char nchr[], search[], gsearch[], gtmp[], ksearch[];
#ifdef __WIN32__
extern unsigned char binary_font_start;
extern unsigned char binary_font_end;
#define font_start binary_font_start
#define font_end binary_font_end
#else
extern unsigned char _binary_font_start;
extern unsigned char _binary_font_end;
#define font_start _binary_font_start
#define font_end _binary_font_end
#endif
extern uint32_t tool_icons[];
extern ssfn_font_t *ui_font;
extern ui_event_t event;
......
......@@ -28,6 +28,7 @@
*/
#include <SDL.h>
#include <string.h>
#include "lang.h"
#include "util.h"
#include "ui.h"
......
......@@ -36,7 +36,13 @@
#define _UNICODE_NAMESDATA
#include "unicode.h"
#ifdef __WIN32__
extern char binary_unicode_dat_start;
#define unicode_start binary_unicode_dat_start
#else
extern char _binary_unicode_dat_start;
#define unicode_start _binary_unicode_dat_start
#endif
char *unicodedb;
/**
......@@ -47,7 +53,7 @@ void uniname_init()
int i, j;
char *ptr, *end;
ptr = unicodedb = (char*)load_file((char*)&_binary_unicode_dat_start, &i);
ptr = unicodedb = (char*)load_file((char*)&unicode_start, &i);
if(!ptr) error("uniname_init", ERR_MEM);
end = ptr + i;
......
......@@ -45,8 +45,18 @@
#endif
char ut[8], gz;
#ifdef __WIN32__
extern char binary_unicode_dat_start;
extern char binary_unicode_dat_end;
#define unicode_start binary_unicode_dat_start
#define unicode_end binary_unicode_dat_end
#else
extern char _binary_unicode_dat_start;
extern char _binary_unicode_dat_end;
#define unicode_start _binary_unicode_dat_start
#define unicode_end _binary_unicode_dat_end
#endif
/**
* Convert hex string to binary number
......@@ -187,13 +197,13 @@ unsigned char *load_file(char *filename, int *size)
TINF_DATA d;
#endif
if(filename == (char*)&_binary_font_start) {
data = (unsigned char*)&_binary_font_start;
*size = (int)(&_binary_font_end - &_binary_font_start);
if(filename == (char*)&font_start) {
data = (unsigned char*)&font_start;
*size = (int)(&font_end - &font_start);
} else
if(filename == (char*)&_binary_unicode_dat_start) {
data = (unsigned char*)&_binary_unicode_dat_start;
*size = (int)(&_binary_unicode_dat_end - &_binary_unicode_dat_start);
if(filename == (char*)&unicode_start) {
data = (unsigned char*)&unicode_start;
*size = (int)(&unicode_end - &unicode_start);
} else {
f = fopen(filename, "rb");
if(!f) return NULL;
......@@ -251,7 +261,7 @@ unsigned char *load_file(char *filename, int *size)
gzerr: error("tinflate", ERR_MEM);
}
#endif
if(data != (unsigned char*)&_binary_font_start && data != (unsigned char*)&_binary_unicode_dat_start)
if(data != (unsigned char*)&font_start && data != (unsigned char*)&unicode_start)
free(data);
*size = s;
return(data2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment