+2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * Chktex.C:
+ * buffer.C:
+ remove #include "support/syscall.h" as it's redundant. Always has been.
+
+ * Chktex.C:
+ * LaTeX.C:
+ * LyXSendto.C:
+ * converter.C:
+ * lyx_cb.C:
+ * vc-backend.C:
+ change Systemcalls::System to Systemcalls::Wait and
+ change Systemcalls::SystemDontWait to Systemcalls::DontWait.
+ No change of functionality, just reflects the stripped down Systemcalls
+ class.
+
2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
* debug.[Ch]: add a GRAPHICS type to the enum.
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/syscall.h"
-#include "support/syscontr.h"
#include "support/path.h"
#include "support/lstrings.h"
string log = OnlyFilename(ChangeExtension(file, ".log"));
string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
Systemcalls one;
- int result= one.startscript(Systemcalls::System, tmp);
+ int result= one.startscript(Systemcalls::Wait, tmp);
if (result == 0) {
result = scanLogFile(terr);
} else {
#include "debug.h"
#include "support/lyxlib.h"
#include "support/syscall.h"
-#include "support/syscontr.h"
#include "support/path.h"
#include "support/LRegex.h"
#include "support/LSubstring.h"
string tmp = cmd + ' ' + file + " > nul";
#endif
Systemcalls one;
- return one.startscript(Systemcalls::System, tmp);
+ return one.startscript(Systemcalls::Wait, tmp);
}
string tmp = "makeindex -c -q ";
tmp += f;
Systemcalls one;
- one.startscript(Systemcalls::System, tmp);
+ one.startscript(Systemcalls::Wait, tmp);
return true;
}
string tmp = "bibtex ";
tmp += OnlyFilename(ChangeExtension(it->aux_file, string()));
Systemcalls one;
- one.startscript(Systemcalls::System, tmp);
+ one.startscript(Systemcalls::Wait, tmp);
}
// Return whether bibtex was run
return result;
// create the .txt file in tmp_dir if this filetype is requested
if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
- Systemcalls one(Systemcalls::System, command);
+ Systemcalls one(Systemcalls::Wait, command);
}
#include "support/filetools.h"
#include "support/path.h"
#include "support/os.h"
-#include "support/syscall.h"
#include "support/lyxlib.h"
#include "support/FileInfo.h"
#include "support/lyxmanip.h"
Path p(OnlyPath(filename));
Systemcalls one;
- int const res = one.startscript(Systemcalls::SystemDontWait, command);
+ int const res = one.startscript(Systemcalls::DontWait, command);
if (res) {
Alert::alert(_("Cannot view file"),
ShowMessage(buffer, _("Executing command:"), command);
Systemcalls::Starttype type = (dummy)
- ? Systemcalls::SystemDontWait : Systemcalls::System;
+ ? Systemcalls::DontWait : Systemcalls::Wait;
Systemcalls one;
int res;
if (conv.original_dir && buffer) {
string const command2 = conv.parselog +
" < " + QuoteName(infile2 + ".out") +
" > " + QuoteName(logfile);
- one.startscript(Systemcalls::System, command2);
+ one.startscript(Systemcalls::Wait, command2);
if (!scanLog(buffer, command, logfile))
return false;
}
+2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * Liason.C:
+ change Systemcalls::System to Systemcalls::Wait and
+ change Systemcalls::SystemDontWait to Systemcalls::DontWait.
+ No change of functionality, just reflects the stripped down Systemcalls
+ class.
+
2002-01-14 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* Liason.C (printBuffer): use Buffer::filePath
command2 += QuoteName(psname);
// First run dvips.
// If successful, then spool command
- res = one.startscript(Systemcalls::System, command);
+ res = one.startscript(Systemcalls::Wait, command);
if (res == 0)
- res = one.startscript(Systemcalls::SystemDontWait,
+ res = one.startscript(Systemcalls::DontWait,
command2);
} else
// case 2
- res = one.startscript(Systemcalls::SystemDontWait,
+ res = one.startscript(Systemcalls::DontWait,
command + QuoteName(dviname));
break;
command += lyxrc.print_to_file
+ QuoteName(MakeAbsPath(pp.file_name, path));
command += ' ' + QuoteName(dviname);
- res = one.startscript(Systemcalls::SystemDontWait, command);
+ res = one.startscript(Systemcalls::DontWait, command);
break;
}
return res == 0;
+2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * ControlGraphics.C: remove #include "support/syscall.h" as it's not
+ used.
+ * ControlTexinfo.C:
+ change Systemcalls::System to Systemcalls::Wait and
+ No change of functionality, just reflects the stripped down Systemcalls
+ class.
+
2002-02-06 Herbert Voss <voss@lyx.org>
* ControlGraphics.[C] (readBB): search also in
#include "support/FileInfo.h" // for FileInfo
#include "helper_funcs.h" // for browseFile
#include "support/lstrings.h"
-#include "support/filetools.h" // for AddName
-#include "support/syscall.h" // for zippedFile()
+#include "support/filetools.h" // for AddName, zippedFile
#include "BufferView.h"
using std::pair;
{
// Run rescan in user lyx directory
Path p(user_lyxdir);
- Systemcalls one(Systemcalls::System,
+ Systemcalls one(Systemcalls::Wait,
LibFileSearch("scripts", "TeXFiles.sh"));
p.pop();
}
Path p(user_lyxdir);
//path to texhash through system
- Systemcalls one(Systemcalls::System,"texhash");
+ Systemcalls one(Systemcalls::Wait, "texhash");
p.pop();
// Alert::alert(_("texhash run!"),
// _("rebuilding of the TeX-tree could only be successfull"),
// Run configure in user lyx directory
Path p(user_lyxdir);
- Systemcalls one(Systemcalls::System,
+ Systemcalls one(Systemcalls::Wait,
AddName(system_lyxdir, "configure"));
p.pop();
bv->owner()->message(_("Reloading configuration..."));
+2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * formula.C: change Systemcalls::System to Systemcalls::Wait and
+ No change of functionality, just reflects the stripped down Systemcalls
+ class.
2002-02-08 André Pönitz <poenitz@gmx.net>
string outfile = lyx::tempName(string(), "mathextern");
string full = "echo '" + data + "' | (" + cmd + ") > " + outfile;
lyxerr << "calling: " << full << "\n";
- Systemcalls dummy(Systemcalls::System, full, 0);
+ Systemcalls dummy(Systemcalls::Wait, full);
string out = GetFileContents(outfile);
lyx::unlink(outfile);
lyxerr << "result: '" << out << "'\n";
+2002-02-16 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * syscontr.[Ch]:
+ * syssingleton.C: files removed.
+
+ * syscall.[Ch]: remove the forked calls interface, as nothing, nowhere
+ uses it. Strip down the Systemcalls interface to make it brutally
+ obvious how unsophisticated it is.
+
2002-02-08 Herbert Voss <voss@perce.de>
* filetools.C: (getExtFromContents) adding TGIF-format
sstream.h \
$(REGEX) syscall.C \
syscall.h \
- syscontr.C \
- syscontr.h \
- syssingleton.C \
tempname.C \
textutils.h \
translator.h \
string const tempfile = lyx::tempName(string(), file);
// Run gunzip
string const command = "gunzip -c "+zipped_file+" > "+tempfile;
- Systemcalls one(Systemcalls::System, command);
+ Systemcalls one(Systemcalls::Wait, command);
// test that command was executed successfully
return tempfile;
}
+/**
+ * \file syscall.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author Asger Alstrup
+ *
+ * Interface cleaned up by
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ *
+ * Class Systemcalls uses "system" to launch the child process.
+ * The user can choose to wait or not wait for the process to complete, but no
+ * callback is invoked upon completion of the child.
+ *
+ * The child process is not killed when the Systemcall instance goes out of
+ * scope.
+ */
+
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
-#include <cerrno>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <csignal>
-#include <cstdlib>
-#include <unistd.h>
-#include "debug.h"
#include "syscall.h"
-#include "syscontr.h"
-#include "support/lstrings.h"
-#include "support/lyxlib.h"
-#include "support/filetools.h"
-#include "support/os.h"
-
-using std::endl;
-
-#ifndef CXX_GLOBAL_CSTD
-using std::strerror;
-#endif
-
-
-Systemcalls::Systemcalls() {
- pid = 0; // No child yet
-}
-
-Systemcalls::Systemcalls(Starttype how, string const & what, Callbackfct cback)
-{
- startscript(how, what, cback);
-}
-
-Systemcalls::~Systemcalls() {
-#if 0
- // If the child is alive, we have to brutally kill it
- if (getpid() != 0) {
- lyx::kill(getpid(), SIGKILL);
- }
-#endif
-}
-
-// Start a childprocess
-//
-// if child runs in background, add information to global controller.
-
-int Systemcalls::startscript() {
- retval = 0;
- switch (start) {
- case System:
- case SystemDontWait:
- retval = ::system(command.c_str());
- callback();
- break;
- case Wait:
- pid = fork();
- if (pid>0) { // Fork succesful. Wait for child
- waitForChild();
- callback();
- } else
- retval = 1;
- break;
- case DontWait:
- pid = fork();
- if (pid>0) {
- // Now integrate into Controller
- SystemcallsSingletoncontroller::Startcontroller starter;
- SystemcallsSingletoncontroller * contr = starter.getController();
- // Add this to controller
- contr->addCall(*this);
- } else
- retval = 1;
- break;
- }
- return retval;
-}
-
-void Systemcalls::kill(int /*tolerance*/) {
- if (getpid() == 0) {
- lyxerr << "LyX: Can't kill non-existing process." << endl;
- return;
- }
- int ret = lyx::kill(getpid(), SIGHUP);
- bool wait_for_death = true;
- if (ret != 0) {
- if (errno == ESRCH) {
- // The process is already dead!
- wait_for_death = false;
- } else {
- // Something is rotten - maybe we lost permissions?
- }
- }
- if (wait_for_death) {
- // Here, we should add the PID to a list of
- // waiting processes to kill if they are not
- // dead within tolerance seconds
-
- // CHECK Implement this using the timer of
- // the singleton systemcontroller (Asger)
-
- }
-}
-
-
-// Wait for child process to finish. Returns returncode from child.
-void Systemcalls::waitForChild() {
- // We'll pretend that the child returns 1 on all errorconditions.
- retval = 1;
- int status;
- bool wait = true;
- while (wait) {
- pid_t waitrpid = waitpid(pid, &status, WUNTRACED);
- if (waitrpid == -1) {
- lyxerr << "LyX: Error waiting for child:"
- << strerror(errno) << endl;
- wait = false;
- } else if (WIFEXITED(status)) {
- // Child exited normally. Update return value.
- retval = WEXITSTATUS(status);
- wait = false;
- } else if (WIFSIGNALED(status)) {
- lyxerr << "LyX: Child didn't catch signal "
- << WTERMSIG(status)
- << "and died. Too bad." << endl;
- wait = false;
- } else if (WIFSTOPPED(status)) {
- lyxerr << "LyX: Child (pid: " << pid
- << ") stopped on signal "
- << WSTOPSIG(status)
- << ". Waiting for child to finish." << endl;
- } else {
- lyxerr << "LyX: Something rotten happened while "
- "waiting for child " << pid << endl;
- wait = false;
- }
- }
-}
+#include "os.h"
-
-// generate child in background
-
-pid_t Systemcalls::fork()
+Systemcalls::Systemcalls(Starttype how, string const & what)
{
- #ifndef __EMX__
- pid_t cpid= ::fork();
- if (cpid == 0) { // child
- #endif
- // TODO: Consider doing all of this before the fork, otherwise me
- // might have troubles with multi-threaded access. (Baruch 20010228)
- string childcommand(command); // copy
- string rest = split(command, childcommand, ' ');
- const int MAX_ARGV = 255;
- char *syscmd = 0;
- char *argv[MAX_ARGV];
- int index = 0;
- bool more = true;
- while (more) {
- childcommand = frontStrip(childcommand);
- if (syscmd == 0) {
- syscmd = new char[childcommand.length() + 1];
- childcommand.copy(syscmd, childcommand.length());
- syscmd[childcommand.length()] = '\0';
- }
- if (!childcommand.empty()) {
- char * tmp = new char[childcommand.length() + 1];
- childcommand.copy(tmp, childcommand.length());
- tmp[childcommand.length()] = '\0';
- argv[index++] = tmp;
- }
-
- // reinit
- more = !rest.empty();
- if (more)
- rest = split(rest, childcommand, ' ');
- }
- argv[index] = 0;
- // replace by command. Expand using PATH-environment-var.
-#ifndef __EMX__
- execvp(syscmd, argv);
- // If something goes wrong, we end up here:
- lyxerr << "LyX: execvp(" << syscmd << ") failed: "
- << strerror(errno) << endl;
- } else if (cpid < 0) { // error
-#else
- pid_t cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND, syscmd, argv);
- if (cpid < 0) { // error
-#endif
- lyxerr << "LyX: Could not fork: "
- << strerror(errno) << endl;
- } else { // parent
- return cpid;
- }
- return 0;
+ startscript(how, what);
}
// Reuse of instance
-
-int Systemcalls::startscript(Starttype how, string const & what,
- Callbackfct cback)
+int Systemcalls::startscript(Starttype how, string const & what)
{
- start = how;
- command = what;
- cbk = cback;
- pid = static_cast<pid_t>(0); // yet no child
- retval = 0;
+ string command = what;
- if (how == SystemDontWait) {
+ if (how == DontWait) {
if (os::shell() == os::UNIX) {
command += " &";
} else {
}
}
- return startscript();
+ return ::system(command.c_str());
}
-
-
-
-//
-// Mini-Test-environment for script-classes
-//
-#ifdef TEST_MAIN
-#include <stdio.h>
-
-
-int SimulateTimer;
-void back(string cmd, int retval)
-{
- ::printf("Done: %s gave %d\n", cmd.c_str(), retval);
- SimulateTimer = 0;
-}
-
-
-int main(int, char **)
-{
-
- SystemcallsSingletoncontroller::Startcontroller starter;
- SystemcallsSingletoncontroller *contr= starter.GetController();
-
- Systemcalls one(Systemcalls::System, "ls -ltag", back);
- Systemcalls two(Systemcalls::Wait, "ls -ltag", back);
- SimulateTimer = 1;
- Systemcalls three(Systemcalls::DontWait , "ls -ltag", back);
- // Simulation of timer
- while (SimulateTimer)
- {
- sleep(1);
- contr->Timer();
- }
-}
-#endif
// -*- C++ -*-
-#include <sys/types.h>
+/**
+ * \file syscall.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author Asger Alstrup
+ *
+ * Interface cleaned up by
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ *
+ * Class Systemcalls uses "system" to launch the child process.
+ * The user can choose to wait or not wait for the process to complete, but no
+ * callback is invoked upon completion of the child.
+ *
+ * The child process is not killed when the Systemcall instance goes out of
+ * scope.
+ */
+
+#ifndef SYSCALL_H
+#define SYSCALL_H
#include "LString.h"
#pragma interface
#endif
-/**
- This class can be used to start child processes.
-
- An instance of the class represents a child process.
- You should use this class if you need to start an external program in LyX.
- If you wish, you can have a callback function executed when the process
- finishes.
- You can chose between three kinds of child processes:
- 1) System processes, which are initiated with the "system" call,
- where the main thread waits for the system call to return.
- 2) Wait for child process, which are forked, but the main thread waits for
- the child to end.
- 3) Don't wait, which are forked, but the main thread is not stopped.
- The process can be considered a background process.
- A timer will make sure that any callback function is called when
- the child process ends.
-
- Notice that any callback associated with a process is called whatever
- the kind of child process.
- */
class Systemcalls {
public:
///
enum Starttype {
- /// Uses system() which uses /bin/sh
- System,
- /// Uses system() which uses /bin/sh
- SystemDontWait,
- /// Uses fork() and execvp()
+ ///
Wait,
- /// Uses fork() and execvp()
+ ///
DontWait
};
- /// Callback function gets commandline and return value from child
- typedef void (*Callbackfct)(string cmd, int retval);
-
///
- Systemcalls();
+ Systemcalls() {}
/** Generate instance and start child process.
- The string "what" contains a commandline with arguments separated
- by spaces.
- When the requested program finishes, the callback-function is
- called with the commandline and the return value from the program.
- The instance is automatically added to a timer check if starttype
- is DontWait (i.e. background execution). When a background child
- finishes, the timer check will automatically call the callback
- function.
- */
- Systemcalls(Starttype how, string const & what, Callbackfct call = 0);
-
- ///
- ~Systemcalls();
-
- /** Start childprocess. "what" contains a command at system level.
- This is for reuse of the Systemcalls instance.
- */
- int startscript(Starttype how, string const & what,
- Callbackfct call = 0);
-
- /** gets PID of childprocess.
- Used by timer
- */
- pid_t getpid() { return pid; }
-
- /// Start callback
- void callback() { if (cbk) cbk(command, retval); }
-
- /** Set return value. Used by timer */
- void setRetValue(int r) { retval = r; }
-
- /** Kill child prematurely.
- First, a SIGHUP is sent to the child.
- If that does not end the child process within "tolerance"
- seconds, the SIGKILL signal is sent to the child.
- When the child is dead, the callback is called.
- */
- void kill(int tolerance = 5);
-
-private:
- /// Type of execution: system, wait for child or background
- Starttype start;
-
- /// Callback function
- Callbackfct cbk;
-
- /// Commmand line
- string command;
-
- /// Process ID of child
- pid_t pid;
-
- /// Return value from child
- int retval;
-
- ///
- int startscript();
-
- ///
- pid_t fork();
-
- /// Wait for child process to finish. Updates returncode from child.
- void waitForChild();
+ * The string "what" contains a commandline with arguments separated
+ * by spaces.
+ */
+ Systemcalls(Starttype how, string const & what);
+
+ /** Start child process.
+ * This is for reuse of the Systemcalls instance.
+ */
+ int startscript(Starttype how, string const & what);
};
+
+#endif // SYSCALL_H
+++ /dev/null
-#include <config.h>
-
-#include <cerrno>
-#include <cstdlib>
-#include <unistd.h>
-#include <sys/wait.h>
-#include "syscontr.h"
-#include "syscall.h"
-#include "debug.h"
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-
-using std::endl;
-
-#ifndef CXX_GLOBAL_CSTD
-using std::strerror;
-#endif
-
-//
-// Default constructor
-//
-
-SystemcallsSingletoncontroller::SystemcallsSingletoncontroller()
-{
- sysCalls = 0;
-}
-
-//
-// Destructor
-//
-// destroy structs for leaving program
-// open question: should we stop childs here?
-// Asger says no: I like to have my xdvi open after closing LyX. Maybe
-// I want to print or something.
-
-SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller()
-{
- ControlledCalls *next;
- while (sysCalls)
- {
- next = sysCalls->next;
- delete sysCalls;
- sysCalls = next;
- }
-
-}
-
-//
-// Add child process information into controlled list
-//
-
-void
-SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) {
- ControlledCalls * newCall = new ControlledCalls;
- if (newCall == 0) // sorry, no idea
- return;
- newCall->next = sysCalls;
- newCall->call = new Systemcalls(newcall);
- sysCalls = newCall;
-}
-
-//
-// Timer-call
-//
-// Check list, if there is a stopped child. If yes, call-back.
-//
-
-void
-SystemcallsSingletoncontroller::timer() {
- lyxerr << "Tick" << endl;
- // check each entry of our list, if it's finished
- ControlledCalls *prev = 0;
- for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next)
- {
- pid_t pid= actCall->call->getpid();
- int stat_loc;
- int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
- if (waitrpid == -1) {
- lyxerr << "LyX: Error waiting for child:"
- << strerror(errno) << endl;
- } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
- if (WIFEXITED(stat_loc)) {
- // Ok, the return value goes into retval.
- actCall->call->setRetValue(WEXITSTATUS(stat_loc));
- } else {
- // Child died, so pretend it returned 1
- actCall->call->setRetValue(1);
- }
- // Callback and release
- actCall->call->callback();
- if (actCall == sysCalls) {
- sysCalls = actCall->next;
- } else {
- prev->next = actCall->next;
- }
- delete actCall;
- actCall = prev;
- } else if (WIFSTOPPED(stat_loc)) {
- lyxerr << "LyX: Child (pid: " << pid
- << ") stopped on signal "
- << WSTOPSIG(stat_loc)
- << ". Waiting for child to finish." << endl;
- } else {
- lyxerr << "LyX: Something rotten happened while "
- "waiting for child " << pid << endl;
- }
- prev = actCall;
- }
-}
+++ /dev/null
-// -*- C++ -*-
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "LString.h"
-
-
-class Systemcalls;
-
-///
-class SystemcallsSingletoncontroller {
-public:
- ///
- class Startcontroller {
- public:
- ///
- Startcontroller();
- ///
- ~Startcontroller();
- ///
- static SystemcallsSingletoncontroller * getController();
- ///
- void reduceRefcount() { --refcount; }
- private:
- ///
- static SystemcallsSingletoncontroller * contr;
- ///
- static int refcount;
- };
- ///
- ~SystemcallsSingletoncontroller();
- ///
- void addCall(Systemcalls const & newcall);
- ///
- void timer();
- /// private: // DEC cxx does not like that (JMarc)
- SystemcallsSingletoncontroller();
-private:
- ///
- struct ControlledCalls {
- ///
- Systemcalls * call;
- ///
- ControlledCalls * next;
- };
- ///
- ControlledCalls * sysCalls;
-};
+++ /dev/null
-#include <config.h>
-
-#include "syscontr.h"
-
-
-//----------------------------------------------------------------------
-// Ensure, that only one controller exist inside process
-//----------------------------------------------------------------------
-
-// global controller variable
-SystemcallsSingletoncontroller *
-SystemcallsSingletoncontroller::Startcontroller::
-contr = 0;
-
-// reference count
-int SystemcallsSingletoncontroller::Startcontroller::
-refcount = 0;
-
-SystemcallsSingletoncontroller::Startcontroller::
-Startcontroller() {
-}
-
-SystemcallsSingletoncontroller::Startcontroller::
-~Startcontroller() {
-}
-
-// Give reference to global controller-instance
-//
-SystemcallsSingletoncontroller *
-SystemcallsSingletoncontroller::Startcontroller::getController()
-{
- if (!contr) {
- // Create the global controller
- contr = new SystemcallsSingletoncontroller;
- }
- ++refcount;
- return contr;
-}
#include "support/path.h"
#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/syscall.h"
#include <fstream>
lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
Systemcalls one;
Path p(path);
- int const ret = one.startscript(Systemcalls::System, cmd);
+ int const ret = one.startscript(Systemcalls::Wait, cmd);
return ret;
}