got rid of the tty_name global

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19441 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-12-07 11:23:31 +00:00
parent 4d5d5756b4
commit b19041249d
8 changed files with 49 additions and 43 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -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.

View File

@ -16,8 +16,10 @@
#include <Roster.h>
#include <Screen.h>
#include <ScrollBar.h>
#include <String.h>
#include <TextControl.h>
#include <WindowScreen.h>
#include <float.h>
#include <stdio.h>
#include <string>
@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 */