From b19041249debf4198f24c60bb78a86e4ad35f47e Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 7 Dec 2006 11:23:31 +0000 Subject: [PATCH] got rid of the tty_name global git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19441 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermApp.cpp | 72 +++++++++++++++++--------------- src/apps/terminal/TermApp.h | 2 +- src/apps/terminal/TermView.cpp | 1 + src/apps/terminal/TermView.h | 1 - src/apps/terminal/TermWindow.cpp | 9 ++-- src/apps/terminal/TermWindow.h | 3 +- src/apps/terminal/spawn.cpp | 3 +- src/apps/terminal/spawn.h | 1 - 8 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/apps/terminal/TermApp.cpp b/src/apps/terminal/TermApp.cpp index 486aae4c46..5732bad6ed 100644 --- a/src/apps/terminal/TermApp.cpp +++ b/src/apps/terminal/TermApp.cpp @@ -107,46 +107,18 @@ TermApp::ReadyToRun() if (usage_requested) return; - const char *command = NULL; - const char *encoding; - int rows, cols; - - encoding = gTermPref->getString(PREF_TEXT_ENCODING); - - // Get encoding name (setenv TTYPE in spawn_shell functions) - const etable *p = encoding_table; - while (p->name) { - if (!strcmp(p->name, encoding)) { - encoding = p->shortname; - break; - } - p++; - } - - if (CommandLine.Length() > 0) - command = CommandLine.String(); - else - command = gTermPref->getString(PREF_SHELL); - - rows = gTermPref->getInt32(PREF_ROWS); - if (rows < 1) - gTermPref->setInt32(PREF_ROWS, rows = 1); - - cols = gTermPref->getInt32(PREF_COLS); - if (cols < MIN_COLS) - gTermPref->setInt32(PREF_COLS, cols = MIN_COLS); - - pfd = spawn_shell(rows, cols, command, encoding); + status_t status = MakeTermWindow(fTermFrame); // failed spawn, print stdout and open alert panel - if (pfd == -1 ) { + if (status < B_OK) { (new BAlert("alert", "Terminal couldn't start the shell. Sorry.", "ok", NULL, NULL, B_WIDTH_FROM_LABEL, B_INFO_ALERT))->Go(NULL); PostMessage(B_QUIT_REQUESTED); + return; } - MakeTermWindow(fTermFrame); + // using BScreen::Frame isn't enough if (fStartFullscreen) BMessenger(fTermWindow).SendMessage(FULLSCREEN); @@ -372,11 +344,43 @@ TermApp::RefsReceived(BMessage *message) } -void +status_t TermApp::MakeTermWindow(BRect &frame) { - fTermWindow = new TermWindow(frame, fWindowTitle.String()); + const char *encoding = gTermPref->getString(PREF_TEXT_ENCODING); + + // Get encoding name (setenv TTYPE in spawn_shell functions) + const etable *p = encoding_table; + while (p->name) { + if (!strcmp(p->name, encoding)) { + encoding = p->shortname; + break; + } + p++; + } + + const char *command = NULL; + if (CommandLine.Length() > 0) + command = CommandLine.String(); + else + command = gTermPref->getString(PREF_SHELL); + + int rows = gTermPref->getInt32(PREF_ROWS); + if (rows < 1) + gTermPref->setInt32(PREF_ROWS, rows = 1); + + int cols = gTermPref->getInt32(PREF_COLS); + if (cols < MIN_COLS) + gTermPref->setInt32(PREF_COLS, cols = MIN_COLS); + + int pfd = spawn_shell(rows, cols, command, encoding); + if (pfd < 0) + return pfd; + + fTermWindow = new TermWindow(frame, fWindowTitle.String(), pfd); fTermWindow->Show(); + + return B_OK; } diff --git a/src/apps/terminal/TermApp.h b/src/apps/terminal/TermApp.h index be83d1d78d..683b4eafbd 100644 --- a/src/apps/terminal/TermApp.h +++ b/src/apps/terminal/TermApp.h @@ -62,7 +62,7 @@ private: /* * Public Member functions. */ - void MakeTermWindow (BRect &frame); + status_t MakeTermWindow (BRect &frame); void SwitchTerm(void); void ActivateTermWindow(team_id id); diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 36d09ec2d0..a8a83a5e7a 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -2342,6 +2342,7 @@ TermView::GetSelection(BString &str) fTextBuffer->GetStringFromRegion(str); } + // Send DrawRect data to Draw Engine thread. inline void TermView::SendDataToDrawEngine(int x1, int y1, int x2, int y2) diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 7a0d818a75..d9133b0ec6 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -186,7 +186,6 @@ public: void GetFontInfo (int *, int*); bool Find (const BString &str, bool forwardSearch, bool matchCase, bool matchWord); void GetSelection (BString &str); - /* * PRIVATE MEMBER. diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 6110cb6a9d..c2feae36c5 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -16,8 +16,10 @@ #include #include #include +#include #include #include + #include #include #include @@ -56,8 +58,9 @@ extern int gNowCoding; /* defined TermParce.cpp */ void SetCoding(int); -TermWindow::TermWindow(BRect frame, const char* title) - : BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE) +TermWindow::TermWindow(BRect frame, const char* title, int pfd) + : BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE), + fPfd(pfd) { InitWindow(); @@ -425,7 +428,7 @@ TermWindow::MessageReceived(BMessage *message) } else if (!strcmp("tty", spe.FindString("property", i))) { BMessage reply(B_REPLY); - reply.AddString("result", &tty_name[8]); + reply.AddString("result", ttyname(fPfd)); message->SendReply(&reply); } else { BWindow::MessageReceived(message); diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 4ee022b90c..b45db03490 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -47,7 +47,7 @@ class FindDlg; class TermWindow : public BWindow { public: - TermWindow(BRect frame, const char* title); + TermWindow(BRect frame, const char* title, int pfd); ~TermWindow(); void Quit (void); @@ -74,6 +74,7 @@ private: /* * data member */ + int fPfd; TermParse *fTermParse; BMenuBar *fMenubar; BMenu *fFilemenu, *fEditmenu, *fEncodingmenu, *fHelpmenu, *fFontMenu, *fWindowSizeMenu, *fNewFontMenu; diff --git a/src/apps/terminal/spawn.cpp b/src/apps/terminal/spawn.cpp index 493f6337d8..c9a1b1e9e6 100644 --- a/src/apps/terminal/spawn.cpp +++ b/src/apps/terminal/spawn.cpp @@ -122,8 +122,6 @@ typedef struct /* global varriables */ pid_t sh_pid; -char tty_name[B_PATH_NAME_LENGTH]; - int spawn_shell(int row, int col, const char *command, const char *coding) @@ -157,6 +155,7 @@ spawn_shell(int row, int col, const char *command, const char *coding) * which is already in use, so we simply go until the open succeeds. */ + char tty_name[B_PATH_NAME_LENGTH]; DIR *dir = opendir("/dev/pt/"); if (dir != NULL) { struct dirent *dirEntry; diff --git a/src/apps/terminal/spawn.h b/src/apps/terminal/spawn.h index 5941b1940f..1b29e4728d 100644 --- a/src/apps/terminal/spawn.h +++ b/src/apps/terminal/spawn.h @@ -88,7 +88,6 @@ int spawn_shell (int, int, const char *, const char *); void Setenv (const char *, const char *); extern pid_t sh_pid; /* shell process ID */ -extern char tty_name[]; /* tty device file name */ extern int pfd_num; /* number of pfd */