diff --git a/.clang-format b/.clang-format index 76f9685..baf8e54 100644 --- a/.clang-format +++ b/.clang-format @@ -111,7 +111,7 @@ PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right +PointerAlignment: Left ReflowComments: true SortIncludes: true SortUsingDeclarations: true diff --git a/src/arg.h b/src/arg.h index 9fa5d83..3c88eb9 100644 --- a/src/arg.h +++ b/src/arg.h @@ -6,14 +6,14 @@ #ifndef ARG_H #define ARG_H -extern char *argv0; +extern char* argv0; /* use main(int argc, char *argv[]) */ #define ARGBEGIN \ for (argv0 = *argv, argv++, argc--; \ argv[0] && argv[0][0] == '-' && argv[0][1]; argc--, argv++) { \ char argc_; \ - char **argv_; \ + char** argv_; \ int brk_; \ if (argv[0][1] == '-' && argv[0][2] == '\0') { \ argv++; \ @@ -35,13 +35,13 @@ extern char *argv0; #define EARGF(x) \ ((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \ - ? ((x), abort(), (char *)0) \ + ? ((x), abort(), (char*)0) \ : (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \ : (argc--, argv++, argv[0]))) #define ARGF() \ ((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \ - ? (char *)0 \ + ? (char*)0 \ : (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \ : (argc--, argv++, argv[0]))) diff --git a/src/config.def.h b/src/config.def.h index d66625c..e732dec 100644 --- a/src/config.def.h +++ b/src/config.def.h @@ -5,7 +5,7 @@ * * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html */ -static char *font = +static char* font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; static int borderpx = 2; @@ -17,14 +17,14 @@ static int borderpx = 2; * 4: value of shell in /etc/passwd * 5: value of shell in config.h */ -static char *shell = "/bin/sh"; -char * utmp = NULL; +static char* shell = "/bin/sh"; +char* utmp = NULL; /* scroll program: to enable use a string like "scroll" */ -char *scroll = NULL; -char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; +char* scroll = NULL; +char* stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; /* identification sequence returned in DA and DECID */ -char *vtiden = "\033[?6c"; +char* vtiden = "\033[?6c"; /* Kerning / character bounding-box multipliers */ static float cwscale = 1.0; @@ -35,7 +35,7 @@ static float chscale = 1.0; * * More advanced example: L" `'\"()[]{}" */ -wchar_t *worddelimiters = L" "; +wchar_t* worddelimiters = L" "; /* selection timeouts (in milliseconds) */ static unsigned int doubleclicktimeout = 300; @@ -75,7 +75,7 @@ static unsigned int cursorthickness = 2; static int bellvolume = 0; /* default TERM value */ -char *termname = "st-256color"; +char* termname = "st-256color"; /* * spaces per tab @@ -95,7 +95,7 @@ char *termname = "st-256color"; unsigned int tabspaces = 8; /* Terminal colors (16 first used in escape sequence) */ -static const char *colorname[] = { +static const char* colorname[] = { /* 8 normal colors */ "black", "red3", diff --git a/src/config.h b/src/config.h index d66625c..e732dec 100644 --- a/src/config.h +++ b/src/config.h @@ -5,7 +5,7 @@ * * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html */ -static char *font = +static char* font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; static int borderpx = 2; @@ -17,14 +17,14 @@ static int borderpx = 2; * 4: value of shell in /etc/passwd * 5: value of shell in config.h */ -static char *shell = "/bin/sh"; -char * utmp = NULL; +static char* shell = "/bin/sh"; +char* utmp = NULL; /* scroll program: to enable use a string like "scroll" */ -char *scroll = NULL; -char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; +char* scroll = NULL; +char* stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; /* identification sequence returned in DA and DECID */ -char *vtiden = "\033[?6c"; +char* vtiden = "\033[?6c"; /* Kerning / character bounding-box multipliers */ static float cwscale = 1.0; @@ -35,7 +35,7 @@ static float chscale = 1.0; * * More advanced example: L" `'\"()[]{}" */ -wchar_t *worddelimiters = L" "; +wchar_t* worddelimiters = L" "; /* selection timeouts (in milliseconds) */ static unsigned int doubleclicktimeout = 300; @@ -75,7 +75,7 @@ static unsigned int cursorthickness = 2; static int bellvolume = 0; /* default TERM value */ -char *termname = "st-256color"; +char* termname = "st-256color"; /* * spaces per tab @@ -95,7 +95,7 @@ char *termname = "st-256color"; unsigned int tabspaces = 8; /* Terminal colors (16 first used in escape sequence) */ -static const char *colorname[] = { +static const char* colorname[] = { /* 8 normal colors */ "black", "red3", diff --git a/src/st/selection.h b/src/st/selection.h index 97cdbe3..c361d69 100644 --- a/src/st/selection.h +++ b/src/st/selection.h @@ -27,7 +27,7 @@ void selinit(void); void selstart(int, int, int); void selnormalize(); void selscroll(int, int); -void selsnap(int *, int *, int); +void selsnap(int*, int*, int); void selclear(void); // Global variable for now diff --git a/src/st/st.c b/src/st/st.c index 6c169cf..687f888 100644 --- a/src/st/st.c +++ b/src/st/st.c @@ -93,9 +93,9 @@ typedef struct { typedef struct { int row; /* nb row */ int col; /* nb col */ - Line * line; /* screen */ - Line * alt; /* alternate screen */ - int * dirty; /* dirtyness of lines */ + Line* line; /* screen */ + Line* alt; /* alternate screen */ + int* dirty; /* dirtyness of lines */ TCursor c; /* cursor */ int ocx; /* old cursor col */ int ocy; /* old cursor row */ @@ -106,7 +106,7 @@ typedef struct { char trantbl[4]; /* charset table translation */ int charset; /* current charset */ int icharset; /* selected charset for sequence */ - int * tabs; + int* tabs; Rune lastc; /* last printed char outside of sequence, 0 if control */ } Term; @@ -125,17 +125,17 @@ typedef struct { /* ESC type [[ [] [;]] ] ESC '\' */ typedef struct { char type; /* ESC type ... */ - char * buf; /* allocated raw string */ + char* buf; /* allocated raw string */ size_t siz; /* allocation size */ size_t len; /* raw string length */ - char * args[STR_ARG_SIZ]; + char* args[STR_ARG_SIZ]; int narg; /* nb of args */ } STREscape; -static void execsh(char *, char **); -static void stty(char **); +static void execsh(char*, char**); +static void stty(char**); static void sigchld(int); -static void ttywriteraw(const char *, size_t); +static void ttywriteraw(const char*, size_t); static void csidump(void); static void csihandle(void); @@ -147,7 +147,7 @@ static void strhandle(void); static void strparse(void); static void strreset(void); -static void tprinter(char *, size_t); +static void tprinter(char*, size_t); static void tdumpsel(void); static void tdumpline(int); static void tdump(void); @@ -166,27 +166,27 @@ static void tputc(Rune); static void treset(void); static void tscrollup(int, int); static void tscrolldown(int, int); -static void tsetattr(int *, int); -static void tsetchar(Rune, Glyph *, int, int); +static void tsetattr(int*, int); +static void tsetchar(Rune, Glyph*, int, int); static void tsetdirt(int, int); static void tsetscroll(int, int); static void tswapscreen(void); -static void tsetmode(int, int, int *, int); -static int twrite(const char *, int, int); +static void tsetmode(int, int, int*, int); +static int twrite(const char*, int, int); static void tfulldirt(void); static void tcontrolcode(uchar); static void tdectest(char); static void tdefutf8(char); -static int32_t tdefcolor(int *, int *, int); +static int32_t tdefcolor(int*, int*, int); static void tdeftran(char); static void tstrsequence(uchar); static void drawregion(int, int, int, int); -static char *base64dec(const char *); -static char base64dec_getc(const char **); +static char* base64dec(const char*); +static char base64dec_getc(const char**); -static ssize_t xwrite(int, const char *, size_t); +static ssize_t xwrite(int, const char*, size_t); /* Globals */ static Term term; @@ -206,7 +206,7 @@ static pid_t pid; * @return p_nbytes if the write was successful, otherwise return negative * error value of write */ -ssize_t xwrite(int p_file_desc, const char *p_str, size_t p_nbytes) { +ssize_t xwrite(int p_file_desc, const char* p_str, size_t p_nbytes) { size_t aux = p_nbytes; ssize_t result; @@ -230,8 +230,8 @@ ssize_t xwrite(int p_file_desc, const char *p_str, size_t p_nbytes) { * @param p_len bytes to allocate * @return pointer to allocated memory */ -void *safe_malloc(size_t p_len) { - void *ptr; +void* safe_malloc(size_t p_len) { + void* ptr; if (!(ptr = malloc(p_len))) die("malloc: %s\n", strerror(errno)); @@ -246,7 +246,7 @@ void *safe_malloc(size_t p_len) { * @param p_len bytes to re-allocate * @return pointer to re-allocated memory */ -void *safe_realloc(void *p_ptr, size_t p_len) { +void* safe_realloc(void* p_ptr, size_t p_len) { if ((p_ptr = realloc(p_ptr, p_len)) == NULL) die("realloc: %s\n", strerror(errno)); @@ -259,7 +259,7 @@ void *safe_realloc(void *p_ptr, size_t p_len) { * @param p_str string to copy * @return pointer to copy of original string */ -char *safe_strdup(char *p_str) { +char* safe_strdup(char* p_str) { if ((p_str = strdup(p_str)) == NULL) die("strdup: %s\n", strerror(errno)); @@ -282,13 +282,13 @@ static const char base64_digits[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -char base64dec_getc(const char **src) { +char base64dec_getc(const char** src) { while (**src && !isprint(**src)) (*src)++; return **src ? *((*src)++) : '='; /* emulate padding if string ends */ } -char *base64dec(const char *src) { +char* base64dec(const char* src) { size_t in_len = strlen(src); char * result, *dst; @@ -386,7 +386,7 @@ int selected(int x, int y) { (y != sel.ne.y || x <= sel.ne.x); } -void selsnap(int *x, int *y, int direction) { +void selsnap(int* x, int* y, int direction) { int newx, newy, xt, yt; int delim, prevdelim; Glyph *gp, *prevgp; @@ -455,7 +455,7 @@ void selsnap(int *x, int *y, int direction) { } } -char *getsel(void) { +char* getsel(void) { char * str, *ptr; int y, bufsize, lastx, linelen; Glyph *gp, *last; @@ -508,7 +508,7 @@ char *getsel(void) { return str; } -void die(const char *errstr, ...) { +void die(const char* errstr, ...) { va_list ap; va_start(ap, errstr); @@ -517,9 +517,9 @@ void die(const char *errstr, ...) { exit(1); } -void execsh(char *cmd, char **args) { +void execsh(char* cmd, char** args) { char * sh, *prog, *arg; - const struct passwd *pw; + const struct passwd* pw; errno = 0; if ((pw = getpwuid(getuid())) == NULL) { @@ -545,7 +545,7 @@ void execsh(char *cmd, char **args) { prog = sh; arg = NULL; } - DEFAULT(args, ((char *[]){prog, arg, NULL})); + DEFAULT(args, ((char*[]){prog, arg, NULL})); unsetenv("COLUMNS"); unsetenv("LINES"); @@ -584,7 +584,7 @@ void sigchld(int a) { _exit(0); } -void stty(char **args) { +void stty(char** args) { char cmd[_POSIX_ARG_MAX], **p, *q, *s; size_t n, siz; @@ -606,7 +606,7 @@ void stty(char **args) { perror("Couldn't call stty"); } -int ttynew(char *line, char *cmd, char *out, char **args) { +int ttynew(char* line, char* cmd, char* out, char** args) { int m, s; if (out) { @@ -686,8 +686,8 @@ size_t ttyread(void) { } } -void ttywrite(const char *s, size_t n, int may_echo) { - const char *next; +void ttywrite(const char* s, size_t n, int may_echo) { + const char* next; if (may_echo && IS_SET(MODE_ECHO)) twrite(s, n, 1); @@ -712,7 +712,7 @@ void ttywrite(const char *s, size_t n, int may_echo) { } } -void ttywriteraw(const char *s, size_t n) { +void ttywriteraw(const char* s, size_t n) { fd_set wfd, rfd; ssize_t r; size_t lim = 256; @@ -865,7 +865,7 @@ void tnew(int col, int row) { } void tswapscreen(void) { - Line *tmp = term.line; + Line* tmp = term.line; term.line = term.alt; term.alt = tmp; @@ -968,8 +968,8 @@ void tmoveto(int x, int y) { term.c.y = LIMIT(y, miny, maxy); } -void tsetchar(Rune u, Glyph *attr, int x, int y) { - static char *vt100_0[62] = { +void tsetchar(Rune u, Glyph* attr, int x, int y) { + static char* vt100_0[62] = { /* 0x41 - 0x7e */ "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ @@ -1005,7 +1005,7 @@ void tsetchar(Rune u, Glyph *attr, int x, int y) { void tclearregion(int x1, int y1, int x2, int y2) { int x, y, temp; - Glyph *gp; + Glyph* gp; if (x1 > x2) temp = x1, x1 = x2, x2 = temp; @@ -1033,7 +1033,7 @@ void tclearregion(int x1, int y1, int x2, int y2) { void tdeletechar(int n) { int dst, src, size; - Glyph *line; + Glyph* line; LIMIT(n, 0, term.col - term.c.x); @@ -1048,7 +1048,7 @@ void tdeletechar(int n) { void tinsertblank(int n) { int dst, src, size; - Glyph *line; + Glyph* line; LIMIT(n, 0, term.col - term.c.x); @@ -1071,7 +1071,7 @@ void tdeleteline(int n) { tscrollup(term.c.y, n); } -int32_t tdefcolor(int *attr, int *npar, int l) { +int32_t tdefcolor(int* attr, int* npar, int l) { int32_t idx = -1; uint r, g, b; @@ -1117,7 +1117,7 @@ int32_t tdefcolor(int *attr, int *npar, int l) { return idx; } -void tsetattr(int *attr, int l) { +void tsetattr(int* attr, int l) { int i; int32_t idx; @@ -1224,7 +1224,7 @@ void tsetscroll(int t, int b) { term.bot = b; } -void tsetmode(int priv, int set, int *args, int narg) { +void tsetmode(int priv, int set, int* args, int narg) { int alt, *lim; for (lim = args + narg; args < lim; ++args) { @@ -1653,7 +1653,7 @@ void strhandle(void) { void strparse(void) { int c; - char *p = strescseq.buf; + char* p = strescseq.buf; strescseq.narg = 0; strescseq.buf[strescseq.len] = '\0'; @@ -1703,12 +1703,12 @@ void strreset(void) { }; } -void sendbreak(const Arg *arg) { +void sendbreak(const Arg* arg) { if (tcsendbreak(cmdfd, 0)) perror("Error sending break"); } -void tprinter(char *s, size_t len) { +void tprinter(char* s, size_t len) { if (iofd != -1 && xwrite(iofd, s, len) < 0) { perror("Error writing to output file"); close(iofd); @@ -1716,14 +1716,14 @@ void tprinter(char *s, size_t len) { } } -void toggleprinter(const Arg *arg) { term.mode ^= MODE_PRINT; } +void toggleprinter(const Arg* arg) { term.mode ^= MODE_PRINT; } -void printscreen(const Arg *arg) { tdump(); } +void printscreen(const Arg* arg) { tdump(); } -void printsel(const Arg *arg) { tdumpsel(); } +void printsel(const Arg* arg) { tdumpsel(); } void tdumpsel(void) { - char *ptr; + char* ptr; if ((ptr = getsel())) { tprinter(ptr, strlen(ptr)); @@ -1776,7 +1776,7 @@ void tdefutf8(char ascii) { void tdeftran(char ascii) { static char cs[] = "0B"; static int vcs[] = {CS_GRAPHIC0, CS_USA}; - char * p; + char* p; if ((p = strchr(cs, ascii)) == NULL) { fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii); @@ -2000,7 +2000,7 @@ void tputc(Rune u) { char c[UTF_SIZE]; int control; int width, len; - Glyph *gp; + Glyph* gp; control = ISCONTROL(u); if (u < 127 || !IS_SET(MODE_UTF8)) { @@ -2130,7 +2130,7 @@ check_control_code: } } -int twrite(const char *buf, int buflen, int show_ctrl) { +int twrite(const char* buf, int buflen, int show_ctrl) { int charsize; Rune u; int n; @@ -2164,7 +2164,7 @@ void tresize(int col, int row) { int i; int minrow = MIN(row, term.row); int mincol = MIN(col, term.col); - int * bp; + int* bp; TCursor c; if (col < 1 || row < 1) { diff --git a/src/st/st.h b/src/st/st.h index 0aaca49..6565285 100644 --- a/src/st/st.h +++ b/src/st/st.h @@ -34,34 +34,34 @@ typedef struct { uint32_t bg; /* background */ } Glyph; -typedef Glyph *Line; +typedef Glyph* Line; typedef union { int i; uint ui; float f; - const void *v; - const char *s; + const void* v; + const char* s; } Arg; -void die(const char *, ...); +void die(const char*, ...); void redraw(void); void draw(void); -void printscreen(const Arg *); -void printsel(const Arg *); -void sendbreak(const Arg *); -void toggleprinter(const Arg *); +void printscreen(const Arg*); +void printsel(const Arg*); +void sendbreak(const Arg*); +void toggleprinter(const Arg*); int tattrset(int); void tnew(int, int); void tresize(int, int); void tsetdirtattr(int); void ttyhangup(void); -int ttynew(char *, char *, char *, char **); +int ttynew(char*, char*, char*, char**); size_t ttyread(void); void ttyresize(int, int); -void ttywrite(const char *, size_t, int); +void ttywrite(const char*, size_t, int); void resettitle(void); @@ -70,23 +70,23 @@ void selinit(void); void selstart(int, int, int); void selextend(int, int, int, int); int selected(int, int); -char *getsel(void); +char* getsel(void); -size_t utf8encode(Rune, char *); +size_t utf8encode(Rune, char*); -void *safe_malloc(size_t); -void *safe_realloc(void *, size_t); -char *safe_strdup(char *); +void* safe_malloc(size_t); +void* safe_realloc(void*, size_t); +char* safe_strdup(char*); /* config.h globals */ -extern char * utmp; -extern char * scroll; -extern char * stty_args; -extern char * vtiden; -extern wchar_t * worddelimiters; +extern char* utmp; +extern char* scroll; +extern char* stty_args; +extern char* vtiden; +extern wchar_t* worddelimiters; extern int allowaltscreen; extern int allowwindowops; -extern char * termname; +extern char* termname; extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; diff --git a/src/st/utf8.c b/src/st/utf8.c index d517541..d1079cd 100644 --- a/src/st/utf8.c +++ b/src/st/utf8.c @@ -15,7 +15,7 @@ static Rune utfmax[UTF_SIZE + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; * @param p_char_len length of the char array * @return size of the decoded rune */ -size_t utf8decode(const char *p_char, Rune *p_rune, size_t p_char_len) { +size_t utf8decode(const char* p_char, Rune* p_rune, size_t p_char_len) { size_t decoded_len, type, i; Rune decoded_rune; @@ -50,7 +50,7 @@ size_t utf8decode(const char *p_char, Rune *p_rune, size_t p_char_len) { * @param p_i counter used in internal for loop * @return decoded rune */ -Rune utf8decodebyte(char p_char, size_t *p_i) { +Rune utf8decodebyte(char p_char, size_t* p_i) { for (*p_i = 0; *p_i < LEN(utfmask); ++(*p_i)) { if (((uchar)p_char & utfmask[*p_i]) == utfbyte[*p_i]) return (uchar)p_char & ~utfmask[*p_i]; @@ -66,7 +66,7 @@ Rune utf8decodebyte(char p_char, size_t *p_i) { * @param p_char char array to encode to * @return */ -size_t utf8encode(Rune p_rune, char *p_char) { +size_t utf8encode(Rune p_rune, char* p_char) { size_t len, i; len = utf8validate(&p_rune, 0); @@ -92,7 +92,7 @@ char utf8encodebyte(Rune u, size_t i) { * @param p_rune rune to validate * @param i */ -size_t utf8validate(Rune *p_rune, size_t i) { +size_t utf8validate(Rune* p_rune, size_t i) { if (!BETWEEN(*p_rune, utfmin[i], utfmax[i]) || BETWEEN(*p_rune, 0xD800, 0xDFFF)) *p_rune = UTF_INVALID; diff --git a/src/st/utf8.h b/src/st/utf8.h index d34c3b4..6ae0f17 100644 --- a/src/st/utf8.h +++ b/src/st/utf8.h @@ -9,9 +9,9 @@ typedef uint_least32_t Rune; -size_t utf8decode(const char *, Rune *, size_t); -Rune utf8decodebyte(char, size_t *); +size_t utf8decode(const char*, Rune*, size_t); +Rune utf8decodebyte(char, size_t*); char utf8encodebyte(Rune, size_t); -size_t utf8validate(Rune *, size_t); +size_t utf8validate(Rune*, size_t); #endif diff --git a/src/win.h b/src/win.h index 1e41bd6..ef984ac 100644 --- a/src/win.h +++ b/src/win.h @@ -34,13 +34,13 @@ void xdrawcursor(int, int, Glyph, int, int, Glyph); void xdrawline(Line, int, int, int); void xfinishdraw(void); void xloadcols(void); -int xsetcolorname(int, const char *); -void xseticontitle(char *); -void xsettitle(char *); +int xsetcolorname(int, const char*); +void xseticontitle(char*); +void xsettitle(char*); int xsetcursor(int); void xsetmode(int, unsigned int); void xsetpointermotion(int); -void xsetsel(char *); +void xsetsel(char*); int xstartdraw(void); void xximspot(int, int); diff --git a/src/x.c b/src/x.c index 07bcf22..d7feaa9 100644 --- a/src/x.c +++ b/src/x.c @@ -15,7 +15,7 @@ #include #include -char *argv0; +char* argv0; #include "arg.h" #include "st/macros.h" #include "st/st.h" @@ -25,14 +25,14 @@ char *argv0; typedef struct { uint mod; KeySym keysym; - void (*func)(const Arg *); + void (*func)(const Arg*); const Arg arg; } Shortcut; typedef struct { uint mod; uint button; - void (*func)(const Arg *); + void (*func)(const Arg*); const Arg arg; uint release; } MouseShortcut; @@ -40,7 +40,7 @@ typedef struct { typedef struct { KeySym k; uint mask; - char * s; + char* s; /* three-valued logic variables: 0 indifferent, 1 on, -1 off */ signed char appkey; /* application keypad */ signed char appcursor; /* application cursor */ @@ -52,14 +52,14 @@ typedef struct { #define XK_SWITCH_MOD (1 << 13) /* function definitions used in config.h */ -static void clipcopy(const Arg *); -static void clippaste(const Arg *); -static void numlock(const Arg *); -static void selpaste(const Arg *); -static void zoom(const Arg *); -static void zoomabs(const Arg *); -static void zoomreset(const Arg *); -static void ttysend(const Arg *); +static void clipcopy(const Arg*); +static void clippaste(const Arg*); +static void numlock(const Arg*); +static void selpaste(const Arg*); +static void zoom(const Arg*); +static void zoomabs(const Arg*); +static void zoomreset(const Arg*); +static void ttysend(const Arg*); /* config.h for applying patches and the configuration. */ #include "config.h" @@ -74,7 +74,7 @@ static void ttysend(const Arg *); #define TRUEGREEN(x) (((x)&0xff00)) #define TRUEBLUE(x) (((x)&0xff) << 8) -typedef XftDraw * Draw; +typedef XftDraw* Draw; typedef XftColor Color; typedef XftGlyphFontSpec GlyphFontSpec; @@ -89,11 +89,11 @@ typedef struct { } TermWindow; typedef struct { - Display * dpy; + Display* dpy; Colormap cmap; Window win; Drawable buf; - GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ + GlyphFontSpec* specbuf; /* font spec buffer used for rendering */ Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid; struct { XIM xim; @@ -102,7 +102,7 @@ typedef struct { XVaNestedList spotlist; } ime; Draw draw; - Visual * vis; + Visual* vis; XSetWindowAttributes attrs; int scr; int isfixed; /* is fixed geometry? */ @@ -128,71 +128,69 @@ typedef struct { int badweight; short lbearing; short rbearing; - XftFont * match; - FcFontSet *set; - FcPattern *pattern; + XftFont* match; + FcFontSet* set; + FcPattern* pattern; } Font; /* Drawing Context */ typedef struct { - Color *col; + Color* col; size_t collen; Font font, bfont, ifont, ibfont; GC gc; } DC; static inline ushort sixd_to_16bit(int); -static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, - int); -static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, - int); +static int xmakeglyphfontspecs(XftGlyphFontSpec*, const Glyph*, int, int, int); +static void xdrawglyphfontspecs(const XftGlyphFontSpec*, Glyph, int, int, int); static void xdrawglyph(Glyph, int, int); static void xclear(int, int, int, int); static int xgeommasktogravity(int); -static int ximopen(Display *); -static void ximinstantiate(Display *, XPointer, XPointer); +static int ximopen(Display*); +static void ximinstantiate(Display*, XPointer, XPointer); static void ximdestroy(XIM, XPointer, XPointer); static int xicdestroy(XIC, XPointer, XPointer); static void xinit(int, int); static void cresize(int, int); static void xresize(int, int); static void xhints(void); -static int xloadcolor(int, const char *, Color *); -static int xloadfont(Font *, FcPattern *); -static void xloadfonts(char *, double); -static void xunloadfont(Font *); +static int xloadcolor(int, const char*, Color*); +static int xloadfont(Font*, FcPattern*); +static void xloadfonts(char*, double); +static void xunloadfont(Font*); static void xunloadfonts(void); static void xsetenv(void); static void xseturgency(int); -static int evcol(XEvent *); -static int evrow(XEvent *); +static int evcol(XEvent*); +static int evrow(XEvent*); -static void expose(XEvent *); -static void visibility(XEvent *); -static void unmap(XEvent *); -static void kpress(XEvent *); -static void cmessage(XEvent *); -static void resize(XEvent *); -static void focus(XEvent *); +static void expose(XEvent*); +static void visibility(XEvent*); +static void unmap(XEvent*); +static void kpress(XEvent*); +static void cmessage(XEvent*); +static void resize(XEvent*); +static void focus(XEvent*); static uint buttonmask(uint); -static int mouseaction(XEvent *, uint); -static void brelease(XEvent *); -static void bpress(XEvent *); -static void bmotion(XEvent *); -static void propnotify(XEvent *); -static void selnotify(XEvent *); -static void selclear_(XEvent *); -static void selrequest(XEvent *); -static void setsel(char *, Time); -static void mousesel(XEvent *, int); -static void mousereport(XEvent *); -static char *kmap(KeySym, uint); +static int mouseaction(XEvent*, uint); +static void brelease(XEvent*); +static void bpress(XEvent*); +static void bmotion(XEvent*); +static void propnotify(XEvent*); +static void selnotify(XEvent*); +static void selclear_(XEvent*); +static void selrequest(XEvent*); +static void setsel(char*, Time); +static void mousesel(XEvent*, int); +static void mousereport(XEvent*); +static char* kmap(KeySym, uint); static int match(uint, uint); static void run(void); static void usage(void); -static void (*handler[LASTEvent])(XEvent *) = { +static void (*handler[LASTEvent])(XEvent*) = { [KeyPress] = kpress, [ClientMessage] = cmessage, [ConfigureNotify] = resize, @@ -228,31 +226,31 @@ static TermWindow win; enum { FRC_NORMAL, FRC_ITALIC, FRC_BOLD, FRC_ITALICBOLD }; typedef struct { - XftFont *font; + XftFont* font; int flags; Rune unicodep; } Fontcache; /* Fontcache is an array now. A new font will be appended to the array. */ -static Fontcache *frc = NULL; +static Fontcache* frc = NULL; static int frclen = 0; static int frccap = 0; -static char * usedfont = NULL; +static char* usedfont = NULL; static double usedfontsize = 0; static double defaultfontsize = 0; -static char * opt_class = NULL; -static char **opt_cmd = NULL; -static char * opt_embed = NULL; -static char * opt_font = NULL; -static char * opt_io = NULL; -static char * opt_line = NULL; -static char * opt_name = NULL; -static char * opt_title = NULL; +static char* opt_class = NULL; +static char** opt_cmd = NULL; +static char* opt_embed = NULL; +static char* opt_font = NULL; +static char* opt_io = NULL; +static char* opt_line = NULL; +static char* opt_name = NULL; +static char* opt_title = NULL; static int oldbutton = 3; /* button event on startup: 3 = release */ -void clipcopy(const Arg *dummy) { +void clipcopy(const Arg* dummy) { Atom clipboard; free(xsel.clipboard); @@ -265,7 +263,7 @@ void clipcopy(const Arg *dummy) { } } -void clippaste(const Arg *dummy) { +void clippaste(const Arg* dummy) { Atom clipboard; clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); @@ -273,21 +271,21 @@ void clippaste(const Arg *dummy) { CurrentTime); } -void selpaste(const Arg *dummy) { +void selpaste(const Arg* dummy) { XConvertSelection(xw.dpy, XA_PRIMARY, xsel.xtarget, XA_PRIMARY, xw.win, CurrentTime); } -void numlock(const Arg *dummy) { win.mode ^= MODE_NUMLOCK; } +void numlock(const Arg* dummy) { win.mode ^= MODE_NUMLOCK; } -void zoom(const Arg *arg) { +void zoom(const Arg* arg) { Arg larg; larg.f = usedfontsize + arg->f; zoomabs(&larg); } -void zoomabs(const Arg *arg) { +void zoomabs(const Arg* arg) { xunloadfonts(); xloadfonts(usedfont, arg->f); cresize(0, 0); @@ -295,7 +293,7 @@ void zoomabs(const Arg *arg) { xhints(); } -void zoomreset(const Arg *arg) { +void zoomreset(const Arg* arg) { Arg larg; if (defaultfontsize > 0) { @@ -304,21 +302,21 @@ void zoomreset(const Arg *arg) { } } -void ttysend(const Arg *arg) { ttywrite(arg->s, strlen(arg->s), 1); } +void ttysend(const Arg* arg) { ttywrite(arg->s, strlen(arg->s), 1); } -int evcol(XEvent *e) { +int evcol(XEvent* e) { int x = e->xbutton.x - borderpx; LIMIT(x, 0, win.tw - 1); return x / win.cw; } -int evrow(XEvent *e) { +int evrow(XEvent* e) { int y = e->xbutton.y - borderpx; LIMIT(y, 0, win.th - 1); return y / win.ch; } -void mousesel(XEvent *e, int done) { +void mousesel(XEvent* e, int done) { int type, seltype = SEL_REGULAR; uint state = e->xbutton.state & ~(Button1Mask | forcemousemod); @@ -333,7 +331,7 @@ void mousesel(XEvent *e, int done) { setsel(getsel(), e->xbutton.time); } -void mousereport(XEvent *e) { +void mousereport(XEvent* e) { int len, x = evcol(e), y = evrow(e), button = e->xbutton.button, state = e->xbutton.state; char buf[40]; @@ -402,8 +400,8 @@ uint buttonmask(uint button) { : 0; } -int mouseaction(XEvent *e, uint release) { - MouseShortcut *ms; +int mouseaction(XEvent* e, uint release) { + MouseShortcut* ms; /* ignore Buttonmask for Button - it's set on release */ uint state = e->xbutton.state & ~buttonmask(e->xbutton.button); @@ -420,7 +418,7 @@ int mouseaction(XEvent *e, uint release) { return 0; } -void bpress(XEvent *e) { +void bpress(XEvent* e) { struct timespec now; int snap; @@ -452,8 +450,8 @@ void bpress(XEvent *e) { } } -void propnotify(XEvent *e) { - XPropertyEvent *xpev; +void propnotify(XEvent* e) { + XPropertyEvent* xpev; Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); xpev = &e->xproperty; @@ -463,7 +461,7 @@ void propnotify(XEvent *e) { } } -void selnotify(XEvent *e) { +void selnotify(XEvent* e) { ulong nitems, ofs, rem; int format; uchar *data, *last, *repl; @@ -530,7 +528,7 @@ void selnotify(XEvent *e) { if (IS_SET(MODE_BRCKTPASTE) && ofs == 0) ttywrite("\033[200~", 6, 0); - ttywrite((char *)data, nitems * format / 8, 1); + ttywrite((char*)data, nitems * format / 8, 1); if (IS_SET(MODE_BRCKTPASTE) && rem == 0) ttywrite("\033[201~", 6, 0); XFree(data); @@ -547,15 +545,15 @@ void selnotify(XEvent *e) { void xclipcopy(void) { clipcopy(NULL); } -void selclear_(XEvent *e) { selclear(); } +void selclear_(XEvent* e) { selclear(); } -void selrequest(XEvent *e) { - XSelectionRequestEvent *xsre; +void selrequest(XEvent* e) { + XSelectionRequestEvent* xsre; XSelectionEvent xev; Atom xa_targets, string, clipboard; - char * seltext; + char* seltext; - xsre = (XSelectionRequestEvent *)e; + xsre = (XSelectionRequestEvent*)e; xev.type = SelectionNotify; xev.requestor = xsre->requestor; xev.selection = xsre->selection; @@ -572,7 +570,7 @@ void selrequest(XEvent *e) { /* respond with the supported type */ string = xsel.xtarget; XChangeProperty(xsre->display, xsre->requestor, xsre->property, - XA_ATOM, 32, PropModeReplace, (uchar *)&string, 1); + XA_ATOM, 32, PropModeReplace, (uchar*)&string, 1); xev.property = xsre->property; } else if (xsre->target == xsel.xtarget || xsre->target == XA_STRING) { /* @@ -591,18 +589,18 @@ void selrequest(XEvent *e) { } if (seltext != NULL) { XChangeProperty(xsre->display, xsre->requestor, xsre->property, - xsre->target, 8, PropModeReplace, (uchar *)seltext, + xsre->target, 8, PropModeReplace, (uchar*)seltext, strlen(seltext)); xev.property = xsre->property; } } /* all done, send a notification to the listener */ - if (!XSendEvent(xsre->display, xsre->requestor, 1, 0, (XEvent *)&xev)) + if (!XSendEvent(xsre->display, xsre->requestor, 1, 0, (XEvent*)&xev)) fprintf(stderr, "Error sending SelectionNotify event\n"); } -void setsel(char *str, Time t) { +void setsel(char* str, Time t) { if (!str) return; @@ -614,9 +612,9 @@ void setsel(char *str, Time t) { selclear(); } -void xsetsel(char *str) { setsel(str, CurrentTime); } +void xsetsel(char* str) { setsel(str, CurrentTime); } -void brelease(XEvent *e) { +void brelease(XEvent* e) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) { mousereport(e); return; @@ -628,7 +626,7 @@ void brelease(XEvent *e) { mousesel(e, 1); } -void bmotion(XEvent *e) { +void bmotion(XEvent* e) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) { mousereport(e); return; @@ -671,7 +669,7 @@ void xresize(int col, int row) { ushort sixd_to_16bit(int x) { return x == 0 ? 0 : 0x3737 + 0x2828 * x; } -int xloadcolor(int i, const char *name, Color *ncolor) { +int xloadcolor(int i, const char* name, Color* ncolor) { XRenderColor color = {.alpha = 0xffff}; if (!name) { @@ -695,7 +693,7 @@ int xloadcolor(int i, const char *name, Color *ncolor) { void xloadcols(void) { int i; static int loaded; - Color * cp; + Color* cp; if (loaded) { for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) @@ -715,7 +713,7 @@ void xloadcols(void) { loaded = 1; } -int xsetcolorname(int x, const char *name) { +int xsetcolorname(int x, const char* name) { Color ncolor; if (!BETWEEN(x, 0, dc.collen)) @@ -742,7 +740,7 @@ void xhints(void) { XClassHint class = {opt_name ? opt_name : termname, opt_class ? opt_class : termname}; XWMHints wm = {.flags = InputHint, .input = 1}; - XSizeHints *sizeh; + XSizeHints* sizeh; sizeh = XAllocSizeHints(); @@ -784,9 +782,9 @@ int xgeommasktogravity(int mask) { return SouthEastGravity; } -int xloadfont(Font *f, FcPattern *pattern) { - FcPattern *configured; - FcPattern *match; +int xloadfont(Font* f, FcPattern* pattern) { + FcPattern* configured; + FcPattern* match; FcResult result; XGlyphInfo extents; int wantattr, haveattr; @@ -839,7 +837,7 @@ int xloadfont(Font *f, FcPattern *pattern) { } } - XftTextExtentsUtf8(xw.dpy, f->match, (const FcChar8 *)ascii_printable, + XftTextExtentsUtf8(xw.dpy, f->match, (const FcChar8*)ascii_printable, strlen(ascii_printable), &extents); f->set = NULL; @@ -856,14 +854,14 @@ int xloadfont(Font *f, FcPattern *pattern) { return 0; } -void xloadfonts(char *fontstr, double fontsize) { - FcPattern *pattern; +void xloadfonts(char* fontstr, double fontsize) { + FcPattern* pattern; double fontval; if (fontstr[0] == '-') pattern = XftXlfdParse(fontstr, False, False); else - pattern = FcNameParse((FcChar8 *)fontstr); + pattern = FcNameParse((FcChar8*)fontstr); if (!pattern) die("can't open font %s\n", fontstr); @@ -923,7 +921,7 @@ void xloadfonts(char *fontstr, double fontsize) { FcPatternDestroy(pattern); } -void xunloadfont(Font *f) { +void xunloadfont(Font* f) { XftFontClose(xw.dpy, f->match); FcPatternDestroy(f->pattern); if (f->set) @@ -941,7 +939,7 @@ void xunloadfonts(void) { xunloadfont(&dc.ibfont); } -int ximopen(Display *dpy) { +int ximopen(Display* dpy) { XIMCallback imdestroy = {.client_data = NULL, .callback = ximdestroy}; XICCallback icdestroy = {.client_data = NULL, .callback = xicdestroy}; @@ -967,7 +965,7 @@ int ximopen(Display *dpy) { return 1; } -void ximinstantiate(Display *dpy, XPointer client, XPointer call) { +void ximinstantiate(Display* dpy, XPointer client, XPointer call) { if (ximopen(dpy)) XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, ximinstantiate, NULL); @@ -1080,7 +1078,7 @@ void xinit(int cols, int rows) { xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False); XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32, - PropModeReplace, (uchar *)&thispid, 1); + PropModeReplace, (uchar*)&thispid, 1); win.mode = MODE_NUMLOCK; resettitle(); @@ -1097,19 +1095,19 @@ void xinit(int cols, int rows) { xsel.xtarget = XA_STRING; } -int xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, +int xmakeglyphfontspecs(XftGlyphFontSpec* specs, const Glyph* glyphs, int len, int x, int y) { float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp; ushort mode, prevmode = USHRT_MAX; - Font * font = &dc.font; + Font* font = &dc.font; int frcflags = FRC_NORMAL; float runewidth = win.cw; Rune rune; FT_UInt glyphidx; FcResult fcres; FcPattern *fcpattern, *fontpattern; - FcFontSet *fcsets[] = {NULL}; - FcCharSet *fccharset; + FcFontSet* fcsets[] = {NULL}; + FcCharSet* fccharset; int i, f, numspecs = 0; for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) { @@ -1223,7 +1221,7 @@ int xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, return numspecs; } -void xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, +void xdrawglyphfontspecs(const XftGlyphFontSpec* specs, Glyph base, int len, int x, int y) { int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, @@ -1443,7 +1441,7 @@ void xsetenv(void) { setenv("WINDOWID", buf, 1); } -void xseticontitle(char *p) { +void xseticontitle(char* p) { XTextProperty prop; DEFAULT(p, opt_title); @@ -1453,7 +1451,7 @@ void xseticontitle(char *p) { XFree(prop.value); } -void xsettitle(char *p) { +void xsettitle(char* p) { XTextProperty prop; DEFAULT(p, opt_title); @@ -1468,7 +1466,7 @@ int xstartdraw(void) { return IS_SET(MODE_VISIBLE); } void xdrawline(Line line, int x1, int y1, int x2) { int i, x, ox, numspecs; Glyph base, new; - XftGlyphFontSpec *specs = xw.specbuf; + XftGlyphFontSpec* specs = xw.specbuf; numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1); i = ox = 0; @@ -1510,15 +1508,15 @@ void xximspot(int x, int y) { XSetICValues(xw.ime.xic, XNPreeditAttributes, xw.ime.spotlist, NULL); } -void expose(XEvent *ev) { redraw(); } +void expose(XEvent* ev) { redraw(); } -void visibility(XEvent *ev) { - XVisibilityEvent *e = &ev->xvisibility; +void visibility(XEvent* ev) { + XVisibilityEvent* e = &ev->xvisibility; MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE); } -void unmap(XEvent *ev) { win.mode &= ~MODE_VISIBLE; } +void unmap(XEvent* ev) { win.mode &= ~MODE_VISIBLE; } void xsetpointermotion(int set) { MODBIT(xw.attrs.event_mask, set, PointerMotionMask); @@ -1540,7 +1538,7 @@ int xsetcursor(int cursor) { } void xseturgency(int add) { - XWMHints *h = XGetWMHints(xw.dpy, xw.win); + XWMHints* h = XGetWMHints(xw.dpy, xw.win); MODBIT(h->flags, add, XUrgencyHint); XSetWMHints(xw.dpy, xw.win, h); @@ -1554,8 +1552,8 @@ void xbell(void) { XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL); } -void focus(XEvent *ev) { - XFocusChangeEvent *e = &ev->xfocus; +void focus(XEvent* ev) { + XFocusChangeEvent* e = &ev->xfocus; if (e->mode == NotifyGrab) return; @@ -1580,8 +1578,8 @@ int match(uint mask, uint state) { return mask == XK_ANY_MOD || mask == (state & ~ignoremod); } -char *kmap(KeySym k, uint state) { - Key *kp; +char* kmap(KeySym k, uint state) { + Key* kp; int i; /* Check for mapped keys out of X11 function keys. */ @@ -1615,14 +1613,14 @@ char *kmap(KeySym k, uint state) { return NULL; } -void kpress(XEvent *ev) { - XKeyEvent *e = &ev->xkey; +void kpress(XEvent* ev) { + XKeyEvent* e = &ev->xkey; KeySym ksym; char buf[64], *customkey; int len; Rune c; Status status; - Shortcut * bp; + Shortcut* bp; if (IS_SET(MODE_KBDLOCK)) return; @@ -1663,7 +1661,7 @@ void kpress(XEvent *ev) { ttywrite(buf, len, 1); } -void cmessage(XEvent *e) { +void cmessage(XEvent* e) { /* * See xembed specs * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html @@ -1681,7 +1679,7 @@ void cmessage(XEvent *e) { } } -void resize(XEvent *e) { +void resize(XEvent* e) { if (e->xconfigure.width == win.w && e->xconfigure.height == win.h) return; @@ -1801,7 +1799,7 @@ void usage(void) { argv0, argv0); } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { xw.l = xw.t = 0; xw.isfixed = False; xsetcursor(cursorshape);