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
|
|
|
|
|
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1995-04-20 14:35:14 +00:00
|
|
|
#define STRICT
|
1994-09-22 07:48:15 +00:00
|
|
|
#include <windows.h>
|
1994-12-16 15:50:08 +00:00
|
|
|
#include <toolhelp.h>
|
1994-11-07 16:32:57 +00:00
|
|
|
#endif
|
|
|
|
|
1994-12-16 15:50:08 +00:00
|
|
|
#include <applicat.h>
|
1994-11-11 18:04:29 +00:00
|
|
|
#include <execp.h>
|
1995-03-22 09:07:04 +00:00
|
|
|
#include <prefix.h>
|
1995-04-20 14:35:14 +00:00
|
|
|
#include <window.h>
|
1994-11-11 18:04:29 +00:00
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
|
|
|
// @mfunc Controlla se il processo puo' essere eseguito
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
|
|
|
// @flag TRUE | Se l'applicazione puo' essere eseguita
|
|
|
|
// @flag FALSE | Se l'applicazione non puo' essere eseguita
|
1994-11-11 18:04:29 +00:00
|
|
|
bool TExternal_app::can_run() const
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @comm Se si opera sotto Windows si controlla se vi sono risorse necessarie
|
|
|
|
// per l'esecuzione del processo, altrimenti viene tornato sempre TRUE.
|
1994-11-11 18:04:29 +00:00
|
|
|
{
|
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-12-16 15:50:08 +00:00
|
|
|
const bool big = p.find("cg0") == 0 && p.right(2) == "-1";
|
|
|
|
const int richieste = big ? 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
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Esegue il processo
|
|
|
|
int TExternal_app::run(
|
|
|
|
bool async, // @parm Per eseguire il processo in parallelo (default FALSE)
|
|
|
|
bool utente) // @parm Permette di inserire il nome dell'utente nella riga
|
|
|
|
// di comando(default FALSE)
|
|
|
|
|
|
|
|
// @comm Se <p asyn> e' FALSE aspetta che termini il processo in esecuzione prima di iniziare il nuovo
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
{
|
1994-11-07 16:32:57 +00:00
|
|
|
TString256 path(_path);
|
1994-11-30 09:04:03 +00:00
|
|
|
|
1995-03-22 09:07:04 +00:00
|
|
|
if (utente)
|
1995-03-27 14:36:11 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
|
|
|
path << " /u" << user();
|
|
|
|
#else
|
|
|
|
path << " -u" << user();
|
|
|
|
#endif
|
1994-11-30 09:04:03 +00:00
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
_error = 0;
|
|
|
|
_exitcode = 0;
|
|
|
|
|
|
|
|
// save cwd
|
1995-03-22 09:07:04 +00:00
|
|
|
xvt_fsys_save_dir();
|
1994-09-22 07:48:15 +00:00
|
|
|
|
1994-10-31 12:09:58 +00:00
|
|
|
#if XVT_OS == XVT_OS_WIN
|
1995-01-04 15:39:38 +00:00
|
|
|
if (can_run())
|
1994-12-16 15:50:08 +00:00
|
|
|
{
|
1995-01-03 15:06:43 +00:00
|
|
|
main_app().begin_wait();
|
1994-12-27 14:59:25 +00:00
|
|
|
_exitcode = WinExec((char*)(const char*)path, SW_SHOW);
|
1994-10-31 12:09:58 +00:00
|
|
|
|
|
|
|
if (_exitcode >= 32)
|
1994-12-16 15:50:08 +00:00
|
|
|
{
|
|
|
|
if (!async)
|
1994-12-27 14:59:25 +00:00
|
|
|
{
|
|
|
|
TTemp_window tw(TASK_WIN);
|
1995-05-29 10:25:10 +00:00
|
|
|
if (utente)
|
|
|
|
{
|
|
|
|
tw.iconize();
|
|
|
|
tw.deactivate();
|
|
|
|
}
|
1994-12-16 15:50:08 +00:00
|
|
|
|
|
|
|
HTASK child = NULL;
|
|
|
|
TASKENTRY te; te.dwSize = sizeof(TASKENTRY);
|
|
|
|
for (bool ok = TaskFirst(&te); ok; ok = TaskNext(&te))
|
1995-04-26 10:54:54 +00:00
|
|
|
if (te.hInst == (HINSTANCE)_exitcode)
|
|
|
|
{
|
|
|
|
child = te.hTask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warning! child could be NULL if you run that beast called Foxpro
|
1994-12-16 15:50:08 +00:00
|
|
|
|
1995-04-20 14:35:14 +00:00
|
|
|
main_app().wait_for((word)child);
|
1995-04-26 10:54:54 +00:00
|
|
|
for (byte i = 0; main_app().waiting() == (word)child; i++)
|
1994-12-16 15:50:08 +00:00
|
|
|
{
|
1995-04-26 10:54:54 +00:00
|
|
|
if (i == 0 && ok && TaskFindHandle(&te, child) == FALSE)
|
1994-12-27 14:59:25 +00:00
|
|
|
break;
|
1995-03-22 09:07:04 +00:00
|
|
|
xvt_app_process_pending_events();
|
1994-12-27 14:59:25 +00:00
|
|
|
}
|
|
|
|
|
1995-05-29 10:25:10 +00:00
|
|
|
if (utente)
|
|
|
|
{
|
|
|
|
tw.maximize();
|
|
|
|
tw.activate();
|
|
|
|
}
|
1994-12-16 15:50:08 +00:00
|
|
|
}
|
1994-12-27 14:59:25 +00:00
|
|
|
xvt_statbar_refresh();
|
1994-11-24 14:01:20 +00:00
|
|
|
}
|
1995-01-03 15:06:43 +00:00
|
|
|
main_app().end_wait();
|
1995-01-04 15:39:38 +00:00
|
|
|
} else _exitcode = 8;
|
|
|
|
|
|
|
|
switch (_exitcode)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 8:
|
|
|
|
error_box("Risorse insufficienti per eseguire '%s'", (const char*)_path); break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
error_box("Impossibile trovare '%s'", (const char*)_path); break;
|
|
|
|
case 16:
|
|
|
|
error_box("'%s' e' gia' in esecuzione", (const char*)_path); break;
|
|
|
|
default:
|
|
|
|
if (_exitcode < 32)
|
|
|
|
error_box("Impossibile eseguire '%s':\nErrore %d", (const char*)_path, _exitcode);
|
|
|
|
else
|
|
|
|
_exitcode = 0;
|
|
|
|
break;
|
|
|
|
}
|
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;
|
1995-03-22 09:07:04 +00:00
|
|
|
xvt_app_escape(XVT_ESC_CH_REFRESH);
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// restore cwd
|
1995-03-22 09:07:04 +00:00
|
|
|
xvt_fsys_restore_dir();
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
// update counts
|
|
|
|
if (_exitcode == 0)
|
|
|
|
_count++;
|
|
|
|
return _exitcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
TExternal_app::TExternal_app(const char* p)
|
|
|
|
{
|
|
|
|
_path = p;
|
|
|
|
_count = 0;
|
|
|
|
_error = 0;
|
|
|
|
_exitcode = 0;
|
|
|
|
}
|