[haiku-commits] r34893 - haiku/trunk/src/apps/terminal

  • From: stefano.ceccherini@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 4 Jan 2010 19:34:52 +0100 (CET)

Author: jackburton
Date: 2010-01-04 19:34:52 +0100 (Mon, 04 Jan 2010)
New Revision: 34893
Changeset: http://dev.haiku-os.org/changeset/34893/haiku

Modified:
   haiku/trunk/src/apps/terminal/Shell.cpp
   haiku/trunk/src/apps/terminal/Shell.h
Log:
fAttached was never set in Shell::AttachBuffer(), and that caused
TermParse::StopThreads() in Shell::DetachBuffer() to be never called.
Moved initialization of termios struct to its own functions.
Added const to some methods.


Modified: haiku/trunk/src/apps/terminal/Shell.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/Shell.cpp     2010-01-04 17:50:52 UTC (rev 
34892)
+++ haiku/trunk/src/apps/terminal/Shell.cpp     2010-01-04 18:34:52 UTC (rev 
34893)
@@ -170,7 +170,7 @@
 
 
 ssize_t
-Shell::Read(void *buffer, size_t numBytes)
+Shell::Read(void *buffer, size_t numBytes) const
 {
        if (fFd < 0)
                return B_NO_INIT;
@@ -202,7 +202,7 @@
 
 
 status_t
-Shell::GetAttr(struct termios &attr)
+Shell::GetAttr(struct termios &attr) const
 {
        if (tcgetattr(fFd, &attr) < 0)
                return errno;
@@ -232,6 +232,8 @@
        if (fAttached)
                return B_ERROR;
 
+       fAttached = true;
+       
        return fTermParse->StartThreads(buffer);
 }
 
@@ -260,6 +262,60 @@
 }
 
 
