Style fixes to TermWindow.cpp

Removed trailing spaces after text generated by file drops
Added a few TODOs


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13940 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2005-08-12 18:59:17 +00:00
parent 401fdf8278
commit 8002431bb4
4 changed files with 582 additions and 642 deletions
+137 -176
View File
@@ -4,8 +4,6 @@
* *
* Distributed unter the terms of the MIT license. * Distributed unter the terms of the MIT license.
*/ */
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h> #include <sys/wait.h>
@@ -27,32 +25,26 @@
#include "PrefHandler.h" #include "PrefHandler.h"
#include "CodeConv.h" #include "CodeConv.h"
// Preference temporary
extern PrefHandler *gTermPref; /* Preference temporary */ extern PrefHandler *gTermPref;
extern char gWindowName[]; extern char gWindowName[];
bool usage_requested = false; bool usage_requested = false;
bool geometry_requested = false; bool geometry_requested = false;
bool color_requested = false; bool color_requested = false;
/* function prototype. */
int argmatch(char **, int, char *, char *, int, char **, int *); int argmatch(char **, int, char *, char *, int, char **, int *);
void sort_args(int, char **); void sort_args(int, char **);
int text_to_rgb(char *, rgb_color *, char *); int text_to_rgb(char *, rgb_color *, char *);
// message
const ulong MSG_ACTIVATE_TERM = 'msat'; const ulong MSG_ACTIVATE_TERM = 'msat';
const ulong MSG_TERM_IS_MINIMIZE = 'mtim'; const ulong MSG_TERM_IS_MINIMIZE = 'mtim';
////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////
TermApp::TermApp(void) TermApp::TermApp(void)
:BApplication( TERM_SIGNATURE ) :BApplication( TERM_SIGNATURE )
{ {
BList teams; BList teams;
be_roster->GetAppList(TERM_SIGNATURE, &teams); be_roster->GetAppList(TERM_SIGNATURE, &teams);
@@ -75,14 +67,12 @@ TermApp::TermApp (void)
fTermFrame.Set(k, l, k + 50, k + 50); fTermFrame.Set(k, l, k + 50, k + 50);
gTermPref = new PrefHandler(); gTermPref = new PrefHandler();
} }
TermApp::~TermApp(void) TermApp::~TermApp(void)
{ {
/* delete (gTermPref); */ // delete gTermPref;
} }
@@ -90,7 +80,8 @@ void
TermApp::ReadyToRun(void) TermApp::ReadyToRun(void)
{ {
// Prevent opeing window when option -h is given. // Prevent opeing window when option -h is given.
if (usage_requested) return; if(usage_requested)
return;
const char *command = NULL; const char *command = NULL;
const char *encoding; const char *encoding;
@@ -98,9 +89,10 @@ TermApp::ReadyToRun (void)
encoding = gTermPref->getString(PREF_TEXT_ENCODING); encoding = gTermPref->getString(PREF_TEXT_ENCODING);
/* Get encoding name (setenv TTYPE in spawn_shell functions). */ // Get encoding name (setenv TTYPE in spawn_shell functions)
const etable *p = encoding_table; const etable *p = encoding_table;
while(p->name) { while(p->name) {
if(!strcmp(p->name, encoding)) { if(!strcmp(p->name, encoding)) {
encoding = p->shortname; encoding = p->shortname;
break; break;
@@ -108,24 +100,22 @@ TermApp::ReadyToRun (void)
p++; p++;
} }
if (CommandLine.Length() > 0){ if(CommandLine.Length() > 0)
command = CommandLine.String(); command = CommandLine.String();
}else{ else
command = gTermPref->getString(PREF_SHELL); command = gTermPref->getString(PREF_SHELL);
}
rows = gTermPref->getInt32(PREF_ROWS); rows = gTermPref->getInt32(PREF_ROWS);
cols = gTermPref->getInt32(PREF_COLS); cols = gTermPref->getInt32(PREF_COLS);
pfd = spawn_shell(rows, cols, command, encoding); pfd = spawn_shell(rows, cols, command, encoding);
/* failed spawn, print stdout and open alert panel. */ // failed spawn, print stdout and open alert panel
if(pfd == -1 ) { if(pfd == -1 ) {
(new BAlert ("alert", (new BAlert("alert", "Terminal couldn't start the shell. Sorry.",
"Terminal Error!!\nCan't execute shell.", "ok", NULL, NULL,B_WIDTH_FROM_LABEL,
"Abort", NULL, NULL, B_INFO_ALERT))->Go(NULL);
B_WIDTH_FROM_LABEL, B_INFO_ALERT))->Go(NULL); PostMessage(B_QUIT_REQUESTED);
this->PostMessage(B_QUIT_REQUESTED);
} }
MakeTermWindow(fTermFrame); MakeTermWindow(fTermFrame);
@@ -136,6 +126,7 @@ void
TermApp::Quit(void) TermApp::Quit(void)
{ {
if(!usage_requested){ if(!usage_requested){
int status; int status;
kill(-sh_pid, SIGHUP); kill(-sh_pid, SIGHUP);
@@ -172,19 +163,23 @@ TermApp::AboutRequested()
void void
TermApp::MessageReceived(BMessage* msg) TermApp::MessageReceived(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what)
{
case MENU_NEW_TREM: case MENU_NEW_TREM:
this->RunNewTerm(); {
RunNewTerm();
break; break;
}
case MENU_SWITCH_TERM: case MENU_SWITCH_TERM:
this->SwitchTerm(); {
SwitchTerm();
break; break;
}
case MSG_ACTIVATE_TERM: case MSG_ACTIVATE_TERM:
{
fTermWindow->TermWinActivate(); fTermWindow->TermWinActivate();
break; break;
}
case MSG_TERM_IS_MINIMIZE: case MSG_TERM_IS_MINIMIZE:
{ {
BMessage reply(B_REPLY); BMessage reply(B_REPLY);
@@ -193,10 +188,12 @@ TermApp::MessageReceived(BMessage* msg)
break; break;
} }
default: default:
{
BApplication::MessageReceived(msg); BApplication::MessageReceived(msg);
break; break;
} }
} }
}
struct standard_args struct standard_args
{ {
@@ -224,11 +221,6 @@ struct standard_args standard_args[] =
{ "-imsel", "--im-select-color", 0, 1, PREF_IM_SELECT_COLOR }, { "-imsel", "--im-select-color", 0, 1, PREF_IM_SELECT_COLOR },
}; };
////////////////////////////////////////////////////////////////////////////
// ArgvReceived
// terminal option '--help' view help screen */
// checking args
////////////////////////////////////////////////////////////////////////////
void void
TermApp::ArgvReceived(int32 argc, char **argv) TermApp::ArgvReceived(int32 argc, char **argv)
{ {
@@ -236,42 +228,43 @@ TermApp::ArgvReceived(int32 argc, char **argv)
char *value = 0; char *value = 0;
rgb_color color; rgb_color color;
if (argc > 1) { if(argc < 2)
return;
sort_args(argc, argv); sort_args(argc, argv);
argc = 0; argc = 0;
while (argv[argc]) argc++; while(argv[argc])
argc++;
/* Print usage. */ // Print usage
if(argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)) { if(argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)) {
this->Usage (argv[0]);
Usage(argv[0]);
usage_requested = true; usage_requested = true;
this->PostMessage (B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
/* Load preference file. */ // Load preference file
if (argmatch (argv, argc, "-p", "--preference", 4, &value, &skip_args)) { if(argmatch(argv, argc, "-p", "--preference", 4, &value, &skip_args))
gTermPref->Open(value); gTermPref->Open(value);
}
// Set window title
/* Set window title. */ if(argmatch(argv ,argc, "-t", "--title", 3, &value, &skip_args))
if (argmatch (argv ,argc, "-t", "--title", 3, &value, &skip_args)) {
strcpy(gWindowName, value); strcpy(gWindowName, value);
} // Set window geometry
/* Set window geometry. */
if(argmatch(argv, argc, "-geom", "--geometry", 4, &value, &skip_args)) { if(argmatch(argv, argc, "-geom", "--geometry", 4, &value, &skip_args)) {
int width, height, xpos, ypos; int width, height, xpos, ypos;
sscanf(value, "%dx%d+%d+%d", &width, &height, &xpos, &ypos); sscanf(value, "%dx%d+%d+%d", &width, &height, &xpos, &ypos);
if (width < 0 || height < 0 || xpos < 0 || ypos < 0 || if(width < 0 || height < 0 || xpos < 0 || ypos < 0
width >= 256 || height >= 256 || xpos >= 2048 || ypos >= 2048) { || width >= 256 || height >= 256 || xpos >= 2048 || ypos >= 2048) {
fprintf(stderr, "%s: invalid geometry format or value.\n", argv[0]); fprintf(stderr, "%s: invalid geometry format or value.\n", argv[0]);
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
usage_requested = true; usage_requested = true;
this->PostMessage (B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
gTermPref->setInt32(PREF_COLS, width); gTermPref->setInt32(PREF_COLS, width);
gTermPref->setInt32(PREF_ROWS, height); gTermPref->setInt32(PREF_ROWS, height);
@@ -280,48 +273,48 @@ TermApp::ArgvReceived(int32 argc, char **argv)
geometry_requested = true; geometry_requested = true;
} }
/* Open '/etc/rgb.txt' file. */ // Open '/etc/rgb.txt' file
BFile inFile; BFile inFile;
status_t sts; status_t sts;
off_t size = 0; off_t size = 0;
sts = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY); sts = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY);
if(sts != B_OK) { if(sts != B_OK) {
fprintf(stderr, "%s: Can't open /etc/rgb.txt file.\n", argv[0]); fprintf(stderr, "%s: Can't open /etc/rgb.txt file.\n", argv[0]);
usage_requested = true; usage_requested = true;
this->PostMessage (B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
inFile.GetSize(&size); inFile.GetSize(&size);
char *buffer = new char [size]; char *buffer = new char [size];
inFile.Read(buffer, size); inFile.Read(buffer, size);
/* Set window, cursor, area and IM color. */ // Set window, cursor, area and IM color
for(int i = 4; i < 13; i++) { for(int i = 4; i < 13; i++) {
if (argmatch (argv, argc, if(argmatch(argv, argc, standard_args[i].name, standard_args[i].longname,
standard_args[i].name,
standard_args[i].longname,
9, &value, &skip_args)) { 9, &value, &skip_args)) {
if (text_to_rgb (value, &color, buffer)) { if(text_to_rgb(value, &color, buffer))
gTermPref->setRGB(standard_args[i].prefname, color); gTermPref->setRGB(standard_args[i].prefname, color);
} else { else
fprintf(stderr, "%s: invalid color string -- %s\n", argv[0], value); fprintf(stderr, "%s: invalid color string -- %s\n", argv[0], value);
} }
} }
}
delete buffer; delete buffer;
skip_args++; skip_args++;
if(skip_args < argc) { if(skip_args < argc) {
/* Check invalid options */ // Check invalid options
if(*argv[skip_args] == '-') { if(*argv[skip_args] == '-') {
fprintf(stderr, "%s: invalid option `%s'\n", argv[0], argv[skip_args]); fprintf(stderr, "%s: invalid option `%s'\n", argv[0], argv[skip_args]);
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
usage_requested = true; usage_requested = true;
this->PostMessage (B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
CommandLine += argv[skip_args++]; CommandLine += argv[skip_args++];
@@ -331,12 +324,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
} }
} }
} }
}
////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////
//void //void
//TermApp::AboutRequested(void) //TermApp::AboutRequested(void)
//{ //{
@@ -353,17 +341,13 @@ TermApp::ArgvReceived(int32 argc, char **argv)
// } // }
//} //}
////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////
void void
TermApp::RefsReceived(BMessage *message) TermApp::RefsReceived(BMessage *message)
{ {
// Works Only Launced by Double-Click file, or Drags file to App. // Works Only Launced by Double-Click file, or Drags file to App.
if (!(this->IsLaunching())){ if(!(IsLaunching()))
return; return;
}
entry_ref ref; entry_ref ref;
if( message->FindRef("refs", 0, &ref) != B_OK ) if( message->FindRef("refs", 0, &ref) != B_OK )
@@ -379,62 +363,46 @@ TermApp::RefsReceived(BMessage *message)
// if App opened by Pref file // if App opened by Pref file
if(!strcmp(mimetype, PREFFILE_MIMETYPE)){ if(!strcmp(mimetype, PREFFILE_MIMETYPE)){
BEntry ent(&ref); BEntry ent(&ref);
BPath path(&ent); BPath path(&ent);
gTermPref->OpenText(path.Path()); gTermPref->OpenText(path.Path());
return; return;
} }
// if App opened by Shell Script // if App opened by Shell Script
if(!strcmp(mimetype, "text/x-haiku-shscript")){ if(!strcmp(mimetype, "text/x-haiku-shscript")){
// Not implemented. // Not implemented.
// beep(); // beep();
return; return;
} }
} }
////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////
void void
TermApp::MakeTermWindow(BRect &frame) TermApp::MakeTermWindow(BRect &frame)
{ {
/* Create Window Object. */
fTermWindow = new TermWindow(frame, fWindowNumber); fTermWindow = new TermWindow(frame, fWindowNumber);
fTermWindow->Show(); fTermWindow->Show();
} }
////////////////////////////////////////////////////////////////////////////
// RunNewTerm
// Launch New Terminal.
////////////////////////////////////////////////////////////////////////////
void void
TermApp::RunNewTerm(void) TermApp::RunNewTerm(void)
{ {
be_roster->Launch(TERM_SIGNATURE); be_roster->Launch(TERM_SIGNATURE);
} }
////////////////////////////////////////////////////////////////////////////
// ActivateTermWindow
// Activate TermWindow (not Pref...)
////////////////////////////////////////////////////////////////////////////
void void
TermApp::ActivateTermWindow(team_id id) TermApp::ActivateTermWindow(team_id id)
{ {
BMessenger app(TERM_SIGNATURE, id); BMessenger app(TERM_SIGNATURE, id);
if (app.IsTargetLocal()){ if(app.IsTargetLocal())
fTermWindow->Activate(); fTermWindow->Activate();
}else{ else
app.SendMessage(MSG_ACTIVATE_TERM); app.SendMessage(MSG_ACTIVATE_TERM);
} }
}
////////////////////////////////////////////////////////////////////////////
// SwitchTerm
// Switch to other running terminal
////////////////////////////////////////////////////////////////////////////
void void
TermApp::SwitchTerm() TermApp::SwitchTerm()
{ {
@@ -442,34 +410,34 @@ TermApp::SwitchTerm()
BList teams; BList teams;
be_roster->GetAppList(TERM_SIGNATURE, &teams); be_roster->GetAppList(TERM_SIGNATURE, &teams);
int32 numTerms = teams.CountItems(); int32 numTerms = teams.CountItems();
if (numTerms <= 1 ) return; //Can't Switch !!
if(numTerms <= 1 )
return; //Can't Switch !!
// Find position of mine in app teams. // Find position of mine in app teams.
int32 i; int32 i;
for(i = 0; i < numTerms; i++) { for(i = 0; i < numTerms; i++) {
if(myId == reinterpret_cast<team_id>(teams.ItemAt(i))) break; if(myId == reinterpret_cast<team_id>(teams.ItemAt(i)))
break;
} }
do{ do{
if(--i < 0) i = numTerms - 1; if(--i < 0)
i = numTerms - 1;
} while(IsMinimize(reinterpret_cast<team_id>(teams.ItemAt(i)))); } while(IsMinimize(reinterpret_cast<team_id>(teams.ItemAt(i))));
// Activate switched terminal. // Activate switched terminal.
ActivateTermWindow(reinterpret_cast<team_id>(teams.ItemAt(i))); ActivateTermWindow(reinterpret_cast<team_id>(teams.ItemAt(i)));
} }
////////////////////////////////////////////////////////////////////////////
// IsMinimize
// Check Specified Terminal Window is Minimized or not.
////////////////////////////////////////////////////////////////////////////
bool bool
TermApp::IsMinimize(team_id id) TermApp::IsMinimize(team_id id)
{ {
BMessenger app(TERM_SIGNATURE, id); BMessenger app(TERM_SIGNATURE, id);
if (app.IsTargetLocal()){ if(app.IsTargetLocal())
return fTermWindow->IsMinimized(); return fTermWindow->IsMinimized();
}
BMessage reply; BMessage reply;
bool hidden; bool hidden;
@@ -481,10 +449,6 @@ TermApp::IsMinimize(team_id id)
return hidden; return hidden;
} }
////////////////////////////////////////////////////////////////////////////
// ShowHTML(const char *url)
// show specified url by Netpositive.
////////////////////////////////////////////////////////////////////////////
//#ifndef B_NETPOSITIVE_APP_SIGNATURE //#ifndef B_NETPOSITIVE_APP_SIGNATURE
//#define B_NETPOSITIVE_APP_SIGNATURE "application/x-vnd.Be-NPOS" //#define B_NETPOSITIVE_APP_SIGNATURE "application/x-vnd.Be-NPOS"
@@ -508,19 +472,16 @@ TermApp::IsMinimize(team_id id)
// be_roster->ActivateApp(be_roster->TeamFor(B_NETPOSITIVE_APP_SIGNATURE)); // be_roster->ActivateApp(be_roster->TeamFor(B_NETPOSITIVE_APP_SIGNATURE));
//} //}
////////////////////////////////////////////////////////////////////////////
// Usage
// Display usage to stderr
////////////////////////////////////////////////////////////////////////////
#define PR(a) fprintf(stderr, a) #define PR(a) fprintf(stderr, a)
// Display usage to stderr
void void
TermApp::Usage(char *name) TermApp::Usage(char *name)
{ {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "Haiku Terminal\n"); fprintf(stderr, "Haiku Terminal\n");
fprintf(stderr, "Copyright 2004 Haiku, Inc.\n"); fprintf(stderr, "Copyright 2004 Haiku, Inc.\n");
fprintf (stderr, "Parts Copyrigth (C) 1999 Kazuho Okui and Takashi Murai.\n"); fprintf(stderr, "Parts Copyright(C) 1999 Kazuho Okui and Takashi Murai.\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "Usage: %s [OPTION] [SHELL]\n", name); fprintf(stderr, "Usage: %s [OPTION] [SHELL]\n", name);
@@ -536,22 +497,18 @@ TermApp::Usage (char *name)
PR(" -selbg, --select-back-color set selection area background color\n"); PR(" -selbg, --select-back-color set selection area background color\n");
PR(" Examples of color are \"#FF00FF\" and \"purple\"\n"); PR(" Examples of color are \"#FF00FF\" and \"purple\"\n");
PR("\n"); PR("\n");
} }
////////////////////////////////////////////////////////////////////////////
// text_to_rgb
// Convert string to rgb_color structure.
////////////////////////////////////////////////////////////////////////////
int int
text_to_rgb(char *name, rgb_color *color, char *buffer) text_to_rgb(char *name, rgb_color *color, char *buffer)
{ {
if(name[0] != '#') { if(name[0] != '#') {
/* Convert from /etc/rgb.txt. */
// Convert from /etc/rgb.txt.
BString inStr(buffer); BString inStr(buffer);
int32 point, offset = 0; int32 point, offset = 0;
/* Search color name */ // Search color name
do { do {
point = inStr.FindFirst(name, offset); point = inStr.FindFirst(name, offset);
if(point < 0) if(point < 0)
@@ -561,33 +518,31 @@ text_to_rgb (char *name, rgb_color *color, char *buffer)
char *p = buffer + point; char *p = buffer + point;
while (*p != '\n') p--; while(*p != '\n')
p--;
p++; p++;
if (sscanf (p, "%d %d %d", if(sscanf(p, "%d %d %d", (int *)&color->red, (int *)&color->green,
(int *)&color->red,
(int *)&color->green,
(int *)&color->blue) == EOF) (int *)&color->blue) == EOF)
return false; return false;
color->alpha = 0; color->alpha = 0;
} }
else if (name[0] == '#') { else
/* Convert from #RRGGBB format */ if(name[0] == '#') {
sscanf (name, "#%2x%2x%2x",
(int *)&color->red, // Convert from #RRGGBB format
(int *)&color->green, sscanf(name, "#%2x%2x%2x", (int *)&color->red, (int *)&color->green,
(int *)&color->blue); (int *)&color->blue);
color->alpha = 0; color->alpha = 0;
} }
else else
return false; return false;
return true; return true;
} }
////////////////////////////////////////////////////////////////////////////
// argmatch
// This routine copy from GNU Emacs. // This routine copy from GNU Emacs.
//////////////////////////////////////////////////////////////////////////// // TODO: This might be a GPL licensing issue here. Investigate.
int int
argmatch(char **argv, int argc, char *sstr, char *lstr, argmatch(char **argv, int argc, char *sstr, char *lstr,
int minlen, char **valptr, int *skipptr) int minlen, char **valptr, int *skipptr)
@@ -596,13 +551,14 @@ argmatch (char **argv, int argc, char *sstr, char *lstr,
int arglen; int arglen;
char *arg; char *arg;
/* Don't access argv[argc]; give up in advance. */ // Don't access argv[argc]; give up in advance
if(argc <= *skipptr + 1) if(argc <= *skipptr + 1)
return 0; return 0;
arg = argv[*skipptr+1]; arg = argv[*skipptr+1];
if(arg == NULL) if(arg == NULL)
return 0; return 0;
if(strcmp(arg, sstr) == 0) if(strcmp(arg, sstr) == 0)
{ {
if(valptr != NULL) if(valptr != NULL)
@@ -614,22 +570,27 @@ argmatch (char **argv, int argc, char *sstr, char *lstr,
*skipptr += 1; *skipptr += 1;
return 1; return 1;
} }
arglen =(valptr != NULL &&(p = strchr(arg, '=')) != NULL arglen =(valptr != NULL &&(p = strchr(arg, '=')) != NULL
? p - arg : strlen(arg)); ? p - arg : strlen(arg));
if(lstr == 0 || arglen < minlen || strncmp(arg, lstr, arglen) != 0) if(lstr == 0 || arglen < minlen || strncmp(arg, lstr, arglen) != 0)
return 0; return 0;
else if (valptr == NULL) else
if(valptr == NULL)
{ {
*skipptr += 1; *skipptr += 1;
return 1; return 1;
} }
else if (p != NULL) else
if(p != NULL)
{ {
*valptr = p+1; *valptr = p+1;
*skipptr += 1; *skipptr += 1;
return 1; return 1;
} }
else if (argv[*skipptr+2] != NULL) else
if(argv[*skipptr+2] != NULL)
{ {
*valptr = argv[*skipptr+2]; *valptr = argv[*skipptr+2];
*skipptr += 2; *skipptr += 2;
@@ -640,19 +601,22 @@ argmatch (char **argv, int argc, char *sstr, char *lstr,
return 0; return 0;
} }
} }
////////////////////////////////////////////////////////////////////////////
// sort_args
// This routine copy from GNU Emacs. // This routine copy from GNU Emacs.
//////////////////////////////////////////////////////////////////////////// // TODO: This might be a GPL licensing issue here. Investigate.
void void
sort_args(int argc, char **argv) sort_args(int argc, char **argv)
{ {
char **newargv = (char **) malloc (sizeof (char *) * argc); /*
/* For each element of argv, For each element of argv,
the corresponding element of options is: the corresponding element of options is:
0 for an option that takes no arguments, 0 for an option that takes no arguments,
1 for an option that takes one argument, etc. 1 for an option that takes one argument, etc.
-1 for an ordinary non-option argument. */ -1 for an ordinary non-option argument.
*/
char **newargv =(char **) malloc(sizeof(char *) * argc);
int *options =(int *) malloc(sizeof(int) * argc); int *options =(int *) malloc(sizeof(int) * argc);
int *priority =(int *) malloc(sizeof(int) * argc); int *priority =(int *) malloc(sizeof(int) * argc);
int to = 1; int to = 1;
@@ -661,8 +625,8 @@ sort_args (int argc, char **argv)
int i; int i;
//int end_of_options = argc; //int end_of_options = argc;
/* Categorize all the options, // Categorize all the options,
and figure out which argv elts are option arguments. */ // and figure out which argv elts are option arguments
for(from = 1; from < argc; from++) for(from = 1; from < argc; from++)
{ {
options[from] = -1; options[from] = -1;
@@ -672,11 +636,10 @@ sort_args (int argc, char **argv)
int match, thislen; int match, thislen;
char *equals; char *equals;
/* If we have found "--", don't consider // If we have found "--", don't consider any more arguments as options
any more arguments as options. */
if(argv[from][1] == '-' && argv[from][2] == 0) if(argv[from][1] == '-' && argv[from][2] == 0)
{ {
/* Leave the "--", and everything following it, at the end. */ // Leave the "--", and everything following it, at the end.
for(; from < argc; from++) for(; from < argc; from++)
{ {
priority[from] = -100; priority[from] = -100;
@@ -685,10 +648,8 @@ sort_args (int argc, char **argv)
break; break;
} }
/* Look for a match with a known old-fashioned option. */ // Look for a match with a known old-fashioned option.
for (i = 0; for(i = 0; i <(int)(sizeof(standard_args) / sizeof(standard_args[0])); i++)
i < (int)(sizeof (standard_args) / sizeof (standard_args[0]));
i++)
if(!strcmp(argv[from], standard_args[i].name)) if(!strcmp(argv[from], standard_args[i].name))
{ {
options[from] = standard_args[i].nargs; options[from] = standard_args[i].nargs;
@@ -699,9 +660,11 @@ sort_args (int argc, char **argv)
goto done; goto done;
} }
/* Look for a match with a known long option. /*
Look for a match with a known long option.
MATCH is -1 if no match so far, -2 if two or more matches so far, MATCH is -1 if no match so far, -2 if two or more matches so far,
>= 0 (the table index of the match) if just one match so far. */ >= 0(the table index of the match) if just one match so far.
*/
if(argv[from][1] == '-') if(argv[from][1] == '-')
{ {
match = -1; match = -1;
@@ -710,12 +673,9 @@ sort_args (int argc, char **argv)
if(equals != 0) if(equals != 0)
thislen = equals - argv[from]; thislen = equals - argv[from];
for (i = 0; for(i = 0;i <(int )(sizeof(standard_args) / sizeof(standard_args[0])); i++)
i < (int )(sizeof (standard_args) / sizeof (standard_args[0]));
i++)
if(standard_args[i].longname if(standard_args[i].longname
&& !strncmp (argv[from], standard_args[i].longname, && !strncmp(argv[from], standard_args[i].longname, thislen))
thislen))
{ {
if(match == -1) if(match == -1)
match = i; match = i;
@@ -723,13 +683,14 @@ sort_args (int argc, char **argv)
match = -2; match = -2;
} }
/* If we found exactly one match, use that. */ // If we found exactly one match, use that
if(match >= 0) if(match >= 0)
{ {
options[from] = standard_args[match].nargs; options[from] = standard_args[match].nargs;
priority[from] = standard_args[match].priority; priority[from] = standard_args[match].priority;
/* If --OPTION=VALUE syntax is used,
this option uses just one argv element. */ // If --OPTION=VALUE syntax is used,
// this option uses just one argv element
if(equals != 0) if(equals != 0)
options[from] = 0; options[from] = 0;
if(from + options[from] >= argc) if(from + options[from] >= argc)
@@ -741,15 +702,15 @@ sort_args (int argc, char **argv)
} }
} }
/* Copy the arguments, in order of decreasing priority, to NEW. */ // Copy the arguments, in order of decreasing priority, to NEW
newargv[0] = argv[0]; newargv[0] = argv[0];
while(incoming_used < argc) while(incoming_used < argc)
{ {
int best = -1; int best = -1;
int best_priority = -9999; int best_priority = -9999;
/* Find the highest priority remaining option. // Find the highest priority remaining option.
If several have equal priority, take the first of them. */ // If several have equal priority, take the first of them.
for(from = 1; from < argc; from++) for(from = 1; from < argc; from++)
{ {
if(argv[from] != 0 && priority[from] > best_priority) if(argv[from] != 0 && priority[from] > best_priority)
@@ -757,7 +718,8 @@ sort_args (int argc, char **argv)
best_priority = priority[from]; best_priority = priority[from];
best = from; best = from;
} }
/* Skip option arguments--they are tied to the options. */
// Skip option arguments--they are tied to the options.
if(options[from] > 0) if(options[from] > 0)
from += options[from]; from += options[from];
} }
@@ -765,10 +727,9 @@ sort_args (int argc, char **argv)
if(best < 0) if(best < 0)
abort(); abort();
/* Copy the highest priority remaining option, with its args, to NEW. // Copy the highest priority remaining option, with its args, to NEW.
Unless it is a duplicate of the previous one. */ // Unless it is a duplicate of the previous one
if (! (options[best] == 0 if(!(options[best] == 0 && ! strcmp(newargv[to - 1], argv[best])))
&& ! strcmp (newargv[to - 1], argv[best])))
{ {
newargv[to++] = argv[best]; newargv[to++] = argv[best];
for(i = 0; i < options[best]; i++) for(i = 0; i < options[best]; i++)
@@ -777,13 +738,13 @@ sort_args (int argc, char **argv)
incoming_used += 1 +(options[best] > 0 ? options[best] : 0); incoming_used += 1 +(options[best] > 0 ? options[best] : 0);
/* Clear out this option in ARGV. */ // Clear out this option in ARGV
argv[best] = 0; argv[best] = 0;
for(i = 0; i < options[best]; i++) for(i = 0; i < options[best]; i++)
argv[best + i + 1] = 0; argv[best + i + 1] = 0;
} }
/* If duplicate options were deleted, fill up extra space with null ptrs. */ // If duplicate options were deleted, fill up extra space with null ptrs
while(to < argc) while(to < argc)
newargv[to++] = 0; newargv[to++] = 0;
+3 -1
View File
@@ -1512,8 +1512,11 @@ TermView::MessageReceived(BMessage *msg)
DoFileDrop(ref); DoFileDrop(ref);
while(msg->FindRef("refs", i++, &ref) == B_OK) while(msg->FindRef("refs", i++, &ref) == B_OK)
{
WritePTY((const uchar*)" ",1);
DoFileDrop(ref); DoFileDrop(ref);
} }
}
else else
{ {
BView::MessageReceived(msg); BView::MessageReceived(msg);
@@ -1608,7 +1611,6 @@ TermView::DoFileDrop(entry_ref &ref)
BString string(path.Path()); BString string(path.Path());
string.CharacterEscape(" ~`#$&*()\\|[]{};'\"<>?!",'\\'); string.CharacterEscape(" ~`#$&*()\\|[]{};'\"<>?!",'\\');
string+=" ";
WritePTY((const uchar *)string.String(), string.Length()); WritePTY((const uchar *)string.String(), string.Length());
} }
+3 -27
View File
@@ -1,34 +1,10 @@
/* /*
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> * Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net>
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net> * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files or portions
* thereof (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice
* in the binary, as well as this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* *
* Distributed unter the terms of the MIT license.
*/ */
#include <app/Application.h> #include <app/Application.h>
#include <Menu.h> #include <Menu.h>
#include <MenuBar.h> #include <MenuBar.h>
+2 -1
View File
@@ -56,6 +56,7 @@ extern PrefHandler *gTermPref;
#define SHELL_COMMAND "/bin/sh -login" #define SHELL_COMMAND "/bin/sh -login"
extern char **environ; extern char **environ;
// TODO: This is *definitely* not a helpful error message
char spawn_alert_msg [] = \ char spawn_alert_msg [] = \
"alert --stop " \ "alert --stop " \
"'Haiku Terminal Error!!\n\ "'Haiku Terminal Error!!\n\
@@ -96,7 +97,7 @@ setenv(const char *var, const char *value, bool overwrite)
/* /*
* reapchild. Child process is out there, let's catch its terminaltion. * reapchild. Child process is out there, let's catch its termination.
*/ */