From 659647211f139e0776b06cfe4bb123f78791217e Mon Sep 17 00:00:00 2001 From: KaiN Date: Fri, 2 Mar 2018 19:08:12 +0100 Subject: [PATCH 1/5] Added Amiga architecture support --- lib/lha_arch.h | 5 +- lib/lha_arch_amiga.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 lib/lha_arch_amiga.c diff --git a/lib/lha_arch.h b/lib/lha_arch.h index 41b4e37c..7400de9a 100644 --- a/lib/lha_arch.h +++ b/lib/lha_arch.h @@ -27,9 +27,12 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define LHA_ARCH_UNIX 1 #define LHA_ARCH_WINDOWS 2 +#define LHA_ARCH_AMIGA 3 -#ifdef _WIN32 +#if defined(_WIN32) #define LHA_ARCH LHA_ARCH_WINDOWS +#elif defined(__amigaos__) +#define LHA_ARCH LHA_ARCH_AMIGA #else #define LHA_ARCH LHA_ARCH_UNIX #endif diff --git a/lib/lha_arch_amiga.c b/lib/lha_arch_amiga.c new file mode 100644 index 00000000..d6cb9ed2 --- /dev/null +++ b/lib/lha_arch_amiga.c @@ -0,0 +1,121 @@ +/* + +Copyright (c) 2012, Simon Howard + +Permission to use, copy, modify, and/or distribute this software +for any purpose with or without fee is hereby granted, provided +that the above copyright notice and this permission notice appear +in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + */ + +// +// Architecture-specific files for compilation on Amiga. +// + +#define _GNU_SOURCE +#include "lha_arch.h" + +#if LHA_ARCH == LHA_ARCH_AMIGA + +#include +#include +#include +#include +#include +#include +#include +#include + +int lha_arch_vasprintf(char **result, char *fmt, va_list args) +{ + int len; + va_list args2; + va_copy(args2, args); + char szTmp[2]; + len = vsnprintf(szTmp, 2, fmt, args2); + va_end(args2); + if (len >= 0) { + *result = malloc(len + 1); + if (*result != NULL) { + va_copy(args2, args); + return vsprintf(*result, fmt, args); + va_end(args2); + } + } + *result = NULL; + return -1; +} + +void lha_arch_set_binary(FILE *handle) +{ + // No-op on Amiga systems: there is no difference between + // "text" and "binary" files. +} + +int lha_arch_mkdir(char *path, unsigned int unix_perms) +{ + return mkdir(path, unix_perms) == 0; +} + +int lha_arch_chown(char *filename, int unix_uid, int unix_gid) +{ + return 1; +} + +int lha_arch_chmod(char *filename, int unix_perms) +{ + return 1; +} + +int lha_arch_utime(char *filename, unsigned int timestamp) +{ + struct utimbuf times; + + times.actime = (time_t) timestamp; + times.modtime = (time_t) timestamp; + + return utime(filename, ×) == 0; +} + +FILE *lha_arch_fopen(char *filename, int unix_uid, int unix_gid, int unix_perms) +{ + return fopen(filename, "wb"); +} + +LHAFileType lha_arch_exists(char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) != 0) { + if (errno == ENOENT) { + return LHA_FILE_NONE; + } else { + return LHA_FILE_ERROR; + } + } + + if (S_ISDIR(statbuf.st_mode)) { + return LHA_FILE_DIRECTORY; + } else { + return LHA_FILE_FILE; + } +} + +int lha_arch_symlink(char *path, char *target) +{ + return 1; +} + +#endif /* LHA_ARCH_AMIGA */ + + From 71517a158ade248336fdba40e0dafc13433c0243 Mon Sep 17 00:00:00 2001 From: KaiN Date: Fri, 2 Mar 2018 19:13:01 +0100 Subject: [PATCH 2/5] Changed compression ratio calc from float percents to int permilles --- src/list.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/list.c b/src/list.c index 79b10d2c..2674e1fd 100644 --- a/src/list.c +++ b/src/list.c @@ -232,12 +232,14 @@ static ListColumn size_column = { // Compression ratio -static float compression_percent(size_t compressed, size_t uncompressed) +static size_t compression_permilles(size_t compressed, size_t uncompressed) { + // Calculated permilles instead of float percents + // On Amiga there's no FPU, avoiding soft floats makes code more optimizable if (uncompressed > 0) { - return ((float) compressed * 100.0f) / (float) uncompressed; + return (compressed * 1000) / uncompressed; } else { - return 100.0f; + return 1000; } } @@ -246,8 +248,9 @@ static void ratio_column_print(LHAFileHeader *header) if (!strcmp(header->compress_method, "-lhd-")) { printf("******"); } else { - printf("%5.1f%%", compression_percent(header->compressed_length, - header->length)); + size_t permilles = compression_permilles(header->compressed_length, + header->length); + printf("%d.%d%%", permilles/10, permilles % 10); } } @@ -256,8 +259,9 @@ static void ratio_column_footer(FileStatistics *stats) if (stats->length == 0) { printf("******"); } else { - printf("%5.1f%%", compression_percent(stats->compressed_length, - stats->length)); + size_t permilles = compression_permilles(stats->compressed_length, + stats->length); + printf("%d.%d%%", permilles/10, permilles % 10); } } From f4b4e5004b3c8e28225b5ed6ff7aad6bef8ffa32 Mon Sep 17 00:00:00 2001 From: KaiN Date: Fri, 2 Mar 2018 19:13:54 +0100 Subject: [PATCH 3/5] Amiga makefile until automake compiling gets supported --- Makefile.amiga | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Makefile.amiga diff --git a/Makefile.amiga b/Makefile.amiga new file mode 100644 index 00000000..e037c109 --- /dev/null +++ b/Makefile.amiga @@ -0,0 +1,65 @@ +# Usage: +# "make" - recommended: builds lib and app +# "make clean" - removes all tmp files +# "make lib" - builds only lib +# "make app" - builds only app if lib is present + +CC = m68k-amigaos-gcc +AR = m68k-amigaos-ar +INCLUDES_APP = -Isrc -Ilib/public -I. +INCLUDES_LIB = -Ilib +CC_FLAGS_COMMON = -Wall -Wsign-compare -std=c11 -O3 -fomit-frame-pointer -fbaserel +CC_FLAGS_APP = $(INCLUDES_APP) $(CC_FLAGS_COMMON) +CC_FLAGS_LIB = $(INCLUDES_LIB) $(CC_FLAGS_COMMON) + +# LTO for Amiga since every optimization counts! +LDFLAGS = -noixemul -flto + +PACKER_SRC_DIR = $(ROOT)/src +TMP_DIR = tmp + +LIB_IGNORE = \ + lib/lh_new_decoder.c \ + lib/pma_common.c \ + lib/bit_stream_reader.c \ + lib/tree_decode.c \ + lib/lha_arch_win32.c \ + lib/lha_arch_unix.c + +LIB_SRCS = $(filter-out $(LIB_IGNORE), $(wildcard lib/*.c)) +LIB_OBJS = $(addprefix $(TMP_DIR)/lib_, $(notdir $(LIB_SRCS:.c=.o))) + +APP_SRCS = $(wildcard src/*.c) +APP_OBJS = $(addprefix $(TMP_DIR)/app_, $(notdir $(APP_SRCS:.c=.o))) + +#------------------------------------------------------------------------- Goals + +lhasa: lib app + +lib: lib/public/liblhasa.a + +app: bin/lhasa + +clean: + @echo Removing tmp and lib contents + $(RM) tmp/*.o + $(RM) lib/public/liblhasa.a + +#----------------------------------------------------------------- How it's made + +tmp/lib_%.o: lib/%.c + @echo Building: $< + @$(CC) $(CC_FLAGS_LIB) -c -o $@ $< + +tmp/app_%.o: src/%.c + @echo Building: $< + @$(CC) $(CC_FLAGS_APP) -c -o $@ $< + +lib/public/liblhasa.a: $(LIB_OBJS) + @echo linking $@ + @$(AR) rcs $@ $(LIB_OBJS) + +bin/lhasa: lib/public/liblhasa.a $(APP_OBJS) + @echo linking $@ + @$(CC) $(CC_FLAGS_LIB) -o $@ $(APP_OBJS) -llhasa -Wall $(LDFLAGS) -Llib/public + From c5edda3c47892b91285db06b23b7690c4ab0d947 Mon Sep 17 00:00:00 2001 From: KaiN Date: Sat, 3 Mar 2018 10:38:55 +0100 Subject: [PATCH 4/5] Included new files in Makefile.am --- Makefile.am | 2 +- lib/Makefile.am | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 575548c2..e1609341 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ AUX_DIST_GEN = $(ac_aux_dir) -EXTRA_DIST = $(AUX_DIST_GEN) gencov rpm.spec +EXTRA_DIST = $(AUX_DIST_GEN) gencov rpm.spec Makefile.amiga MAINTAINERCLEANFILES = $(AUX_DIST_GEN) pkgconfigdir = ${libdir}/pkgconfig diff --git a/lib/Makefile.am b/lib/Makefile.am index e70de16b..5ed5a3bd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -14,6 +14,7 @@ SRC = \ ext_header.c ext_header.h \ lha_arch_unix.c lha_arch.h \ lha_arch_win32.c \ + lha_arch_amiga.c \ lha_decoder.c lha_decoder.h \ lha_endian.c lha_endian.h \ lha_file_header.c lha_file_header.h \ From 7f0aa496d7e39a0e8248fbc11dafe57c78704055 Mon Sep 17 00:00:00 2001 From: KaiN Date: Sat, 3 Mar 2018 10:44:13 +0100 Subject: [PATCH 5/5] Fixed unsigned permilles rounding and ratio format string --- src/list.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/list.c b/src/list.c index 2674e1fd..0b067318 100644 --- a/src/list.c +++ b/src/list.c @@ -237,7 +237,7 @@ static size_t compression_permilles(size_t compressed, size_t uncompressed) // Calculated permilles instead of float percents // On Amiga there's no FPU, avoiding soft floats makes code more optimizable if (uncompressed > 0) { - return (compressed * 1000) / uncompressed; + return (compressed * 1000 + uncompressed/2) / uncompressed; } else { return 1000; } @@ -250,7 +250,7 @@ static void ratio_column_print(LHAFileHeader *header) } else { size_t permilles = compression_permilles(header->compressed_length, header->length); - printf("%d.%d%%", permilles/10, permilles % 10); + printf("%3u.%u%%", permilles/10, permilles % 10); } } @@ -261,7 +261,7 @@ static void ratio_column_footer(FileStatistics *stats) } else { size_t permilles = compression_permilles(stats->compressed_length, stats->length); - printf("%d.%d%%", permilles/10, permilles % 10); + printf("%3u.%u%%", permilles/10, permilles % 10); } }