Пример #1
0
int main()
{
	tryPath("//usr/lib/libSystem.B.dylib");
	tryPath("/usr/bin/../lib/libSystem.B.dylib");
	tryPath("/usr/lib/./libSystem.B.dylib");
	tryPath("/usr/lib//libSystem.B.dylib");

	PASS("dlopen-non-canonical-path");
	return EXIT_SUCCESS;
}
Пример #2
0
bool GBitmap::sFindFiles( const Path &path, Vector<Path> *outFoundPaths )
{
   PROFILE_SCOPE( GBitmap_sFindFiles );
   
   Path  tryPath( path );

   for ( U32 i = 0; i < GBitmap::sRegistrations.size(); i++ )
   {
      const GBitmap::Registration   &reg = GBitmap::sRegistrations[i];
      const Vector<String>          &extensions = reg.extensions;

      for ( U32 j = 0; j < extensions.size(); ++j )
      {
         tryPath.setExtension( extensions[j] );

         if ( Torque::FS::IsFile( tryPath ) )
         {
            if ( outFoundPaths )
               outFoundPaths->push_back( tryPath );
            else
               return true;
         }
      }
   }

   return outFoundPaths ? outFoundPaths->size() > 0 : false;
}
Пример #3
0
bool GBitmap::sFindFile( const Path &path, Path *outPath )
{
   PROFILE_SCOPE( GBitmap_sFindFile );

   const String origExt( String::ToLower( path.getExtension() ) );

   Path tryPath( path );

   for ( U32 i = 0; i < sRegistrations.size(); i++ )
   {
      const Registration &reg = sRegistrations[i];
      const Vector<String> &extensions = reg.extensions;

      for ( U32 j = 0; j < extensions.size(); ++j )
      {
         // We've already tried this one.
         if ( extensions[j] == origExt )
            continue;

         tryPath.setExtension( extensions[j] );
         if ( !Torque::FS::IsFile( tryPath ) )
            continue;

         if ( outPath )
            *outPath = tryPath;
         return true;
      }
   }

   return false;
}
Пример #4
0
void tryPath(Location* location, int level, int path_distance) {
	int i, j, skip;
	
	path[level] = location;
	
	if (level == size - 1) {
		if (path_distance < min_distance) {
			min_distance = path_distance;
			for (i = 0; i < size; i++) 
				min_path[i] = path[i];
		} 
		
		if (path_distance > max_distance) {
			max_distance = path_distance;
			for (i = 0; i < size; i++)
				max_path[i] = path[i];
		}
		
		return;
	}
	
	for (i = 0; i < location->nr_connections; i++) {
		skip = 0;
		for (j = 0; j < level; j++) {
			if (!strcmp(path[j]->name, location->connections[i].location->name)) {
				skip = 1;
			}
		}
		
		if (skip) continue;
		
		tryPath(location->connections[i].location, level + 1, path_distance + location->connections[i].distance);
	}
}
Пример #5
0
int main(void) {
	int i, j;
	int found_src, found_dest;
	char src_name[MAXNAME + 1];
	char dest_name[MAXNAME + 1];
	int distance;
	
	while (scanf("%s to %s = %d", src_name, dest_name, &distance) != EOF) {
		found_src = found_dest = 0;
		min_distance += distance;
		
		for (i = 0; i < size; i++) {
			if (!strcmp(src_name, locations[i].name)) {
				found_src = 1;
				break;
			}
		}
		
		for (j = 0; j < size; j++) {
			if (!strcmp(dest_name, locations[j].name)) {
				found_dest = 1;
				break;
			}
		}
		
		if (!found_src) {
			i = newLocation(src_name);
		}
		
		if (!found_dest) {
			j = newLocation(dest_name);
		}
		
		addConnection(&locations[i], &locations[j], distance);
	}
	
	for(i = 0; i < size; i++)
		tryPath(locations + i, 0, 0);
	
	printf("Minimum path: %d\n", min_distance);
	printPath(min_path, size);
	
	printf("Maximum path: %d\n", max_distance);
	printPath(max_path, size);

	return 0;
}
Пример #6
0
int FindFilePath( const char *pgm, char *buffer, const char *ext_list )
{
    const char  *p;
    char        *p2;
    const char  *p3;
    BOOL        have_ext;
    BOOL        have_path;
    char        *envbuf;
    DWORD       envlen;
    int         rc;

    have_ext = FALSE;
    have_path = FALSE;
    for( p = pgm, p2 = buffer; (*p2 = *p) != 0; ++p, ++p2 ) {
        switch( *p ) {
        case '\\':
        case '/':
        case ':':
            have_path = TRUE;
            have_ext = FALSE;
            break;
        case '.':
            have_ext = TRUE;
            break;
        }
    }
    if( have_ext ) {
        ext_list = "";
    }
    if( !tryPath( buffer, p2, ext_list ) ) {
        return( 0 );
    }
    if( have_path ) {
        return( 1 );
    }
    envlen = GetEnvironmentVariable( "PATH", NULL, 0 );
    if( envlen == 0 )
        return( -1 );
    envbuf = LocalAlloc( LMEM_FIXED, envlen );
    GetEnvironmentVariable( "PATH", envbuf, envlen );
    rc = -1;
    for( p = envbuf; *p != '\0'; ++p ) {
        p2 = buffer;
        while( *p != '\0' ) {
            if( *p == ';' ) {
                break;
            }
            *p2++ = *p++;
        }
        if( p2[-1] != '\\' && p2[-1] != '/' ) {
            *p2++ = '\\';
        }
        for( p3 = pgm; (*p2 = *p3) != '\0'; ++p2, ++p3 ) {
        }
        if( !tryPath( buffer, p2, ext_list ) ) {
            rc = 0;
            break;
        }
        if( *p == '\0' ) {
            break;
        }
    }
    LocalFree( envbuf );
    return( rc );
}
Пример #7
0
void KfmView::slotDropEvent( KDNDDropZone *_zone )
{
      // check if dropped data is an URL
      if ( _zone->getDataType() != DndURL )
      {
	QMessageBox::warning( 0, klocale->translate( "KFM Error" ),
			      klocale->translate("ERROR: You may only drop URLs") );
	return;
      }
      
      QPoint p = view->mapFromGlobal( QPoint( _zone->getMouseX(), _zone->getMouseY() ) );
      const char *url = view->getURL( p );
 
      // Dropped over an object or not ?
      if ( url == 0L )
	// dropped over white ground
	url = manager->getURL();
      //-------- Sven's write to pseudo global mime/app dirs start ---

      // Consider the following case:
      // User opened mime/apps dir and has not any local items =>
      // displayed are global items or global dirs with items.
      // Now he clicks on dir Images/. Global Images/ dir openes. Now
      // user wants to drag some new item  he got from friend to this
      // dir; He can't; this is a global directory. He is frustrated.

      // the code is moved to kfm.cpp: static Kfm::setUpDest (QString *)

      QString tryPath(url);      // copy (hope deep)
      if (!getGUI()->sumode) // if not root...
      {
	Kfm::setUpDest(&tryPath);  // check/modify...
	url = tryPath.data();      // return back
      }
      //-------- Sven's write to pseudo global mime/app dirs end ---
      
    KURL u( url );
    if ( u.isMalformed() )
    {
	QMessageBox::warning( 0, klocale->translate( "KFM Error" ),
			      klocale->translate("ERROR: Drop over malformed URL") );
	return;
    }
    
    // Check whether we drop a directory on itself or one of its children
    int nested = 0;
    QStrList list( _zone->getURLList() );
    char *s;
    for ( s = list.first(); s != 0L; s = list.next() )
    {
	int j;
	if ( ( j = testNestedURLs( s, url ) ) )
	    if ( j == -1 || ( j > nested && nested != -1 ) )
		nested = j;
    }
    
    if ( nested == -1 )
    {
	QMessageBox::warning( 0, klocale->translate( "KFM Error" ),
			      klocale->translate("ERROR: Malformed URL") );
	return;
    }
    if ( nested == 2 )
    {
        // Commented out useless warning. David.
	// QMessageBox::warning( 0, klocale->translate( "KFM Error" ),
	// 		      klocale->translate("ERROR: You dropped some URL over itself") );
	return;
    }
    
    QPoint p2( _zone->getMouseX(), _zone->getMouseY() );
    manager->dropPopupMenu( _zone, url, &p2, ( nested == 0 ? false : true ) );

}