mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 11:48:30 +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
|
@ -71,7 +71,8 @@ static void SetXsFb(struct Tty *tty, unsigned short xsfb) {
|
|||
static bool SetWcs(struct Tty *tty, unsigned init_flags) {
|
||||
#ifdef VGA_USE_WCS
|
||||
struct DirectMap dm;
|
||||
if (!(init_flags & kTtyAllocWcs)) return false;
|
||||
if (!(init_flags & kTtyAllocWcs))
|
||||
return false;
|
||||
dm = sys_mmap_metal(NULL, Yn(tty) * Xn(tty) * sizeof(wchar_t),
|
||||
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
|
||||
0);
|
||||
|
@ -200,11 +201,14 @@ void _StartTty(struct Tty *tty, unsigned char type, unsigned short yp,
|
|||
tty->yc = yc;
|
||||
tty->xc = xc;
|
||||
tty->fb = fb;
|
||||
if (starty >= yn) starty = yn - 1;
|
||||
if (startx >= xn) startx = xn - 1;
|
||||
if (starty >= yn)
|
||||
starty = yn - 1;
|
||||
if (startx >= xn)
|
||||
startx = xn - 1;
|
||||
tty->y = starty;
|
||||
tty->x = startx;
|
||||
if ((init_flags & kTtyKlog) != 0) init_flags &= ~kTtyAllocWcs;
|
||||
if ((init_flags & kTtyKlog) != 0)
|
||||
init_flags &= ~kTtyAllocWcs;
|
||||
tty->xs = xs;
|
||||
TtySetType(tty, type, init_flags);
|
||||
if (SetWcs(tty, init_flags)) {
|
||||
|
@ -212,7 +216,8 @@ void _StartTty(struct Tty *tty, unsigned char type, unsigned short yp,
|
|||
size_t n = (size_t)yn * xn, i;
|
||||
if (type == PC_VIDEO_TEXT) {
|
||||
struct VgaTextCharCell *ccs = fb;
|
||||
for (i = 0; i < n; ++i) wcs[i] = bing(ccs[i].ch, 0);
|
||||
for (i = 0; i < n; ++i)
|
||||
wcs[i] = bing(ccs[i].ch, 0);
|
||||
} else
|
||||
wmemset(wcs, L' ', n);
|
||||
}
|
||||
|
@ -334,9 +339,12 @@ static void TtySetCodepage(struct Tty *tty, char id) {
|
|||
static uint8_t TtyGetTextColor(TtyCanvasColor color) {
|
||||
uint8_t r = color.bgr.r, g = color.bgr.g, b = color.bgr.b;
|
||||
uint8_t hue = 0, max = MAX(MAX(r, g), b);
|
||||
if (r > max / 2) hue |= 4;
|
||||
if (g > max / 2) hue |= 2;
|
||||
if (b > max / 2) hue |= 1;
|
||||
if (r > max / 2)
|
||||
hue |= 4;
|
||||
if (g > max / 2)
|
||||
hue |= 2;
|
||||
if (b > max / 2)
|
||||
hue |= 1;
|
||||
if (hue == 7 && max <= 0x55)
|
||||
hue = 8;
|
||||
else if (max > 0xaa)
|
||||
|
@ -367,9 +375,11 @@ static uint8_t TtyGetTextAttr(struct Tty *tty) {
|
|||
* simplistic than what Linux does, but should be enough.
|
||||
*/
|
||||
attr &= ~0x80;
|
||||
if ((tty->pr & kTtyBlink) != 0) attr |= 0x80;
|
||||
if ((tty->pr & kTtyBlink) != 0)
|
||||
attr |= 0x80;
|
||||
#endif
|
||||
if ((tty->pr & kTtyBold) != 0) attr |= 0x08;
|
||||
if ((tty->pr & kTtyBold) != 0)
|
||||
attr |= 0x08;
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
@ -381,7 +391,8 @@ static void TtyTextDrawChar(struct Tty *tty, size_t y, size_t x, wchar_t wc) {
|
|||
struct VgaTextCharCell *ccs = (struct VgaTextCharCell *)tty->canvas;
|
||||
size_t i = tty->y * Xn(tty) + tty->x;
|
||||
int c = unbing(wc);
|
||||
if (c == -1) c = 0xFE;
|
||||
if (c == -1)
|
||||
c = 0xFE;
|
||||
ccs[i] = (struct VgaTextCharCell){c, attr};
|
||||
}
|
||||
|
||||
|
@ -390,7 +401,8 @@ static void TtyTextEraseLineCells(struct Tty *tty, size_t dsty, size_t dstx,
|
|||
uint8_t attr = TtyGetTextAttr(tty);
|
||||
struct VgaTextCharCell *ccs = (struct VgaTextCharCell *)tty->canvas;
|
||||
size_t dst = dsty * Xn(tty) + dstx, i;
|
||||
for (i = 0; i < n; ++i) ccs[dst + i] = (struct VgaTextCharCell){' ', attr};
|
||||
for (i = 0; i < n; ++i)
|
||||
ccs[dst + i] = (struct VgaTextCharCell){' ', attr};
|
||||
}
|
||||
|
||||
void _TtyEraseLineCells(struct Tty *tty, size_t dsty, size_t dstx, size_t n) {
|
||||
|
@ -423,7 +435,8 @@ void _TtyMoveLineCells(struct Tty *tty, size_t dsty, size_t dstx, size_t srcy,
|
|||
size_t xn = Xn(tty);
|
||||
size_t dst = dsty * xn + dstx, src = srcy * xn + srcx;
|
||||
tty->movelinecells(tty, dsty, dstx, srcy, srcx, n);
|
||||
if (Wcs(tty)) wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n);
|
||||
if (Wcs(tty))
|
||||
wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n);
|
||||
}
|
||||
|
||||
void _TtyMoveLines(struct Tty *tty, size_t dsty, size_t srcy, size_t n) {
|
||||
|
@ -435,7 +448,8 @@ void _TtyMoveLines(struct Tty *tty, size_t dsty, size_t srcy, size_t n) {
|
|||
++srcy;
|
||||
}
|
||||
} else if (dsty > srcy) {
|
||||
while (n-- != 0) _TtyMoveLineCells(tty, dsty + n, 0, srcy + n, 0, xn);
|
||||
while (n-- != 0)
|
||||
_TtyMoveLineCells(tty, dsty + n, 0, srcy + n, 0, xn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,12 +534,14 @@ static void TtyAdvance(struct Tty *tty) {
|
|||
}
|
||||
|
||||
static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) {
|
||||
if (w < 1) wc = L' ', w = 1;
|
||||
if (w < 1)
|
||||
wc = L' ', w = 1;
|
||||
if ((tty->conf & kTtyRedzone) || tty->x + w > Xn(tty)) {
|
||||
TtyAdvance(tty);
|
||||
}
|
||||
tty->drawchar(tty, tty->y, tty->x, wc);
|
||||
if (Wcs(tty)) Wcs(tty)[tty->y * Xn(tty) + tty->x] = wc;
|
||||
if (Wcs(tty))
|
||||
Wcs(tty)[tty->y * Xn(tty) + tty->x] = wc;
|
||||
if ((tty->x += w) >= Xn(tty)) {
|
||||
tty->x = Xn(tty) - 1;
|
||||
tty->conf |= kTtyRedzone;
|
||||
|
@ -556,14 +572,17 @@ static void TtyWriteTab(struct Tty *tty) {
|
|||
|
||||
int TtyAtoi(const char *s, const char **e) {
|
||||
int i;
|
||||
for (i = 0; isdigit(*s); ++s) i *= 10, i += *s - '0';
|
||||
if (e) *e = s;
|
||||
for (i = 0; isdigit(*s); ++s)
|
||||
i *= 10, i += *s - '0';
|
||||
if (e)
|
||||
*e = s;
|
||||
return i;
|
||||
}
|
||||
|
||||
static int TtyGetMoveParam(struct Tty *tty) {
|
||||
int x = TtyAtoi(tty->esc.s, NULL);
|
||||
if (x < 1) x = 1;
|
||||
if (x < 1)
|
||||
x = 1;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
@ -571,7 +590,8 @@ static void TtySetCursorPosition(struct Tty *tty) {
|
|||
int row, col;
|
||||
const char *s = tty->esc.s;
|
||||
row = max(1, TtyAtoi(s, &s));
|
||||
if (*s == ';') ++s;
|
||||
if (*s == ';')
|
||||
++s;
|
||||
col = max(1, TtyAtoi(s, &s));
|
||||
_TtySetY(tty, row - 1);
|
||||
_TtySetX(tty, col - 1);
|
||||
|
@ -593,12 +613,14 @@ static void TtyMoveCursor(struct Tty *tty, int dy, int dx) {
|
|||
|
||||
static void TtyScrollUp(struct Tty *tty) {
|
||||
int n = TtyGetMoveParam(tty);
|
||||
while (n--) TtyScroll(tty);
|
||||
while (n--)
|
||||
TtyScroll(tty);
|
||||
}
|
||||
|
||||
static void TtyScrollDown(struct Tty *tty) {
|
||||
int n = TtyGetMoveParam(tty);
|
||||
while (n--) TtyReverse(tty);
|
||||
while (n--)
|
||||
TtyReverse(tty);
|
||||
}
|
||||
|
||||
static void TtySetCursorStatus(struct Tty *tty, bool status) {
|
||||
|
@ -1110,8 +1132,10 @@ static void TtyCsi(struct Tty *tty) {
|
|||
static void TtyScreenAlignmentDisplay(struct Tty *tty) {
|
||||
size_t yn = Yn(tty), xn = Xn(tty), y, x;
|
||||
for (y = 0; y < yn; ++y)
|
||||
for (x = 0; x < xn; ++x) tty->drawchar(tty, y, x, 'E');
|
||||
if (Wcs(tty)) wmemset(Wcs(tty), L'E', yn * xn);
|
||||
for (x = 0; x < xn; ++x)
|
||||
tty->drawchar(tty, y, x, 'E');
|
||||
if (Wcs(tty))
|
||||
wmemset(Wcs(tty), L'E', yn * xn);
|
||||
}
|
||||
|
||||
static void TtyEscHash(struct Tty *tty) {
|
||||
|
@ -1212,7 +1236,8 @@ static void TtyUpdate(struct Tty *tty) {
|
|||
if (tty->type == PC_VIDEO_TEXT) {
|
||||
unsigned char start = tty->yc - 2, end = tty->yc - 1;
|
||||
unsigned short pos = tty->y * Xn(tty) + tty->x;
|
||||
if ((tty->conf & kTtyNocursor)) start |= 1 << 5;
|
||||
if ((tty->conf & kTtyNocursor))
|
||||
start |= 1 << 5;
|
||||
outb(CRTPORT, 0x0A);
|
||||
outb(CRTPORT + 1, start);
|
||||
outb(CRTPORT, 0x0B);
|
||||
|
@ -1251,7 +1276,8 @@ ssize_t _TtyWrite(struct Tty *tty, const void *data, size_t n) {
|
|||
case kTtyUtf8:
|
||||
if (ThomPikeCont(p[i])) {
|
||||
tty->u8 = ThomPikeMerge(tty->u8, p[i]);
|
||||
if (--tty->n8) break;
|
||||
if (--tty->n8)
|
||||
break;
|
||||
}
|
||||
wc = tty->u8;
|
||||
if ((0x00 <= wc && wc <= 0x1F) || (0x7F <= wc && wc <= 0x9F)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue