1994-11-11 18:04:29 +00:00
|
|
|
// fv 6/10/93
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <xvt.h>
|
|
|
|
|
|
|
|
#if XVT_OS == XVT_OS_SCOUNIX
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
1994-11-07 16:32:57 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
#include <windows.h>
|
1994-11-07 16:32:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if XVT_OS == XVT_OS_DOS
|
|
|
|
#include <holdev.h>
|
1994-09-22 07:48:15 +00:00
|
|
|
#endif
|
|
|
|
|
1994-11-11 18:04:29 +00:00
|
|
|
#include <execp.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool TExternal_app::can_run() const
|
|
|
|
{
|
1994-11-14 12:03:26 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-11-11 18:04:29 +00:00
|
|
|
const TFixed_string p(_path);
|
1994-11-22 15:03:51 +00:00
|
|
|
const bool clifo = p.find("cg0") == 0 && p.right(2) == "-1";
|
|
|
|
const int richieste = clifo ? 50 : 15;
|
1994-11-11 18:04:29 +00:00
|
|
|
const int libere = GetFreeSystemResources(GFSR_SYSTEMRESOURCES);
|
|
|
|
return libere >= richieste;
|
1994-11-14 12:03:26 +00:00
|
|
|
#else
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
1994-11-11 18:04:29 +00:00
|
|
|
}
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// char _path[120]; // app name
|
|
|
|
// int _error; // last error
|
|
|
|
// int _exitcode; // last exit code
|
|
|
|
// int _count; // count of calls returning 0
|
|
|
|
// int error() { return _error};
|
|
|
|
// int exitcode() { return _exitcode};
|
|
|
|
// int count() { return _count; };
|
|
|
|
|
1994-11-11 18:04:29 +00:00
|
|
|
int TExternal_app::run(bool async, bool iconized)
|
1994-09-22 07:48:15 +00:00
|
|
|
{
|
1994-11-07 16:32:57 +00:00
|
|
|
TString256 path(_path);
|
1994-11-11 18:04:29 +00:00
|
|
|
if (iconized)
|
|
|
|
path << " -icon";
|
1994-11-08 16:51:02 +00:00
|
|
|
path << " -u" << main_app().user();
|
1994-09-22 07:48:15 +00:00
|
|
|
_error = 0;
|
|
|
|
_exitcode = 0;
|
|
|
|
|
|
|
|
// save cwd
|
|
|
|
save_dir();
|
|
|
|
|
1994-10-31 12:09:58 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1994-11-11 18:04:29 +00:00
|
|
|
if (!can_run())
|
1994-09-22 07:48:15 +00:00
|
|
|
{
|
1994-11-11 18:04:29 +00:00
|
|
|
error_box("Le risorse di Windows sono quasi esaurite:\n"
|
|
|
|
"impossibile eseguire %s", (const char*)_path);
|
|
|
|
_exitcode = 8;
|
1994-10-31 12:09:58 +00:00
|
|
|
}
|
1994-09-22 07:48:15 +00:00
|
|
|
|
1994-11-11 18:04:29 +00:00
|
|
|
if (_exitcode == 0)
|
|
|
|
{
|
|
|
|
set_cursor(TASK_WIN, CURSOR_WAIT);
|
|
|
|
|
|
|
|
const UINT sh = iconized ? SW_SHOWMINIMIZED : SW_SHOW;
|
|
|
|
_exitcode = WinExec((char*)(const char*)path, sh);
|
1994-10-31 12:09:58 +00:00
|
|
|
|
|
|
|
if (_exitcode >= 32)
|
|
|
|
{
|
|
|
|
if (!async) main_app().wait_for(_path);
|
|
|
|
_exitcode = 0;
|
|
|
|
}
|
|
|
|
else
|
1994-11-24 14:01:20 +00:00
|
|
|
{
|
|
|
|
if (_exitcode == 16)
|
|
|
|
error_box("'%s' e' gia' in esecuzione", (const char*)_path);
|
|
|
|
else
|
|
|
|
error_box("Impossibile eseguire '%s':\nErrore %d", (const char*)_path, _exitcode);
|
|
|
|
}
|
1994-11-11 18:04:29 +00:00
|
|
|
|
|
|
|
set_cursor(TASK_WIN, CURSOR_ARROW);
|
1994-10-31 12:09:58 +00:00
|
|
|
}
|
1994-09-22 07:48:15 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
switch (fork())
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
_error = errno;
|
|
|
|
_exitcode = -1;
|
|
|
|
break;
|
|
|
|
case 0:
|
1994-11-11 18:04:29 +00:00
|
|
|
const char* s = strdup(path);
|
1994-09-22 07:48:15 +00:00
|
|
|
char* p = strchr(s, ' ');
|
|
|
|
if (p) *p = '\0';
|
|
|
|
const char* pathn = strdup(s);
|
|
|
|
const char* args[21];
|
|
|
|
int i = 0;
|
|
|
|
args[i++] = pathn;
|
|
|
|
while ((i < 20) && (p))
|
|
|
|
{
|
|
|
|
s = p + 1;
|
|
|
|
p = strchr(s, ' ');
|
|
|
|
if (p) *p = '\0';
|
|
|
|
args[i++] = strdup(s);
|
|
|
|
}
|
|
|
|
args[i] = NULL;
|
|
|
|
for (i = 3; i < _NFILE; i++) fcntl(i,F_SETFD,1);
|
1994-11-07 16:32:57 +00:00
|
|
|
// execvp( path, NULL);
|
1994-09-22 07:48:15 +00:00
|
|
|
execvp ( pathn , args );
|
|
|
|
exit ( -1 );
|
|
|
|
default:
|
|
|
|
if(wait(&_exitcode) == -1)
|
1994-11-07 16:32:57 +00:00
|
|
|
{
|
|
|
|
error_box("Impossibile eseguire '%s':\nErrore %d", (const char*)_path, _exitcode);
|
1994-09-22 07:48:15 +00:00
|
|
|
_exitcode = -1;
|
1994-11-07 16:32:57 +00:00
|
|
|
}
|
1994-09-22 07:48:15 +00:00
|
|
|
else _exitcode = _exitcode >> 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_error = errno;
|
|
|
|
xvt_escape(XVT_ESC_CH_REFRESH);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// restore cwd
|
|
|
|
restore_dir();
|
|
|
|
|
|
|
|
// update counts
|
|
|
|
if (_exitcode == 0)
|
|
|
|
_count++;
|
|
|
|
return _exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
TExternal_app::TExternal_app(const char* p)
|
|
|
|
{
|
|
|
|
_path = p;
|
|
|
|
_count = 0;
|
|
|
|
_error = 0;
|
|
|
|
_exitcode = 0;
|
|
|
|
}
|