Пример #1
0
int InitMsg( void )
{
    char        buff[_MAX_PATH];
    int         initerror;
#if defined( IDE_PGM )
    char        fname[_MAX_PATH];

    initerror = _cmdname( fname ) == NULL;
#else
    char        *fname;

    fname = _LpDllName;
    initerror = fname == NULL;
#endif
    Res_Flag = EXIT_SUCCESS;
    BannerPrinted = FALSE;
    if( !initerror ) {
        OpenResFile( &hInstance, fname );
        if( hInstance.handle == NIL_HANDLE ) {
            initerror = TRUE;
        } else {
            initerror = FindResources( &hInstance );
        }
    }
    if( !initerror ) {
        initerror = InitResources( &hInstance );
    }
    MsgShift = WResLanguage() * MSG_LANG_SPACING;
    if( !initerror && !Msg_Get( MSG_PRODUCT, buff ) ) {
        initerror = 1;
    }
    if( initerror ) {
        Res_Flag = EXIT_FAILURE;
        WriteInfoStdOut( NO_RES_MESSAGE, ERR, NULL );
    } else {
        Res_Flag = EXIT_SUCCESS;
    }
    return( Res_Flag );
}
Пример #2
0
int MsgInit( void )
/*****************/
{
#ifndef BOOTSTRAP
    static char     name[_MAX_PATH]; // static because address passed outside.

    hInstance.handle = NIL_HANDLE;
    if( _cmdname( name ) != NULL && !OpenResFile( &hInstance, name ) ) {
        if( !FindResources( &hInstance ) && !InitResources( &hInstance ) ) {
            MsgShift = _WResLanguage() * MSG_LANG_SPACING;
            if( MsgGet( MSG_USAGE_BASE, name ) ) {
                return( 1 );
            }
        }
    }
    write( STDOUT_FILENO, NO_RES_MESSAGE, NO_RES_SIZE );
    MsgFini();
    return( 0 );
#else    
    return( 1 );
#endif
}
Пример #3
0
extern void InitPaths( void )
/***************************/
{
    char        *env;
#if defined(__UNIX__)
    char        buff [ _MAX_PATH ];
    char        *p;
#endif

    env = getenv( PATH_NAME );
    FilePathList = AddPath( FilePathList, env );
    HelpPathList = AddPath( HelpPathList, env );
    env = getenv( HELP_NAME );
    HelpPathList = AddPath( HelpPathList, env );
#if defined(__UNIX__)
    if( _cmdname( buff ) != NULL ) {
        p = strrchr( buff, '/' );
        if( p != NULL ) {
            *p = NULLCHAR;
            p = strrchr( buff, '/' );
            if( p != NULL ) {
                /* look in the sibling directories of where the executable is */
                strcpy( p + 1, "wd" );
                HelpPathList = AddPath( HelpPathList, buff );
                DipExePathList = AddPath( DipExePathList, buff );
                *p = NULLCHAR;
                HelpPathList = AddPath( HelpPathList, buff );
                DipExePathList = AddPath( DipExePathList, buff );
            }
        }
    }
    HelpPathList = AddPath( HelpPathList, "/usr/watcom/wd" );
    DipExePathList = AddPath( DipExePathList, "/usr/watcom/wd" );
    HelpPathList = AddPath( HelpPathList, "/usr/watcom" );
    DipExePathList = AddPath( DipExePathList, "/usr/watcom" );
#endif
}
Пример #4
0
bool AsMsgInit( void )
//********************
{
#ifdef _STANDALONE_
    char        name[_MAX_PATH];

    hInstance.status = 0;
    if( _cmdname( name ) != NULL && OpenResFile( &hInstance, name ) ) {
        msgShift = _WResLanguage() * MSG_LANG_SPACING;
        if( AsMsgGet( USAGE_1, AsResBuffer ) ) {
            return( true );
        }
    }
    CloseResFile( &hInstance );
    printf( NO_RES_MESSAGE );
    return( false );
#else
    msgShift = _WResLanguage() * TXT_MSG_LANG_SPACING;
    if( msgShift >= TXT_MSG_SIZE )
        msgShift = 0;
    msgShift -= AS_MSG_BASE;
    return( true );
#endif
}
Пример #5
0
unsigned EnvLkup( char *name, char *buff, unsigned max_len )
{
    char        *env;
    char        *ptr;
    char        *p;
    char        cmd[_MAX_PATH];
    char        *str;
    char        *end = NULL;

    if( buff == NULL ) {
        buff = cmd;
    } else if( max_len != 0 ) {
        end = buff + max_len - 1;
    }
    ptr = str = buff;
    /* if we're asking for the PATH variable, we really want to know where
     * to search for our support files
     */
    if( strcmp( name, "PATH" ) == 0 ) {
        /* look in current directory */
        ptr = copy_char_to_buff( ptr, '.', &end );
        ptr = copy_char_to_buff( ptr, ':', &end );
        env = getenv( "WD_PATH" );
        if( env != NULL ) {
            /* look in WD_PATH dirs */
            ptr = copy_str_to_buff( ptr, env, &end );
            ptr = copy_char_to_buff( ptr, ':', &end );
        }
        env = getenv( "HOME" );
        if( env != NULL ) {
            /* look in HOME dir */
            ptr = copy_str_to_buff( ptr, env, &end );
            ptr = copy_char_to_buff( ptr, ':', &end );
        }
        if( _cmdname( cmd ) != NULL ) {
            p = strrchr( cmd, '/' );
            if( p != NULL ) {
                *p = NULLCHAR;
                /* look in the executable's directory */
                ptr = copy_str_to_buff( ptr, cmd, &end );
                ptr = copy_char_to_buff( ptr, ':', &end );
                p = strrchr( cmd, '/' );
                if( p != NULL ) {
                    /* look in a sibling directory of where the executable is */
                    memcpy( p + 1, "wd", 3 );
                    ptr = copy_str_to_buff( ptr, cmd, &end );
                    ptr = copy_char_to_buff( ptr, ':', &end );
                }
            }
        }
        /* look in "/opt/watcom/wd" */
        ptr = copy_str_to_buff( ptr, "/opt/watcom/wd", &end );
    }
    env = getenv( name );
    if( env != NULL ) {
        if( ptr != str )
            ptr = copy_char_to_buff( ptr, ':', &end );
        ptr = copy_str_to_buff( ptr, env, &end );
    }
    return( ptr - str );
}
Пример #6
0
void fill_pathname_application_path(char *s, size_t len)
{
   size_t i;
#ifdef __APPLE__
  CFBundleRef bundle = CFBundleGetMainBundle();
#endif
#ifdef _WIN32
   DWORD ret;
   wchar_t wstr[PATH_MAX_LENGTH] = {0};
#endif
#ifdef __HAIKU__
   image_info info;
   int32_t cookie = 0;
#endif
   (void)i;

   if (!len)
      return;

#ifdef _WIN32
#ifdef LEGACY_WIN32
   ret    = GetModuleFileNameA(GetModuleHandle(NULL), s, len);
#else
   ret    = GetModuleFileNameW(GetModuleHandle(NULL), wstr, ARRAY_SIZE(wstr));

   if (*wstr)
   {
      char *str = utf16_to_utf8_string_alloc(wstr);

      if (str)
      {
         strlcpy(s, str, len);
         free(str);
      }
   }
#endif
   s[ret] = '\0';
#elif defined(__APPLE__)
   if (bundle)
   {
      CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
      CFStringRef bundle_path = CFURLCopyPath(bundle_url);
      CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
      CFRelease(bundle_path);
      CFRelease(bundle_url);

      retro_assert(strlcat(s, "nobin", len) < len);
      return;
   }
#elif defined(__HAIKU__)
   while (get_next_image_info(0, &cookie, &info) == B_OK)
   {
      if (info.type == B_APP_IMAGE)
      {
         strlcpy(s, info.name, len);
         return;
      }
   }
#elif defined(__QNX__)
   char *buff = malloc(len);

   if(_cmdname(buff))
      strlcpy(s, buff, len);

   free(buff);
#else
   {
      pid_t pid;
      static const char *exts[] = { "exe", "file", "path/a.out" };
      char link_path[255];

      link_path[0] = *s = '\0';
      pid       = getpid();

      /* Linux, BSD and Solaris paths. Not standardized. */
      for (i = 0; i < ARRAY_SIZE(exts); i++)
      {
         ssize_t ret;

         snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
               (unsigned)pid, exts[i]);
         ret = readlink(link_path, s, len - 1);

         if (ret >= 0)
         {
            s[ret] = '\0';
            return;
         }
      }
   }
