From eafc087e69e52add5952190bfd5bcbbf931ad12b Mon Sep 17 00:00:00 2001
From: Guilhem Lavaux <lavaux@easynet.fr>
Date: Fri, 3 Jul 1998 17:44:34 +0000
Subject: [PATCH] * Fixed Async -> sync in wxExecute * Added documentation
 about wxProcess, ... * Added wxDataStream::WriteString and
 wxDataStream::ReadString

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@178 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/classes.tex  |  1 +
 docs/latex/wx/function.tex | 10 +++++++---
 docs/latex/wx/process.tex  | 39 ++++++++++++++++++++++++++++++++++++++
 include/wx/datstrm.h       |  2 ++
 src/common/datstrm.cpp     | 34 +++++++++++++++++++++++++++++++++
 src/gtk/utilsgtk.cpp       |  8 ++++----
 src/gtk1/utilsgtk.cpp      |  8 ++++----
 7 files changed, 91 insertions(+), 11 deletions(-)
 create mode 100644 docs/latex/wx/process.tex

diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex
index a8cef0ce42..d7b446e48c 100644
--- a/docs/latex/wx/classes.tex
+++ b/docs/latex/wx/classes.tex
@@ -120,6 +120,7 @@ $$\image{14cm;0cm}{wxclass.ps}$$
 \input point.tex
 \input prevwin.tex
 \input print.tex
+\input process.tex
 \input postscpt.tex
 \input query.tex
 \input radiobox.tex
diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 0a2fee8aa4..9d3d820f1e 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -905,9 +905,9 @@ See also \helpref{wxIsBusy}{wxisbusy}.
 
 \membersection{::wxExecute}\label{wxexecute}
 
-\func{long}{wxExecute}{\param{const wxString\& }{command}, \param{bool }{sync = FALSE}}
+\func{long}{wxExecute}{\param{const wxString\& }{command}, \param{bool }{sync = FALSE}, \param{wxProcess *}{callback = NULL}}
 
-\func{long}{wxExecute}{\param{const wxString\& *}{argv}, \param{bool }{sync = FALSE}}
+\func{long}{wxExecute}{\param{const wxString\& *}{argv}, \param{bool }{sync = FALSE}, \param{wxProcess *}{callback = NULL}}
 
 Executes another program in UNIX or Windows.
 
@@ -923,7 +923,11 @@ If execution is asynchronous, the return value is the process id,
 otherwise it is a status value.  A zero value indicates that the command could not
 be executed.
 
-See also \helpref{wxShell}{wxshell}.
+If callback isn't NULL and if execution is asynchronous,
+\helpref{wxProcess::OnTerminate}{wxprocessonterminate} will be called when
+the process finishes.
+
+See also \helpref{wxShell}{wxshell}, \helpref{wxProcess}{wxprocess}.
 
 \membersection{::wxExit}\label{wxexit}
 
diff --git a/docs/latex/wx/process.tex b/docs/latex/wx/process.tex
new file mode 100644
index 0000000000..160d34e1b2
--- /dev/null
+++ b/docs/latex/wx/process.tex
@@ -0,0 +1,39 @@
+\section{\class{wxProcess}}\label{wxprocess}
+
+This class contains a method which is invoked when a process finishes.
+It can raise a \helpref{wxProcessEvent}{wxprocessevent} if wxProcess::OnTerminate
+isn't overriden.
+
+\wxheading{Derived from}
+
+\helpref{wxEvtHandler}{wxevthandler}
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+\membersection{wxProcess::wxProcess}\label{wxprocessconstr}
+
+\func{}{wxProcess}{\param{wxEvtHandler *}{ parent = NULL}, \param{int}{ id = -1}}
+
+Constructs a process object. {\it id} is only used in the case you want to
+use wxWindows events. 
+
+\wxheading{Parameters}
+
+\docparam{parent}{The event handler parent.}
+
+\docparam{id}{id of an event.}
+
+\membersection{wxProcess::\destruct{wxProcess}}
+
+\func{}{\destruct{wxProcess}}{\void}
+
+Destroys the wxProcess object.
+
+\membersection{wxProcess::OnTerminate}\label{wxprocessonterminate}
+
+\constfunc{void}{OnTerminate}{\param{int}{ pid}}
+
+It is called when the process with the pid {\it pid} finishes.
+It raises a wxWindows event when it isn't overriden.
+
+\docparam{pid}{The pid of the process which ends.}
diff --git a/include/wx/datstrm.h b/include/wx/datstrm.h
index 169c86b627..b5bd8a1664 100644
--- a/include/wx/datstrm.h
+++ b/include/wx/datstrm.h
@@ -31,12 +31,14 @@ public:
   unsigned char Read8();
   double ReadDouble();
   wxString ReadLine();
+  wxString ReadString();
 
   void Write32(unsigned long i);
   void Write16(unsigned short i);
   void Write8(unsigned char i);
   void WriteDouble(double d);
   void WriteLine(const wxString& line);
+  void WriteString(const wxString& string);
 protected:
   istream *m_istream;
   ostream *m_ostream;
diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp
index 980a280c13..c79eedb07a 100644
--- a/src/common/datstrm.cpp
+++ b/src/common/datstrm.cpp
@@ -116,6 +116,27 @@ wxString wxDataStream::ReadLine()
   return i_strg;
 }
 
+wxString wxDataStream::ReadString()
+{
+  wxString wx_string;
+  char *string;
+  unsigned long len;
+
+  if (!m_istream)
+    return "";
+
+  len = Read32();
+  string = new char[len+1];
+
+  m_istream->read(string, len);
+
+  string[len] = 0;
+  wx_string = string;
+  delete string;
+
+  return wx_string; 
+}
+
 void wxDataStream::Write32(unsigned long i)
 {
   char buf[4];
@@ -152,11 +173,24 @@ void wxDataStream::Write8(unsigned char i)
 
 void wxDataStream::WriteLine(const wxString& line)
 {
+#ifdef __WINDOWS__
+  wxString tmp_string = line + "\r\n";
+#else
   wxString tmp_string = line + '\n';
+#endif
+
+  if (!m_ostream)
+    return;
 
+  m_ostream->write((const char *) tmp_string, tmp_string.Length());
+}
+
+void wxDataStream::WriteString(const wxString& string)
+{
   if (!m_ostream)
     return;
 
+  Write32(tmp_string.Length());
   m_ostream->write((const char *) tmp_string, tmp_string.Length());
 }
 
diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp
index ccd767f3b6..dedecb696e 100644
--- a/src/gtk/utilsgtk.cpp
+++ b/src/gtk/utilsgtk.cpp
@@ -364,7 +364,7 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
     proc_data->pid = 0;
 };
 
-long wxExecute( char **argv, bool Async, wxProcess *process )
+long wxExecute( char **argv, bool sync, wxProcess *process )
 {
     wxEndProcessData *data = new wxEndProcessData;
     int end_proc_detect[2];
@@ -409,7 +409,7 @@ long wxExecute( char **argv, bool Async, wxProcess *process )
     data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ,
                               GTK_EndProcessDetector, (gpointer)data);
     data->pid = pid;
-    if (Async) {
+    if (!sync) {
       data->process = process;
     } else {
       data->process = NULL;
@@ -424,7 +424,7 @@ long wxExecute( char **argv, bool Async, wxProcess *process )
     return pid;
 };
 
-long wxExecute( const wxString& command, bool Async, wxProcess *process )
+long wxExecute( const wxString& command, bool sync, wxProcess *process )
 {
     if (command.IsNull() || command == "") return FALSE;
 
@@ -438,6 +438,6 @@ long wxExecute( const wxString& command, bool Async, wxProcess *process )
     argv[argc++] = strtok (tmp, IFS);
     while ((argv[argc++] = strtok(NULL, IFS)) != NULL)
 	/* loop */ ;
-    return wxExecute(argv, Async, process);
+    return wxExecute(argv, sync, process);
 };
 
diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp
index ccd767f3b6..dedecb696e 100644
--- a/src/gtk1/utilsgtk.cpp
+++ b/src/gtk1/utilsgtk.cpp
@@ -364,7 +364,7 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
     proc_data->pid = 0;
 };
 
-long wxExecute( char **argv, bool Async, wxProcess *process )
+long wxExecute( char **argv, bool sync, wxProcess *process )
 {
     wxEndProcessData *data = new wxEndProcessData;
     int end_proc_detect[2];
@@ -409,7 +409,7 @@ long wxExecute( char **argv, bool Async, wxProcess *process )
     data->tag = gdk_input_add(end_proc_detect[0], GDK_INPUT_READ,
                               GTK_EndProcessDetector, (gpointer)data);
     data->pid = pid;
-    if (Async) {
+    if (!sync) {
       data->process = process;
     } else {
       data->process = NULL;
@@ -424,7 +424,7 @@ long wxExecute( char **argv, bool Async, wxProcess *process )
     return pid;
 };
 
-long wxExecute( const wxString& command, bool Async, wxProcess *process )
+long wxExecute( const wxString& command, bool sync, wxProcess *process )
 {
     if (command.IsNull() || command == "") return FALSE;
 
@@ -438,6 +438,6 @@ long wxExecute( const wxString& command, bool Async, wxProcess *process )
     argv[argc++] = strtok (tmp, IFS);
     while ((argv[argc++] = strtok(NULL, IFS)) != NULL)
 	/* loop */ ;
-    return wxExecute(argv, Async, process);
+    return wxExecute(argv, sync, process);
 };
 
-- 
2.50.0

