Example #1
0
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at pVfs->mxPathname characters.
*/
static int os2GetTempname( sqlite3_vfs *pVfs, int nBuf, char *zBuf ){
  static const unsigned char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  PSZ zTempPath = "";
  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
           ULONG ulDriveNum = 0, ulDriveMap = 0;
           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
      }
    }
  }
  /* strip off a trailing slashes or backslashes, otherwise we would get *
   * multiple (back)slashes which causes DosOpen() to fail               */
  j = strlen(zTempPath);
  while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ) ){
    j--;
  }
  zTempPath[j] = '\0';
  assert( nBuf>=pVfs->mxPathname );
  sqlite3_snprintf( pVfs->mxPathname-30, zBuf,
                    "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath );
  j = strlen( zBuf );
  sqlite3Randomness( 20, &zBuf[j] );
  for( i = 0; i < 20; i++, j++ ){
    zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
  }
  zBuf[j] = 0;
  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
  return SQLITE_OK;
}
Example #2
0
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
int sqlite3Os2TempFileName( char *zBuf ){
  static const unsigned char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  PSZ zTempPath = 0;
  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
           ULONG ulDriveNum = 0, ulDriveMap = 0;
           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
      }
    }
  }
  for(;;){
      sprintf( zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath );
      j = strlen( zBuf );
      sqlite3Randomness( 15, &zBuf[j] );
      for( i = 0; i < 15; i++, j++ ){
        zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
      }
      zBuf[j] = 0;
      if( !sqlite3OsFileExists( zBuf ) ) break;
  }
  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
  return SQLITE_OK;
}
Example #3
0
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at pVfs->mxPathname characters.
*/
static int getTempname(int nBuf, char *zBuf ){
  static const unsigned char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  char zTempPathBuf[3];
  PSZ zTempPath = (PSZ)&zTempPathBuf;
  if( sqlite3_temp_directory ){
    zTempPath = sqlite3_temp_directory;
  }else{
    if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
      if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
        if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
           ULONG ulDriveNum = 0, ulDriveMap = 0;
           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
        }
      }
    }
  }
  /* Strip off a trailing slashes or backslashes, otherwise we would get *
   * multiple (back)slashes which causes DosOpen() to fail.              *
   * Trailing spaces are not allowed, either.                            */
  j = sqlite3Strlen30(zTempPath);
  while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/'
                    || zTempPath[j-1] == ' ' ) ){
    j--;
  }
  zTempPath[j] = '\0';
  if( !sqlite3_temp_directory ){
    char *zTempPathUTF = convertCpPathToUtf8( zTempPath );
    sqlite3_snprintf( nBuf-30, zBuf,
                      "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPathUTF );
    free( zTempPathUTF );
  }else{
    sqlite3_snprintf( nBuf-30, zBuf,
                      "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath );
  }
  j = sqlite3Strlen30( zBuf );
  sqlite3_randomness( 20, &zBuf[j] );
  for( i = 0; i < 20; i++, j++ ){
    zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
  }
  zBuf[j] = 0;
  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
  return SQLITE_OK;
}
Example #4
0
char *xine_home(char *subdir) {
   PSZ root;
   size_t len;

   DosScanEnv("MMBASE",&root);
   strcpy(tmp_os2_path,root);
   len=strlen(tmp_os2_path);
   if (tmp_os2_path[len-1]==';') tmp_os2_path[len-1]='\0';
   len=strlen(tmp_os2_path);
   strcpy(&(tmp_os2_path[len]),"/xine");
   if (subdir!=NULL) {
      len=strlen(tmp_os2_path);
      if (tmp_os2_path[len-1]!='\\' && tmp_os2_path[len-1]!='/') {
         tmp_os2_path[len]='/';
         tmp_os2_path[len+1]='\0';
      } /* endif */
      len=strlen(tmp_os2_path);
      strcpy(&(tmp_os2_path[len]),subdir);
   }
   len=strlen(tmp_os2_path);
   if (tmp_os2_path[len-1]=='\\' || tmp_os2_path[len-1]=='/') tmp_os2_path[len-1]='\0';
   len=0;
   while (tmp_os2_path[len]) {
     if (tmp_os2_path[len]=='\\') tmp_os2_path[len]='/';
     len++;
   }
   return tmp_os2_path;
}
Example #5
0
//------------------------------- CMD_DosScanEnv -------------------------------
void CMD_DosScanEnv(HFILE hFile,LXIOCPA_DMN_CMDPARMPACKET* pParam,char* pData)
{
 PSZ pszVal;
 pParam->rc=DosScanEnv(pData,&pszVal);
 if(!pParam->rc)
  strcpy(pData,pszVal);
}
Example #6
0
static void LoadInterpreter( void )
{
   handle_type handle=(handle_type)NULL ;
   char *ptr;

   if ( DosScanEnv( "REXX_TRACEFILE", (PSZ *)&ptr ) )
      ptr = NULL;
   if ( ptr != NULL )
   {
      Trace = 1;
      strcpy( TraceFileName, ptr );
   }

   handle = (handle_type)FindInterpreter( "REGINA" );
   if ( handle == (handle_type)NULL )
   {
      fprintf( stderr, "Could not find Regina DLL. Cannot continue.\n" );
      exit( 11 );
   }
   if ( Trace )
   {
      TraceString( "----------- Initialisation Complete - Program Execution Begins -----------\n" );
   }
   InterpreterIdx = 0;
   return;
}
Example #7
0
unsigned EnvLkup( const char *name, char *buff, unsigned buff_len )
{
    const char  __far *env;
    unsigned    len;
    int         output = 0;
    char        c;

    if( DosScanEnv( name, &env ) != 0 )
        return( 0 );
    if( buff_len != 0 && buff != NULL ) {
        --buff_len;
        output = 1;
    }
    for( len = 0; (c = *env++) != '\0'; ++len ) {
        if( output ) {
            if( len >= buff_len ) {
                break;
            }
            *buff++ = c;
        }
    }
    if( output ) {
        buff[len] = '\0';
    }
    return( len );
}
char *
_nl_getenv (const char *name)
{
  unsigned char *value;
  if (DosScanEnv (name, &value))
    return NULL;
  else
    return value;
}
Example #9
0
/* Replacement version of getenv(), because the one in the EMX 0.9c, fix03
   dist appears to be busted when called from inside a DLL. (MJJ) */
char *getenv(const char *envar)
{
	APIRET 	rc;
	unsigned char *envstring;

	/* just call the OS/2 function directly */
	rc = DosScanEnv(envar, &envstring);
	if (rc)
		return NULL;
	else
		return envstring;
}
Example #10
0
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
int sqlite3Os2TempFileName( char *zBuf ){
  static const unsigned char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  PSZ zTempPath = 0;
  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
           ULONG ulDriveNum = 0, ulDriveMap = 0;
           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
      }
    }
  }
  /* strip off a trailing slashes or backslashes, otherwise we would get *
   * multiple (back)slashes which causes DosOpen() to fail               */
  j = strlen(zTempPath);
  while( j > 0 && zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ){
      j--;
  }
  zTempPath[j] = '\0';
  for(;;){
      sprintf( zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath );
      j = strlen( zBuf );
      sqlite3Randomness( 15, &zBuf[j] );
      for( i = 0; i < 15; i++, j++ ){
        zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
      }
      zBuf[j] = 0;
      if( !sqlite3OsFileExists( zBuf ) ) break;
  }
  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
  return SQLITE_OK;
}
Example #11
0
static int archdep_search_path(const char *name, char *pBuf, int lBuf)
{
    const int flags = SEARCH_CUR_DIRECTORY|SEARCH_IGNORENETERRS;
    char *path = "";        /* PATH environment variable */
    char *pgmName = util_concat(name, ".exe", NULL);

    // Search the program in the path
    DosScanEnv("PATH", &path);


    if (DosSearchPath(flags, path, pgmName, pBuf, lBuf)) {
        return -1;
    }
    lib_free(pgmName);

    return 0;
}
Example #12
0
char * hb_getenv( const char * szName )
{
   char * pszBuffer = NULL;

#if defined( HB_OS_WIN )
   {
      LPTSTR lpName = HB_CHARDUP( szName );
      DWORD size = GetEnvironmentVariable( lpName, NULL, 0 );

      if( size != 0 )
      {
         LPTSTR lpBuffer = ( LPTSTR ) hb_xgrab( size * sizeof( TCHAR ) );
         GetEnvironmentVariable( lpName, lpBuffer, size );
         pszBuffer = HB_OSSTRDUP( lpBuffer );
         hb_xfree( lpBuffer );
      }
      hb_xfree( lpName );
   }
#elif defined( HB_OS_OS2 )
   {
      PSZ EnvValue = ( PSZ ) "";
      char * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      if( DosScanEnv( ( PCSZ ) szName, &EnvValue ) == NO_ERROR )
         pszBuffer = hb_osStrDecode( ( char * ) EnvValue );
      if( pszNameFree )
         hb_xfree( pszNameFree );
   }
#else
   {
      char * pszTemp, * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      pszTemp = getenv( szName );
      if( pszNameFree )
         hb_xfree( pszNameFree );

      if( pszTemp != NULL )
         pszBuffer = hb_osStrDecode( pszTemp );
   }
#endif

   return pszBuffer;
}
Example #13
0
int archdep_search_path(const char *name, char *pBuf, int lBuf)
{
    const int flags = SEARCH_CUR_DIRECTORY|SEARCH_IGNORENETERRS;
    char *path = "";        /* PATH environment variable */
    char *pgmName = util_concat(name, ".exe", NULL);

    // Search the program in the path
    if (DosScanEnv("PATH", &path)) {
        log_warning(archlog, "Environment variable PATH not found.");
    }

    if (DosSearchPath(flags, path, pgmName, pBuf, lBuf)) {
        log_error(archlog, "File \"%s\" not found.", pgmName);
        return -1;
    }
    lib_free(pgmName);

    return 0;
}
Example #14
0
BOOL ChangeWPS(PCHAR pszUserIni, PCHAR pszSystemIni)
   {
   PCHAR        pcEnv;
   PRFPROFILE   prfProfile;
   BOOL         bSuccess;

   if (*pszSystemIni == '\0')
      prfProfile.pszSysName = pShareInitOS2->pszRootSystemIni;
   else
      prfProfile.pszSysName = pszSystemIni;

   if (*prfProfile.pszSysName == '\0')
      prfProfile.pszSysName = (DosScanEnv (ENV_SYSTEM_INI, &pcEnv) ? "" : pcEnv);

   if (*pszUserIni == '\0')
      {
      prfProfile.pszUserName = pShareInitOS2->pszRootUserIni;
      pShareInitOS2->ulFlag  = pShareInitOS2->ulFlag_Root; // ulFlag f�r Rootdesktop
      }
   else
      prfProfile.pszUserName = pszUserIni;

   if (*prfProfile.pszUserName == '\0')
      prfProfile.pszUserName = (DosScanEnv (ENV_USER_INI, &pcEnv) ? "" : pcEnv);

   prfProfile.cchUserName = strlen(prfProfile.pszUserName);
   prfProfile.cchSysName  = strlen(prfProfile.pszSysName);

   if (ulOldFlag & CLOSEAPPL)
      WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "WORKAREA=YES");
   else
      WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "WORKAREA=NO");

   WinPostMsg(WinQueryWindow(HWND_DESKTOP, QW_BOTTOM), WM_CLOSE, 0, 0);
   DebugS (1, "HWND_DESKTOP closed");

   if( hevPrfResetLock )
      {
      DosWaitEventSem (hevPrfResetLock, SEM_INDEFINITE_WAIT);
      DosSleep(1000);
      DebugS (1, "hevPrfResetLock released");
      }
   else
      DosSleep(20000);

   bSuccess = PrfReset(hab, &prfProfile);
   DebugULd (1, "PrfReset", "return", bSuccess);