#endif
}
Пример #7
0
/* Check that the WATCOM environment variable exists and if not, try to
 * heuristically determine what it should be and set it. Then check if
 * the PATH contains the appropriate paths and if not, add them depending
 * on the host platform.
 */
int watcom_setup_env( void )
{
    const char  *watcom;
    char        buf[FILENAME_MAX * 2];
    int         rc;
    size_t      len;
    char        *p;

    watcom = getenv( "WATCOM" );
    /* If WATCOM env var isn't set, try to construct it */
    if( watcom == NULL ) {
        char    *path_sep = NULL;
        char    *prev_path_sep = NULL;

        dbg_puts( "autoenv: WATCOM environment variable not found" );
        if( _cmdname( buf ) == NULL ) {
            return( -1 );
        }
        /* Set WATCOM to a directory one level up from the executable */
        p = buf;
        while( *p != '\0' ) {
            if( IS_DIR_SEP( *p ) ) {
                if( path_sep != NULL ) {
                    prev_path_sep = path_sep;
                }
                path_sep = p;
            }
            ++p;
        }
        if( prev_path_sep == NULL ) {
            return( -1 );
        }
        /* Cut off path at next-to-last directory separator */
        *prev_path_sep = '\0';
        if( setenv( "WATCOM", buf, 0 ) != 0 ) {
            return( -1 );
        }
        watcom = getenv( "WATCOM" );
        dbg_puts( "autoenv: WATCOM environment successfully set:" );
        dbg_puts( watcom );
    }
    /* At this point, WATCOM is set; construct what we want in PATH */
    len = strlen( watcom );
    if( sizeof( buf ) < (2 * len + 16) ) {
        return( -2 );
    }
    p = memcpy( buf, watcom, len );
    p += len;
    *p++ = DIR_SEP;
    strcpy( p, PRIMARY_PATH );
#if defined( SECONDARY_PATH )
    /* Add second path component on platforms that require it */
    p += strlen( p );
    *p++ = PATH_LIST_SEP;
    memcpy( p, watcom, len );
    p += len;
    *p++ = DIR_SEP;
    strcpy( p, SECONDARY_PATH );
#endif

    /* Stick it in the PATH env var */
    rc = add_path( "PATH", buf );
    if( rc ) {
        return( rc );
    }

    /* Finally set up platform specific stuff if applicable */
#ifdef HAVE_SETUP_OS_ENV
    return( setup_os_env( watcom ) );
#else
    return( 0 );
#endif
}
Пример #8
0
/*
 * GetArgv0 tries to find the fully qualified filename of the current program.
 * It uses some ugly and system specific tricks and it may return NULL if
 * it can't find any useful value.
 * The argument should be argv[0] of main() and it may be returned.
 * This function must not be called from another as the sole one when starting
 * up.
 */
