minor changes (a couple of error messages added to wxExecute)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@867 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1998-10-18 21:33:25 +00:00
parent ddbbbdd486
commit 02847e5984
3 changed files with 133 additions and 113 deletions

View File

@ -172,7 +172,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList) IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList)
#endif #endif
wxPostScriptDC::wxPostScriptDC (void) wxPostScriptDC::wxPostScriptDC ()
{ {
// m_yOrigin = 792; // For EPS output // m_yOrigin = 792; // For EPS output
m_yOrigin = 842; // For A4 output m_yOrigin = 842; // For A4 output
@ -236,7 +236,7 @@ bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *pa
return m_ok; return m_ok;
} }
wxPostScriptDC::~wxPostScriptDC (void) wxPostScriptDC::~wxPostScriptDC ()
{ {
if (m_pstream) if (m_pstream)
delete m_pstream; delete m_pstream;
@ -305,7 +305,7 @@ void wxPostScriptDC::SetClippingRegion (long cx, long cy, long cw, long ch)
*m_pstream << "closepath clip newpath\n"; *m_pstream << "closepath clip newpath\n";
} }
void wxPostScriptDC::DestroyClippingRegion (void) void wxPostScriptDC::DestroyClippingRegion ()
{ {
if (!m_pstream) if (!m_pstream)
return; return;
@ -316,7 +316,7 @@ void wxPostScriptDC::DestroyClippingRegion (void)
} }
} }
void wxPostScriptDC::Clear (void) void wxPostScriptDC::Clear ()
{ {
} }
@ -1084,7 +1084,7 @@ bool wxPostScriptDC::StartDoc (const wxString& message)
} }
void wxPostScriptDC::EndDoc (void) void wxPostScriptDC::EndDoc ()
{ {
static char wxPostScriptHeaderReencodeISO1[] = static char wxPostScriptHeaderReencodeISO1[] =
"\n/reencodeISO {\n" "\n/reencodeISO {\n"
@ -1323,7 +1323,7 @@ void wxPostScriptDC::EndDoc (void)
#endif #endif
} }
void wxPostScriptDC::StartPage (void) void wxPostScriptDC::StartPage ()
{ {
if (!m_pstream) if (!m_pstream)
return; return;
@ -1355,7 +1355,7 @@ void wxPostScriptDC::StartPage (void)
*m_pstream << translate_x << " " << translate_y << " translate\n"; *m_pstream << translate_x << " " << translate_y << " translate\n";
} }
void wxPostScriptDC::EndPage (void) void wxPostScriptDC::EndPage ()
{ {
if (!m_pstream) if (!m_pstream)
return; return;
@ -1545,7 +1545,7 @@ Blit (long xdest, long ydest, long fwidth, long fheight,
return TRUE; return TRUE;
} }
long wxPostScriptDC::GetCharHeight (void) long wxPostScriptDC::GetCharHeight ()
{ {
if (m_font.Ok()) if (m_font.Ok())
return m_font.GetPointSize (); return m_font.GetPointSize ();
@ -1866,7 +1866,7 @@ void wxPostScriptDC::DrawSpline( wxList *points )
*(GetStream()) << c << " " << (GetYOrigin() - d) << " lineto stroke\n"; *(GetStream()) << c << " " << (GetYOrigin() - d) << " lineto stroke\n";
} }
long wxPostScriptDC::GetCharWidth (void) long wxPostScriptDC::GetCharWidth ()
{ {
// Chris Breeze: reasonable approximation using wxMODERN/Courier // Chris Breeze: reasonable approximation using wxMODERN/Courier
return (long) (GetCharHeight() * 72.0 / 120.0); return (long) (GetCharHeight() * 72.0 / 120.0);
@ -2136,7 +2136,7 @@ wxDialog(parent, -1, title, pos, size, style)
wxEndBusyCursor(); wxEndBusyCursor();
} }
int wxPostScriptPrintDialog::ShowModal (void) int wxPostScriptPrintDialog::ShowModal ()
{ {
if ( wxDialog::ShowModal() == wxID_OK ) if ( wxDialog::ShowModal() == wxID_OK )
{ {
@ -2221,27 +2221,27 @@ void wxSetAFMPath(const char *f)
} }
// Get current values // Get current values
char *wxGetPrinterCommand(void) char *wxGetPrinterCommand()
{ {
return wxThePrintSetupData->GetPrinterCommand(); return wxThePrintSetupData->GetPrinterCommand();
} }
char *wxGetPrintPreviewCommand(void) char *wxGetPrintPreviewCommand()
{ {
return wxThePrintSetupData->GetPrintPreviewCommand(); return wxThePrintSetupData->GetPrintPreviewCommand();
} }
char *wxGetPrinterOptions(void) char *wxGetPrinterOptions()
{ {
return wxThePrintSetupData->GetPrinterOptions(); return wxThePrintSetupData->GetPrinterOptions();
} }
char *wxGetPrinterFile(void) char *wxGetPrinterFile()
{ {
return wxThePrintSetupData->GetPrinterFile(); return wxThePrintSetupData->GetPrinterFile();
} }
int wxGetPrinterOrientation(void) int wxGetPrinterOrientation()
{ {
return wxThePrintSetupData->GetPrinterOrientation(); return wxThePrintSetupData->GetPrinterOrientation();
} }
@ -2256,12 +2256,12 @@ void wxGetPrinterTranslation(long *x, long *y)
wxThePrintSetupData->GetPrinterTranslation(x, y); wxThePrintSetupData->GetPrinterTranslation(x, y);
} }
int wxGetPrinterMode(void) int wxGetPrinterMode()
{ {
return wxThePrintSetupData->GetPrinterMode(); return wxThePrintSetupData->GetPrinterMode();
} }
char *wxGetAFMPath(void) char *wxGetAFMPath()
{ {
return wxThePrintSetupData->GetAFMPath(); return wxThePrintSetupData->GetAFMPath();
} }
@ -2270,7 +2270,7 @@ char *wxGetAFMPath(void)
* Print setup data * Print setup data
*/ */
wxPrintSetupData::wxPrintSetupData(void) wxPrintSetupData::wxPrintSetupData()
{ {
printerCommand = (char *) NULL; printerCommand = (char *) NULL;
previewCommand = (char *) NULL; previewCommand = (char *) NULL;
@ -2288,7 +2288,7 @@ wxPrintSetupData::wxPrintSetupData(void)
printerFile = (char *) NULL; printerFile = (char *) NULL;
} }
wxPrintSetupData::~wxPrintSetupData(void) wxPrintSetupData::~wxPrintSetupData()
{ {
if (printerCommand) if (printerCommand)
delete[] printerCommand; delete[] printerCommand;
@ -2411,32 +2411,32 @@ void wxPrintSetupData::SetColour(bool col)
} }
// Get current values // Get current values
char *wxPrintSetupData::GetPrinterCommand(void) char *wxPrintSetupData::GetPrinterCommand()
{ {
return printerCommand; return printerCommand;
} }
char *wxPrintSetupData::GetPrintPreviewCommand(void) char *wxPrintSetupData::GetPrintPreviewCommand()
{ {
return previewCommand; return previewCommand;
} }
char *wxPrintSetupData::GetPrinterOptions(void) char *wxPrintSetupData::GetPrinterOptions()
{ {
return printerFlags; return printerFlags;
} }
char *wxPrintSetupData::GetPrinterFile(void) char *wxPrintSetupData::GetPrinterFile()
{ {
return printerFile; return printerFile;
} }
char *wxPrintSetupData::GetPaperName(void) char *wxPrintSetupData::GetPaperName()
{ {
return paperName; return paperName;
} }
int wxPrintSetupData::GetPrinterOrientation(void) int wxPrintSetupData::GetPrinterOrientation()
{ {
return printerOrient; return printerOrient;
} }
@ -2453,17 +2453,17 @@ void wxPrintSetupData::GetPrinterTranslation(long *x, long *y)
*y = printerTranslateY; *y = printerTranslateY;
} }
int wxPrintSetupData::GetPrinterMode(void) int wxPrintSetupData::GetPrinterMode()
{ {
return printerMode; return printerMode;
} }
char *wxPrintSetupData::GetAFMPath(void) char *wxPrintSetupData::GetAFMPath()
{ {
return afmPath; return afmPath;
} }
bool wxPrintSetupData::GetColour(void) bool wxPrintSetupData::GetColour()
{ {
return printColour; return printColour;
} }
@ -2538,21 +2538,21 @@ wxPrintPaperType::wxPrintPaperType(const char *name, int wmm, int hmm, int wp, i
pageName = copystring(name); pageName = copystring(name);
} }
wxPrintPaperType::~wxPrintPaperType(void) wxPrintPaperType::~wxPrintPaperType()
{ {
delete[] pageName; delete[] pageName;
} }
wxPrintPaperDatabase::wxPrintPaperDatabase(void):wxList(wxKEY_STRING) wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING)
{ {
DeleteContents(TRUE); DeleteContents(TRUE);
} }
wxPrintPaperDatabase::~wxPrintPaperDatabase(void) wxPrintPaperDatabase::~wxPrintPaperDatabase()
{ {
} }
void wxPrintPaperDatabase::CreateDatabase(void) void wxPrintPaperDatabase::CreateDatabase()
{ {
// Need correct values for page size in pixels. // Need correct values for page size in pixels.
// Each unit is one 'point' = 1/72 of an inch. // Each unit is one 'point' = 1/72 of an inch.
@ -2570,7 +2570,7 @@ void wxPrintPaperDatabase::CreateDatabase(void)
AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009); AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009);
} }
void wxPrintPaperDatabase::ClearDatabase(void) void wxPrintPaperDatabase::ClearDatabase()
{ {
Clear(); Clear();
} }