/*
 *  Beim Umschalten auf den Root, egal ob von Sammy oder von WPSamF ausgel�st,
 *  wird die Shell vom PrfReset nicht geschlossen.
 *  Solange die Ursache nicht bekannt ist, bleibt nichts anderes �brig,
 *  als an dieser Stelle symptomatisch vorzugehen und die Shell abzuschie�en.
 */
   if (*pszUserIni == '\0')
      {
      DosSuspendThread (tid1);
      DosKillProcess( DKP_PROCESSTREE, ulShellID );   // sog. Budnik'scher Arschtritt
      DebugS (1, "Shell killed");
      DosResumeThread (tid1);
      }

   if( !bSuccess )
      {
      WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "OPEN=ICON;WORKAREA=YES");
      DebugS (1, "Desktop set to <WP_DESKTOP>");
      intSammyRetCode = 250;
      WinPostQueueMsg (hmq, WM_QUIT, 0L, 0L);
      }
   else
      ulOldFlag = pShareInitOS2->ulFlag;

   return( bSuccess );
   }
Example #15
0
ULONG ulExecProg (CHAR *szProgName)
   {
   ULONG        ulBootDrive;
   ULONG        ulAppType;
   CHAR         szCmdName[CCHMAXPATH];
   CHAR         szLine[CCHMAXPATH];
   PSZ          pszScanEnv;
   RESULTCODES  rcTermination;
   APIRET       rcFailure = 0;
   PCHAR        pszEnvironment;

/*
 *  Diese Routine versucht eine Shell zu starten.
 */

   pszEnvironment = MakeEnv (pShareInitOS2->pszEnvironment);

   if ( !(rcFailure = ScanEnv(ENV_SAMWORKPLACE, &pszScanEnv, pszEnvironment)) )
      {
      rcFailure = DosQueryAppType(pszScanEnv, &ulAppType);

      if ( !rcFailure )
         if ( ( (ulAppType & 7) == FAPPTYP_NOTSPEC) ||
              ( (ulAppType & 7) == FAPPTYP_WINDOWAPI) )
            rcFailure = DosExecPgm (szLine,           /* Object name buffer */
                                 sizeof(szLine),      /* Length of object name buffer */
                                 EXEC_ASYNCRESULT,    /* Execution flags */
                                 "",                  /* Argument string */
                                 pszEnvironment,       /* Environment */
                                 &rcTermination,      /* Termination codes */
                                 pszScanEnv);         /* Program file name */
         else
            rcFailure = 1;
      }

   if (rcFailure)
      {
      WinAlarm (HWND_DESKTOP, WA_ERROR);
      DebugS (1, "DosExecPgm <1> failed");
      }

   if (rcFailure)
      {
      rcFailure = DosExecPgm (szLine,              /* Object name buffer */
                              sizeof(szLine),      /* Length of object name buffer */
                              EXEC_ASYNCRESULT,    /* Execution flags */
                              "",                  /* Argument string */
                              pszEnvironment,       /* Environment */
                              &rcTermination,      /* Termination codes */
                              szProgName);         /* Program file name */
      }

   if (rcFailure)
      {
      if (!(rcFailure = DosScanEnv (ENV_SAMWORKPLACE, &pszScanEnv)))
         rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "",                  /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           pszScanEnv);         /* Program file name */
      }

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <2> failed");
      DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof (ULONG));

      memset (szCmdName, '\0', sizeof(szCmdName));
      szCmdName[0] = (CHAR) (ulBootDrive - 1) + 'A';
      strcpy (szCmdName+1, ":\\OS2\\PMSHELL.EXE");

      rcFailure = DosExecPgm (szLine,           /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "",                  /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           szCmdName);          /* Program file name */
      }

