JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
merged tscroll() with tscrollup().
[st.git] / st.c
diff --git a/st.c b/st.c
index ebe896c..eabc0c5 100644 (file)
--- a/st.c
+++ b/st.c
 #include <X11/keysym.h>
 #include <X11/Xutil.h>
 
+#if   defined(LINUX)
+ #include <pty.h>
+#elif defined(OPENBSD)
+ #include <util.h>
+#elif defined(FREEBSD)
+ #include <libutil.h>
+#endif
+
 /* Arbitrary sizes */
 #define ESC_TITLE_SIZ 256
 #define ESC_BUF_SIZ   256
@@ -34,7 +42,7 @@
 #define BETWEEN(x, a, b)  ((a) <= (x) && (x) <= (b))
 #define LIMIT(x, a, b)    (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
-#define IS_SET(flag) (term.mode & flag)
+#define IS_SET(flag) (term.mode & (flag))
 
 /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */
 enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 };
@@ -141,7 +149,6 @@ static void tputc(char);
 static void tputs(char*, int);
 static void treset(void);
 static void tresize(int, int);
-static void tscroll(void);
 static void tscrollup(int);
 static void tscrolldown(int);
 static void tsetattr(int*, int);
@@ -242,19 +249,12 @@ sigchld(int a) {
 void
 ttynew(void) {
        int m, s;
-       char *pts;
-
-       if((m = posix_openpt(O_RDWR | O_NOCTTY)) < 0)
-               die("openpt failed: %s\n", SERRNO);
-       if(grantpt(m) < 0)
-               die("grantpt failed: %s\n", SERRNO);
-       if(unlockpt(m) < 0)
-               die("unlockpt failed: %s\n", SERRNO);
-       if(!(pts = ptsname(m)))
-               die("ptsname failed: %s\n", SERRNO);
-       if((s = open(pts, O_RDWR | O_NOCTTY)) < 0)
-               die("Couldn't open slave: %s\n", SERRNO);
-       fcntl(s, F_SETFL, O_NDELAY);
+       
+       /* seems to work fine on linux, openbsd and freebsd */
+       struct winsize w = {term.row, term.col, 0, 0};
+       if(openpty(&m, &s, NULL, NULL, &w) < 0)
+               die("openpty failed: %s\n", SERRNO);
+
        switch(pid = fork()) {
        case -1:
                die("fork failed\n");
@@ -354,18 +354,6 @@ tnew(int col, int row) {
                term.line[row] = calloc(term.col, sizeof(Glyph));
 }
 
-/* TODO: Replace with scrollup/scolldown */
-void
-tscroll(void) {
-       Line temp = term.line[term.top];
-       int i;
-
-       for(i = term.top; i < term.bot; i++)
-               term.line[i] = term.line[i+1];
-       memset(temp, 0, sizeof(Glyph) * term.col);
-       term.line[term.bot] = temp;
-}
-
 void
 tscrolldown (int n) {
        int i;
@@ -403,7 +391,7 @@ void
 tnewline(void) {
        int y = term.c.y + 1;
        if(y > term.bot)
-               tscroll(), y = term.bot;
+               tscrollup(1), y = term.bot;
        tmoveto(0, y);
 }
 
@@ -1078,10 +1066,9 @@ xhints(void)
 
 void
 xinit(void) {
-       xw.dis = XOpenDisplay(NULL);
-       xw.scr = XDefaultScreen(xw.dis);
-       if(!xw.dis)
+       if(!(xw.dis = XOpenDisplay(NULL)))
                die("Can't open display\n");
+       xw.scr = XDefaultScreen(xw.dis);
        
        /* font */
        if(!(dc.font = XLoadQueryFont(xw.dis, FONT)) || !(dc.bfont = XLoadQueryFont(xw.dis, BOLDFONT)))