[dev] [st] [PATCH 1/3] Add NUL character dealing

2012-09-13 Thread Roberto E. Vargas Caballero
NUL character is usually used as padding (basically  for timming purpouses),
and it should be ignorted. Some old telnet servers send it together each
character. It is also used in some terminfo entries (for example in xterm
terminfo entry).
---
 st.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/st.c b/st.c
index 0db81f4..26237de 100644
--- a/st.c
+++ b/st.c
@@ -1714,6 +1714,8 @@ tputc(char *c) {
if(sel.bx != -1  BETWEEN(term.c.y, sel.by, sel.ey))
sel.bx = -1;
switch(ascii) {
+   case '\0': /* padding character, do nothing */
+   break;
case '\t':
tputtab(1);
break;
--
1.7.10.4



[dev] [st] [PATCH 2/3] Restore default signal behaviour

2012-09-13 Thread Roberto E. Vargas Caballero
Signal handlers are inherited from parent process, so we can not be sure
which it is the handler our shell process has. This can cause some problems
with some window managers (for example with some wmii versions).
---
 st.c |7 +++
 1 file changed, 7 insertions(+)

diff --git a/st.c b/st.c
index 26237de..868300c 100644
--- a/st.c
+++ b/st.c
@@ -772,6 +772,13 @@ execsh(void) {
unsetenv(COLUMNS);
unsetenv(LINES);
unsetenv(TERMCAP);
+   signal(SIGCHLD, SIG_DFL);
+   signal(SIGHUP, SIG_DFL);
+   signal(SIGINT, SIG_DFL);
+   signal(SIGQUIT, SIG_DFL);
+   signal(SIGTERM, SIG_DFL);
+   signal(SIGALRM, SIG_DFL);
+

DEFAULT(envshell, SHELL);
putenv(TERM=TNAME);
--
1.7.10.4



[dev] [st] [PATCH 3/3] Move geometry initialization to xinit()

2012-09-13 Thread Roberto E. Vargas Caballero
xinit() is the function which performs all the X Windows initilization, so
it can be desired doing the geometry parsing into that function, and let the
argv loop of main as simple like other parameter cases.
---
 st.c |   53 +++--
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/st.c b/st.c
index 868300c..e87a0cd 100644
--- a/st.c
+++ b/st.c
@@ -358,6 +358,7 @@ static Selection sel;
 static int iofd = -1;
 static char **opt_cmd  = NULL;
 static char *opt_io= NULL;
+static char *opt_geo   = NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
@@ -1965,6 +1966,11 @@ xinit(void) {
Cursor cursor;
Window parent;
int sw, sh;
+   int bitm, xr, yr;
+   unsigned int wr, hr;
+
+   xw.fw = xw.fh = xw.fx = xw.fy = 0;
+   xw.isfixed = False;

if(!(xw.dpy = XOpenDisplay(NULL)))
die(Can't open display\n);
@@ -1981,6 +1987,23 @@ xinit(void) {
xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
xloadcols();

+   if(opt_geo) {
+   bitm = XParseGeometry(opt_geo, xr, yr, wr, hr);
+   if(bitm  XValue)
+   xw.fx = xr;
+   if(bitm  YValue)
+   xw.fy = yr;
+   if(bitm  WidthValue)
+   xw.fw = (int)wr;
+   if(bitm  HeightValue)
+   xw.fh = (int)hr;
+   if(bitm  XNegative  xw.fx == 0)
+   xw.fx = -1;
+   if(bitm  XNegative  xw.fy == 0)
+   xw.fy = -1;
+   if(xw.fh != 0  xw.fw != 0)
+   xw.isfixed = True;
+   }
/* adjust fixed window geometry */
if(xw.isfixed) {
sw = DisplayWidth(xw.dpy, xw.scr);
@@ -2378,11 +2401,7 @@ run(void) {

 int
 main(int argc, char *argv[]) {
-   int i, bitm, xr, yr;
-   unsigned int wr, hr;
-
-   xw.fw = xw.fh = xw.fx = xw.fy = 0;
-   xw.isfixed = False;
+   int i;

for(i = 1; i  argc; i++) {
switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) {
@@ -2398,31 +2417,13 @@ main(int argc, char *argv[]) {
case 'f':
if(++i  argc) opt_io = argv[i];
break;
+   case 'g':
+   if(++i  argc) opt_geo = argv[i];
+   break;
case 'e':
/* eat every remaining arguments */
if(++i  argc) opt_cmd = argv[i];
goto run;
-   case 'g':
-   if(++i = argc)
-   break;
-
-   bitm = XParseGeometry(argv[i], xr, yr, wr, hr);
-   if(bitm  XValue)
-   xw.fx = xr;
-   if(bitm  YValue)
-   xw.fy = yr;
-   if(bitm  WidthValue)
-   xw.fw = (int)wr;
-   if(bitm  HeightValue)
-   xw.fh = (int)hr;
-   if(bitm  XNegative  xw.fx == 0)
-   xw.fx = -1;
-   if(bitm  XNegative  xw.fy == 0)
-   xw.fy = -1;
-
-   if(xw.fh != 0  xw.fw != 0)
-   xw.isfixed = True;
-   break;
case 'v':
default:
die(USAGE);
--
1.7.10.4