コード例 #1
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_import ( int argc, const char *argv[] )
{
    if (argc != 2)
    {
        printf("Missing filespec parameter.\n");
        return 1;
    }

    LearnTree tree;
    if ( OpenForRead(tree) )       // actually, this opens existing file for modification
    {
        try
        {
            char            dir [512];
            char            fullpath [512];
            int             numfiles = 0;
            _finddata_t     finfo;

            if (ExtractDir (dir, sizeof(dir), argv[1]))
            {
                intptr_t handle = _findfirst (argv[1], &finfo);
                if (handle != -1)
                {
                    do
                    {
                        if (!(finfo.attrib & _A_SUBDIR))
                        {
                            if (bscat (fullpath, sizeof(fullpath), dir, finfo.name))
                            {
                                if (ImportGameFile (tree, fullpath))
                                {
                                    ++numfiles;
                                }
                            }
                            else
                            {
                                printf("!!! ERROR forming full path !!!\n");
                                break;
                            }
                        }
                    }
                    while (0 == _findnext(handle,&finfo));
                    _findclose (handle);
                }

                if (numfiles == 0)
                {
                    printf ("!!! ERROR importing files using '%s' as filespec.\n", argv[1]);
                }
                else
                {
                    printf ("Imported %d game files.\n", numfiles);
                }
            }
            else
            {
                printf("!!! ERROR extracting dir from filespec.\n");
            }
        }
        catch (const char *message)
        {
            printf (">>> %s\n", message);
        }
    }

    return 0;
}
コード例 #2
0
ファイル: dri_glx.c プロジェクト: DavidGriffith/finx
/**
 * Try to \c dlopen the named driver.
 *
 * This function adds the "_dri.so" suffix to the driver name and searches the
 * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
 * order to find the driver.
 *
 * \param driverName - a name like "tdfx", "i810", "mga", etc.
 *
 * \returns
 * A handle from \c dlopen, or \c NULL if driver file not found.
 */
static __DRIdriver *OpenDriver(const char *driverName)
{
   char *libPaths = NULL;
   char libDir[1000];
   int i;
   __DRIdriver *driver;

   /* First, search Drivers list to see if we've already opened this driver */
   for (driver = Drivers; driver; driver = driver->next) {
      if (strcmp(driver->name, driverName) == 0) {
         /* found it */
         return driver;
      }
   }

   if (geteuid() == getuid()) {
      /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
      libPaths = getenv("LIBGL_DRIVERS_PATH");
      if (!libPaths)
         libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
   }
   if (!libPaths)
      libPaths = DEFAULT_DRIVER_DIR;

   for ( i = 0 ; ExtractDir(i, libPaths, 1000, libDir) != 0 ; i++ ) {
      char realDriverName[200];
      void *handle = NULL;

      
      /* If TLS support is enabled, try to open the TLS version of the driver
       * binary first.  If that fails, try the non-TLS version.
       */
#ifdef GLX_USE_TLS
      snprintf(realDriverName, 200, "%s/tls/%s_dri.so", libDir, driverName);
      InfoMessageF("OpenDriver: trying %s\n", realDriverName);
      handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
#endif

      if ( handle == NULL ) {
	 snprintf(realDriverName, 200, "%s/%s_dri.so", libDir, driverName);
	 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
	 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
      }

      if ( handle != NULL ) {
         /* allocate __DRIdriver struct */
         driver = (__DRIdriver *) Xmalloc(sizeof(__DRIdriver));
         if (!driver)
            return NULL; /* out of memory! */
         /* init the struct */
         driver->name = __glXstrdup(driverName);
         if (!driver->name) {
            Xfree(driver);
            return NULL; /* out of memory! */
         }

         driver->createNewScreenFunc = (PFNCREATENEWSCREENFUNC)
            dlsym(handle, createNewScreenName);

         if ( driver->createNewScreenFunc == NULL ) {
            /* If the driver doesn't have this symbol then something's
             * really, really wrong.
             */
            ErrorMessageF("%s not defined in %s_dri.so!\n"
			  "Your driver may be too old for this libGL.\n",
			  createNewScreenName, driverName);
            Xfree(driver);
            dlclose(handle);
            continue;
         }
         driver->handle = handle;
         /* put at head of linked list */
         driver->next = Drivers;
         Drivers = driver;
         return driver;
      }
      else {
	 ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
      }
   }

   ErrorMessageF("unable to find driver: %s_dri.so\n", driverName);
   return NULL;
}