static const char *GetArgv0(const char *argv0)
{
#ifdef WIN32
   char buf[512];

   if (GetModuleFileName(NULL, buf, sizeof(buf)) != 0)
      return(strdup(buf)); /* never freed up */
#elif defined(__QNX__) && defined(__WATCOMC__)
   char buffer[PATH_MAX];
   char *buf;
   if ( (buf = _cmdname(buffer) ) != NULL )
      return(strdup(buf)); /* never freed up */
#elif defined(OS2)
   char buf[512];
   PPIB ppib;

# ifdef __EMX__
   if (_osmode == OS2_MODE)
   {
# endif
      if (DosGetInfoBlocks(NULL, &ppib) == 0)
         if (DosQueryModuleName(ppib->pib_hmte, sizeof(buf), buf) == 0)
            return(strdup(buf));
# ifdef __EMX__
   }
# endif
#endif

#ifdef HAVE_READLINK
   {
      /*
       * will work on Linux 2.1+
       */
      char buf[1024];
      int result;
      result = readlink("/proc/self/exe", buf, sizeof( buf ) );
      if ( ( result > 0 ) && ( result < (int) sizeof( buf ) ) && ( buf[0] != '[' ) )
      {
         buf[result] = '\0';
         return strdup( buf );
      }
   }
#endif
   /* No specific code has found the right file name. Maybe, it's coded
    * in argv0. Check it, if it is an absolute path. Be absolutely sure
    * to detect it safely!
    */
   if (argv0 == NULL)
      return(NULL);

   if (argv0[0] == '/') /* unix systems and some others */
      return(argv0);

   if ((argv0[0] == '\\') && (argv0[1] == '\\')) /* MS and OS/2 UNC names */
      return(argv0);

   if (rx_isalpha(argv0[0]) && (argv0[1] == ':') && (argv0[2] == '\\'))
      return(argv0); /* MS and OS/2 drive letter with path */

   return(NULL); /* not a proven argv0 argument */
}