View File

@ -16,6 +16,9 @@
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/string.h" #include "wx/string.h"
#include "wx/intl.h"
#include "wx/log.h"
#include <stdarg.h> #include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
@ -30,7 +33,7 @@
#ifdef __SVR4__ #ifdef __SVR4__
#include <sys/systeminfo.h> #include <sys/systeminfo.h>
#endif #endif
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -203,7 +206,7 @@ void wxFatalError( const wxString &msg, const wxString &title )
if (!title.IsNull()) fprintf( stderr, "%s ", WXSTRINGCAST(title) ); if (!title.IsNull()) fprintf( stderr, "%s ", WXSTRINGCAST(title) );
if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) ); if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) );
fprintf( stderr, ".\n" ); fprintf( stderr, ".\n" );
exit(1); exit(3); // the same exit code as for abort()
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -222,10 +225,11 @@ bool wxDirExists( const wxString& dir )
// subprocess routines // subprocess routines
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef struct { struct wxEndProcessData
{
gint pid, tag; gint pid, tag;
wxProcess *process; wxProcess *process;
} wxEndProcessData; };
static void GTK_EndProcessDetector(gpointer data, gint source, static void GTK_EndProcessDetector(gpointer data, gint source,
GdkInputCondition WXUNUSED(condition) ) GdkInputCondition WXUNUSED(condition) )
@ -261,12 +265,11 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
wxEndProcessData *data = new wxEndProcessData; wxEndProcessData *data = new wxEndProcessData;
int end_proc_detect[2]; int end_proc_detect[2];
if (*argv == NULL) wxCHECK_MSG( *argv, 0, "can't exec empty command" );
return 0;
/* Create pipes */ /* Create pipes */
if (pipe(end_proc_detect) == -1) { if (pipe(end_proc_detect) == -1) {
perror("pipe failed"); wxLogSysError(_("Pipe creation failed"));
return 0; return 0;
} }
@ -277,60 +280,67 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
pid_t pid = fork(); pid_t pid = fork();
#endif #endif
if (pid == -1) { if (pid == -1) {
perror ("fork failed"); // error
wxLogSysError(_("Fork failed"));
return 0; return 0;
} else if (pid == 0) { }
/* Close fd not useful */ else if (pid == 0) {
// we're in child
close(end_proc_detect[0]); // close reading side close(end_proc_detect[0]); // close reading side
/* child */
#ifdef _AIX #ifdef _AIX
execvp ((const char *)*argv, (const char **)argv); execvp ((const char *)*argv, (const char **)argv);
#else #else
execvp (*argv, argv); execvp (*argv, argv);
#endif #endif
if (errno == ENOENT) // there is no return after successful exec()
wxError("command not found", *argv); wxLogSysError(_("Can't execute '%s'"), *argv);
else
perror (*argv); _exit(-1);
wxError("could not execute", *argv);
_exit (-1);
} }
else {
// we're in parent
close(end_proc_detect[1]); // close writing side
data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ,
GTK_EndProcessDetector, (gpointer)data);
data->pid = pid;
if (!sync) {
data->process = process;
}
else {
data->process = (wxProcess *) NULL;
data->pid = -(data->pid);
close(end_proc_detect[1]); // close writing side while (data->pid != 0)
data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ, wxYield();
GTK_EndProcessDetector, (gpointer)data);
data->pid = pid;
if (!sync) {
data->process = process;
} else {
data->process = (wxProcess *) NULL;
data->pid = -(data->pid);
while (data->pid != 0) delete data;
wxYield(); }
delete data; // @@@ our return value indicates success even if execvp() in the child
// failed!
return pid;
} }
return pid;
}; };
long wxExecute( const wxString& command, bool sync, wxProcess *process ) long wxExecute( const wxString& command, bool sync, wxProcess *process )
{ {
if (command.IsNull() || command == "") return FALSE; static const char *IFS = " \t\n";
wxCHECK_MSG( !command.IsEmpty(), 0, "can't exec empty command" );
int argc = 0; int argc = 0;
char *argv[127]; char *argv[127];
char tmp[1024]; char *tmp = new char[command.Len() + 1];
const char *IFS = " \t\n"; strcpy(tmp, command);
strncpy (tmp, command, sizeof(tmp) / sizeof(char) - 1); argv[argc++] = strtok(tmp, IFS);
tmp[sizeof (tmp) / sizeof (char) - 1] = '\0';
argv[argc++] = strtok (tmp, IFS);
while ((argv[argc++] = strtok((char *) NULL, IFS)) != NULL) while ((argv[argc++] = strtok((char *) NULL, IFS)) != NULL)
/* loop */ ; /* loop */ ;
return wxExecute(argv, sync, process);
long lRc = wxExecute(argv, sync, process);
delete [] tmp;
return lRc;
}; };