/* Falls Shell nicht gestartet werden konnte, wird cmd.exe aufgerufen */

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <3> failed");
      if (!(rcFailure = DosScanEnv ("COMSPEC", &pszScanEnv)))
         rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "/K",                /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           pszScanEnv);         /* Program file name */
      }

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <4> failed");
      DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof (ULONG));

      memset (szCmdName, '\0', sizeof(szCmdName));
      szCmdName[0] = (CHAR) (ulBootDrive - 1) + 'A';
      strcpy (szCmdName+1, ":\\OS2\\CMD.EXE");

      rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                        sizeof(szLine),      /* Length of object name buffer */
                        EXEC_ASYNCRESULT,    /* Execution flags */
                        "/K",                /* Argument string */
                        pszEnvironment,       /* Environment */
                        &rcTermination,      /* Termination codes */
                        szCmdName);          /* Program file name */
      }

   DosFreeMem(pszEnvironment);

   if (rcFailure)
      {
      intSammyRetCode = rcFailure;
      WinPostQueueMsg (hmq, WM_CLOSE, 0L, 0L);
      DebugS (1, "DosExecPgm <5> failed");
      }

   return (rcFailure ? 0 : rcTermination.codeTerminate);
   }
static FILE *internal_OpenNLSFile(char *pchHomeDirectory)
{
  char achRealLocaleName[128];
  char *pchFileName, *pchLang;
  ULONG rc;
  int i;
  FILE *hfNLSFile;

  hfNLSFile = NULLHANDLE;

  pchFileName = (char *) malloc(1024);
  if (pchFileName)
  {
    // Let's check the currently set Languagecode string!
    achRealLocaleName[0] = 0;
    if (DosRequestMutexSem(hmtxUseNLSTextArray, SEM_INDEFINITE_WAIT)==NO_ERROR)
    {
      if (apchNLSText[SSMODULE_NLSTEXT_LANGUAGECODE])
        strncpy(achRealLocaleName, apchNLSText[SSMODULE_NLSTEXT_LANGUAGECODE], sizeof(achRealLocaleName));
      DosReleaseMutexSem(hmtxUseNLSTextArray);
    }

    if (achRealLocaleName[0]==0)
    {
      // The ssaver core did not tell us anything about its language, so
      // try to get language from LANG env variable!
#ifdef DEBUG_LOGGING
      AddLog("[internal_OpenNLSFile] : No language told by SSaver core, using LANG env. variable!\n");
#endif
      rc = DosScanEnv("LANG", &pchLang);
      if ((rc!=NO_ERROR) || (!pchLang))
      {
#ifdef DEBUG_LOGGING
        AddLog("[internal_OpenNLSFile] : Could not query LANG env. var., will use 'en'\n");
#endif
        pchLang = "en"; // Default
      }
      strncpy(achRealLocaleName, pchLang, sizeof(achRealLocaleName));
    }

    // Get language code
    if (achRealLocaleName[0]!=0)
    {
      // Aaah, there is a language set!
      // Try that one!

      pchLang = (char *) malloc(1024);
      if (!pchLang)
      {
	// Not enough memory, so we won't do the long
	// method of searching for every combination of
        // the language string, but only for the string itself!

	// Assemble NLS file name
	sprintf(pchFileName, "%sModules\\Text\\%s.msg", pchHomeDirectory, achRealLocaleName);
#ifdef DEBUG_LOGGING
	AddLog("[internal_OpenNLSFile] : Trying to open NLS file: [");
	AddLog(pchFileName);
	AddLog("] by achLocalLanguage setting (in Not enough memory branch)!\n");
#endif

	hfNLSFile = fopenMessageFile(pchFileName);
      } else
      {
	// Fine, we can start trying a lot of filenames!
	sprintf(pchLang, "%s", achRealLocaleName);

	do {
	  // Assemble NLS file name
	  sprintf(pchFileName, "%sModules\\Text\\%s.msg", pchHomeDirectory, pchLang);
#ifdef DEBUG_LOGGING
	  AddLog("[internal_OpenNLSFile] : Trying to open NLS file: [");
	  AddLog(pchFileName);
	  AddLog("] by achLocalLanguage setting! (in Loop)\n");
#endif

	  hfNLSFile = fopenMessageFile(pchFileName);

	  // Make pchLang shorter, until the next underscore!
	  i = strlen(pchLang)-1;
	  while ((i>=0) && (pchLang[i]!='_'))
	    i--;
	  if (i<0) i = 0;
          pchLang[i] = 0;

	} while ((pchLang[0]) && (!hfNLSFile));

        free(pchLang); pchLang = NULL;
      }
    }

    free(pchFileName);
  }

#ifdef DEBUG_LOGGING
  if (hfNLSFile)
    AddLog("[internal_OpenNLSFile] : NLS file opened.\n");
  else
    AddLog("[internal_OpenNLSFile] : NLS file could not be opened.\n");

  AddLog("[internal_OpenNLSFile] : Done.\n");
#endif

  return hfNLSFile;
}
Example #17
0
SOM_Scope BOOL SOMLINK WPSamFolder_RootDesktop (WPSamF *somSelf)
    {
    static PRFPROFILE    prfProfile;
    PCHAR                szUserIni;
    PCHAR                szSysIni;
    /* WPSamFData *somThis = WPSamFGetData(somSelf); */
    WPSamFMethodDebug ("WPSamF","WPSamFolder_RootDesktop");

    /** Untersuchung, ob bereits im Rootdesktop **/
    /* Namen der laufenden User- und System-INI-Dateien */
    prfProfile.cchUserName = 0L;
    prfProfile.cchSysName  = 0L;

    PrfQueryProfile (WinQueryAnchorBlock(HWND_DESKTOP), &prfProfile);

    prfProfile.pszUserName = malloc (prfProfile.cchUserName);
    prfProfile.pszSysName  = malloc (prfProfile.cchSysName);

    PrfQueryProfile (WinQueryAnchorBlock(HWND_DESKTOP), &prfProfile);

    DebugE (D_SWT, "RootDesktop (current user-INI)",   prfProfile.pszUserName);
    DebugE (D_SWT, "RootDesktop (current system-INI)", prfProfile.pszSysName);

    /* Namen der Stammprofile */
    if (pShareInitOS2)
        {
        szUserIni = pShareInitOS2->pszRootUserIni;
        szSysIni  = pShareInitOS2->pszRootSystemIni;
        }
    else
        szUserIni = szSysIni = "";

    if (szUserIni[0] == '\0')
        if (DosScanEnv(USER_INI, &szUserIni))
            goto root_false;

    if (szSysIni[0] == '\0')
        if (DosScanEnv (SYSTEM_INI, &szSysIni))
            goto root_false;

    /* Vergleich der User-Ini Namen */
    if (strcmpi (szUserIni, prfProfile.pszUserName) == 0)
        {
        WinAlarm (HWND_DESKTOP, WA_NOTE);
        MessageBox (IDS_ALREADYINROOT, IDS_INFORMATION, MB_ENTER | MB_INFORMATION);
            goto root_false;
        }

    free (prfProfile.pszUserName);
    free (prfProfile.pszSysName);

    /** Umschaltung **/
    if (hevSammy)
        {
        pShareInitOS2->pszEnvironment[0] = '\0';
        pShareInitOS2->pszEnvironment[1] = '\0';
        pShareInitOS2->pszSystemIni[0]   = '\0';
        pShareInitOS2->pszUserIni[0]     = '\0';
        DebugE (D_SWT, "RootDesktop", "Ab hier macht Sammy weiter");
        DosPostEventSem (hevSammy);
        }

    return TRUE;

root_false:
    free (prfProfile.pszUserName);
    free (prfProfile.pszSysName);

    return FALSE;
    }