+static void
+initialize_termios(struct termios &tio)
+{
+       /*
+        * Set Terminal interface.
+        */
+
+       tio.c_line = 0;
+       tio.c_lflag |= ECHOE; 
+
+       /* input: nl->nl, cr->nl */
+       tio.c_iflag &= ~(INLCR|IGNCR);
+       tio.c_iflag |= ICRNL;
+       tio.c_iflag &= ~ISTRIP;
+
+       /* output: cr->cr, nl in not retrun, no delays, ln->cr/ln */
+       tio.c_oflag &= ~(OCRNL|ONLRET|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
+       tio.c_oflag |= ONLCR;
+       tio.c_oflag |= OPOST;
+
+       /* baud rate is 19200 (equal beterm) */
+       tio.c_cflag &= ~(CBAUD);
+       tio.c_cflag |= B19200;
+
+       tio.c_cflag &= ~CSIZE;
+       tio.c_cflag |= CS8;
+       tio.c_cflag |= CREAD;
+
+       tio.c_cflag |= HUPCL;
+       tio.c_iflag &= ~(IGNBRK|BRKINT);
+
+       /*
+        * enable signals, canonical processing (erase, kill, etc), echo.
+       */
+       tio.c_lflag |= ISIG|ICANON|ECHO|ECHOE|ECHONL;
+       tio.c_lflag &= ~(ECHOK | IEXTEN);
+
+       /* set control characters. */
+       tio.c_cc[VINTR]  = 'C' & 0x1f;  /* '^C' */
+       tio.c_cc[VQUIT]  = CQUIT;               /* '^\' */
+       tio.c_cc[VERASE] = 0x7f;                /* '^?' */
+       tio.c_cc[VKILL]  = 'U' & 0x1f;  /* '^U' */
+       tio.c_cc[VEOF]   = CEOF;                /* '^D' */
+       tio.c_cc[VEOL]   = CEOL;                /* '^@' */
+       tio.c_cc[VMIN]   = 4;
+       tio.c_cc[VTIME]  = 0;
+       tio.c_cc[VEOL2]  = CEOL;                /* '^@' */
+       tio.c_cc[VSWTCH] = CSWTCH;              /* '^@' */
+       tio.c_cc[VSTART] = CSTART;              /* '^S' */
+       tio.c_cc[VSTOP]  = CSTOP;               /* '^Q' */
+       tio.c_cc[VSUSP]  = CSUSP;               /* '^Z' */
+}
+
+
 status_t
 Shell::_Spawn(int row, int col, const char *encoding, int argc, const char 
**argv)
 {
@@ -379,57 +435,10 @@
                 * TODO: so why are we doing it ?
                 */
                tcgetattr(slave, &tio);
+               
+               initialize_termios(tio);
 
                /*
-                * Set Terminal interface.
-                */
-
-               tio.c_line = 0;
-               tio.c_lflag |= ECHOE; 
-
-               /* input: nl->nl, cr->nl */
-               tio.c_iflag &= ~(INLCR|IGNCR);
-               tio.c_iflag |= ICRNL;
-               tio.c_iflag &= ~ISTRIP;
-
-               /* output: cr->cr, nl in not retrun, no delays, ln->cr/ln */
-               tio.c_oflag &= 
~(OCRNL|ONLRET|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
-               tio.c_oflag |= ONLCR;
-               tio.c_oflag |= OPOST;
-
-               /* baud rate is 19200 (equal beterm) */
-               tio.c_cflag &= ~(CBAUD);
-               tio.c_cflag |= B19200;
-
-               tio.c_cflag &= ~CSIZE;
-               tio.c_cflag |= CS8;
-               tio.c_cflag |= CREAD;
-
-               tio.c_cflag |= HUPCL;
-               tio.c_iflag &= ~(IGNBRK|BRKINT);
-
-               /*
-                * enable signals, canonical processing (erase, kill, etc), 
echo.
-               */
-               tio.c_lflag |= ISIG|ICANON|ECHO|ECHOE|ECHONL;
-               tio.c_lflag &= ~(ECHOK | IEXTEN);
-
-               /* set control characters. */
-               tio.c_cc[VINTR]  = 'C' & 0x1f;  /* '^C' */
-               tio.c_cc[VQUIT]  = CQUIT;               /* '^\' */
-               tio.c_cc[VERASE] = 0x7f;                /* '^?' */
-               tio.c_cc[VKILL]  = 'U' & 0x1f;  /* '^U' */
-               tio.c_cc[VEOF]   = CEOF;                /* '^D' */
-               tio.c_cc[VEOL]   = CEOL;                /* '^@' */
-               tio.c_cc[VMIN]   = 4;
-               tio.c_cc[VTIME]  = 0;
-               tio.c_cc[VEOL2]  = CEOL;                /* '^@' */
-               tio.c_cc[VSWTCH] = CSWTCH;              /* '^@' */
-               tio.c_cc[VSTART] = CSTART;              /* '^S' */
-               tio.c_cc[VSTOP]  = CSTOP;               /* '^Q' */
-               tio.c_cc[VSUSP]  = CSUSP;               /* '^Z' */
-
-               /*
                 * change control tty. 
                 */
 
@@ -468,10 +477,7 @@
                        exit(1);
                }
 
-               struct winsize ws;
-       
-               ws.ws_row = handshake.row;
-               ws.ws_col = handshake.col;
+               struct winsize ws = { handshake.row, handshake.col };
 
                ioctl(0, TIOCSWINSZ, &ws);
 
@@ -498,6 +504,7 @@
 
                /*
                 * Exec failed.
+                * TODO: This doesn't belong here.
                 */
                
                sleep(1);

Modified: haiku/trunk/src/apps/terminal/Shell.h
===================================================================
--- haiku/trunk/src/apps/terminal/Shell.h       2010-01-04 17:50:52 UTC (rev 
34892)
+++ haiku/trunk/src/apps/terminal/Shell.h       2010-01-04 18:34:52 UTC (rev 
34893)
@@ -29,12 +29,12 @@
        
        const char *    TTYName() const;
 
-       ssize_t         Read(void *buffer, size_t numBytes);
+       ssize_t         Read(void *buffer, size_t numBytes) const;
        ssize_t         Write(const void *buffer, size_t numBytes);
 
        status_t        UpdateWindowSize(int row, int columns);
 
-       status_t        GetAttr(struct termios &attr);
+       status_t        GetAttr(struct termios &attr) const;
        status_t        SetAttr(struct termios &attr);
 
        int                     FD() const;


Other related posts:

  • » [haiku-commits] r34893 - haiku/trunk/src/apps/terminal - stefano . ceccherini