mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
Replace COSMO define with _COSMO_SOURCE
This change might cause ABI breakages for /opt/cosmos. It's needed to help us better conform to header declaration practices.
This commit is contained in:
parent
a033b65a33
commit
c776a32f75
238 changed files with 858 additions and 1069 deletions
|
@ -5,8 +5,10 @@
|
|||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Hex to binary converter program.
|
||||
|
@ -15,14 +17,14 @@
|
|||
*/
|
||||
|
||||
int main() {
|
||||
int o, t = -1;
|
||||
while (0 <= (o = getchar()) && o <= 255) {
|
||||
if (!isxdigit(o)) continue;
|
||||
int h = hextoint(o);
|
||||
if (t != -1) putchar(t * 16 + h), h = -1;
|
||||
t = h;
|
||||
int h, o, t = -1;
|
||||
while ((o = getchar()) != -1) {
|
||||
if ((h = kHexToInt[o & 255]) != -1) {
|
||||
if (t != -1) {
|
||||
putchar(t * 16 + h);
|
||||
h = -1;
|
||||
}
|
||||
t = h;
|
||||
}
|
||||
}
|
||||
if (ferror(stdout)) return 1;
|
||||
if (t != -1) return 2;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tab.internal.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
@ -129,8 +130,11 @@ int main(int argc, char *argv[]) {
|
|||
for (k = 0, i = optind; i < argc; ++i) {
|
||||
CheckHex(argv[i]);
|
||||
for (j = 0; argv[i][j]; j += 2) {
|
||||
if (++k > XED_MAX_INSTRUCTION_BYTES) ShowUsage(EX_DATAERR, stderr);
|
||||
buf[k - 1] = hextoint(argv[i][j + 0]) << 4 | hextoint(argv[i][j + 1]);
|
||||
if (++k > XED_MAX_INSTRUCTION_BYTES) {
|
||||
ShowUsage(EX_DATAERR, stderr);
|
||||
}
|
||||
buf[k - 1] = kHexToInt[argv[i][j + 0] & 255] << 4 |
|
||||
kHexToInt[argv[i][j + 1] & 255];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Hex to binary converter program.
|
||||
* Non-hex bytes are ignored. If you've got imposter syndrome you could
|
||||
* call this a compiler and start coding in hex.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
size_t i, j, l;
|
||||
uint8_t *buf;
|
||||
if (argc == 1) return 1;
|
||||
buf = gc(xmalloc((l = strlen(argv[1]) / 2)));
|
||||
for (j = 0; j < l; ++j) {
|
||||
buf[j] = 0;
|
||||
}
|
||||
for (i = 1; i < argc; ++i) {
|
||||
for (j = 0; j < l; ++j) {
|
||||
buf[j] ^= hextoint(argv[i][j + 0]) << 4 | hextoint(argv[i][j + 1]);
|
||||
}
|
||||
}
|
||||
for (j = 0; j < l; ++j) {
|
||||
putchar("0123456789abcdef"[(buf[j] >> 4) & 0xf]);
|
||||
putchar("0123456789abcdef"[(buf[j] >> 0) & 0xf]);
|
||||
}
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue