On Sat, 4 Dec 1999 14:22:34 +0100 (MET), Asger K. Alstrup Nielsen
wrote:

>> It's easier (IMO) to use the exec calls.
>
>It is easy to change in the new LyX code:
>
>The system() call is done in the SystemCalls framework.
>
>This framework (originally introduced by Bernhard a long time ago,
>and enhanced by me later) is very nice for invoking external programs.  
>It supports background execution of programs, callbacks when programs
>end, and is pretty robust when it comes to error situations.
>

Do you mean Systemcalls class? If so, I once wrote a little patch to
use spawn*() instead of fork()/exec*(). Maybe its of interest for
win32, too.


Greets,

        Arnd

-----snip-----------
diff -p -N -r -u -X excl.tmp lyx103/src/syscall.C modified/syscall.C
--- lyx103/src/syscall.C        Tue Nov 10 09:44:48 1998
+++ modified/syscall.C  Thu Aug 26 12:30:58 1999
@@ -1,5 +1,10 @@
 #include <config.h>
 
+// how many strings allowed in command line (AHanses)
+#ifndef MAX_ARGV
+#define MAX_ARGV  255
+#endif
+
 #ifdef __GNUG__
 #pragma implementation
 #endif
@@ -9,6 +14,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <process.h>
 #include "syscall.h"
 #include "syscontr.h"
 
@@ -54,15 +60,19 @@ int Systemcalls::Startscript()
                Callback();
                break;
        case Wait:   
-               pid = Fork();
+               pid = FORK(P_WAIT);
                if (pid>0) { // Fork succesful. Wait for child
+#ifndef __EMX__
                        waitForChild();
+#else
+                       retval = pid;
+#endif
                        Callback();
                } else
                        retval = 1;
                break;
        case DontWait:
-               pid=Fork();
+               pid=FORK(P_NOWAIT);
                if (pid>0) {
                        // Now integrate into Controller

                        SystemcallsSingletoncontroller::Startcontroller
starter;
@@ -81,9 +91,10 @@ int Systemcalls::Startscript()
 
 
 // Wait for child process to finish. Returns returncode from child.
+#ifndef __EMX__
 void Systemcalls::waitForChild()
 {
-       // We'll pretend that the child returns 1 on all
errorconditions.
+       // We'll pretend that the child returns 1 on all
errorconditions.
        retval = 1;
        int status;
        bool wait = true;
@@ -111,17 +122,19 @@ void Systemcalls::waitForChild()
                }
        }
 }
+#endif
 
 
 // generate child in background
 
-pid_t Systemcalls::Fork()
+pid_t Systemcalls::FORK(int spawnFlag)
 {
+#ifndef __EMX__
        pid_t cpid=fork();
        if (cpid == 0) { // child
+#endif
                LString childcommand(command); // copy
                LString rest = command.split(childcommand, ' ');
-               const int MAX_ARGV = 255;
                char *syscmd = NULL; 
                char *argv[MAX_ARGV];
                int  index = 0;
@@ -138,10 +151,15 @@ pid_t Systemcalls::Fork()
                } while (Abbruch);
                argv[index] = NULL;
                // replace by command. Expand using
PATH-environment-var.
+#ifndef __EMX__
                execvp(syscmd, argv);
                // If something goes wrong, we end up here:
                perror("LyX: execvp failed");
-       } else if (cpid < 0) { // error
+       } else
+#else
+               int cpid = spawnvp(spawnFlag, syscmd, argv);
+#endif
+               if (cpid < 0) { // error
                perror("LyX: Could not fork");
        } else { // parent
                return cpid;
diff -p -N -r -u -X excl.tmp lyx103/src/syscall.h modified/syscall.h
--- lyx103/src/syscall.h        Thu Aug 26 18:01:04 1999
+++ modified/syscall.h  Thu Aug 26 18:02:32 1999
@@ -2,12 +2,30 @@
 #include <sys/types.h>
 #include <LString.h>
 
+/** AHanses: Eliminate unneeded parameter for Unix: 'fork(void)' 
+    
+     
+     Unix will just ignore the spawnFlag parameter
+     
+    
+    
+    */
+ 
+ 
+ 
+
 #ifdef __GNUG__
 #pragma interface
 #endif
 
 
-/*@Doc:
+/// Class to controll system-calls according to OS-specific interface
+/**@Doc:
+ Class, which controlls a system-call according to the specific
interface of
+ your operating system. Hides OS-dependant hacks by providing a common
+ interface for calling. Should become part of a LyX-tools support
library: 
+ OS-dependant hacks should be completely opaque to the rest of LyX
(AHanses).
+  
   Instance starts and represents childprocesses.
   You should use this class if you need to start an external program
in LyX.
   You can start a child in the background and have a callback function
@@ -28,7 +46,7 @@ public:
        ///
        Systemcalls();
        
-       /** Geberate instance and start childprocess 
+       /** Generate instance and start childprocess 
          The string "what" contains a commandline with arguments
separated 
          by spaces.
          When the requested program finishes, the callback-function
is 
@@ -71,9 +89,17 @@ private:
        ///
        int Startscript();
        
-       ///
-       pid_t Fork();
+       
+       /// Spawn child according to the interface of your OS
(AHanses)
+       pid_t FORK(int spawnFlag);
        
        /// Wait for child process to finish. Updates returncode from
child.
+       /**
+       Waitforchild not necessary with spawnvp() of emx.
+       Note (concerning OS/2 specifics): Emx interface implementation
of 
+       spawnvp(P_WAIT, ...) returns returncode from child (AHanses).
+       */
+#ifndef __EMX__
        void waitForChild();
+#endif
 };
---------snap-------------------------


Reply via email to