From e701b3cdc097e668cb2f91f55c2edf97da0c8b42 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Wed, 21 Dec 2016 23:43:44 +0100 Subject: [PATCH] Fixed some compatibility issues --- .gitignore | 2 ++ Makefile | 3 +++ src/p7/dump.c | 23 ++++++++++++++--------- src/p7/main.c | 23 ++++++++++------------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 377570b..33b527d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /obj /man /p7 +/p7.exe /p7screen +/p7screen.exe diff --git a/Makefile b/Makefile index 66f081f..b6fa66a 100755 --- a/Makefile +++ b/Makefile @@ -111,6 +111,9 @@ $(eval $(call make-binary-rule,$(bin)))) $(call rmsg,Removing binaries.) $(call qcmd,$(RM) $(BINARIES:%=%*)) +# Remake binaries + re-bins: clean-bins all-bins + # Install a binary define make-installbinary-rule install-$1: $(CHECKCFG) $1$(if $(FOR_WINDOWS),.exe) diff --git a/src/p7/dump.c b/src/p7/dump.c index 25d7d59..c4b1f1b 100644 --- a/src/p7/dump.c +++ b/src/p7/dump.c @@ -8,8 +8,11 @@ /* */ /* ************************************************************************** */ #include "main.h" +#include #include #define info (response->ack) +#define numformat "%" PRIuFAST32 +#define addrformat "0x%08" PRIxFAST32 /** * dump: @@ -40,31 +43,33 @@ int dump(p7_handle_t *handle) /* - preprogrammed ROM - */ if (!info.preprog_rom_wiped) { - printf("Preprogrammed ROM capacity : %luo\n", info.preprog_rom_capacity); - printf("Preprogrammed ROM version : %02u.%02u.%02u\n", + printf("Preprogrammed ROM capacity : " numformat "o\n", + info.preprog_rom_capacity); + printf("Preprogrammed ROM version : %02u.%02u.%04u\n", info.preprog_rom_version.major, info.preprog_rom_version.minor, info.preprog_rom_version.rev); - printf("Preprogrammed ROM type : \"%s\"\n", info.preprog_rom_version.type); + printf("Preprogrammed ROM type : \"%s\"\n", + info.preprog_rom_version.type); } /* - ROM - */ - printf("ROM capacity : %luo\n", info.flash_rom_capacity); + printf("ROM capacity : " numformat "o\n", info.flash_rom_capacity); /* - RAM - */ - printf("RAM capacity : %luo\n", info.ram_capacity); + printf("RAM capacity : " numformat "o\n", info.ram_capacity); /* - Bootcode - */ if (!info.bootcode_wiped) { printf("Bootcode version : %02u.%02u.%02u\n", info.bootcode_version.major, info.bootcode_version.minor, info.bootcode_version.rev); printf("Bootcode type : \"%s\"\n", info.bootcode_version.type); - printf("Bootcode offset : %#08lx\n", info.bootcode_offset); - printf("Bootcode size : %luo\n", info.bootcode_size); + printf("Bootcode offset : " addrformat "\n", info.bootcode_offset); + printf("Bootcode size : " numformat "o\n", info.bootcode_size); } /* - OS - */ printf("OS version : %02u.%02u.%02u\n", info.os_version.major, info.os_version.minor, info.os_version.rev); printf("OS type : \"%s\"\n", info.os_version.type); - printf("OS offset : %#08lx\n", info.os_offset); - printf("OS size : %luo\n", info.os_size); + printf("OS offset : " addrformat "\n", info.os_offset); + printf("OS size : " numformat "o\n", info.os_size); /* - Miscallenous info - */ printf("Protocol version : %01u.%02u\n", info.protocol_version.major, info.protocol_version.minor); diff --git a/src/p7/main.c b/src/p7/main.c index a57c7e3..ddbfd6e 100644 --- a/src/p7/main.c +++ b/src/p7/main.c @@ -10,7 +10,6 @@ #include "main.h" #include #include -#include /* ************************************************************************** */ /* Error messages */ @@ -75,19 +74,18 @@ static const char error_nospace[] = static int sendfile_display_initialized = 0; static int sendfile_confirm(void) { + char line[10]; + /* Print stuff */ printf("It looks like the file already exists on the calculator.\n"); printf("Overwrite ? ([n]/y) "); /* Get the line */ - char *line = NULL; size_t n; - ssize_t err = getline(&line, &n, stdin); - if (err < 0) return (0); + if (!fgets(line, 10, stdin)) + return (0); /* Check if should overwrite */ - int overwrite = err >= 1 && !strncmp(line, "y", 1); - free(line); - return (overwrite); + return (*line == 'y'); } /** @@ -158,10 +156,10 @@ static void print_file_info(const char *dir, const char *name, p7uint_t size) memset(buf, ' ', 28); /* put path in buffer */ char *b = buf; - if (dir) b = stpcpy(b, dir), *b++ = '/'; - b = stpcpy(b, name), *b = ' '; + if (dir) b += sprintf(b, "%s/", dir); + b[sprintf(b, "%s", name)] = ' '; /* put size */ - sprintf(&buf[28], "% 10luo", size); + sprintf(&buf[28], "%10uo", (unsigned)size); /* put the string */ puts(buf); @@ -203,7 +201,7 @@ int main(int ac, char **av) fclose(args.local); if (args.menu == mn_get && args.local != stdout) { fclose(args.local); - unlink(args.localpath); + remove(args.localpath); } return (1); } @@ -219,7 +217,6 @@ int main(int ac, char **av) err = p7_reqfile(handle, args.local, args.dirname, args.filename, args.storage, args.nicedisp && args.local != stdout ? &sendfile_display : NULL); - if (err) unlink(args.localpath); break; case mn_copy: err = p7_copyfile(handle, args.dirname, args.filename, @@ -251,7 +248,7 @@ int main(int ac, char **av) /* close the file */ if (args.local) fclose(args.local); if (args.menu == mn_get && args.local != stdout) - unlink(args.localpath); + remove(args.localpath); /* put the error string */ switch (err) {