String FileFilter::MakeAPIFilter() const { String filter; if ( !extensions.IsEmpty() ) { if ( !description.IsEmpty() ) { filter += description; filter += " ("; } for ( StringList::const_iterator i = extensions.Begin(); i != extensions.End(); ++i ) { if ( i != extensions.Begin() ) filter += ' '; // also legal are ';' and ',' if ( i->StartsWith( '.' ) ) filter += '*'; filter += *i; } if ( !description.IsEmpty() ) filter += ')'; } return filter; }
ArgumentList ExtractArguments( const StringList& argv, argument_item_mode mode, ArgumentOptions options ) { bool noItems = mode == ArgumentItemMode::NoItems; bool itemsAsFiles = mode == ArgumentItemMode::AsFiles; bool itemsAsViews = mode == ArgumentItemMode::AsViews; bool allowWildcards = !noItems && options.IsFlagSet( ArgumentOption::AllowWildcards ); bool noPreviews = itemsAsViews && options.IsFlagSet( ArgumentOption::NoPreviews ); bool recursiveDirSearch = itemsAsFiles && allowWildcards && options.IsFlagSet( ArgumentOption::RecursiveDirSearch ); bool recursiveSearchArgs = recursiveDirSearch && options.IsFlagSet( ArgumentOption::RecursiveSearchArgs ); // This is the recursive search mode flag, controlled by --r[+|-] bool recursiveSearch = false; // The list of existing view identifiers, in case itemsAsViews = true. SortedStringList imageIds; // The list of extracted arguments ArgumentList arguments; for ( StringList::const_iterator i = argv.Begin(); i != argv.End(); ++i ) { if ( i->StartsWith( '-' ) ) { Argument arg( i->At( 1 ) ); if ( recursiveSearchArgs && arg.Id() == s_recursiveSearchArg ) { if ( arg.IsSwitch() ) recursiveSearch = arg.SwitchState(); else if ( arg.IsLiteral() ) recursiveSearch = true; else arguments.Add( arg ); } else arguments.Add( arg ); } else { if ( noItems ) throw ParseError( "Non-parametric arguments are not allowed", *i ); StringList items; if ( itemsAsFiles ) { String fileName = *i; if ( fileName.StartsWith( '\"' ) ) fileName.Delete( 0 ); if ( fileName.EndsWith( '\"' ) ) fileName.Delete( fileName.UpperBound() ); fileName.Trim(); if ( fileName.IsEmpty() ) throw ParseError( "Empty path specification", *i ); fileName = File::FullPath( fileName ); if ( fileName.HasWildcards() ) { if ( !allowWildcards ) throw ParseError( "Wildcards not allowed", fileName ); items = SearchDirectory( fileName, recursiveSearch ); } else items.Add( fileName ); } else if ( itemsAsViews ) { String viewId = *i; if ( !allowWildcards ) if ( viewId.HasWildcards() ) throw ParseError( "Wildcards not allowed", viewId ); size_type p = viewId.Find( "->" ); if ( p != String::notFound ) { if ( noPreviews ) throw ParseError( "Preview identifiers not allowed", viewId ); String imageId = viewId.Left( p ); if ( imageId.IsEmpty() ) throw ParseError( "Missing image identifier", viewId ); String previewId = viewId.Substring( p+2 ); if ( previewId.IsEmpty() ) throw ParseError( "Missing preview identifier", viewId ); FindPreviews( items, imageId, previewId ); } else { if ( viewId.HasWildcards() ) { Array<ImageWindow> W = ImageWindow::AllWindows(); for ( size_type i = 0; i < W.Length(); ++i ) { View v = W[i].MainView(); if ( String( v.Id() ).WildMatch( viewId ) ) AddView( items, v ); } } else { ImageWindow w = ImageWindow::WindowById( IsoString( viewId ) ); if ( w.IsNull() ) throw ParseError( "Image not found", viewId ); AddView( items, w.MainView() ); } } } else items.Add( *i ); Argument arg( *i, items ); arguments.Add( arg ); } } return arguments; }