Example #18
0
int main(VOID) {



   PSZ       PathValue         = "";        /* PATH environment variable    */

   UCHAR     SearchResult[256] = "";        /* Result of PATH search        */

   APIRET    rc                = NO_ERROR;  /* Return code                  */



   rc=DosScanEnv("PATH",&PathValue);  /* Get contents of PATH environment

                                         variable                         */

   if (rc != NO_ERROR) {

       printf("DosScanEnv error: return code = %u\n",rc);

       return 1;

   } else {

       printf("PATH is:\n%s\n\n", PathValue);

   }

      /* Scan the current directory and path for the VIEW.EXE program.

         Ignore any errors from network drives which may not be in use. */



   rc=DosSearchPath(SEARCH_CUR_DIRECTORY | SEARCH_IGNORENETERRS,

                    PathValue,               /* Path value just obtained */

                    "VIEW.EXE",              /* Name of file to look for */

                    SearchResult,            /* Result of the search     */

                    sizeof(SearchResult));   /* Length of search buffer  */



   if (rc != NO_ERROR) {

       printf("DosSearchPath error: return code = %u\n",rc);

       return 1;

   } else {

       printf("Found desired file -- %s\n", SearchResult);

   }

  return NO_ERROR;

 }
Example #19
0
extern "C" APIRET APIENTRY dll_initterm (HMODULE hmod, ULONG flag)
{
  PSZ       pszValue;
  char      LoadError[256];
  APIRET    rc;

  // call C startup init first
  rc = __DLLstart_(hmod, flag);

  //dummy_print = &dummy;

  if (!rc)
    return 0;

  if (flag)
  {
    // terminate
    if (hmodBE) DosFreeModule(hmodBE);
  }
  else
  {
    //fatal    = &_fatal;
    //db_print = &_db_print;

    // init
    rc = DosScanEnv("PM_COMM_BACKEND", &pszValue);
    if (rc) pszValue = "PMPIPE";
    rc = DosLoadModule(LoadError, sizeof(LoadError), pszValue, &hmodBE);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 1, 0, (PFN *)&InitServerConnection);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 2, 0, (PFN *)&CloseServerConnection);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 3, 0, (PFN *)&startServerThreads);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 4, 0, (PFN *)&F_SendCmdToServer);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 5, 0, (PFN *)&F_SendDataToServer);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 6, 0, (PFN *)&F_RecvDataFromServer);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 7, 0, (PFN *)&F_SendGenCmdToServer);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 8, 0, (PFN *)&F_SendGenCmdDataToServer);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 9, 0, (PFN *)&F_RecvCmdFromClient);

    if (rc)
     return 0;

    rc = DosQueryProcAddr(hmodBE, 10, 0, (PFN *)&F_RecvDataFromClient);

    if (rc)
     return 0;

    rc = DosQueryProcAddr(hmodBE, 11, 0, (PFN *)&F_SendDataToClient);

    if (rc)
     return 0;
