bin2h for Mac
parent
2563066919
commit
c0b0fffd9c
25
src/Makefile
25
src/Makefile
|
@ -4,7 +4,7 @@ MACSDL = ~/Library/Frameworks/SDL.framework/Versions/A/Headers
|
|||
# -------------------------------------------------
|
||||
|
||||
TARGET = mtsedit
|
||||
SRCS = $(wildcard *.c)
|
||||
SRCS = $(filter-out bin2h.c,$(wildcard *.c))
|
||||
|
||||
CFLAGS = -Wall -Wextra -ansi -pedantic -g
|
||||
|
||||
|
@ -32,9 +32,9 @@ endif
|
|||
endif
|
||||
endif
|
||||
|
||||
OBJS = icons.o font.o $(SRCS:.c=.o)
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
all: configure $(OBJS) $(TARGET)
|
||||
all: configure data.h $(OBJS) $(TARGET)
|
||||
|
||||
configure:
|
||||
ifeq ("$(LIBS)","")
|
||||
|
@ -44,13 +44,20 @@ ifeq ("$(LIBS)","")
|
|||
@false
|
||||
endif
|
||||
|
||||
icons.o: icons.png
|
||||
@$(LD) -r -b binary -o icons.o icons.png
|
||||
# MaxOSX developers are bunch of loosers, they have removed "ld -r -b binary"
|
||||
# support without providing an alternative! Hahahahaha, such loosers!
|
||||
#icons.o: icons.png
|
||||
# @$(LD) -r -b binary -o icons.o icons.png
|
||||
#
|
||||
#font.o: font.psf.gz
|
||||
# @$(LD) -r -b binary -o font.o font.psf.gz
|
||||
|
||||
font.o: font.psf.gz
|
||||
@$(LD) -r -b binary -o font.o font.psf.gz
|
||||
data.h: bin2h.c icons.png font.psf.gz
|
||||
@$(CC) bin2h.c -o bin2h
|
||||
./bin2h icons.png font.psf.gz >data.h
|
||||
@rm bin2h
|
||||
|
||||
%: %.c main.h lang.h
|
||||
%: %.c main.h lang.h data.h
|
||||
$(CC) $(CFLAGS) $< -c $@
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
|
@ -78,4 +85,4 @@ else
|
|||
endif
|
||||
|
||||
clean:
|
||||
@rm $(TARGET) $(TARGET).exe *.o *.zip 2>/dev/null || true
|
||||
@rm $(TARGET) $(TARGET).exe data.h *.o *.zip 2>/dev/null || true
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* mtsedit/bin2h.c
|
||||
*
|
||||
* Copyright (C) 2019 bzt (bztsrc@gitlab)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* @brief Small utility to convert binary to C header, because MacOSX does not support ld -b binary!
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
long size;
|
||||
unsigned char *buff = NULL;
|
||||
char *fn, name[255];
|
||||
int i, file;
|
||||
|
||||
if(argc < 2){
|
||||
printf("bin2h <bin file> [bin file2...]\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(file = 1; file < argc; file++){
|
||||
f = fopen(argv[file],"r");
|
||||
if(f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buff = (unsigned char*)realloc(buff, size);
|
||||
if(!buff) {
|
||||
fprintf(stderr, "memory allocation error\r\n");
|
||||
exit(2);
|
||||
}
|
||||
fread(buff, size, 1, f);
|
||||
fclose(f);
|
||||
fn = strrchr(argv[file], '/');
|
||||
if(!fn) fn = strrchr(argv[file], '\\');
|
||||
if(!fn) fn = argv[file]; else fn++;
|
||||
for(i = 0; fn[i]; i++)
|
||||
name[i] = fn[i] == '.' || fn[i] <= ' ' ? '_' : fn[i];
|
||||
name[i] = 0;
|
||||
printf("unsigned char binary_%s[%ld] = { ", name, size);
|
||||
for(i = 0; i < size; i++) {
|
||||
if(i) printf(", ");
|
||||
printf("0x%02x", buff[i]);
|
||||
}
|
||||
printf(" };\n");
|
||||
} else
|
||||
fprintf(stderr, "Unable to open input file: %s\n", argv[file]);
|
||||
}
|
||||
}
|
16
src/main.h
16
src/main.h
|
@ -75,24 +75,8 @@
|
|||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
extern char binary_icons_png_start;
|
||||
extern char binary_icons_png_end;
|
||||
extern char binary_font_psf_gz_start;
|
||||
extern char binary_font_psf_gz_end;
|
||||
#define icons_start binary_icons_png_start
|
||||
#define icons_end binary_icons_png_end
|
||||
#define font_start binary_font_psf_gz_start
|
||||
#define font_end binary_font_psf_gz_end
|
||||
#define DIRSEP '\\'
|
||||
#else
|
||||
extern char _binary_icons_png_start;
|
||||
extern char _binary_icons_png_end;
|
||||
extern char _binary_font_psf_gz_start;
|
||||
extern char _binary_font_psf_gz_end;
|
||||
#define icons_start _binary_icons_png_start
|
||||
#define icons_end _binary_icons_png_end
|
||||
#define font_start _binary_font_psf_gz_start
|
||||
#define font_end _binary_font_psf_gz_end
|
||||
#define DIRSEP '/'
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "data.h"
|
||||
|
||||
uint32_t theme[] = { 0xFFF0F0F0, 0xFFF4F4F4, 0xFFBEBEBE, 0xFF808080, 0xFF5C5C5C, 0xFF4C4C4C, 0xFF454545, 0xFF383838, 0xFF303030,
|
||||
0xFFC00000, 0xFF800000 };
|
||||
|
@ -317,8 +318,8 @@ void sdlmain()
|
|||
SDL_Event event;
|
||||
|
||||
/* get our font */
|
||||
font = (psf_t*)stbi_zlib_decode_malloc_guesssize_headerflag((const char*)&font_start + 10,
|
||||
(char*)&font_end - (char*)&font_start - 10, 32768, &len, 0);
|
||||
font = (psf_t*)stbi_zlib_decode_malloc_guesssize_headerflag((const char*)binary_font_psf_gz + 10,
|
||||
sizeof(binary_font_psf_gz) - 10, 32768, &len, 0);
|
||||
if(!font) error(lang[ERR_MEM]);
|
||||
|
||||
/* initialize SDL */
|
||||
|
@ -336,8 +337,8 @@ void sdlmain()
|
|||
|
||||
/* get icons and surfaces */
|
||||
s.read_from_callbacks = 0;
|
||||
s.img_buffer = s.img_buffer_original = (unsigned char *)&icons_start;
|
||||
s.img_buffer_end = s.img_buffer_original_end = (unsigned char *)&icons_end;
|
||||
s.img_buffer = s.img_buffer_original = binary_icons_png;
|
||||
s.img_buffer_end = s.img_buffer_original_end = binary_icons_png + sizeof(binary_icons_png);
|
||||
ri.bits_per_channel = 8;
|
||||
icondata = (uint8_t*)stbi__png_load(&s, &iw, &ih, &len, 0, &ri);
|
||||
icons = SDL_CreateRGBSurfaceFrom((uint32_t*)icondata, iw, iw, 32, iw*4, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
|
||||
|
|
Loading…
Reference in New Issue