Supporto exec a 32 bit
Supporto cambio di direttorio Supporto applicazioni spezzate git-svn-id: svn://10.65.10.50/trunk@4538 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									119f3193c4
								
							
						
					
					
						commit
						35797b7f20
					
				@ -1,18 +1,21 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#define XVT_INCL_NATIVE
 | 
			
		||||
#define STRICT
 | 
			
		||||
#define XVT_INCL_NATIVE
 | 
			
		||||
#include <xvt.h>
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
#include <toolhelp.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_SCOUNIX
 | 
			
		||||
#include <sys/fcntl.h>
 | 
			
		||||
#include <sys/wait.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
#include <toolhelp.h>
 | 
			
		||||
#include <hlapi_c.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <applicat.h>
 | 
			
		||||
#include <execp.h> 
 | 
			
		||||
@ -21,6 +24,7 @@
 | 
			
		||||
#include <window.h>
 | 
			
		||||
#include <extcdecl.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// @doc EXTERNAL
 | 
			
		||||
 | 
			
		||||
// @mfunc Controlla se il processo puo' essere eseguito
 | 
			
		||||
@ -59,10 +63,23 @@ word TExternal_app::run(
 | 
			
		||||
  // @comm Se <p asyn> e' FALSE aspetta che termini il processo in esecuzione prima di iniziare il nuovo
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  TString256 path(_path);                                  
 | 
			
		||||
  TFilename path(_path);                                  
 | 
			
		||||
  TString name(path.name()); 
 | 
			
		||||
  int p = name.find(' ');
 | 
			
		||||
  
 | 
			
		||||
  if (p >=0)
 | 
			
		||||
    name = name.left(p);
 | 
			
		||||
  const bool our_app = name.len() > 2 && (isalpha(name[0]) || name[0] == '7') && 
 | 
			
		||||
    isalnum(name[1]) && isdigit(name[2]);
 | 
			
		||||
 | 
			
		||||
  if (!our_app)
 | 
			
		||||
    utente = FALSE;
 | 
			
		||||
  if (utente)
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
 | 
			
		||||
    path << " /u" << user();
 | 
			
		||||
#else 
 | 
			
		||||
    path << " -u" << user();
 | 
			
		||||
#endif    
 | 
			
		||||
  
 | 
			
		||||
  _error = 0;
 | 
			
		||||
  _exitcode =  0;
 | 
			
		||||
@ -70,20 +87,62 @@ word TExternal_app::run(
 | 
			
		||||
  // save cwd
 | 
			
		||||
  xvt_fsys_save_dir();
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
  const TFilename dir(path.path()); 
 | 
			
		||||
 | 
			
		||||
  if (dir.not_empty())
 | 
			
		||||
  {
 | 
			
		||||
    DIRECTORY d;
 | 
			
		||||
  
 | 
			
		||||
    if (xvt_fsys_convert_str_to_dir((char *) (const char *) dir, &d))
 | 
			
		||||
      xvt_fsys_set_dir(&d);
 | 
			
		||||
  }                
 | 
			
		||||
  if (our_app)
 | 
			
		||||
  {
 | 
			
		||||
    TString parms(_path);  
 | 
			
		||||
    TString new_suffix;
 | 
			
		||||
    int p = parms.find(' ');
 | 
			
		||||
  
 | 
			
		||||
    if (p < 0)
 | 
			
		||||
    {
 | 
			
		||||
      parms = "";
 | 
			
		||||
      new_suffix = "_0";
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      parms = parms.mid(p + 1); 
 | 
			
		||||
      p = parms.find(' ');
 | 
			
		||||
      if (p >= 0)
 | 
			
		||||
        new_suffix = parms.left(p);
 | 
			
		||||
      else new_suffix = parms;
 | 
			
		||||
      if (new_suffix[0] == '-') new_suffix[0] = '_';
 | 
			
		||||
      else new_suffix = "__";
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
    TFilename newpath(dir);
 | 
			
		||||
  
 | 
			
		||||
    if (newpath.not_empty())
 | 
			
		||||
      newpath << '/';
 | 
			
		||||
    newpath << name << new_suffix;
 | 
			
		||||
    newpath.ext("exe");
 | 
			
		||||
    if (fexist(newpath))
 | 
			
		||||
    {
 | 
			
		||||
      newpath.ext("");
 | 
			
		||||
      newpath << parms;
 | 
			
		||||
      path = newpath;
 | 
			
		||||
      if (utente)
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
 | 
			
		||||
        path << " /u" << user();
 | 
			
		||||
#else 
 | 
			
		||||
        path << " -u" << user();
 | 
			
		||||
#endif    
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
 | 
			
		||||
  if (can_run())
 | 
			
		||||
  {                
 | 
			
		||||
    TFilename dir(_path); 
 | 
			
		||||
    
 | 
			
		||||
    dir = dir.path();
 | 
			
		||||
    if (dir.not_empty())
 | 
			
		||||
    {
 | 
			
		||||
      DIRECTORY d;
 | 
			
		||||
      
 | 
			
		||||
      if (xvt_fsys_convert_str_to_dir((char *) (const char *) dir, &d))
 | 
			
		||||
        xvt_fsys_set_dir(&d);
 | 
			
		||||
    }
 | 
			
		||||
    main_app().begin_wait();
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
    HL_LOGOUT();
 | 
			
		||||
    _exitcode = WinExec((char*)(const char*)path, SW_SHOW);
 | 
			
		||||
 | 
			
		||||
@ -130,9 +189,61 @@ word TExternal_app::run(
 | 
			
		||||
      }
 | 
			
		||||
      xvt_statbar_refresh();
 | 
			
		||||
    }  
 | 
			
		||||
#else
 | 
			
		||||
    STARTUPINFO start; 
 | 
			
		||||
    PROCESS_INFORMATION pi;
 | 
			
		||||
 | 
			
		||||
    start.cb = sizeof(start);
 | 
			
		||||
    start.lpReserved = start.lpDesktop = start.lpTitle = NULL;                                             
 | 
			
		||||
    start.dwX = start.dwY = start.dwXSize = start.dwYSize = CW_USEDEFAULT;
 | 
			
		||||
    start.dwXCountChars = start.dwYCountChars = start.dwFillAttribute = 0L;
 | 
			
		||||
    start.dwFlags = STARTF_USESHOWWINDOW;
 | 
			
		||||
    start.wShowWindow = SW_SHOW ;
 | 
			
		||||
    start.cbReserved2 = 0;
 | 
			
		||||
    start.lpReserved2 = NULL;
 | 
			
		||||
    start.hStdInput = NULL;  
 | 
			
		||||
    start.hStdOutput = NULL ;
 | 
			
		||||
    start.hStdError = NULL;
 | 
			
		||||
    BOOL started = CreateProcess(NULL,(char*)(const char*)path, NULL, NULL, FALSE, 0,
 | 
			
		||||
                                 NULL, NULL, &start, &pi); 
 | 
			
		||||
    if (started)
 | 
			
		||||
    {
 | 
			
		||||
      HANDLE hProcess = pi.hProcess;
 | 
			
		||||
 | 
			
		||||
      if (!async)
 | 
			
		||||
      {
 | 
			
		||||
        TTemp_window tw(TASK_WIN);
 | 
			
		||||
        if (utente) 
 | 
			
		||||
        {
 | 
			
		||||
          tw.iconize();
 | 
			
		||||
          tw.deactivate();
 | 
			
		||||
        }  
 | 
			
		||||
        if (WaitForSingleObject(hProcess, INFINITE) != 0xFFFFFFFF)
 | 
			
		||||
        {
 | 
			
		||||
          unsigned long exitcode;
 | 
			
		||||
          if (GetExitCodeProcess(hProcess, &exitcode))
 | 
			
		||||
            _exitcode = (int) exitcode;
 | 
			
		||||
           else
 | 
			
		||||
            _exitcode = -2;
 | 
			
		||||
        }
 | 
			
		||||
        if (utente) 
 | 
			
		||||
        {
 | 
			
		||||
          tw.maximize();
 | 
			
		||||
          tw.activate();             
 | 
			
		||||
        }  
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
        _exitcode = 0;
 | 
			
		||||
      CloseHandle(pi.hThread);
 | 
			
		||||
      CloseHandle(hProcess);
 | 
			
		||||
    }
 | 
			
		||||
    else _exitcode  = -1;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
    main_app().end_wait();
 | 
			
		||||
  } else _exitcode = 1;
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
  _error = _exitcode;
 | 
			
		||||
  switch (_exitcode)
 | 
			
		||||
  {
 | 
			
		||||
@ -154,6 +265,21 @@ word TExternal_app::run(
 | 
			
		||||
    }  
 | 
			
		||||
    break;
 | 
			
		||||
  }  
 | 
			
		||||
#else
 | 
			
		||||
  switch (_exitcode)
 | 
			
		||||
  {
 | 
			
		||||
    case -2:
 | 
			
		||||
      error_box("Impossibile ricevere il valore di ritorno da '%s':\nErrore %ld", (const char*)_path, GetLastError()); break;
 | 
			
		||||
    case -1:
 | 
			
		||||
      error_box("Impossibile eseguire '%s':\nErrore %ld", (const char*)_path, GetLastError()); break;
 | 
			
		||||
    case 8:
 | 
			
		||||
      error_box("Risorse insufficienti per eseguire '%s'", (const char*)_path); break;
 | 
			
		||||
    case 0:
 | 
			
		||||
      break;
 | 
			
		||||
    default:
 | 
			
		||||
      error_box("Valore di ritorno di '%s':\n %ld", (const char*)_path, _exitcode); break;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
  switch (fork())
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user