/*
    rc = DosQueryProcAddr(hmodBE, 12, 0, (PFN *)&fatal);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 13, 0, (PFN *)&db_print);

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 14, 0, (PFN *)&FreePM_db_level);
    //FreePM_db_level = *addr;

    if (rc)
      return 0;

    rc = DosQueryProcAddr(hmodBE, 15, 0, (PFN *)&FreePM_debugLevels);

    if (rc)
      return 0;
 */
    //memset(FreePM_debugLevels, 0, sizeof(FreePM_debugLevels));

    // init osFree DosLogWrite output
    log_init();
  }

  return 1;
}
SOM_Scope HWND   SOMLINK vptextc_InitHelpInstance(M_VPText *somSelf)
{
    M_VPTextData *somThis = M_VPTextGetData(somSelf);
    HELPINIT hmiHelpData;       /* Help initialization structure     */
    HWND hwndHelpInstance;
    CHAR pszHelp[CCHMAXPATH];
    PSZ pszTemp;

    M_VPTextMethodDebug("M_VPText","vptextc_InitHelpInstance");

    if (DosScanEnv("VISPRORX",&pszTemp)) {
       strcpy(pszHelp,"C:\\VISPRORX");
    } else {
       strcpy(pszHelp,pszTemp);
    } /* endif */
    strcat(pszHelp,"\\VPText.HLP");

    /**********************************************************************/
    /* IPF Initialization Structure                                       */
    /**********************************************************************/
    /* size of initialization structure                                   */
    /**********************************************************************/
    hmiHelpData.cb = sizeof(HELPINIT);
    /**********************************************************************/
    /* store HM return code from init.                                    */
    /**********************************************************************/
    hmiHelpData.ulReturnCode = (ULONG)NULL;
    /**********************************************************************/
    /* no tutorial program                                                */
    /**********************************************************************/
    hmiHelpData.pszTutorialName = NULL;
    /**********************************************************************/
    /* indicates help table is defined in the RC file.                    */
    /**********************************************************************/
    hmiHelpData.phtHelpTable = 0;
    /**********************************************************************/
    /* action bar is not tailored                                         */
    /**********************************************************************/
    hmiHelpData.hmodAccelActionBarModule = 0;
    hmiHelpData.idAccelTable = 0;
    hmiHelpData.idActionBar = 0;
    /**********************************************************************/
    /* help window title                                                  */
    /**********************************************************************/
    hmiHelpData.pszHelpWindowTitle = "VisPro/REXX Circular Slider Help Window";
    /**********************************************************************/
    /* help table in not in a DLL                                         */
    /**********************************************************************/
    hmiHelpData.hmodHelpTableModule = 0;
    /**********************************************************************/
    /* help panels ID is not displayed                                    */
    /**********************************************************************/
    hmiHelpData.fShowPanelId = 0;
    /**********************************************************************/
    /* library with help panels                                           */
    /**********************************************************************/
    hmiHelpData.pszHelpLibraryName = pszHelp;
    /**********************************************************************/
    /* Create Instance of IPF pass Anchor Block handle and address of IPF */
    /* initialization structure, and check that creation was successful.  */
    /**********************************************************************/
    hwndHelpInstance = WinCreateHelpInstance(0, &hmiHelpData);


    return (hwndHelpInstance);
}
Example #21
0
PRProcess * _PR_CreateOS2Process(
    const char *path,
    char *const *argv,
    char *const *envp,
    const PRProcessAttr *attr)
{
    PRProcess *proc = NULL;
    char *cmdLine = NULL;
    char **newEnvp = NULL;
    char *envBlock = NULL;
   
    STARTDATA startData = {0};
    APIRET    rc;
    ULONG     ulAppType = 0;
    PID       pid = 0;
    char     *pszComSpec;
    char      pszEXEName[CCHMAXPATH] = "";
    char      pszFormatString[CCHMAXPATH];
    char      pszObjectBuffer[CCHMAXPATH];
    char     *pszFormatResult = NULL;

    /*
     * Variables for DosExecPgm
     */
    char szFailed[CCHMAXPATH];
    char *pszCmdLine = NULL;
    RESULTCODES procInfo;
    HFILE hStdIn  = 0,
          hStdOut = 0,
          hStdErr = 0;
    HFILE hStdInSave  = -1,
          hStdOutSave = -1,
          hStdErrSave = -1;

    proc = PR_NEW(PRProcess);
    if (!proc) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        goto errorExit;
    }
   
    if (assembleCmdLine(argv, &cmdLine) == -1) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        goto errorExit;
    }

#ifdef MOZ_OS2_HIGH_MEMORY
    /*
     * DosQueryAppType() fails if path (the char* in the first argument) is in
     * high memory. If that is the case, the following moves it to low memory.
     */ 
    if ((ULONG)path >= 0x20000000) {
        size_t len = strlen(path) + 1;
        char *copy = (char *)alloca(len);
        memcpy(copy, path, len);
        path = copy;
    }
#endif
   
    if (envp == NULL) {
        newEnvp = NULL;
    } else {
        int i;
        int numEnv = 0;
        while (envp[numEnv]) {
            numEnv++;
        }
        newEnvp = (char **) PR_MALLOC((numEnv+1) * sizeof(char *));
        for (i = 0; i <= numEnv; i++) {
            newEnvp[i] = envp[i];
        }
        qsort((void *) newEnvp, (size_t) numEnv, sizeof(char *), compare);
    }
    if (assembleEnvBlock(newEnvp, &envBlock) == -1) {
        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
        goto errorExit;
    }
  
    rc = DosQueryAppType(path, &ulAppType);
    if (rc != NO_ERROR) {
       char *pszDot = strrchr(path, '.');
       if (pszDot) {
          /* If it is a CMD file, launch the users command processor */
          if (!stricmp(pszDot, ".cmd")) {
             rc = DosScanEnv("COMSPEC", (PSZ *)&pszComSpec);
             if (!rc) {
                strcpy(pszFormatString, "/C %s %s");
                strcpy(pszEXEName, pszComSpec);
                ulAppType = FAPPTYP_WINDOWCOMPAT;
             }
          }
       }
    }
    if (ulAppType == 0) {
       PR_SetError(PR_UNKNOWN_ERROR, 0);
       goto errorExit;
    }
 
    if ((ulAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) {
        startData.SessionType = SSF_TYPE_PM;
    }
    else if (ulAppType & FAPPTYP_WINDOWCOMPAT) {
        startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
    }
    else {
        startData.SessionType = SSF_TYPE_DEFAULT;
    }
 
    if (ulAppType & (FAPPTYP_WINDOWSPROT31 | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL))
    {
        strcpy(pszEXEName, "WINOS2.COM");
        startData.SessionType = PROG_31_STDSEAMLESSVDM;
        strcpy(pszFormatString, "/3 %s %s");
    }
 
    startData.InheritOpt = SSF_INHERTOPT_SHELL;
 
    if (pszEXEName[0]) {
        pszFormatResult = PR_MALLOC(strlen(pszFormatString)+strlen(path)+strlen(cmdLine));
        sprintf(pszFormatResult, pszFormatString, path, cmdLine);
        startData.PgmInputs = pszFormatResult;
    } else {
        strcpy(pszEXEName, path);
        startData.PgmInputs = cmdLine;
    }
    startData.PgmName = pszEXEName;
 
    startData.Length = sizeof(startData);
    startData.Related = SSF_RELATED_INDEPENDENT;
    startData.ObjectBuffer = pszObjectBuffer;
    startData.ObjectBuffLen = CCHMAXPATH;
    startData.Environment = envBlock;
 
    if (attr) {
        /* On OS/2, there is really no way to pass file handles for stdin,
         * stdout, and stderr to a new process.  Instead, we can make it
         * a child process and make the given file handles a copy of our
         * stdin, stdout, and stderr.  The child process then inherits
         * ours, and we set ours back.  Twisted and gross I know. If you
         * know a better way, please use it.
         */
        if (attr->stdinFd) {
            hStdIn = 0;
            DosDupHandle(hStdIn, &hStdInSave);
            DosDupHandle((HFILE) attr->stdinFd->secret->md.osfd, &hStdIn);
        }

        if (attr->stdoutFd) {
            hStdOut = 1;
            DosDupHandle(hStdOut, &hStdOutSave);
            DosDupHandle((HFILE) attr->stdoutFd->secret->md.osfd, &hStdOut);
        }

        if (attr->stderrFd) {
            hStdErr = 2;
            DosDupHandle(hStdErr, &hStdErrSave);
            DosDupHandle((HFILE) attr->stderrFd->secret->md.osfd, &hStdErr);
        }
        /*
         * Build up the Command Line for DosExecPgm
         */
        pszCmdLine = PR_MALLOC(strlen(pszEXEName) +
                               strlen(startData.PgmInputs) + 3);
        sprintf(pszCmdLine, "%s%c%s%c", pszEXEName, '\0',
                startData.PgmInputs, '\0');
        rc = DosExecPgm(szFailed,
                        CCHMAXPATH,
                        EXEC_ASYNCRESULT,
                        pszCmdLine,
                        envBlock,
                        &procInfo,
                        pszEXEName);
        PR_DELETE(pszCmdLine);

        /* Restore our old values.  Hope this works */
        if (hStdInSave != -1) {
            DosDupHandle(hStdInSave, &hStdIn);
            DosClose(hStdInSave);
        }

        if (hStdOutSave != -1) {
            DosDupHandle(hStdOutSave, &hStdOut);
            DosClose(hStdOutSave);
        }

        if (hStdErrSave != -1) {
            DosDupHandle(hStdErrSave, &hStdErr);
            DosClose(hStdErrSave);
        }

        if (rc != NO_ERROR) {
            /* XXX what error code? */
            PR_SetError(PR_UNKNOWN_ERROR, rc);
            goto errorExit;
        }

        proc->md.pid = procInfo.codeTerminate;
    } else {	
        /*
         * If no STDIN/STDOUT redirection is not needed, use DosStartSession
         * to create a new, independent session
         */
        rc = DosStartSession(&startData, &ulAppType, &pid);

        if ((rc != NO_ERROR) && (rc != ERROR_SMG_START_IN_BACKGROUND)) {
            PR_SetError(PR_UNKNOWN_ERROR, rc);
            goto errorExit;
        }
 
        proc->md.pid = pid;
    }

    if (pszFormatResult) {
        PR_DELETE(pszFormatResult);
    }

    PR_DELETE(cmdLine);
    if (newEnvp) {
        PR_DELETE(newEnvp);
    }
    if (envBlock) {
        PR_DELETE(envBlock);
    }
    return proc;

errorExit:
    if (cmdLine) {
        PR_DELETE(cmdLine);
    }
    if (newEnvp) {
        PR_DELETE(newEnvp);
    }
    if (envBlock) {
        PR_DELETE(envBlock);
    }
    if (proc) {
        PR_DELETE(proc);
    }
    return NULL;
}  /* _PR_CreateOS2Process */
Example #22
0
int main (int argc, char *argv[])
   {
   APIRET       rc;
   PCHAR        pcEnv;
   PRFPROFILE   prfProfile;

#ifdef DEBUG
   ulDebugMask = 0xFFFFFFFF;
#endif /* DEBUG */

   hab = WinInitialize(0);
   hmq = WinCreateMsgQueue(hab, 0);
   DebugS (1, "PM Interface initialized");

   /* Shared Memory organisieren */
   if (rc = DosGetNamedSharedMem ((PPVOID) &pShareInitOS2,
                                  SHARE_INITOS2,
                                  PAG_READ | PAG_WRITE))
      {
      if (rc = DosAllocSharedMem( (PPVOID) &pShareInitOS2,    // Pointer to shared mem
                                  SHARE_INITOS2,              // Name
                                  CCHSHARE_INITOS2,           // Size of shared mem
                                  PAG_COMMIT | PAG_READ | PAG_WRITE)) // Flags
         return(1);
      else
         {
         /* Shared Memory initialisieren */

         memset (pShareInitOS2, '\0', CCHSHARE_INITOS2);

         pShareInitOS2->pszRegFile       = (PCHAR) pShareInitOS2 +
                                          sizeof(*pShareInitOS2);
         strcpy (pShareInitOS2->pszRegFile,
                 DosScanEnv (ENV_SYSTEM_INI, &pcEnv) ? "" : pcEnv);
         pShareInitOS2->pszRootUserIni   = pShareInitOS2->pszRegFile +
                                          strlen(pShareInitOS2->pszRegFile) + 1;
         pShareInitOS2->pszRootSystemIni = pShareInitOS2->pszRootUserIni + 1;
         pShareInitOS2->pszUserIni       = pShareInitOS2->pszRootSystemIni + 1;
         pShareInitOS2->pszSystemIni     = pShareInitOS2->pszUserIni   + CCHMAXPATH;
         pShareInitOS2->pszEnvironment   = pShareInitOS2->pszSystemIni + CCHMAXPATH;
         }
      }
   DebugS (1, "Shared Memory initialized");

   /* Semaphoren organisieren */
   rc = DosOpenEventSem (HEV_SAMMY, &hevSammy);

   if( rc )
      rc = DosCreateEventSem( HEV_SAMMY,   // Name
                              &hevSammy,   // Pointer to sem
                              0,           // Not used with named sems
                              FALSE);      // Initial state (FALSE = SET)

   else        /* Sammy ist bereits installiert */
      {
      pShareInitOS2->pszEnvironment[0] = '\0';
      pShareInitOS2->pszEnvironment[1] = '\0';
      pShareInitOS2->pszSystemIni[0]   = '\0';
      pShareInitOS2->pszUserIni[0]     = '\0';
      DosPostEventSem(hevSammy);
      goto Exit;
      }

   if( rc )
      {
      intSammyRetCode = rc;
      goto Exit;
      }

   rc = DosOpenEventSem (HEV_PRFRESETLOCK, &hevPrfResetLock);

   if( rc )
      rc = DosCreateEventSem( HEV_PRFRESETLOCK, // Name
                              &hevPrfResetLock, // Pointer to sem
                              0,                // Not used with named sems
                              TRUE);            // Initial state (TRUE = POSTED)

   if( rc )
      {
      intSammyRetCode = rc;
      goto Exit;
      }
   DebugS (1, "Semaphores initialized");

   ChangeWPS(pShareInitOS2->pszUserIni, pShareInitOS2->pszSystemIni);

   /* Hintergrundloop starten, das Shell mit aktueller Env. startet */

   DosCreateThread (&tid1,
                    (PFNTHREAD) thStartProg,
                    (ULONG) ((argc > 1) ? argv[1] : ""),
                    0,
                    THREADSTACK);
   DebugS (1, "Background loop started");

   /* Hintergrundloop starten, das jeweils nach L�schen einer Semaphore */
   /* einen prfReset initiiert                      */
   DosCreateThread (&tid2,
                    (PFNTHREAD) thSwitch,
                    (ULONG) 0,
                    0,
                    THREADSTACK);

   while (WinGetMsg (hab, &qmsg, 0, 0, 0))
      WinDispatchMsg (hab, &qmsg);

   if (intSammyRetCode)
      {
      DosKillThread (tid1);
      DosKillThread (tid2);

      WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "WORKAREA=NO");
      WinPostMsg(WinQueryWindow(HWND_DESKTOP, QW_BOTTOM), WM_CLOSE, 0, 0);

      WinAlarm (HWND_DESKTOP, WA_ERROR);

      prfProfile.pszSysName  = (DosScanEnv (ENV_SYSTEM_INI, &pcEnv) ? "" : pcEnv);
      prfProfile.pszUserName = (DosScanEnv (ENV_USER_INI, &pcEnv) ? "" : pcEnv);

      prfProfile.cchUserName = strlen(prfProfile.pszUserName);
      prfProfile.cchSysName  = strlen(prfProfile.pszSysName);

      DosSleep (1000);
      DosKillProcess( DKP_PROCESSTREE, ulShellID );

      if ( !PrfReset(hab, &prfProfile))
         WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "OPEN=ICON;WORKAREA=YES");
      }
