Left-align stub arguments to dd (fixes #374)

This satisfies busybox's non-standard integer
argument parsing, and even saves a few bytes.
This commit is contained in:
Connor Olding 2022-09-06 22:08:22 +00:00
parent dbf12c30b0
commit 1f10bff58e
2 changed files with 39 additions and 40 deletions

View file

@ -569,11 +569,11 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
.ascii "t=\"${TMPDIR:-${HOME:-.}}/.ape\"\n" .ascii "t=\"${TMPDIR:-${HOME:-.}}/.ape\"\n"
.ascii "[ -x \"$t\" ] || {\n" .ascii "[ -x \"$t\" ] || {\n"
.ascii "mkdir -p \"${t%/*}\" &&\n" .ascii "mkdir -p \"${t%/*}\" &&\n"
.ascii "dd if=\"$o\" of=\"$t.$$\" skip=\"" .ascii "dd if=\"$o\" of=\"$t.$$\" skip="
.shstub ape_loader_dd_skip,2 .shstub ape_loader_dd_skip,2
.ascii "\" count=\"" .ascii " count="
.shstub ape_loader_dd_count,2 .shstub ape_loader_dd_count,2
.ascii "\" bs=64 2>/dev/null\n" .ascii " bs=64 2>/dev/null\n"
#if SupportsXnu() #if SupportsXnu()
.ascii "[ -d /Applications ] && " .ascii "[ -d /Applications ] && "
.ascii "dd if=\"$t.$$\"" .ascii "dd if=\"$t.$$\""
@ -637,11 +637,11 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
.ascii "dd if=\"$o\"" .ascii "dd if=\"$o\""
.ascii " of=\"$o\"" .ascii " of=\"$o\""
.ascii " bs=8" .ascii " bs=8"
.ascii " skip=\"" .ascii " skip="
.shstub ape_macho_dd_skip,2 .shstub ape_macho_dd_skip,2
.ascii "\" count=\"" .ascii " count="
.shstub ape_macho_dd_count,2 .shstub ape_macho_dd_count,2
.ascii "\" conv=notrunc 2>/dev/null\n" .ascii " conv=notrunc 2>/dev/null\n"
#endif /* XNU */ #endif /* XNU */
.ascii "[ x\"$1\" = x--assimilate ] && exit 0\n" .ascii "[ x\"$1\" = x--assimilate ] && exit 0\n"
#ifndef APE_NO_MODIFY_SELF #ifndef APE_NO_MODIFY_SELF

View file

@ -226,38 +226,37 @@
* parameters must be quoted; and eight digits should be good enough. * parameters must be quoted; and eight digits should be good enough.
*/ */
#define SHSTUB2(SYM, X) \ #define SHSTUB2(SYM, X) \
HIDDEN(SYM##_bcs0 = BCD10K(X)); \ HIDDEN(SYM##_bcs0 = BCD_LEFT(X)); \
HIDDEN(SYM##_bcs1 = BCD(X)) HIDDEN(SYM##_bcs1 = BCD_RIGHT(X))
#define BCD(X) \ #define BCD_HELPER(X) \
((X) == 0 \ (((X)) < 10 ? 0x20202030 + \
? 0x20202030 \ (X) % 10 \
: (X) < 10 ? 0x30202020 + (((X) % 10) << 24) \ : (X) < 100 ? 0x20203030 + \
: (X) < 100 ? 0x30302020 + (((X) % 10) << 24) + \ ((X) / 10) % 10 + \
(((X) / 10 % 10) << 16) \ (X) % 10 * 0x100 \
: (X) < 1000 ? 0x30303020 + (((X) % 10) << 24) + \ : (X) < 1000 ? 0x20303030 + \
(((X) / 10 % 10) << 16) + \ ((X) / 100) % 10 + \
(((X) / 100 % 10) << 8) \ ((X) / 10) % 10 * 0x100 + \
: 0x30303030 + (((X) % 10) << 24) + \ (X) % 10 * 0x10000 \
(((X) / 10 % 10) << 16) + \ : (X) < 10000 ? 0x30303030 + \
(((X) / 100 % 10) << 8) + \ ((X) / 1000) % 10 + \
(((X) / 1000 % 10) << 0)) ((X) / 100) % 10 * 0x100 + \
#define BCD10K(X) \ ((X) / 10) % 10 * 0x10000 + \
((X) < 10000 \ (X) % 10 * 0x1000000 \
? 0x20202020 \ : 0xffffffffffffffff)
: (X) < 100000 \ #define BCD_LEFT(X) \
? 0x30202020 + (((X) / 10000 % 10) << 24) \ (((X)) < 10000 ? BCD_HELPER(X) \
: (X) < 1000000 \ : (X) < 100000 ? BCD_HELPER((X) / 10) \
? 0x30302020 + (((X) / 10000 % 10) << 24) + \ : (X) < 1000000 ? BCD_HELPER((X) / 100) \
(((X) / 100000 % 10) << 16) \ : (X) < 10000000 ? BCD_HELPER((X) / 1000) \
: (X) < 10000000 \ : (X) < 100000000 ? BCD_HELPER((X) / 10000) \
? 0x30303020 + (((X) / 10000 % 10) << 24) + \ : 0xffffffffffffffff)
(((X) / 100000 % 10) << 16) + \ #define BCD_RIGHT(X) \
(((X) / 1000000 % 10) << 8) \ (((X)) < 10000 ? 0x20202020 \
: (X) < 100000000 \ : (X) < 100000 ? BCD_HELPER((X) % 10) \
? 0x30303030 + (((X) / 10000 % 10) << 24) + \ : (X) < 1000000 ? BCD_HELPER((X) % 100) \
(((X) / 100000 % 10) << 16) + \ : (X) < 10000000 ? BCD_HELPER((X) % 1000) \
(((X) / 1000000 % 10) << 8) + \ : (X) < 100000000 ? BCD_HELPER((X) % 10000) \
(((X) / 10000000 % 10) << 0) \
: 0xffffffffffffffff) : 0xffffffffffffffff)
#endif /* __ASSEMBLER__ */ #endif /* __ASSEMBLER__ */