aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-08 15:49:53 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-08 15:49:53 -0700
commit5daf8d56cdf6aecd1b7301c622c3e35eaa47bd42 (patch)
treeb7e4fffef25795dbebacb2bb65a7648c6bdd299a /sys/cmd
parentede65127cb813cd1efc8c8237c69c4308a761b33 (diff)
checkin: looking at curses API surface area
Diffstat (limited to 'sys/cmd')
-rw-r--r--sys/cmd/dvtm/LICENSE1
-rw-r--r--sys/cmd/dvtm/dvtm.c126
-rw-r--r--sys/cmd/dvtm/dvtm.h52
-rw-r--r--sys/cmd/dvtm/hook.c2
-rw-r--r--sys/cmd/dvtm/vt.c416
-rw-r--r--sys/cmd/dvtm/vt.h87
6 files changed, 379 insertions, 305 deletions
diff --git a/sys/cmd/dvtm/LICENSE b/sys/cmd/dvtm/LICENSE
index 7873302..8afe5bf 100644
--- a/sys/cmd/dvtm/LICENSE
+++ b/sys/cmd/dvtm/LICENSE
@@ -2,6 +2,7 @@ MIT/X Consortium License
(c) 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
(c) 2007-2016 Marc André Tanner <mat at brain-dump dot org>
+ (c) 2020-???? Nicholas Noll <nbnoll at eml dot cc>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
diff --git a/sys/cmd/dvtm/dvtm.c b/sys/cmd/dvtm/dvtm.c
index a2ba03b..802f891 100644
--- a/sys/cmd/dvtm/dvtm.c
+++ b/sys/cmd/dvtm/dvtm.c
@@ -2,19 +2,21 @@
/* global variables */
uint waw, wah, wax, way;
-Client *clients = NULL;
+Client *clients = nil;
char *title;
const char *dvtm_name = "dvtm";
Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY };
-static Client *stack = NULL;
-static Client *sel = NULL;
-static Client *lastsel = NULL;
-static Client *msel = NULL;
+static Client *stack = nil;
+static Client *sel = nil;
+static Client *lastsel = nil;
+static Client *msel = nil;
+
static uint seltags;
static uint tagset[2] = { 1, 1 };
static bool mouse_events_enabled = ENABLE_MOUSE;
static Layout *layout = layouts;
+
static StatusBar bar = { .fd = -1, .lastpos = BAR_POS, .pos = BAR_POS, .autohide = BAR_AUTOHIDE, .h = 1 };
static CmdFifo cmdfifo = { .fd = -1 };
static const char *shell;
@@ -235,7 +237,7 @@ draw(Client *c) {
static void
draw_all(void) {
if (!nextvisible(clients)) {
- sel = NULL;
+ sel = nil;
curs_set(0);
erase();
drawbar();
@@ -287,7 +289,7 @@ arrange(void) {
}
wah++;
}
- focus(NULL);
+ focus(nil);
wnoutrefresh(stdscr);
drawbar();
draw_all();
@@ -298,7 +300,7 @@ attach(Client *c) {
if (clients)
clients->prev = c;
c->next = clients;
- c->prev = NULL;
+ c->prev = nil;
clients = c;
for (int o = 1; c; c = nextvisible(c->next), o++)
c->order = o;
@@ -340,7 +342,7 @@ detach(Client *c) {
}
if (c == clients)
clients = c->next;
- c->next = c->prev = NULL;
+ c->next = c->prev = nil;
}
static void
@@ -483,7 +485,7 @@ static
Client*
get_client_by_coord(uint x, unsigned int y) {
if (y < way || y >= way+wah)
- return NULL;
+ return nil;
if (isarrange(fullscreen))
return sel;
for (Client *c = nextvisible(clients); c; c = nextvisible(c->next)) {
@@ -492,7 +494,7 @@ get_client_by_coord(uint x, unsigned int y) {
return c;
}
}
- return NULL;
+ return nil;
}
static
@@ -575,7 +577,7 @@ keybinding(KeyCombo keys, uint keycount)
return &bindings[b];
}
}
- return NULL;
+ return nil;
}
static
@@ -599,8 +601,8 @@ tagschanged() {
}
}
if (allminimized && nextvisible(clients)) {
- focus(NULL);
- toggleminimize(NULL);
+ focus(nil);
+ toggleminimize(nil);
}
arrange();
}
@@ -726,13 +728,13 @@ mouse_setup(void) {
for (uint i = 0; i < arrlen(buttons); i++)
mask |= buttons[i].mask;
}
- mousemask(mask, NULL);
+ mousemask(mask, nil);
#endif /* CONFIG_MOUSE */
}
static bool
checkshell(const char *shell) {
- if (shell == NULL || *shell == '\0' || *shell != '/')
+ if (shell == nil || *shell == '\0' || *shell != '/')
return false;
if (!strcmp(strrchr(shell, '/')+1, dvtm_name))
return false;
@@ -781,41 +783,41 @@ setup(void) {
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigwinch_handler;
- sigaction(SIGWINCH, &sa, NULL);
+ sigaction(SIGWINCH, &sa, nil);
sa.sa_handler = sigchld_handler;
- sigaction(SIGCHLD, &sa, NULL);
+ sigaction(SIGCHLD, &sa, nil);
sa.sa_handler = sigterm_handler;
- sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGTERM, &sa, nil);
sa.sa_handler = SIG_IGN;
- sigaction(SIGPIPE, &sa, NULL);
+ sigaction(SIGPIPE, &sa, nil);
}
static void
destroy(Client *c) {
if (sel == c)
- focusnextnm(NULL);
+ focusnextnm(nil);
detach(c);
detachstack(c);
if (sel == c) {
Client *next = nextvisible(clients);
if (next) {
focus(next);
- toggleminimize(NULL);
+ toggleminimize(nil);
} else {
- sel = NULL;
+ sel = nil;
}
}
if (lastsel == c)
- lastsel = NULL;
+ lastsel = nil;
werase(c->window);
wnoutrefresh(c->window);
vt_destroy(c->term);
delwin(c->window);
if (!clients && arrlen(actions)) {
if (!strcmp(c->cmd, shell))
- quit(NULL);
+ quit(nil);
else
- create(NULL);
+ create(nil);
}
free(c);
arrange();
@@ -840,26 +842,26 @@ cleanup(void) {
static char *getcwd_by_pid(Client *c) {
if (!c)
- return NULL;
+ return nil;
char buf[32];
snprintf(buf, sizeof buf, "/proc/%d/cwd", c->pid);
- return realpath(buf, NULL);
+ return realpath(buf, nil);
}
void
create(const char *args[])
{
- const char *pargs[4] = { shell, NULL };
- char buf[8], *cwd = NULL;
+ const char *pargs[4] = { shell, nil };
+ char buf[8], *cwd = nil;
const char *env[] = {
"DVTM_WINDOW_ID", buf,
- NULL
+ nil
};
if (args && args[0]) {
pargs[1] = "-c";
pargs[2] = args[0];
- pargs[3] = NULL;
+ pargs[3] = nil;
}
Client *c = calloc(1, sizeof(Client));
if (!c)
@@ -896,7 +898,7 @@ create(const char *args[])
if (args && args[2])
cwd = !strcmp(args[2], "$CWD") ? getcwd_by_pid(sel) : (char*)args[2];
- c->pid = vt_forkpty(c->term, shell, pargs, cwd, env, NULL, NULL);
+ c->pid = vt_forkpty(c->term, shell, pargs, cwd, env, nil, nil);
if (args && args[2] && !strcmp(args[2], "$CWD"))
free(cwd);
vt_data_set(c->term, c);
@@ -917,31 +919,31 @@ copymode(const char *args[])
if (!args || !args[0] || !sel || sel->editor)
return;
- bool colored = strstr(args[0], "pager") != NULL;
+ bool colored = strstr(args[0], "pager") != nil;
if (!(sel->editor = vt_create(sel->h - sel->has_title_line, sel->w, 0)))
return;
int *to = &sel->editor_fds[0];
- int *from = strstr(args[0], "editor") ? &sel->editor_fds[1] : NULL;
+ int *from = strstr(args[0], "editor") ? &sel->editor_fds[1] : nil;
sel->editor_fds[0] = sel->editor_fds[1] = -1;
- const char *argv[3] = { args[0], NULL, NULL };
+ const char *argv[3] = { args[0], nil, nil };
char argline[32];
int line = vt_content_start(sel->app);
snprintf(argline, sizeof(argline), "+%d", line);
argv[1] = argline;
- if (vt_forkpty(sel->editor, args[0], argv, NULL, NULL, to, from) < 0) {
+ if (vt_forkpty(sel->editor, args[0], argv, nil, nil, to, from) < 0) {
vt_destroy(sel->editor);
- sel->editor = NULL;
+ sel->editor = nil;
return;
}
sel->term = sel->editor;
if (sel->editor_fds[0] != -1) {
- char *buf = NULL;
+ char *buf = nil;
size_t len = vt_content_get(sel->app, &buf, colored);
char *cur = buf;
while (len > 0) {
@@ -970,7 +972,7 @@ focusn(const char *args[])
if (c->order == atoi(args[0])) {
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
return;
}
}
@@ -987,7 +989,7 @@ focusid(const char *args[])
if (c->id == win_id) {
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
if (!isvisible(c)) {
c->tags |= tagset[seltags];
tagschanged();
@@ -1196,7 +1198,7 @@ incnmaster(const char *args[])
if (isarrange(fullscreen) || isarrange(grid))
return;
/* arg handling, manipulate nmaster */
- if (args[0] == NULL) {
+ if (args[0] == nil) {
screen.nmaster = NMASTER;
} else if (sscanf(args[0], "%d", &delta) == 1) {
if (args[0][0] == '+' || args[0][0] == '-')
@@ -1217,7 +1219,7 @@ setmfact(const char *args[])
if (isarrange(fullscreen) || isarrange(grid))
return;
/* arg handling, manipulate mfact */
- if (args[0] == NULL) {
+ if (args[0] == nil) {
screen.mfact = MFACT;
} else if (sscanf(args[0], "%f", &delta) == 1) {
if (args[0][0] == '+' || args[0][0] == '-')
@@ -1248,7 +1250,7 @@ togglebar(const char *args[])
hidebar();
bar.autohide = false;
updatebarpos();
- redraw(NULL);
+ redraw(nil);
}
void
@@ -1263,7 +1265,7 @@ togglebarpos(const char *args[])
break;
}
updatebarpos();
- redraw(NULL);
+ redraw(nil);
}
void
@@ -1295,7 +1297,7 @@ toggleminimize(const char *args[])
} else if (m->minimized) {
/* non master window got minimized move it above all other
* minimized ones */
- focusnextnm(NULL);
+ focusnextnm(nil);
detach(m);
for (c = nextvisible(clients); c && (t = nextvisible(c->next)) && !t->minimized; c = t);
attachafter(m, c);
@@ -1338,7 +1340,7 @@ zoom(const char *args[])
attach(c);
focus(c);
if (c->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
arrange();
}
@@ -1348,28 +1350,28 @@ mouse_focus(const char *args[])
{
focus(msel);
if (msel->minimized)
- toggleminimize(NULL);
+ toggleminimize(nil);
}
void
mouse_fullscreen(const char *args[])
{
- mouse_focus(NULL);
- setlayout(isarrange(fullscreen) ? NULL : args);
+ mouse_focus(nil);
+ setlayout(isarrange(fullscreen) ? nil : args);
}
void
mouse_minimize(const char *args[])
{
focus(msel);
- toggleminimize(NULL);
+ toggleminimize(nil);
}
void
mouse_zoom(const char *args[])
{
focus(msel);
- zoom(NULL);
+ zoom(nil);
}
static
@@ -1379,7 +1381,7 @@ get_cmd_by_name(const char *name) {
if (!strcmp(name, commands[i].name))
return &commands[i];
}
- return NULL;
+ return nil;
}
static
@@ -1403,7 +1405,7 @@ handle_cmdfifo(void) {
for (s = p; *p && *p != ' ' && *p != '\n'; p++);
if ((c = *p))
*p++ = '\0';
- if (*s && (cmd = get_cmd_by_name(s)) != NULL) {
+ if (*s && (cmd = get_cmd_by_name(s)) != nil) {
bool quote = false;
int argc = 0;
const char *args[MAX_ARGS], *arg;
@@ -1499,7 +1501,7 @@ handle_mouse(void) {
buttons[i].action.cmd(buttons[i].action.args);
}
- msel = NULL;
+ msel = nil;
#endif /* CONFIG_MOUSE */
}
@@ -1553,7 +1555,7 @@ handle_editor(Client *c) {
c->editor_died = false;
c->editor_fds[1] = -1;
vt_destroy(c->editor);
- c->editor = NULL;
+ c->editor = nil;
c->term = c->app;
vt_dirty(c->term);
draw_content(c);
@@ -1603,7 +1605,7 @@ parse_args(int argc, char *argv[]) {
set_escdelay(100);
for (int arg = 1; arg < argc; arg++) {
if (argv[arg][0] != '-') {
- const char *args[] = { argv[arg], NULL, NULL };
+ const char *args[] = { argv[arg], nil, nil };
if (!init) {
setup();
init = true;
@@ -1649,7 +1651,7 @@ parse_args(int argc, char *argv[]) {
case 'c': {
const char *fifo;
cmdfifo.fd = open_or_create_fifo(argv[++arg], &cmdfifo.file);
- if (!(fifo = realpath(argv[arg], NULL)))
+ if (!(fifo = realpath(argv[arg], nil)))
fatal("%s\n", strerror(errno));
setenv("DVTM_CMD_FIFO", fifo, 1);
break;
@@ -1671,14 +1673,14 @@ main(int argc, char *argv[]) {
setenv("DVTM", VERSION, 1);
if (!parse_args(argc, argv)) {
setup();
- startup(NULL);
+ startup(nil);
}
sigemptyset(&emptyset);
sigemptyset(&blockset);
sigaddset(&blockset, SIGWINCH);
sigaddset(&blockset, SIGCHLD);
- sigprocmask(SIG_BLOCK, &blockset, NULL);
+ sigprocmask(SIG_BLOCK, &blockset, nil);
while (running) {
int r, nfds = 0;
@@ -1718,7 +1720,7 @@ main(int argc, char *argv[]) {
}
doupdate();
- r = pselect(nfds + 1, &rd, NULL, NULL, NULL, &emptyset);
+ r = pselect(nfds + 1, &rd, nil, nil, nil, &emptyset);
if (r < 0) {
if (errno == EINTR)
@@ -1731,7 +1733,7 @@ main(int argc, char *argv[]) {
int code = getch();
if (code >= 0) {
keys[key_index++] = code;
- KeyBinding *binding = NULL;
+ KeyBinding *binding = nil;
if (code == KEY_MOUSE) {
key_index = 0;
handle_mouse();
diff --git a/sys/cmd/dvtm/dvtm.h b/sys/cmd/dvtm/dvtm.h
index 18669fb..c36cb87 100644
--- a/sys/cmd/dvtm/dvtm.h
+++ b/sys/cmd/dvtm/dvtm.h
@@ -1,44 +1,18 @@
+ /* See LICENSE for details. */
#pragma once
-
-/*
- * The initial "port" of dwm to curses was done by
- *
- * © 2007-2016 Marc André Tanner <mat at brain-dump dot org>
- * © 2020-???? Nicholas Noll <nbnoll at eml.cc>
- *
- * It is highly inspired by the original X11 dwm and
- * reuses some code of it which is mostly
- *
- * © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
- *
- * See LICENSE for details.
- */
-
#include <u.h>
+#include <libn.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <wchar.h>
-#include <limits.h>
+#include <locale.h>
#include <libgen.h>
+
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <fcntl.h>
-#include <curses.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <locale.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <errno.h>
-#include <pwd.h>
+
#include <termios.h>
#include "vt.h"
@@ -48,12 +22,12 @@ int ESCDELAY;
#endif
#ifndef NCURSES_REENTRANT
-# define set_escdelay(d) (ESCDELAY = (d))
+#define set_escdelay(d) (ESCDELAY = (d))
#endif
typedef struct {
float mfact;
- unsigned int nmaster;
+ uint nmaster;
int history;
int w;
int h;
@@ -88,7 +62,7 @@ struct Client {
Client *next;
Client *prev;
Client *snext;
- unsigned int tags;
+ uint tags;
};
typedef struct {
@@ -106,11 +80,13 @@ typedef struct {
} ColorRule;
#define ALT(k) ((k) + (161 - 'a'))
+
#if defined CTRL && defined _AIX
- #undef CTRL
+#undef CTRL
#endif
+
#ifndef CTRL
- #define CTRL(k) ((k) & 0x1F)
+#define CTRL(k) ((k) & 0x1F)
#endif
#define CTRL_ALT(k) ((k) + (129 - 'a'))
@@ -123,7 +99,7 @@ typedef struct {
#define MAX_KEYS 3
-typedef unsigned int KeyCombo[MAX_KEYS];
+typedef uint KeyCombo[MAX_KEYS];
typedef struct {
KeyCombo keys;
@@ -228,7 +204,7 @@ void focus(Client *c);
void resize(Client *c, int x, int y, int w, int h);
extern Screen screen;
-extern unsigned int waw, wah, wax, way;
+extern uint waw, wah, wax, way;
extern Client *clients;
extern char *title;
diff --git a/sys/cmd/dvtm/hook.c b/sys/cmd/dvtm/hook.c
index da3946c..6865f87 100644
--- a/sys/cmd/dvtm/hook.c
+++ b/sys/cmd/dvtm/hook.c
@@ -316,7 +316,7 @@ bstack(void)
}
}
-/* A vertical stack layout, all windows have the full screen width. */
+/* a vertical stack layout, all windows have the full screen width. */
void
vstack(void)
{
diff --git a/sys/cmd/dvtm/vt.c b/sys/cmd/dvtm/vt.c
index 916b8b4..c48a84f 100644
--- a/sys/cmd/dvtm/vt.c
+++ b/sys/cmd/dvtm/vt.c
@@ -1,20 +1,6 @@
-/*
- * Copyright © 2004 Bruno T. C. de Oliveira
- * Copyright © 2006 Pierre Habouzit
- * Copyright © 2008-2016 Marc André Tanner
- *
- * Permission to use, copy, modify, and 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 MIND, 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.
- */
+/* See license for details */
+#include <u.h>
+
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
@@ -32,6 +18,7 @@
#include <sys/types.h>
#include <termios.h>
#include <wchar.h>
+
#if defined(__linux__) || defined(__CYGWIN__)
# include <pty.h>
#elif defined(__FreeBSD__) || defined(__DragonFly__)
@@ -48,20 +35,24 @@
#ifndef NCURSES_ACS
# ifdef PDCURSES
-# define NCURSES_ACS(c) (acs_map[(unsigned char)(c)])
+# define NCURSES_ACS(c) (acs_map[(uchar)(c)])
# else /* BSD curses */
-# define NCURSES_ACS(c) (_acs_map[(unsigned char)(c)])
+# define NCURSES_ACS(c) (_acs_map[(uchar)(c)])
# endif
#endif
#ifdef NCURSES_VERSION
-# ifndef NCURSES_EXT_COLORS
-# define NCURSES_EXT_COLORS 0
-# endif
-# if !NCURSES_EXT_COLORS
-# define MAX_COLOR_PAIRS MIN(COLOR_PAIRS, 256)
-# endif
+
+#ifndef NCURSES_EXT_COLORS
+# define NCURSES_EXT_COLORS 0
+#endif
+
+#if !NCURSES_EXT_COLORS
+# define MAX_COLOR_PAIRS MIN(COLOR_PAIRS, 256)
#endif
+
+#endif
+
#ifndef MAX_COLOR_PAIRS
# define MAX_COLOR_PAIRS COLOR_PAIRS
#endif
@@ -74,8 +65,6 @@
#endif
#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#define LENGTH(arr) (sizeof(arr) / sizeof((arr)[0]))
static bool is_utf8, has_default_colors;
static short color_pairs_reserved, color_pairs_max, color_pair_current;
@@ -91,7 +80,7 @@ typedef struct {
typedef struct {
Cell *cells;
- unsigned dirty:1;
+ uint dirty:1;
} Row;
/* Buffer holding the current terminal window content (as an array) as well
@@ -168,21 +157,21 @@ struct Vt {
int pty; /* master side pty file descriptor */
pid_t pid; /* process id of the process running in this vt */
/* flags */
- unsigned seen_input:1;
- unsigned insert:1;
- unsigned escaped:1;
- unsigned curshid:1;
- unsigned curskeymode:1;
- unsigned bell:1;
- unsigned relposmode:1;
- unsigned mousetrack:1;
- unsigned graphmode:1;
- unsigned savgraphmode:1;
+ uint seen_input:1;
+ uint insert:1;
+ uint escaped:1;
+ uint curshid:1;
+ uint curskeymode:1;
+ uint bell:1;
+ uint relposmode:1;
+ uint mousetrack:1;
+ uint graphmode:1;
+ uint savgraphmode:1;
bool charsets[2];
/* buffers and parsing state */
char rbuf[BUFSIZ];
char ebuf[BUFSIZ];
- unsigned int rlen, elen;
+ uint rlen, elen;
int srow, scol; /* last known offset to display start row, start column */
char title[256]; /* xterm style window title */
vt_title_handler_t title_handler; /* hook which is called when title changes */
@@ -249,14 +238,17 @@ static void puttab(Vt *t, int count);
static void process_nonprinting(Vt *t, wchar_t wc);
static void send_curs(Vt *t);
-__attribute__ ((const))
-static attr_t build_attrs(attr_t curattrs)
+const static
+attr_t
+build_attrs(attr_t curattrs)
{
return ((curattrs & ~A_COLOR) | COLOR_PAIR(curattrs & 0xff))
>> NCURSES_ATTR_SHIFT;
}
-static void row_set(Row *row, int start, int len, Buffer *t)
+static
+void
+row_set(Row *row, int start, int len, Buffer *t)
{
Cell cell = {
.text = L'\0',
@@ -270,7 +262,9 @@ static void row_set(Row *row, int start, int len, Buffer *t)
row->dirty = true;
}
-static void row_roll(Row *start, Row *end, int count)
+static
+void
+row_roll(Row *start, Row *end, int count)
{
int n = end - start;
@@ -288,7 +282,9 @@ static void row_roll(Row *start, Row *end, int count)
}
}
-static void buffer_clear(Buffer *b)
+static
+void
+buffer_clear(Buffer *b)
{
Cell cell = {
.text = L'\0',
@@ -306,7 +302,9 @@ static void buffer_clear(Buffer *b)
}
}
-static void buffer_free(Buffer *b)
+static
+void
+buffer_free(Buffer *b)
{
for (int i = 0; i < b->rows; i++)
free(b->lines[i].cells);
@@ -317,7 +315,9 @@ static void buffer_free(Buffer *b)
free(b->tabs);
}
-static void buffer_scroll(Buffer *b, int s)
+static
+void
+buffer_scroll(Buffer *b, int s)
{
/* work in screenfuls */
int ssz = b->scroll_bot - b->scroll_top;
@@ -362,7 +362,9 @@ static void buffer_scroll(Buffer *b, int s)
}
}
-static void buffer_resize(Buffer *b, int rows, int cols)
+static
+void
+buffer_resize(Buffer *b, int rows, int cols)
{
Row *lines = b->lines;
@@ -383,14 +385,14 @@ static void buffer_resize(Buffer *b, int rows, int cols)
for (int row = 0; row < b->rows; row++) {
lines[row].cells = realloc(lines[row].cells, sizeof(Cell) * cols);
if (b->cols < cols)
- row_set(lines + row, b->cols, cols - b->cols, NULL);
+ row_set(lines + row, b->cols, cols - b->cols, nil);
lines[row].dirty = true;
}
Row *sbuf = b->scroll_buf;
for (int row = 0; row < b->scroll_size; row++) {
sbuf[row].cells = realloc(sbuf[row].cells, sizeof(Cell) * cols);
if (b->cols < cols)
- row_set(sbuf + row, b->cols, cols - b->cols, NULL);
+ row_set(sbuf + row, b->cols, cols - b->cols, nil);
}
b->tabs = realloc(b->tabs, sizeof(*b->tabs) * cols);
for (int col = b->cols; col < cols; col++)
@@ -431,7 +433,9 @@ static void buffer_resize(Buffer *b, int rows, int cols)
}
}
-static bool buffer_init(Buffer *b, int rows, int cols, int scroll_size)
+static
+bool
+buffer_init(Buffer *b, int rows, int cols, int scroll_size)
{
b->curattrs = A_NORMAL; /* white text over black background */
b->curfg = b->curbg = -1;
@@ -444,15 +448,18 @@ static bool buffer_init(Buffer *b, int rows, int cols, int scroll_size)
return true;
}
-static void buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae) {
+static
+void
+buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae)
+{
if (bs)
- *bs = NULL;
+ *bs = nil;
if (be)
- *be = NULL;
+ *be = nil;
if (as)
- *as = NULL;
+ *as = nil;
if (ae)
- *ae = NULL;
+ *ae = nil;
if (!b->scroll_size)
return;
@@ -470,29 +477,35 @@ static void buffer_boundry(Buffer *b, Row **bs, Row **be, Row **as, Row **ae) {
}
}
-static Row *buffer_row_first(Buffer *b) {
+static
+Row *
+buffer_row_first(Buffer *b) {
Row *bstart;
if (!b->scroll_size || !b->scroll_above)
return b->lines;
- buffer_boundry(b, &bstart, NULL, NULL, NULL);
+ buffer_boundry(b, &bstart, nil, nil, nil);
return bstart;
}
-static Row *buffer_row_last(Buffer *b) {
+static
+Row *
+buffer_row_last(Buffer *b) {
Row *aend;
if (!b->scroll_size || !b->scroll_below)
return b->lines + b->rows - 1;
- buffer_boundry(b, NULL, NULL, NULL, &aend);
+ buffer_boundry(b, nil, nil, nil, &aend);
return aend;
}
-static Row *buffer_row_next(Buffer *b, Row *row)
+static
+Row *
+buffer_row_next(Buffer *b, Row *row)
{
Row *before_start, *before_end, *after_start, *after_end;
Row *first = b->lines, *last = b->lines + b->rows - 1;
if (!row)
- return NULL;
+ return nil;
buffer_boundry(b, &before_start, &before_end, &after_start, &after_end);
@@ -503,19 +516,21 @@ static Row *buffer_row_next(Buffer *b, Row *row)
if (row == before_end)
return first;
if (row == after_end)
- return NULL;
+ return nil;
if (row == &b->scroll_buf[b->scroll_size - 1])
return b->scroll_buf;
return ++row;
}
-static Row *buffer_row_prev(Buffer *b, Row *row)
+static
+Row *
+buffer_row_prev(Buffer *b, Row *row)
{
Row *before_start, *before_end, *after_start, *after_end;
Row *first = b->lines, *last = b->lines + b->rows - 1;
if (!row)
- return NULL;
+ return nil;
buffer_boundry(b, &before_start, &before_end, &after_start, &after_end);
@@ -524,7 +539,7 @@ static Row *buffer_row_prev(Buffer *b, Row *row)
if (row == first)
return before_end;
if (row == before_start)
- return NULL;
+ return nil;
if (row == after_start)
return last;
if (row == b->scroll_buf)
@@ -532,7 +547,9 @@ static Row *buffer_row_prev(Buffer *b, Row *row)
return --row;
}
-static void cursor_clamp(Vt *t)
+static
+void
+cursor_clamp(Vt *t)
{
Buffer *b = t->buffer;
Row *lines = t->relposmode ? b->scroll_top : b->lines;
@@ -548,10 +565,12 @@ static void cursor_clamp(Vt *t)
b->curs_col = b->cols - 1;
}
-static void cursor_line_down(Vt *t)
+static
+void
+cursor_line_down(Vt *t)
{
Buffer *b = t->buffer;
- row_set(b->curs_row, b->cols, b->maxcols - b->cols, NULL);
+ row_set(b->curs_row, b->cols, b->maxcols - b->cols, nil);
b->curs_row++;
if (b->curs_row < b->scroll_bot)
return;
@@ -563,14 +582,18 @@ static void cursor_line_down(Vt *t)
row_set(b->curs_row, 0, b->cols, b);
}
-static void cursor_save(Vt *t)
+static
+void
+cursor_save(Vt *t)
{
Buffer *b = t->buffer;
b->curs_srow = b->curs_row - b->lines;
b->curs_scol = b->curs_col;
}
-static void cursor_restore(Vt *t)
+static
+void
+cursor_restore(Vt *t)
{
Buffer *b = t->buffer;
b->curs_row = b->lines + b->curs_srow;
@@ -578,7 +601,9 @@ static void cursor_restore(Vt *t)
cursor_clamp(t);
}
-static void attributes_save(Vt *t)
+static
+void
+attributes_save(Vt *t)
{
Buffer *b = t->buffer;
b->savattrs = b->curattrs;
@@ -587,7 +612,9 @@ static void attributes_save(Vt *t)
t->savgraphmode = t->graphmode;
}
-static void attributes_restore(Vt *t)
+static
+void
+attributes_restore(Vt *t)
{
Buffer *b = t->buffer;
b->curattrs = b->savattrs;
@@ -596,21 +623,27 @@ static void attributes_restore(Vt *t)
t->graphmode = t->savgraphmode;
}
-static void new_escape_sequence(Vt *t)
+static
+void
+new_escape_sequence(Vt *t)
{
t->escaped = true;
t->elen = 0;
t->ebuf[0] = '\0';
}
-static void cancel_escape_sequence(Vt *t)
+static
+void
+cancel_escape_sequence(Vt *t)
{
t->escaped = false;
t->elen = 0;
t->ebuf[0] = '\0';
}
-static bool is_valid_csi_ender(int c)
+static
+bool
+is_valid_csi_ender(int c)
{
return (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
@@ -618,7 +651,9 @@ static bool is_valid_csi_ender(int c)
}
/* interprets a 'set attribute' (SGR) CSI escape sequence */
-static void interpret_csi_sgr(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_sgr(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
if (pcount == 0) {
@@ -714,7 +749,9 @@ static void interpret_csi_sgr(Vt *t, int param[], int pcount)
}
/* interprets an 'erase display' (ED) escape sequence */
-static void interpret_csi_ed(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_ed(Vt *t, int param[], int pcount)
{
Row *row, *start, *end;
Buffer *b = t->buffer;
@@ -743,7 +780,9 @@ static void interpret_csi_ed(Vt *t, int param[], int pcount)
}
/* interprets a 'move cursor' (CUP) escape sequence */
-static void interpret_csi_cup(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_cup(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
Row *lines = t->relposmode ? b->scroll_top : b->lines;
@@ -764,7 +803,9 @@ static void interpret_csi_cup(Vt *t, int param[], int pcount)
/* Interpret the 'relative mode' sequences: CUU, CUD, CUF, CUB, CNL,
* CPL, CHA, HPR, VPA, VPR, HPA */
-static void interpret_csi_c(Vt *t, char verb, int param[], int pcount)
+static
+void
+interpret_csi_c(Vt *t, char verb, int param[], int pcount)
{
Buffer *b = t->buffer;
int n = (pcount && param[0] > 0) ? param[0] : 1;
@@ -805,7 +846,9 @@ static void interpret_csi_c(Vt *t, char verb, int param[], int pcount)
}
/* Interpret the 'erase line' escape sequence */
-static void interpret_csi_el(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_el(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
switch (pcount ? param[0] : 0) {
@@ -822,7 +865,9 @@ static void interpret_csi_el(Vt *t, int param[], int pcount)
}
/* Interpret the 'insert blanks' sequence (ICH) */
-static void interpret_csi_ich(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_ich(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
Row *row = b->curs_row;
@@ -838,7 +883,9 @@ static void interpret_csi_ich(Vt *t, int param[], int pcount)
}
/* Interpret the 'delete chars' sequence (DCH) */
-static void interpret_csi_dch(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_dch(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
Row *row = b->curs_row;
@@ -854,7 +901,9 @@ static void interpret_csi_dch(Vt *t, int param[], int pcount)
}
/* Interpret an 'insert line' sequence (IL) */
-static void interpret_csi_il(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_il(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
int n = (pcount && param[0] > 0) ? param[0] : 1;
@@ -870,7 +919,9 @@ static void interpret_csi_il(Vt *t, int param[], int pcount)
}
/* Interpret a 'delete line' sequence (DL) */
-static void interpret_csi_dl(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_dl(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
int n = (pcount && param[0] > 0) ? param[0] : 1;
@@ -886,7 +937,9 @@ static void interpret_csi_dl(Vt *t, int param[], int pcount)
}
/* Interpret an 'erase characters' (ECH) sequence */
-static void interpret_csi_ech(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_ech(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
int n = (pcount && param[0] > 0) ? param[0] : 1;
@@ -898,7 +951,9 @@ static void interpret_csi_ech(Vt *t, int param[], int pcount)
}
/* Interpret a 'set scrolling region' (DECSTBM) sequence */
-static void interpret_csi_decstbm(Vt *t, int param[], int pcount)
+static
+void
+interpret_csi_decstbm(Vt *t, int param[], int pcount)
{
Buffer *b = t->buffer;
int new_top, new_bot;
@@ -935,7 +990,9 @@ static void interpret_csi_decstbm(Vt *t, int param[], int pcount)
b->curs_col = 0;
}
-static void interpret_csi_mode(Vt *t, int param[], int pcount, bool set)
+static
+void
+interpret_csi_mode(Vt *t, int param[], int pcount, bool set)
{
for (int i = 0; i < pcount; i++) {
switch (param[i]) {
@@ -946,7 +1003,9 @@ static void interpret_csi_mode(Vt *t, int param[], int pcount, bool set)
}
}
-static void interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set)
+static
+void
+interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set)
{
for (int i = 0; i < pcount; i++) {
switch (param[i]) {
@@ -982,11 +1041,13 @@ static void interpret_csi_priv_mode(Vt *t, int param[], int pcount, bool set)
}
}
-static void interpret_csi(Vt *t)
+static
+void
+interpret_csi(Vt *t)
{
Buffer *b = t->buffer;
int csiparam[16];
- unsigned int param_count = 0;
+ uint param_count = 0;
const char *p = t->ebuf + 1;
char verb = t->ebuf[t->elen - 1];
@@ -995,10 +1056,10 @@ static void interpret_csi(Vt *t)
if (IS_CONTROL(*p)) {
process_nonprinting(t, *p);
} else if (*p == ';') {
- if (param_count >= LENGTH(csiparam))
+ if (param_count >= arrlen(csiparam))
return; /* too long! */
csiparam[param_count++] = 0;
- } else if (isdigit((unsigned char)*p)) {
+ } else if (isdigit((uchar)*p)) {
if (param_count == 0)
csiparam[param_count++] = 0;
csiparam[param_count - 1] *= 10;
@@ -1101,7 +1162,9 @@ static void interpret_csi(Vt *t)
}
/* Interpret an 'index' (IND) sequence */
-static void interpret_csi_ind(Vt *t)
+static
+void
+interpret_csi_ind(Vt *t)
{
Buffer *b = t->buffer;
if (b->curs_row < b->lines + b->rows - 1)
@@ -1109,7 +1172,9 @@ static void interpret_csi_ind(Vt *t)
}
/* Interpret a 'reverse index' (RI) sequence */
-static void interpret_csi_ri(Vt *t)
+static
+void
+interpret_csi_ri(Vt *t)
{
Buffer *b = t->buffer;
if (b->curs_row > b->scroll_top)
@@ -1121,7 +1186,9 @@ static void interpret_csi_ri(Vt *t)
}
/* Interpret a 'next line' (NEL) sequence */
-static void interpret_csi_nel(Vt *t)
+static
+void
+interpret_csi_nel(Vt *t)
{
Buffer *b = t->buffer;
if (b->curs_row < b->lines + b->rows - 1) {
@@ -1131,7 +1198,9 @@ static void interpret_csi_nel(Vt *t)
}
/* Interpret a 'select character set' (SCS) sequence */
-static void interpret_csi_scs(Vt *t)
+static
+void
+interpret_csi_scs(Vt *t)
{
/* ESC ( sets G0, ESC ) sets G1 */
t->charsets[!!(t->ebuf[0] == ')')] = (t->ebuf[1] == '0');
@@ -1139,13 +1208,15 @@ static void interpret_csi_scs(Vt *t)
}
/* Interpret an 'operating system command' (OSC) sequence */
-static void interpret_osc(Vt *t)
+static
+void
+interpret_osc(Vt *t)
{
/* ESC ] command ; data BEL
* ESC ] command ; data ESC \\
* Note that BEL or ESC \\ have already been replaced with NUL.
*/
- char *data = NULL;
+ char *data = nil;
int command = strtoul(t->ebuf + 1, &data, 10);
if (data && *data == ';') {
switch (command) {
@@ -1165,7 +1236,9 @@ static void interpret_osc(Vt *t)
}
}
-static void try_interpret_escape_seq(Vt *t)
+static
+void
+try_interpret_escape_seq(Vt *t)
{
char lastchar = t->ebuf[t->elen - 1];
@@ -1232,7 +1305,7 @@ static void try_interpret_escape_seq(Vt *t)
cancel:
#ifndef NDEBUG
fprintf(stderr, "cancelled: \\033");
- for (unsigned int i = 0; i < t->elen; i++) {
+ for (uint i = 0; i < t->elen; i++) {
if (isprint(t->ebuf[i])) {
fputc(t->ebuf[i], stderr);
} else {
@@ -1246,7 +1319,9 @@ handled:
}
}
-static void puttab(Vt *t, int count)
+static
+void
+puttab(Vt *t, int count)
{
Buffer *b = t->buffer;
int direction = count >= 0 ? 1 : -1;
@@ -1266,7 +1341,9 @@ static void puttab(Vt *t, int count)
}
}
-static void process_nonprinting(Vt *t, wchar_t wc)
+static
+void
+process_nonprinting(Vt *t, wchar_t wc)
{
Buffer *b = t->buffer;
switch (wc) {
@@ -1301,7 +1378,9 @@ static void process_nonprinting(Vt *t, wchar_t wc)
}
}
-static void is_utf8_locale(void)
+static
+void
+is_utf8_locale(void)
{
const char *cset = nl_langinfo(CODESET);
if (!cset)
@@ -1309,7 +1388,9 @@ static void is_utf8_locale(void)
is_utf8 = !strcmp(cset, "UTF-8");
}
-static wchar_t get_vt100_graphic(char c)
+static
+wchar_t
+get_vt100_graphic(char c)
{
static char vt100_acs[] = "`afgjklmnopqrstuvwxyz{|}~";
@@ -1335,7 +1416,9 @@ static wchar_t get_vt100_graphic(char c)
return '\0';
}
-static void put_wc(Vt *t, wchar_t wc)
+static
+void
+put_wc(Vt *t, wchar_t wc)
{
int width = 0;
@@ -1392,10 +1475,11 @@ static void put_wc(Vt *t, wchar_t wc)
}
}
-int vt_process(Vt *t)
+int
+vt_process(Vt *t)
{
int res;
- unsigned int pos = 0;
+ uint pos = 0;
mbstate_t ps;
memset(&ps, 0, sizeof(ps));
@@ -1434,21 +1518,23 @@ int vt_process(Vt *t)
return 0;
}
-void vt_default_colors_set(Vt *t, attr_t attrs, short fg, short bg)
+void
+vt_default_colors_set(Vt *t, attr_t attrs, short fg, short bg)
{
t->defattrs = attrs;
t->deffg = fg;
t->defbg = bg;
}
-Vt *vt_create(int rows, int cols, int scroll_size)
+Vt *
+vt_create(int rows, int cols, int scroll_size)
{
if (rows <= 0 || cols <= 0)
- return NULL;
+ return nil;
Vt *t = calloc(1, sizeof(Vt));
if (!t)
- return NULL;
+ return nil;
t->pty = -1;
t->deffg = t->defbg = -1;
@@ -1457,13 +1543,14 @@ Vt *vt_create(int rows, int cols, int scroll_size)
if (!buffer_init(&t->buffer_normal, rows, cols, scroll_size) ||
!buffer_init(&t->buffer_alternate, rows, cols, 0)) {
free(t);
- return NULL;
+ return nil;
}
return t;
}
-void vt_resize(Vt *t, int rows, int cols)
+void
+vt_resize(Vt *t, int rows, int cols)
{
struct winsize ws = { .ws_row = rows, .ws_col = cols };
@@ -1478,7 +1565,8 @@ void vt_resize(Vt *t, int rows, int cols)
kill(-t->pid, SIGWINCH);
}
-void vt_destroy(Vt *t)
+void
+vt_destroy(Vt *t)
{
if (!t)
return;
@@ -1488,14 +1576,16 @@ void vt_destroy(Vt *t)
free(t);
}
-void vt_dirty(Vt *t)
+void
+vt_dirty(Vt *t)
{
Buffer *b = t->buffer;
for (Row *row = b->lines, *end = row + b->rows; row < end; row++)
row->dirty = true;
}
-void vt_draw(Vt *t, WINDOW *win, int srow, int scol)
+void
+vt_draw(Vt *t, WINDOW *win, int srow, int scol)
{
Buffer *b = t->buffer;
@@ -1512,7 +1602,7 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol)
continue;
wmove(win, srow + i, scol);
- Cell *cell = NULL;
+ Cell *cell = nil;
for (int j = 0; j < b->cols; j++) {
Cell *prev_cell = cell;
cell = row->cells + j;
@@ -1526,12 +1616,12 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol)
if (cell->bg == -1)
cell->bg = t->defbg;
wattrset(win, cell->attr << NCURSES_ATTR_SHIFT);
- wcolor_set(win, vt_color_get(t, cell->fg, cell->bg), NULL);
+ wcolor_set(win, vt_color_get(t, cell->fg, cell->bg), nil);
}
if (is_utf8 && cell->text >= 128) {
char buf[MB_CUR_MAX + 1];
- size_t len = wcrtomb(buf, cell->text, NULL);
+ size_t len = wcrtomb(buf, cell->text, nil);
if (len > 0) {
waddnstr(win, buf, len);
if (wcwidth(cell->text) > 1)
@@ -1554,7 +1644,8 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol)
wmove(win, srow + b->curs_row - b->lines, scol + b->curs_col);
}
-void vt_scroll(Vt *t, int rows)
+void
+vt_scroll(Vt *t, int rows)
{
Buffer *b = t->buffer;
if (!b->scroll_size)
@@ -1570,14 +1661,16 @@ void vt_scroll(Vt *t, int rows)
b->scroll_below -= rows;
}
-void vt_noscroll(Vt *t)
+void
+vt_noscroll(Vt *t)
{
int scroll_below = t->buffer->scroll_below;
if (scroll_below)
vt_scroll(t, scroll_below);
}
-pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from)
+pid_t
+vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from)
{
int vt2ed[2], ed2vt[2];
struct winsize ws;
@@ -1587,14 +1680,14 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons
if (to && pipe(vt2ed)) {
*to = -1;
- to = NULL;
+ to = nil;
}
if (from && pipe(ed2vt)) {
*from = -1;
- from = NULL;
+ from = nil;
}
- pid_t pid = forkpty(&t->pty, NULL, NULL, &ws);
+ pid_t pid = forkpty(&t->pty, nil, nil, &ws);
if (pid < 0)
return -1;
@@ -1603,7 +1696,7 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons
sigset_t emptyset;
sigemptyset(&emptyset);
- sigprocmask(SIG_SETMASK, &emptyset, NULL);
+ sigprocmask(SIG_SETMASK, &emptyset, nil);
if (to) {
close(vt2ed[1]);
@@ -1647,12 +1740,14 @@ pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, cons
return t->pid = pid;
}
-int vt_pty_get(Vt *t)
+int
+vt_pty_get(Vt *t)
{
return t->pty;
}
-ssize_t vt_write(Vt *t, const char *buf, size_t len)
+ssize_t
+vt_write(Vt *t, const char *buf, size_t len)
{
ssize_t ret = len;
@@ -1670,7 +1765,9 @@ ssize_t vt_write(Vt *t, const char *buf, size_t len)
return ret;
}
-static void send_curs(Vt *t)
+static
+void
+send_curs(Vt *t)
{
Buffer *b = t->buffer;
char keyseq[16];
@@ -1678,7 +1775,8 @@ static void send_curs(Vt *t)
vt_write(t, keyseq, strlen(keyseq));
}
-void vt_keypress(Vt *t, int keycode)
+void
+vt_keypress(Vt *t, int keycode)
{
vt_noscroll(t);
@@ -1705,7 +1803,8 @@ void vt_keypress(Vt *t, int keycode)
}
}
-void vt_mouse(Vt *t, int x, int y, mmask_t mask)
+void
+vt_mouse(Vt *t, int x, int y, mmask_t mask)
{
#ifdef NCURSES_MOUSE_VERSION
char seq[6] = { '\e', '[', 'M' }, state = 0, button = 0;
@@ -1744,7 +1843,9 @@ void vt_mouse(Vt *t, int x, int y, mmask_t mask)
#endif /* NCURSES_MOUSE_VERSION */
}
-static unsigned int color_hash(short fg, short bg)
+static
+uint
+color_hash(short fg, short bg)
{
if (fg == -1)
fg = COLORS;
@@ -1753,7 +1854,8 @@ static unsigned int color_hash(short fg, short bg)
return fg * (COLORS + 2) + bg;
}
-short vt_color_get(Vt *t, short fg, short bg)
+short
+vt_color_get(Vt *t, short fg, short bg)
{
if (fg >= COLORS)
fg = (t ? t->deffg : default_fg);
@@ -1769,14 +1871,14 @@ short vt_color_get(Vt *t, short fg, short bg)
if (!color2palette || (fg == -1 && bg == -1))
return 0;
- unsigned int index = color_hash(fg, bg);
+ uint index = color_hash(fg, bg);
if (color2palette[index] == 0) {
short oldfg, oldbg;
for (;;) {
if (++color_pair_current >= color_pairs_max)
color_pair_current = color_pairs_reserved + 1;
pair_content(color_pair_current, &oldfg, &oldbg);
- unsigned int old_index = color_hash(oldfg, oldbg);
+ uint old_index = color_hash(oldfg, oldbg);
if (color2palette[old_index] >= 0) {
if (init_pair(color_pair_current, fg, bg) == OK) {
color2palette[old_index] = 0;
@@ -1791,7 +1893,8 @@ short vt_color_get(Vt *t, short fg, short bg)
return color_pair >= 0 ? color_pair : -color_pair;
}
-short vt_color_reserve(short fg, short bg)
+short
+vt_color_reserve(short fg, short bg)
{
if (!color2palette || fg >= COLORS || bg >= COLORS)
return 0;
@@ -1801,7 +1904,7 @@ short vt_color_reserve(short fg, short bg)
bg = default_bg;
if (fg == -1 && bg == -1)
return 0;
- unsigned int index = color_hash(fg, bg);
+ uint index = color_hash(fg, bg);
if (color2palette[index] >= 0) {
if (init_pair(color_pairs_reserved + 1, fg, bg) == OK)
color2palette[index] = -(++color_pairs_reserved);
@@ -1810,7 +1913,9 @@ short vt_color_reserve(short fg, short bg)
return color_pair >= 0 ? color_pair : -color_pair;
}
-static void init_colors(void)
+static
+void
+init_colors(void)
{
pair_content(0, &default_fg, &default_bg);
if (default_fg == -1)
@@ -1832,7 +1937,8 @@ static void init_colors(void)
vt_color_reserve(COLOR_WHITE, COLOR_BLACK);
}
-void vt_init(void)
+void
+vt_init(void)
{
init_colors();
is_utf8_locale();
@@ -1842,7 +1948,8 @@ void vt_init(void)
snprintf(vt_term, sizeof vt_term, "%s%s", term, COLORS >= 256 ? "-256color" : "");
}
-void vt_keytable_set(const char * const keytable_overlay[], int count)
+void
+vt_keytable_set(const char * const keytable_overlay[], int count)
{
for (int k = 0; k < count && k < KEY_MAX; k++) {
const char *keyseq = keytable_overlay[k];
@@ -1851,42 +1958,50 @@ void vt_keytable_set(const char * const keytable_overlay[], int count)
}
}
-void vt_shutdown(void)
+void
+vt_shutdown(void)
{
free(color2palette);
}
-void vt_title_handler_set(Vt *t, vt_title_handler_t handler)
+void
+vt_title_handler_set(Vt *t, vt_title_handler_t handler)
{
t->title_handler = handler;
}
-void vt_urgent_handler_set(Vt *t, vt_urgent_handler_t handler)
+void
+vt_urgent_handler_set(Vt *t, vt_urgent_handler_t handler)
{
t->urgent_handler = handler;
}
-void vt_data_set(Vt *t, void *data)
+void
+vt_data_set(Vt *t, void *data)
{
t->data = data;
}
-void *vt_data_get(Vt *t)
+void *
+vt_data_get(Vt *t)
{
return t->data;
}
-bool vt_cursor_visible(Vt *t)
+bool
+vt_cursor_visible(Vt *t)
{
return t->buffer->scroll_below ? false : !t->curshid;
}
-pid_t vt_pid_get(Vt *t)
+pid_t
+vt_pid_get(Vt *t)
{
return t->pid;
}
-size_t vt_content_get(Vt *t, char **buf, bool colored)
+size_t
+vt_content_get(Vt *t, char **buf, bool colored)
{
Buffer *b = t->buffer;
int lines = b->scroll_above + b->scroll_below + b->rows + 1;
@@ -1898,7 +2013,7 @@ size_t vt_content_get(Vt *t, char **buf, bool colored)
return 0;
char *s = *buf;
- Cell *prev_cell = NULL;
+ Cell *prev_cell = nil;
for (Row *row = buffer_row_first(b); row; row = buffer_row_next(b, row)) {
size_t len = 0;
@@ -1956,7 +2071,8 @@ size_t vt_content_get(Vt *t, char **buf, bool colored)
return s - *buf;
}
-int vt_content_start(Vt *t)
+int
+vt_content_start(Vt *t)
{
return t->buffer->scroll_above;
}
diff --git a/sys/cmd/dvtm/vt.h b/sys/cmd/dvtm/vt.h
index dbc9c8e..3b738f6 100644
--- a/sys/cmd/dvtm/vt.h
+++ b/sys/cmd/dvtm/vt.h
@@ -1,25 +1,6 @@
-/*
- * Copyright © 2004 Bruno T. C. de Oliveira
- * Copyright © 2006 Pierre Habouzit
- * Copyright © 2008-2013 Marc André Tanner
- * Copyright © 2020-20?? Nicholas Noll
- *
- * Permission to use, copy, modify, and 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 MIND, 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.
- */
-#ifndef VT_H
-#define VT_H
+/* see LICENSE for details */
+#pragma once
-#include <curses.h>
#include <stdbool.h>
#include <sys/types.h>
@@ -31,37 +12,35 @@ typedef struct Vt Vt;
typedef void (*vt_title_handler_t)(Vt*, const char *title);
typedef void (*vt_urgent_handler_t)(Vt*);
-void vt_init(void);
-void vt_shutdown(void);
-
-void vt_keytable_set(char const * const keytable_overlay[], int count);
-void vt_default_colors_set(Vt*, attr_t attrs, short fg, short bg);
-void vt_title_handler_set(Vt*, vt_title_handler_t);
-void vt_urgent_handler_set(Vt*, vt_urgent_handler_t);
-void vt_data_set(Vt*, void *);
-void *vt_data_get(Vt*);
-
-Vt *vt_create(int rows, int cols, int scroll_buf_sz);
-void vt_resize(Vt*, int rows, int cols);
-void vt_destroy(Vt*);
-pid_t vt_forkpty(Vt*, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from);
-int vt_pty_get(Vt*);
-bool vt_cursor_visible(Vt*);
-
-int vt_process(Vt *);
-void vt_keypress(Vt *, int keycode);
+void vt_init(void);
+void vt_shutdown(void);
+
+void vt_keytable_set(char const * const keytable_overlay[], int count);
+void vt_default_colors_set(Vt*, attr_t attrs, short fg, short bg);
+void vt_title_handler_set(Vt*, vt_title_handler_t);
+void vt_urgent_handler_set(Vt*, vt_urgent_handler_t);
+void vt_data_set(Vt*, void *);
+void *vt_data_get(Vt*);
+
+Vt *vt_create(int rows, int cols, int scroll_buf_sz);
+void vt_resize(Vt*, int rows, int cols);
+void vt_destroy(Vt*);
+pid_t vt_forkpty(Vt*, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from);
+int vt_pty_get(Vt*);
+bool vt_cursor_visible(Vt*);
+
+int vt_process(Vt *);
+void vt_keypress(Vt *, int keycode);
ssize_t vt_write(Vt*, const char *buf, size_t len);
-void vt_mouse(Vt*, int x, int y, mmask_t mask);
-void vt_dirty(Vt*);
-void vt_draw(Vt*, WINDOW *win, int startrow, int startcol);
-short vt_color_get(Vt*, short fg, short bg);
-short vt_color_reserve(short fg, short bg);
-
-void vt_scroll(Vt*, int rows);
-void vt_noscroll(Vt*);
-
-pid_t vt_pid_get(Vt*);
-size_t vt_content_get(Vt*, char **s, bool colored);
-int vt_content_start(Vt*);
-
-#endif /* VT_H */
+void vt_mouse(Vt*, int x, int y, mmask_t mask);
+void vt_dirty(Vt*);
+void vt_draw(Vt*, WINDOW *win, int startrow, int startcol);
+short vt_color_get(Vt*, short fg, short bg);
+short vt_color_reserve(short fg, short bg);
+
+void vt_scroll(Vt*, int rows);
+void vt_noscroll(Vt*);
+
+pid_t vt_pid_get(Vt*);
+size_t vt_content_get(Vt*, char **s, bool colored);
+int vt_content_start(Vt*);