mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Clean up some code
This commit is contained in:
parent
531bfbd61f
commit
ed161b240e
17 changed files with 107 additions and 182 deletions
|
@ -2328,7 +2328,7 @@ static void OnKeyboardServiceReadKeyPress(void) {
|
|||
static char buf[32];
|
||||
static size_t pending;
|
||||
pty->conf |= kPtyBlinkcursor;
|
||||
if (!pending && !(pending = ReadAnsi(0, buf, sizeof(buf)))) {
|
||||
if (!pending && !(pending = ReadAnsi(ttyin, buf, sizeof(buf)))) {
|
||||
exitcode = 0;
|
||||
action |= EXIT;
|
||||
return;
|
||||
|
|
72
tool/build/fastdiff.c
Normal file
72
tool/build/fastdiff.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* @fileoverview scalable diff tool
|
||||
*
|
||||
* The normal `diff` command can take hours to diff text files that are
|
||||
* hundreds of megabytes in size. This tool is a useful replacement for
|
||||
* use cases like comparing a log of CPU registers.
|
||||
*/
|
||||
|
||||
char line1[4096];
|
||||
char line2[4096];
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int line;
|
||||
char *l1, *l2;
|
||||
FILE *f1, *f2;
|
||||
int differences;
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "usage: %s FILE1 FILE2\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (!(f1 = fopen(argv[1], "r"))) {
|
||||
perror(argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if (!(f2 = fopen(argv[2], "r"))) {
|
||||
perror(argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
for (differences = 0, line = 1;; ++line) {
|
||||
l1 = fgets(line1, sizeof(line1), f1);
|
||||
l2 = fgets(line2, sizeof(line2), f2);
|
||||
if (!l1 && !l2) {
|
||||
exit(0);
|
||||
}
|
||||
if (l1) _chomp(l1);
|
||||
if (l2) _chomp(l2);
|
||||
if (!l1 || !l2) {
|
||||
printf("> %s\n", l1 ? l1 : "EOF");
|
||||
printf("< %s\n", l2 ? l2 : "EOF");
|
||||
exit(0);
|
||||
}
|
||||
if (!strcmp(l1, l2)) {
|
||||
printf("%s\n", l1);
|
||||
} else {
|
||||
printf("# line %d differed!\n", line);
|
||||
printf("> %s\n", l1);
|
||||
printf("< %s\n", l2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -469,7 +469,7 @@ int64_t Ror32(uint64_t x64, uint64_t y, uint32_t *f) {
|
|||
uint32_t x = x64;
|
||||
if ((y &= 31)) {
|
||||
x = x >> y | x << (32 - y);
|
||||
return RotateFlags(x, x >> 31, f, (x >> 31) ^ (x >> 30) & 1);
|
||||
return RotateFlags(x, x >> 31, f, ((x >> 31) ^ (x >> 30)) & 1);
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ int64_t Ror32(uint64_t x64, uint64_t y, uint32_t *f) {
|
|||
int64_t Ror64(uint64_t x, uint64_t y, uint32_t *f) {
|
||||
if ((y &= 63)) {
|
||||
x = x >> y | x << (64 - y);
|
||||
return RotateFlags(x, x >> 63, f, (x >> 63) ^ (x >> 62) & 1);
|
||||
return RotateFlags(x, x >> 63, f, ((x >> 63) ^ (x >> 62)) & 1);
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ int64_t Ror8(uint64_t x64, uint64_t y, uint32_t *f) {
|
|||
uint8_t x = x64;
|
||||
if (y & 31) {
|
||||
if ((y &= 7)) x = x >> y | x << (8 - y);
|
||||
return RotateFlags(x, x >> 7, f, (x >> 7) ^ (x >> 6) & 1);
|
||||
return RotateFlags(x, x >> 7, f, ((x >> 7) ^ (x >> 6)) & 1);
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ int64_t Ror16(uint64_t x64, uint64_t y, uint32_t *f) {
|
|||
uint16_t x = x64;
|
||||
if (y & 31) {
|
||||
if ((y &= 15)) x = x >> y | x << (16 - y);
|
||||
return RotateFlags(x, x >> 15, f, (x >> 15) ^ (x >> 14) & 1);
|
||||
return RotateFlags(x, x >> 15, f, ((x >> 15) ^ (x >> 14)) & 1);
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/fmt/bing.internal.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/tpenc.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/arraylist2.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -90,7 +91,7 @@ static char *DisAddr(struct Dis *d, char *p) {
|
|||
int64_t x = d->addr;
|
||||
if (0 <= x && x < 0x10fff0) {
|
||||
return p + uint64toarray_fixed16(x, p, 24);
|
||||
} else if (-2147483648 <= x && x <= 2147483647) {
|
||||
} else if (INT_MIN <= x && x <= INT_MAX) {
|
||||
return p + uint64toarray_fixed16(x, p, 32);
|
||||
} else {
|
||||
return p + uint64toarray_fixed16(x, p, 48);
|
||||
|
|
|
@ -186,8 +186,9 @@ long DisFindSym(struct Dis *d, int64_t addr) {
|
|||
l = m + 1;
|
||||
}
|
||||
}
|
||||
if (r && d->syms.p[r - 1].addr < 256) {
|
||||
/* XXX: prevent skewed binbase from doing weirdness */
|
||||
// TODO(jart): This was <256 but that broke SectorLISP debugging
|
||||
// Why did the Cosmo binbase bootloader need this?
|
||||
if (r && d->syms.p[r - 1].addr < 32) {
|
||||
return -1;
|
||||
}
|
||||
if (r && (addr == d->syms.p[r - 1].addr ||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
(gcc-builtin-functions
|
||||
'("__has_attribute"
|
||||
"__has_builtin"
|
||||
"__has_feature"
|
||||
"__has_cpp_attribute"
|
||||
"__builtin_va_arg"
|
||||
"__builtin_va_copy"
|
||||
|
|
|
@ -11,11 +11,15 @@
|
|||
|
||||
(c11
|
||||
'("_Atomic"
|
||||
"alignas"
|
||||
"_Alignas"
|
||||
"alignof"
|
||||
"_Alignof"
|
||||
"_Noreturn"
|
||||
"_Generic"
|
||||
"thread_local"
|
||||
"_Thread_local"
|
||||
"static_assert"
|
||||
"_Static_assert"
|
||||
"_Complex_I"
|
||||
"_Imaginary_I"))
|
||||
|
@ -30,8 +34,9 @@
|
|||
"textexit"
|
||||
"externinline"
|
||||
"dontinline"
|
||||
"noclone"
|
||||
"dontclone"
|
||||
"donothing"
|
||||
"notsan"
|
||||
"printfesque"
|
||||
"flattenout"
|
||||
"mallocesque"
|
||||
|
@ -68,7 +73,9 @@
|
|||
"frownedupon"
|
||||
"wontreturn"
|
||||
"noasan"
|
||||
"nomsan"
|
||||
"noubsan"
|
||||
"smashmystack"
|
||||
"initarray"
|
||||
"mayalias"
|
||||
"noinstrument"
|
||||
|
@ -171,6 +178,7 @@
|
|||
"__no_sanitize_address__"
|
||||
"__no_address_safety_analysis__"
|
||||
"__no_sanitize_thread__"
|
||||
"__no_stack_protector__"
|
||||
"__leaf__"
|
||||
"__no_sanitize_undefined__"
|
||||
"__no_split_stack__"
|
||||
|
@ -203,7 +211,9 @@
|
|||
|
||||
(clang
|
||||
'("__optnone__"
|
||||
"__nodebug__"))
|
||||
"__nodebug__"
|
||||
"musttail"
|
||||
"__musttail__"))
|
||||
|
||||
)
|
||||
(concat "\\_<"
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
"__SSP_EXPLICIT__"
|
||||
"__SANITIZE_ADDRESS__"
|
||||
"__SANITIZE_THREAD__"
|
||||
"__SANITIZE_MEMORY__"
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"
|
||||
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
|
||||
|
|
|
@ -164,7 +164,7 @@
|
|||
((eq arg 3) "rel")
|
||||
((eq arg 4) "dbg")
|
||||
((eq arg 5) "")
|
||||
((eq arg 6) "optlinux")
|
||||
((eq arg 6) "llvm")
|
||||
((eq arg 7) "tinylinux")
|
||||
((eq arg 8) "tsan")
|
||||
(default default)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue