mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 09:30:31 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -33,9 +33,11 @@ static bool IsSymbolChar2(char c) {
|
|||
}
|
||||
|
||||
static bool IsSymbolString(const char *s) {
|
||||
if (!IsSymbolChar1(*s++)) return false;
|
||||
if (!IsSymbolChar1(*s++))
|
||||
return false;
|
||||
while (*s) {
|
||||
if (!IsSymbolChar2(*s++)) return false;
|
||||
if (!IsSymbolChar2(*s++))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ void AppendData(struct Buffer *b, const char *data, size_t len) {
|
|||
unsigned n;
|
||||
if (b->i + len + 1 > b->n) {
|
||||
n = MAX(b->i + len + 1, MAX(16, b->n + (b->n >> 1)));
|
||||
if (!(p = realloc(b->p, n))) return;
|
||||
if (!(p = realloc(b->p, n)))
|
||||
return;
|
||||
b->p = p;
|
||||
b->n = n;
|
||||
}
|
||||
|
|
|
@ -65,17 +65,21 @@ char *CopySymbol(char *p, size_t pn, const char *s, size_t sn) {
|
|||
assert(pn >= 1 + 3 + 1 + 1);
|
||||
iscomplicated = memchr(s, ' ', sn) || memchr(s, '(', sn);
|
||||
extra = 1;
|
||||
if (iscomplicated) extra += 2;
|
||||
if (iscomplicated)
|
||||
extra += 2;
|
||||
if (sn + extra > pn) {
|
||||
sn = pn - extra - 3;
|
||||
showdots = true;
|
||||
} else {
|
||||
showdots = false;
|
||||
}
|
||||
if (iscomplicated) *p++ = '"';
|
||||
if (iscomplicated)
|
||||
*p++ = '"';
|
||||
p = mempcpy(p, s, sn);
|
||||
if (showdots) p = stpcpy(p, "...");
|
||||
if (iscomplicated) *p++ = '"';
|
||||
if (showdots)
|
||||
p = stpcpy(p, "...");
|
||||
if (iscomplicated)
|
||||
*p++ = '"';
|
||||
*p = '\0';
|
||||
return p;
|
||||
}
|
||||
|
@ -85,8 +89,10 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) {
|
|||
size_t got;
|
||||
struct iovec iov[2];
|
||||
static char buf[4096];
|
||||
if (!g_cxxfilt.pid) SpawnCxxFilt();
|
||||
if (g_cxxfilt.pid == -1) return NULL;
|
||||
if (!g_cxxfilt.pid)
|
||||
SpawnCxxFilt();
|
||||
if (g_cxxfilt.pid == -1)
|
||||
return NULL;
|
||||
buf[0] = '\n';
|
||||
iov[0].iov_base = (void *)s;
|
||||
iov[0].iov_len = sn;
|
||||
|
@ -96,7 +102,8 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) {
|
|||
if ((rc = read(g_cxxfilt.reader, buf, sizeof(buf))) != -1) {
|
||||
got = rc;
|
||||
if (got >= 2 && buf[got - 1] == '\n') {
|
||||
if (buf[got - 2] == '\r') --got;
|
||||
if (buf[got - 2] == '\r')
|
||||
--got;
|
||||
--got;
|
||||
return CopySymbol(p, pn, buf, got);
|
||||
}
|
||||
|
@ -117,7 +124,8 @@ char *Demangle(char *p, const char *symbol, size_t n) {
|
|||
size_t sn;
|
||||
sn = strlen(symbol);
|
||||
if (startswith(symbol, "_Z")) {
|
||||
if ((r = DemangleCxxFilt(p, n, symbol, sn))) return r;
|
||||
if ((r = DemangleCxxFilt(p, n, symbol, sn)))
|
||||
return r;
|
||||
}
|
||||
return CopySymbol(p, n, symbol, sn);
|
||||
}
|
||||
|
|
|
@ -249,7 +249,8 @@ void elfwriter_commit(struct ElfWriter *elf, size_t size) {
|
|||
|
||||
void elfwriter_finishsection(struct ElfWriter *elf) {
|
||||
size_t section = FinishSection(elf);
|
||||
if (elf->relas->j < elf->relas->i) MakeRelaSection(elf, section);
|
||||
if (elf->relas->j < elf->relas->i)
|
||||
MakeRelaSection(elf, section);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -164,7 +164,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname,
|
|||
lfilehdrsize = kZipLfileHdrMinSize + namesize;
|
||||
crc = crc32_z(0, data, uncompsize);
|
||||
GetDosLocalTime(mtim.tv_sec, &mtime, &mdate);
|
||||
if (isutf8(name, namesize)) gflags |= kZipGflagUtf8;
|
||||
if (isutf8(name, namesize))
|
||||
gflags |= kZipGflagUtf8;
|
||||
if (S_ISREG(mode) && istext(data, size)) {
|
||||
iattrs |= kZipIattrText;
|
||||
}
|
||||
|
|
|
@ -65,8 +65,10 @@ static ssize_t EzWritevAll(int fd, struct iovec *iov, int iovlen) {
|
|||
total = 0;
|
||||
do {
|
||||
if (i) {
|
||||
while (i < iovlen && !iov[i].iov_len) ++i;
|
||||
if (i == iovlen) break;
|
||||
while (i < iovlen && !iov[i].iov_len)
|
||||
++i;
|
||||
if (i == iovlen)
|
||||
break;
|
||||
}
|
||||
if ((rc = writev(fd, iov + i, iovlen - i)) != -1) {
|
||||
wrote = rc;
|
||||
|
@ -99,7 +101,8 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) {
|
|||
v[1].iov_base = (void *)buf;
|
||||
v[1].iov_len = len;
|
||||
if (EzWritevAll(bio->fd, v, 2) != -1) {
|
||||
if (bio->c > 0) bio->c = 0;
|
||||
if (bio->c > 0)
|
||||
bio->c = 0;
|
||||
} else if (errno == EAGAIN) {
|
||||
return MBEDTLS_ERR_SSL_TIMEOUT;
|
||||
} else if (errno == EPIPE || errno == ECONNRESET || errno == ENETRESET) {
|
||||
|
@ -121,7 +124,8 @@ static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) {
|
|||
bio->c += len;
|
||||
return len;
|
||||
}
|
||||
if ((rc = EzTlsFlush(bio, buf, len)) < 0) return rc;
|
||||
if ((rc = EzTlsFlush(bio, buf, len)) < 0)
|
||||
return rc;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -130,11 +134,13 @@ static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) {
|
|||
int r;
|
||||
struct iovec v[2];
|
||||
struct EzTlsBio *bio = ctx;
|
||||
if ((r = EzTlsFlush(bio, 0, 0)) < 0) return r;
|
||||
if ((r = EzTlsFlush(bio, 0, 0)) < 0)
|
||||
return r;
|
||||
if (bio->a < bio->b) {
|
||||
r = MIN(n, bio->b - bio->a);
|
||||
memcpy(p, bio->t + bio->a, r);
|
||||
if ((bio->a += r) == bio->b) bio->a = bio->b = 0;
|
||||
if ((bio->a += r) == bio->b)
|
||||
bio->a = bio->b = 0;
|
||||
return r;
|
||||
}
|
||||
v[0].iov_base = p;
|
||||
|
@ -153,7 +159,8 @@ static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) {
|
|||
return MBEDTLS_ERR_NET_RECV_FAILED;
|
||||
}
|
||||
}
|
||||
if (r > n) bio->b = r - n;
|
||||
if (r > n)
|
||||
bio->b = r - n;
|
||||
return MIN(n, r);
|
||||
}
|
||||
|
||||
|
@ -237,7 +244,8 @@ void EzSetup(char psk[32]) {
|
|||
}
|
||||
|
||||
void EzDestroy(void) {
|
||||
if (!mytid) return;
|
||||
if (!mytid)
|
||||
return;
|
||||
EzSanity();
|
||||
mbedtls_ssl_free(&ezssl);
|
||||
mbedtls_ctr_drbg_free(&ezrng);
|
||||
|
|
|
@ -77,7 +77,8 @@
|
|||
|
||||
static wontreturn void getargs_fail(const char *path, const char *reason) {
|
||||
const char *errstr;
|
||||
if (!(errstr = _strerdoc(errno))) errstr = "Unknown error";
|
||||
if (!(errstr = _strerdoc(errno)))
|
||||
errstr = "Unknown error";
|
||||
tinyprint(2, path, ": ", reason, ": ", errstr, "\n", NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -97,7 +98,8 @@ void getargs_init(struct GetArgs *ga, char **args) {
|
|||
*/
|
||||
void getargs_destroy(struct GetArgs *ga) {
|
||||
if (ga->map) {
|
||||
if (munmap(ga->map, ga->mapsize)) notpossible;
|
||||
if (munmap(ga->map, ga->mapsize))
|
||||
notpossible;
|
||||
}
|
||||
bzero(ga, sizeof(*ga));
|
||||
}
|
||||
|
@ -152,7 +154,8 @@ const char *getargs_next(struct GetArgs *ga) {
|
|||
ga->j += ++k;
|
||||
return p;
|
||||
}
|
||||
if (munmap(ga->map, ga->mapsize)) notpossible;
|
||||
if (munmap(ga->map, ga->mapsize))
|
||||
notpossible;
|
||||
ga->map = 0;
|
||||
ga->mapsize = 0;
|
||||
ga->j = 0;
|
||||
|
|
|
@ -43,7 +43,8 @@ static void rehash(struct InternerObject *it) {
|
|||
p = it->p;
|
||||
it->p = xcalloc((it->n <<= 1), sizeof(struct InternerHash));
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (!p[i].hash) continue;
|
||||
if (!p[i].hash)
|
||||
continue;
|
||||
step = 0;
|
||||
do {
|
||||
j = (p[i].hash + step * ((step + 1) >> 1)) & (it->n - 1);
|
||||
|
@ -120,15 +121,21 @@ size_t internobj(struct Interner *t, const void *data, size_t size) {
|
|||
} while (it->p[i].hash);
|
||||
}
|
||||
off = it->pool.i;
|
||||
if (ckd_add(&need, off, size)) abort();
|
||||
if (ckd_add(&need, need, 1)) abort();
|
||||
if (ckd_add(&need, off, size))
|
||||
abort();
|
||||
if (ckd_add(&need, need, 1))
|
||||
abort();
|
||||
if (need > it->pool.n) {
|
||||
if (ckd_add(&n2, it->pool.n, 1)) abort();
|
||||
if (ckd_add(&n2, it->pool.n, 1))
|
||||
abort();
|
||||
do {
|
||||
if (ckd_add(&n2, n2, n2 >> 1)) abort();
|
||||
if (ckd_add(&n2, n2, n2 >> 1))
|
||||
abort();
|
||||
} while (need > n2);
|
||||
if (ckd_mul(&bytes, n2, sizeof(*it->pool.p))) abort();
|
||||
if (!(p2 = realloc(it->pool.p, bytes))) abort();
|
||||
if (ckd_mul(&bytes, n2, sizeof(*it->pool.p)))
|
||||
abort();
|
||||
if (!(p2 = realloc(it->pool.p, bytes)))
|
||||
abort();
|
||||
it->pool.p = p2;
|
||||
it->pool.n = n2;
|
||||
}
|
||||
|
|
|
@ -32,13 +32,16 @@ struct Lines {
|
|||
|
||||
static char *SkipEmptyFirstLine(char *p) {
|
||||
int i = 0;
|
||||
while (p[i] == ' ' || p[i] == '\t') ++i;
|
||||
while (p[i] == ' ' || p[i] == '\t')
|
||||
++i;
|
||||
return p[i] == '\n' ? p + i + 1 : p;
|
||||
}
|
||||
|
||||
static void DeleteLastEmptyLine(char *p, size_t n) {
|
||||
while (n && (p[n - 1] == ' ' || p[n - 1] == '\t')) --n;
|
||||
if (n && p[n - 1] == '\n') p[n - 1] = '\0';
|
||||
while (n && (p[n - 1] == ' ' || p[n - 1] == '\t'))
|
||||
--n;
|
||||
if (n && p[n - 1] == '\n')
|
||||
p[n - 1] = '\0';
|
||||
}
|
||||
|
||||
static void AppendLine(struct Lines *lines) {
|
||||
|
@ -88,7 +91,8 @@ static unsigned GetMinPrefixLen(struct Lines *lines,
|
|||
for (m = -1, i = 0; i < lines->n; ++i) {
|
||||
if (lines->p[i].n) {
|
||||
n = GetPrefixLen(lines->p[i].p, lines->p[i].n);
|
||||
if (n < m) m = n;
|
||||
if (n < m)
|
||||
m = n;
|
||||
}
|
||||
}
|
||||
return m == -1 ? 0 : m;
|
||||
|
@ -112,7 +116,8 @@ static void SplitLines(struct Lines *lines, char *p) {
|
|||
AppendLine(lines);
|
||||
lines->p[lines->n - 1].p = p;
|
||||
lines->p[lines->n - 1].n = (q = strchr(p, '\n')) ? q - p : strlen(p);
|
||||
if (!q) break;
|
||||
if (!q)
|
||||
break;
|
||||
p = q + 1;
|
||||
}
|
||||
RemovePrefixes(lines, GetMinPrefixLen(lines, GetSpaceStarPrefixLen));
|
||||
|
@ -175,7 +180,8 @@ static int ExtractText(struct Javadown *jd, struct Lines *lines, int i) {
|
|||
char *p;
|
||||
size_t n;
|
||||
for (p = NULL, n = j = 0; i + j < lines->n; ++j) {
|
||||
if (lines->p[i + j].n && lines->p[i + j].p[0] == '@') break;
|
||||
if (lines->p[i + j].n && lines->p[i + j].p[0] == '@')
|
||||
break;
|
||||
if (j) {
|
||||
p = realloc(p, ++n);
|
||||
p[n - 1] = '\n';
|
||||
|
@ -194,11 +200,14 @@ static void ExtractTags(struct Javadown *jd, struct Lines *lines, int i) {
|
|||
char *tag, *text, *p2;
|
||||
unsigned taglen, textlen, n2;
|
||||
for (; i < lines->n; ++i) {
|
||||
if (!lines->p[i].n) continue;
|
||||
if (lines->p[i].p[0] != '@') continue;
|
||||
if (!lines->p[i].n)
|
||||
continue;
|
||||
if (lines->p[i].p[0] != '@')
|
||||
continue;
|
||||
tag = lines->p[i].p + 1;
|
||||
taglen = GetTagLen(tag, lines->p[i].n - 1);
|
||||
if (!taglen) continue;
|
||||
if (!taglen)
|
||||
continue;
|
||||
text = tag + taglen;
|
||||
tag = strndup(tag, taglen);
|
||||
textlen = lines->p[i].n - 1 - taglen;
|
||||
|
|
|
@ -27,25 +27,30 @@
|
|||
|
||||
static int tpdecode(const char *s, wint_t *out) {
|
||||
uint32_t wc, cb, need, msb, j, i = 0;
|
||||
if ((wc = s[i++] & 255) == -1) return -1;
|
||||
if ((wc = s[i++] & 255) == -1)
|
||||
return -1;
|
||||
while ((wc & 0300) == 0200) {
|
||||
if ((wc = s[i++] & 255) == -1) return -1;
|
||||
if ((wc = s[i++] & 255) == -1)
|
||||
return -1;
|
||||
}
|
||||
if (!(0 <= wc && wc <= 0x7F)) {
|
||||
msb = wc < 252 ? bsr(~wc & 0xff) : 1;
|
||||
need = 7 - msb;
|
||||
wc &= ((1u << msb) - 1) | 0003;
|
||||
for (j = 1; j < need; ++j) {
|
||||
if ((cb = s[i++] & 255) == -1) return -1;
|
||||
if ((cb = s[i++] & 255) == -1)
|
||||
return -1;
|
||||
if ((cb & 0300) == 0200) {
|
||||
wc = wc << 6 | (cb & 077);
|
||||
} else {
|
||||
if (out) *out = 0xFFFD;
|
||||
if (out)
|
||||
*out = 0xFFFD;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (out) *out = wc;
|
||||
if (out)
|
||||
*out = wc;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -71,7 +76,8 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
|
|||
bzero(&b, sizeof(b));
|
||||
AppendStr(&b, "\e[H");
|
||||
for (y = 0; y < tyn; ++y) {
|
||||
if (y) AppendFmt(&b, "\e[%dH", y + 1);
|
||||
if (y)
|
||||
AppendFmt(&b, "\e[%dH", y + 1);
|
||||
for (x = i = 0; i < pn; ++i) {
|
||||
if (p[i].top <= y && y < p[i].bottom) {
|
||||
j = state = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue