pinosaur
/
st.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed a memory leak & segfault in tresize.
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
f295955
..
8ddfa8b
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-364,21
+364,6
@@
void
tsetattr(int *attr, int l) {
int i;
tsetattr(int *attr, int l) {
int i;
-#ifdef TRUECOLOR /* ESC [ ? <fg/bg> ; <r> ; <g> ; <b> m */
- Color col;
- if(escseq.priv && escseq.len == 4) { /* True color extension :) */
- col = (escseq.arg[1]<<16) + (escseq.arg[2]<<8) + escseq.arg[3];
- switch(escseq.arg[0]) {
- case 3: /* foreground */
- term.c.attr.fg = col;
- break;
- case 4: /* background */
- term.c.attr.bg = col;
- break;
- }
- }
- else
-#endif
for(i = 0; i < l; i++) {
switch(attr[i]) {
case 0:
for(i = 0; i < l; i++) {
switch(attr[i]) {
case 0:
@@
-573,11
+558,22
@@
escreset(void) {
memset(&escseq, 0, sizeof(escseq));
}
memset(&escseq, 0, sizeof(escseq));
}
+void
+tputtab(void) {
+ int space = TAB - term.c.x % TAB;
+
+ if(term.c.x + space >= term.col)
+ space--;
+
+ for(; space > 0; space--)
+ tcursor(CSright);
+}
+
void
tputc(char c) {
static int inesc = 0;
void
tputc(char c) {
static int inesc = 0;
- dump(c);
+
//
dump(c);
/* start of escseq */
if(c == '\033')
escreset(), inesc = 1;
/* start of escseq */
if(c == '\033')
escreset(), inesc = 1;
@@
-589,6
+585,9
@@
tputc(char c) {
tsetchar(c);
tcursor(CSright);
break;
tsetchar(c);
tcursor(CSright);
break;
+ case '\t':
+ tputtab();
+ break;
case '\b':
tcursor(CSleft);
break;
case '\b':
tcursor(CSleft);
break;
@@
-637,20
+636,24
@@
tresize(int col, int row) {
if(col < 1 || row < 1)
return;
if(col < 1 || row < 1)
return;
+ /* alloc */
line = calloc(row, sizeof(Line));
for(i = 0 ; i < row; i++)
line[i] = calloc(col, sizeof(Glyph));
line = calloc(row, sizeof(Line));
for(i = 0 ; i < row; i++)
line[i] = calloc(col, sizeof(Glyph));
- for(i = 0 ; i < minrow; i++) {
- memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
- free(term.line[i]);
- }
+ /* copy */
+ for(i = 0 ; i < minrow; i++)
+ memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
+ /* free */
+ for(i = 0; i < term.row; i++)
+ free(term.line[i]);
free(term.line);
free(term.line);
+
LIMIT(term.c.x, 0, col-1);
LIMIT(term.c.y, 0, row-1);
LIMIT(term.top, 0, row-1);
LIMIT(term.bot, 0, row-1);
LIMIT(term.c.x, 0, col-1);
LIMIT(term.c.y, 0, row-1);
LIMIT(term.top, 0, row-1);
LIMIT(term.bot, 0, row-1);
- // if(term.bot == term.row-1)
-
term.bot = row-1;
+
+ term.bot = row-1;
term.line = line;
term.col = col, term.row = row;
}
term.line = line;
term.col = col, term.row = row;
}
@@
-703,18
+706,25
@@
xinit(void) {
xw.dis = XOpenDisplay(NULL);
xw.scr = XDefaultScreen(xw.dis);
xw.dis = XOpenDisplay(NULL);
xw.scr = XDefaultScreen(xw.dis);
+ if(!xw.dis)
+ die("can not open display");
+
/* font */
/* font */
- dc.font = XLoadQueryFont(xw.dis, FONT);
+ if(!(dc.font = XLoadQueryFont(xw.dis, FONT)))
+ die("can not find font " FONT);
+
xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing;
xw.ch = dc.font->ascent + dc.font->descent + LINESPACE;
xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing;
xw.ch = dc.font->ascent + dc.font->descent + LINESPACE;
+
/* colors */
for(i = 0; i < LEN(colorname); i++)
dc.col[i] = xgetcol(colorname[i]);
/* colors */
for(i = 0; i < LEN(colorname); i++)
dc.col[i] = xgetcol(colorname[i]);
+
term.c.attr.fg = DefaultFG;
term.c.attr.bg = DefaultBG;
term.c.attr.mode = ATnone;
/* windows */
term.c.attr.fg = DefaultFG;
term.c.attr.bg = DefaultBG;
term.c.attr.mode = ATnone;
/* windows */
-
xw.h = term.row * xw.ch;
+ xw.h = term.row * xw.ch;
xw.w = term.col * xw.cw;
/* XXX: this BORDER is useless after the first resize, handle it in xdraws() */
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
xw.w = term.col * xw.cw;
/* XXX: this BORDER is useless after the first resize, handle it in xdraws() */
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
@@
-736,6
+746,7
@@
xinit(void) {
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
XStoreName(xw.dis, xw.win, TNAME);
XSync(xw.dis, 0);
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
XStoreName(xw.dis, xw.win, TNAME);
XSync(xw.dis, 0);
+
}
void
}
void
@@
-768,7
+779,10
@@
xcursor(int mode) {
static int oldx = 0;
static int oldy = 0;
Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0};
static int oldx = 0;
static int oldy = 0;
Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0};
-
+
+ LIMIT(oldx, 0, term.col-1);
+ LIMIT(oldy, 0, term.row-1);
+
if(term.line[term.c.y][term.c.x].state & CRset)
g.c = term.line[term.c.y][term.c.x].c;
/* remove the old cursor */
if(term.line[term.c.y][term.c.x].state & CRset)
g.c = term.line[term.c.y][term.c.x].c;
/* remove the old cursor */
@@
-852,7
+866,7
@@
resize(XEvent *e) {
col = e->xconfigure.width / xw.cw;
row = e->xconfigure.height / xw.ch;
col = e->xconfigure.width / xw.cw;
row = e->xconfigure.height / xw.ch;
- if(term.col != col
&&
term.row != row) {
+ if(term.col != col
||
term.row != row) {
tresize(col, row);
ttyresize(col, row);
xw.w = e->xconfigure.width;
tresize(col, row);
ttyresize(col, row);
xw.w = e->xconfigure.width;
@@
-908,13
+922,13
@@
run(void) {
int
main(int argc, char *argv[]) {
if(argc == 2 && !strncmp("-v", argv[1], 3))
int
main(int argc, char *argv[]) {
if(argc == 2 && !strncmp("-v", argv[1], 3))
- die("st-"
VERSION
", © 2009 st engineers\n");
+ die("st-"
VERSION
", © 2009 st engineers\n");
else if(argc != 1)
die("usage: st [-v]\n");
setlocale(LC_CTYPE, "");
else if(argc != 1)
die("usage: st [-v]\n");
setlocale(LC_CTYPE, "");
-
tnew(80, 24);
-
ttynew();
-
xinit();
-
run();
+ tnew(80, 24);
+ ttynew();
+ xinit();
+ run();
return 0;
}
return 0;
}