View File

@ -16,6 +16,9 @@
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/string.h" #include "wx/string.h"
#include "wx/intl.h"
#include "wx/log.h"
#include <stdarg.h> #include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
@ -30,7 +33,7 @@
#ifdef __SVR4__ #ifdef __SVR4__
#include <sys/systeminfo.h> #include <sys/systeminfo.h>
#endif #endif
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -203,7 +206,7 @@ void wxFatalError( const wxString &msg, const wxString &title )
if (!title.IsNull()) fprintf( stderr, "%s ", WXSTRINGCAST(title) ); if (!title.IsNull()) fprintf( stderr, "%s ", WXSTRINGCAST(title) );
if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) ); if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) );
fprintf( stderr, ".\n" ); fprintf( stderr, ".\n" );
exit(1); exit(3); // the same exit code as for abort()
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -222,10 +225,11 @@ bool wxDirExists( const wxString& dir )
// subprocess routines // subprocess routines
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef struct { struct wxEndProcessData
{
gint pid, tag; gint pid, tag;
wxProcess *process; wxProcess *process;
} wxEndProcessData; };
static void GTK_EndProcessDetector(gpointer data, gint source, static void GTK_EndProcessDetector(gpointer data, gint source,
GdkInputCondition WXUNUSED(condition) ) GdkInputCondition WXUNUSED(condition) )
@ -261,12 +265,11 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
wxEndProcessData *data = new wxEndProcessData; wxEndProcessData *data = new wxEndProcessData;
int end_proc_detect[2]; int end_proc_detect[2];
if (*argv == NULL) wxCHECK_MSG( *argv, 0, "can't exec empty command" );
return 0;
/* Create pipes */ /* Create pipes */
if (pipe(end_proc_detect) == -1) { if (pipe(end_proc_detect) == -1) {
perror("pipe failed"); wxLogSysError(_("Pipe creation failed"));
return 0; return 0;
} }
@ -277,60 +280,67 @@ long wxExecute( char **argv, bool sync, wxProcess *process )
pid_t pid = fork(); pid_t pid = fork();
#endif #endif
if (pid == -1) { if (pid == -1) {
perror ("fork failed"); // error
wxLogSysError(_("Fork failed"));
return 0; return 0;
} else if (pid == 0) { }
/* Close fd not useful */ else if (pid == 0) {
// we're in child
close(end_proc_detect[0]); // close reading side close(end_proc_detect[0]); // close reading side
/* child */
#ifdef _AIX #ifdef _AIX
execvp ((const char *)*argv, (const char **)argv); execvp ((const char *)*argv, (const char **)argv);
#else #else
execvp (*argv, argv); execvp (*argv, argv);
#endif #endif
if (errno == ENOENT) // there is no return after successful exec()
wxError("command not found", *argv); wxLogSysError(_("Can't execute '%s'"), *argv);
else
perror (*argv); _exit(-1);
wxError("could not execute", *argv);
_exit (-1);
} }
else {
// we're in parent
close(end_proc_detect[1]); // close writing side
data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ,
GTK_EndProcessDetector, (gpointer)data);
data->pid = pid;
if (!sync) {
data->process = process;
}
else {
data->process = (wxProcess *) NULL;
data->pid = -(data->pid);
close(end_proc_detect[1]); // close writing side while (data->pid != 0)
data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ, wxYield();
GTK_EndProcessDetector, (gpointer)data);
data->pid = pid;
if (!sync) {
data->process = process;
} else {
data->process = (wxProcess *) NULL;
data->pid = -(data->pid);
while (data->pid != 0) delete data;
wxYield(); }
delete data; // @@@ our return value indicates success even if execvp() in the child
// failed!
return pid;
} }
return pid;
}; };
long wxExecute( const wxString& command, bool sync, wxProcess *process ) long wxExecute( const wxString& command, bool sync, wxProcess *process )
{ {
if (command.IsNull() || command == "") return FALSE; static const char *IFS = " \t\n";
wxCHECK_MSG( !command.IsEmpty(), 0, "can't exec empty command" );
int argc = 0; int argc = 0;
char *argv[127]; char *argv[127];
char tmp[1024]; char *tmp = new char[command.Len() + 1];
const char *IFS = " \t\n"; strcpy(tmp, command);
strncpy (tmp, command, sizeof(tmp) / sizeof(char) - 1); argv[argc++] = strtok(tmp, IFS);
tmp[sizeof (tmp) / sizeof (char) - 1] = '\0';
argv[argc++] = strtok (tmp, IFS);
while ((argv[argc++] = strtok((char *) NULL, IFS)) != NULL) while ((argv[argc++] = strtok((char *) NULL, IFS)) != NULL)
/* loop */ ; /* loop */ ;
return wxExecute(argv, sync, process);
long lRc = wxExecute(argv, sync, process);
delete [] tmp;
return lRc;
}; };