Exit:
   WinDestroyMsgQueue(hmq);
   WinTerminate(hab);

   DebugS (1, "Application terminated");

   return intSammyRetCode;
   }
void GTPMWin::backup()
{
#ifdef __TK21__
 PSZ   tempEnv;
#else
 PCSZ  tempEnv;
#endif 
 PSZ      pstr;
 ULONG    item, items;
 OString  path;
 OString  includes;
 OString  excludes;
 OString  batch;
 OString  dirfile;
 OString  str;
 ofstream incfile;
 ofstream excfile;
 ofstream batchfile;
 
 if ((DosScanEnv("TEMP", &tempEnv)) &&
     (DosScanEnv("TMP", &tempEnv)))
  {
   path << GTPMApp::GTakPM->callName;
   path.rightCut('\\');
  }
 else
   path << (PSZ)tempEnv;

 if (path.getText()[strlen(path) - 1] != '\\')
   path + "\\";

 includes << path;
 includes + "gtmp.inc";
 excludes << path;
 excludes + "gtmp.exc";
 batch << path;
 batch + "gtmp.cmd";
 dirfile << path;
 dirfile + "gtmp.dir";

 path << "Cannot open: ";

 incfile.open(includes);
 if (!incfile) {
   path + includes;
   throw OPMException(path, 0); }

 excfile.open(excludes);
 if (!excfile) {
   path + excludes;
   throw OPMException(path, 0); }

 batchfile.open(batch);
 if (!batchfile) {
   path + batch;
   throw OPMException(path, 0); }

// write includes-file 
 items = Includes->queryItemCount();
 for(item = 0; item < items; item++)
   if (Includes->queryItemText(str, item)) {
     pstr = str.getText();
     while((pstr = strchr(pstr, '\\'))!=NULL)
       pstr[0] = '/';
     incfile << ((PSZ)(strchr(str, ' ')+1)) << endl; }
 incfile.close();

// write excludes-file 
 items = Excludes->queryItemCount();
 for(item = 0; item < items; item++)
   if (Excludes->queryItemText(str, item)) {
     pstr = str.getText();
     while((pstr = strchr(pstr, '\\'))!=NULL)
       pstr[0] = '/';
     excfile << ((PSZ)(strchr(str, ' ')+1)) << endl; }
 excfile.close();

// write batchfile
 batchfile << "@ECHO OFF\n"
           << "echo Initializing Tape\n"
           << "tape stat >NUL 2>NUL\n"
           << "tape blocksize 0 stat sel 0 eraseq tell\n"
           << "echo Backup in progress\ntar -cEppP @"
           << (PSZ) includes
           << " --totals --exclude-from "
           << (PSZ) excludes
           << " -D "
           << (PSZ) dirfile
           << "\ntape stat\n"
           << "echo Compare in progress\n"
           << "tape rew >NUL 2>NUL\n"
           << "tar -dEppP\n"
           << "tape stat\n"
           << "echo Operation completed.\n";
 batchfile.close();
 tape->batch(batch);
}
Example #24
0
HB_BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize )
{
   HB_BOOL fRetVal;

#if defined( HB_OS_WIN )
   {
      LPTSTR lpName = HB_CHARDUP( szName ), lpBuffer;

      if( szBuffer != NULL || nSize > 0 )
         lpBuffer = ( LPTSTR ) hb_xgrab( nSize * sizeof( TCHAR ) );
      else
         lpBuffer = NULL;

      fRetVal = GetEnvironmentVariable( lpName, lpBuffer, nSize ) != 0;

      if( lpBuffer )
      {
         if( fRetVal )
         {
            lpBuffer[ nSize - 1 ] = TEXT( '\0' );
            HB_OSSTRDUP2( lpBuffer, szBuffer, nSize - 1 );
         }
         hb_xfree( lpBuffer );
      }
      hb_xfree( lpName );
   }
#elif defined( HB_OS_OS2 )
   {
      PSZ EnvValue = ( PSZ ) "";
      char * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      fRetVal = DosScanEnv( ( PCSZ ) szName, &EnvValue ) == NO_ERROR;
      if( pszNameFree )
         hb_xfree( pszNameFree );

      if( fRetVal && szBuffer != NULL && nSize != 0 )
         hb_osStrDecode2( ( char * ) EnvValue, szBuffer, nSize - 1 );
   }
#else
   {
      char * pszTemp, * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      pszTemp = getenv( szName );
      if( pszNameFree )
         hb_xfree( pszNameFree );

      if( pszTemp != NULL )
      {
         fRetVal = HB_TRUE;
         if( szBuffer != NULL && nSize != 0 )
            hb_osStrDecode2( pszTemp, szBuffer, nSize - 1 );
      }
      else
         fRetVal = HB_FALSE;
   }
#endif

   if( ! fRetVal && szBuffer != NULL && nSize != 0 )
      szBuffer[ 0 ] = '\0';

   return fRetVal;
}
Example #25
0
static void *get_log_instance()
{
  if (gLogInstance || gLogInstanceState == 2 || gInFork)
    return gLogInstance;

  /* Set a flag that we're going to init a new log instance */
  if (!__atomic_cmpxchg32(&gLogInstanceState, 1, 0))
  {
    /*
     * Another thread was faster in starting instance creation, wait for it
     * to complete in a simple spin loop (completion should be really quick).
     */
    while (gLogInstanceState == 1)
      DosSleep(1);
    return gLogInstance;
  }

  void *logInstance = NULL;
  __LIBC_LOGGROUPS *logGroups = NULL;

#if defined(TRACE_ENABLED)
  logGroups = &gLogGroups;
  __libc_LogGroupInit(&gLogGroups, "LIBCX_TRACE");
#endif

  /* Check if we are asked to log to console */
  {
    PSZ dummy;
    gLogToConsole = DosScanEnv("LIBCX_TRACE_TO_CONSOLE", &dummy) == NO_ERROR;
  }

  char buf[CCHMAXPATH + 128];

  if (gLogToConsole)
  {
    logInstance = __libc_LogInit(0, logGroups, "NUL");
    if (logInstance)
    {
      /*
       * This is a dirty hack to write logs to stdout,
       * LIBC isn't capable of it on its own (@todo fix LIBC).
       */
      typedef struct __libc_logInstance
      {
        /** Write Semaphore. */
        HMTX                    hmtx;
        /** Filehandle. */
        HFILE                   hFile;
        /** Api groups. */
        __LIBC_PLOGGROUPS       pGroups;
      } __LIBC_LOGINST, *__LIBC_PLOGINST;

      /* Sanity check (note: we use LIBC assert here to avoid recursion) */
      assert(((__LIBC_PLOGINST)logInstance)->pGroups == logGroups);

      /* Duplicate STDOUT */
      DosDupHandle(1, &((__LIBC_PLOGINST)logInstance)->hFile);
    }
  }
  else
  {
    /*
     * We don't query QSV_TIME_HIGH as it will remain 0 until 19-Jan-2038 and for
     * our purposes (generate an unique log name sorted by date) it's fine.
     */
    ULONG time;
    DosQuerySysInfo(QSV_TIME_LOW, QSV_TIME_LOW, &time, sizeof(time));

    // Get log directory (boot drive if no UNIXROOT)
    const char *path = "/var/log/libcx";
    PSZ unixroot;
    if (DosScanEnv("UNIXROOT", &unixroot) != NO_ERROR)
    {
      ULONG drv;
      DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &drv, sizeof(drv));

      unixroot = "C:";
      unixroot[0] = '@' + drv;
      path = "";
    }
    else
    {
      /*
       * Make sure the directory exists (no error checks here as a failure to
       * do so will pop up later in __libc_LogInit anyway).
       */
      if (strlen(unixroot) >= CCHMAXPATH)
        return NULL;
      strcpy(buf, unixroot);
      strcat(buf, path);
      DosCreateDir(buf, NULL);
    }

    // Get program name
    char name[CCHMAXPATH];
    PPIB ppib = NULL;
    DosGetInfoBlocks(NULL, &ppib);
    if (DosQueryModuleName(ppib->pib_hmte, sizeof(name), name) != NO_ERROR)
      return NULL;
    _remext(name);

    logInstance = __libc_LogInit(0, logGroups, "%s%s/%s-%08lx-%04x.log",
                                 unixroot, path, _getname(name), time, getpid());
  }

  /* Bail out if we failed to create a log file at all */
  if (!logInstance)
  {
    gLogInstanceState = 0;
    return NULL;
  }

  if (!gLogToConsole)
  {
    // Write out LIBCx info
    strcpy(buf, "LIBCx version : " VERSION_MAJ_MIN_BLD LIBCX_DEBUG_SUFFIX LIBCX_DEV_SUFFIX "\n");
    strcat(buf, "LIBCx module  : ");
    APIRET arc = DosQueryModuleName(ghModule, CCHMAXPATH, buf + strlen(buf));
    if (arc == NO_ERROR)
      sprintf(buf + strlen(buf), " (hmod=%04lx)\n", ghModule);
    else
      sprintf(buf + strlen(buf), " <error %ld>\n", arc);
    __libc_LogRaw(logInstance, __LIBC_LOG_MSGF_FLUSH, buf, strlen(buf));
  }

  /*
   * Finish initialization by storing the instance and setting the state to 2
   * (this will unfreeze other threads that started instance creation, if any).
   */
  gLogInstance = logInstance;
  gLogInstanceState = 2;
  return gLogInstance;
}