示例#1
0
int
pathconv(char **converted, char *fname)
{
  struct I_Fs_srv *fsrv;
  char drv;
  char *directory;
  char *name;
  char *newfilename;
  char *newdirectory;

  drv = tolower(get_drv(fname));
  LOG("drv=%c:", drv);

  if(drv == '\0') 
  {
    return 1;
  }

  directory = get_directory(fname);
  LOG("directory=%s", directory);
  
  if (directory==NULL)
  {
    return 1;
  }
  
  name = get_name(fname);
  LOG("name=%s", name);

  DosNameConversion(directory);
  DosNameConversion(name);

  LOG("directory=%s", directory);
  LOG("name=%s", name);
  
  if (drv >= 'c' && drv <= 'z')
  { 
    fsrv = FSRouter_route(&fsrouter, drv);

    newdirectory=malloc(strlen(fsrv->mountpoint)+
                          strlen(directory)+1);

    strcpy(newdirectory, fsrv->mountpoint);
    newdirectory=strcat(newdirectory, directory);
  }
  else
  {
    newdirectory = malloc(strlen(directory) + 1);
    strcpy(newdirectory, directory);
  }

  newfilename=malloc(strlen(newdirectory)+
                     strlen(name)+1);

  strcpy(newfilename, newdirectory);
  newfilename=strcat(newfilename, name);

  LOG("newfilename=%s", newfilename);
  *converted = newfilename;

  return 0;
}
示例#2
0
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] ) {

  std::string path;
  std::string temp_path, root_path;

  // names of files and directories
  std::string test_file = "test.txt";
  std::string subdir1_name = "subdir1";
  std::string subdir2_name = "subdir2";
  std::string subsubdir1_name = "subsubdir1";
  std::string subdir_test_file = "subtest.txt";


  // get the current working path from the system 
  std::string working_path = get_current_path();

  // attempt to create a temporary directory
  if( !get_temp_directory( temp_path ) ) return 5;

  // temp path just reported to be successfully created.  test existence method
  if( !path_exists( temp_path ) ) return 1;

  // temp path is a path to a directory, so test is_directory
  if( !is_directory( temp_path ) ) return 2;

  // create a file in the temp path
  if( !create_test_file( temp_path, test_file ) ) return 8;

  // already know temp path is not a file, so test is_file for negative case
  if( is_file( temp_path ) ) return 3;

  // test whether the is file method reports the test file correctly
  path = combine_path( temp_path, test_file );
  if( !is_file( path ) ) return 3;

  // attempt to remove the temporary directory
  if( !remove_directory( temp_path ) ) return 6;

  //--
  
  // get another temporary directory this time call it the root path
  if( !get_temp_directory( root_path ) ) return 7;

  // create a file in the root path
  if( !create_test_file( root_path, test_file ) ) return 8;

  // create a directory in the root path
  std::string subdir1_path = combine_path( root_path, subdir1_name );
  if( !get_directory( subdir1_path ) ) return 9;

  // create another directory in the root path
  std::string subdir2_path = combine_path( root_path, subdir2_name );
  if( !get_directory( subdir2_path ) ) return 9;

  // create a directory in the first child directory of the root path
  std::string subsubdir1_path = combine_path( subdir1_path, subsubdir1_name );
  if( !get_directory( subsubdir1_path ) ) return 9;

  // create a file in the child of the child directory
  if( !create_test_file( subsubdir1_path, subdir_test_file ) ) return 8;
/*
  // get the subdirectories of the root
  std::vector<std::string> dirs = get_subdirectories( root_path );
  for( std::vector<std::string>::iterator it = dirs.begin(); it != dirs.end(); it++ ) {
    printf( "dir: %s\n", it->c_str() );
  }
*/
  // test find file without recursion.  search for the test file in the root
  if( !find_file( path, test_file, root_path ) ) return 1;

  // validate the path returned from find file
  temp_path = combine_path( root_path, test_file );
  if( temp_path != path ) return 1;

  // test find file with recursion.  search for the subtest file in the dirs
  if( !find_file( path, subdir_test_file, root_path, true ) ) return 1;
  temp_path = combine_path( subsubdir1_path, subdir_test_file );
  if( temp_path != path ) return 1; 

  // clean up the root path
  if( !remove_directory( root_path ) ) return 6;

  if( find_file( path, "gzserver", "/usr/local", true ) ) {
    printf( "path: %s\n", path.c_str() );
  }

  return 0;
}
示例#3
0
/**
 *  Resolve native and culture assembly directories based on "asset_type" parameter.
 */
bool deps_resolver_t::resolve_probe_dirs(
        deps_entry_t::asset_types asset_type,
        pal::string_t* output,
        std::unordered_set<pal::string_t>* breadcrumb)
{
    bool is_resources = asset_type == deps_entry_t::asset_types::resources;
    assert(is_resources || asset_type == deps_entry_t::asset_types::native);

    // For resources assemblies, we need to provide the base directory of the resources path.
    // For example: .../Foo/en-US/Bar.dll, then, the resolved path is .../Foo
    std::function<pal::string_t(const pal::string_t&)> resources = [] (const pal::string_t& str) {
        return get_directory(get_directory(str));
    };
    // For native assemblies, obtain the directory path from the file path
    std::function<pal::string_t(const pal::string_t&)> native = [] (const pal::string_t& str) {
        return get_directory(str);
    };
    // Action for post processing the resolved path
    std::function<pal::string_t(const pal::string_t&)>& action = is_resources ? resources : native;

    // Set for de-duplication
    std::unordered_set<pal::string_t> items;

    pal::string_t core_servicing = m_core_servicing;
    pal::realpath(&core_servicing, true);

    // Filter out non-serviced assets so the paths can be added after servicing paths.
    pal::string_t non_serviced;

    std::vector<deps_entry_t> empty(0);

    pal::string_t candidate;

    auto add_package_cache_entry = [&](const deps_entry_t& entry, const pal::string_t& deps_dir, int fx_level) -> bool
    {
        if (breadcrumb != nullptr && entry.is_serviceable)
        {
            breadcrumb->insert(entry.library_name + _X(",") + entry.library_version);
            breadcrumb->insert(entry.library_name);
        }

        if (items.count(entry.asset.name))
        {
            return true;
        }

        // Ignore placeholders
        if (ends_with(entry.asset.relative_path, _X("/_._"), false))
        {
            return true;
        }

        trace::verbose(_X("Processing native/culture for deps entry [%s, %s, %s]"), 
            entry.library_name.c_str(), entry.library_version.c_str(), entry.asset.relative_path.c_str());

        if (probe_deps_entry(entry, deps_dir, fx_level, &candidate))
        {
            init_known_entry_path(entry, candidate);
            add_unique_path(asset_type, action(candidate), &items, output, &non_serviced, core_servicing);
        }
        else
        {
            // For self-contained apps do not use the full package name
            // because of rid-fallback could happen (ex: CentOS falling back to RHEL)
            if ((entry.asset.name == _X("apphost")) && ends_with(entry.library_name, _X(".Microsoft.NETCore.DotNetAppHost"), false))
            {
                return report_missing_assembly_in_manifest(entry, true);
            }

            return report_missing_assembly_in_manifest(entry);
        }

        return true;
    };

    // Add app entries
    const auto& entries = get_deps().get_entries(asset_type);
    for (const auto& entry : entries)
    {
        if (!add_package_cache_entry(entry, m_app_dir, 0))
        {
            return false;
        }
    }

    // If the deps file is missing add known locations.
    if (!get_deps().exists())
    {
        // App local path
        add_unique_path(asset_type, m_app_dir, &items, output, &non_serviced, core_servicing);

        (void) library_exists_in_dir(m_app_dir, LIBCORECLR_NAME, &m_coreclr_path);
        (void) library_exists_in_dir(m_app_dir, LIBCLRJIT_NAME, &m_clrjit_path);
    }

    // Handle any additional deps.json that were specified.
    for (const auto& additional_deps : m_additional_deps)
    {
        const auto additional_deps_entries = additional_deps->get_entries(asset_type);
        for (const auto entry : additional_deps_entries)
        {
            if (!add_package_cache_entry(entry, m_app_dir, 0))
            {
                return false;
            }
        }
    }

    // Add fx package locations to fx_dir
    for (int i = 1; i < m_fx_definitions.size(); ++i)
    {
        const auto& fx_entries = m_fx_definitions[i]->get_deps().get_entries(asset_type);

        for (const auto& entry : fx_entries)
        {
            if (!add_package_cache_entry(entry, m_fx_definitions[i]->get_dir(), i))
            {
                return false;
            }
        }
    }

    output->append(non_serviced);

    return true;
}
示例#4
0
文件: w_dir.c 项目: coliveira/xfignew
void
create_dirinfo(Boolean file_exp, Widget parent, Widget below, Widget *ret_beside, Widget *ret_below, Widget *mask_w, Widget *dir_w, Widget *flist_w, Widget *dlist_w, int file_width, Boolean file_panel)
{
    Widget	    w,dir_alt,home;
    Widget	    file_viewport;
    Widget	    dir_viewport;
    XFontStruct	   *temp_font;
    int		    char_ht,char_wd;
    char	   *dir;

    dir_entry_cnt = NENTRIES;
    file_entry_cnt = NENTRIES;
    filelist = (char **) calloc(file_entry_cnt, sizeof(char *));
    dirlist = (char **) calloc(dir_entry_cnt, sizeof(char *));

    if (browse_up) {
	get_directory(cur_browse_dir);
	dir = cur_browse_dir;
    } else if (export_up) {
	get_directory(cur_export_dir);
	dir = cur_export_dir;
    } else {
	get_directory(cur_file_dir);
	dir = cur_file_dir;
    }

    if (file_up) {
	FirstArg(XtNlabel, "Fig files");
    } else {
	FirstArg(XtNlabel, "     Existing");
    }
    NextArg(XtNfromVert, below);
    NextArg(XtNborderWidth, 0);
    NextArg(XtNtop, XtChainTop);
    NextArg(XtNbottom, XtChainTop);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("file_alt_label", labelWidgetClass,
			      parent, Args, ArgCount);

    FirstArg(XtNfont, &temp_font);
    GetValues(w);
    char_ht = max_char_height(temp_font) + 2;
    char_wd = char_width(temp_font) + 2;

    /* make a viewport to hold the list widget of filenames */
    FirstArg(XtNallowVert, True);
    if (file_up) {
	/* for the file panel, put the viewport below the Alternatives label */
	NextArg(XtNfromVert, w);
	NextArg(XtNheight, char_ht * 15);	/* show first 15 filenames */
    } else {
	/* for the export or browse panel, put the viewport beside the Alternatives label */
	NextArg(XtNfromVert, below);
	NextArg(XtNfromHoriz, w);
	if (browse_up) {
	    NextArg(XtNheight, char_ht * 10);	/* show 10 lines for existing browse files */
	} else {
	    NextArg(XtNheight, char_ht * 4);	/* show 4 lines for existing export files */
	}
    }
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_width);
    NextArg(XtNtop, XtChainTop);		/* chain so the viewport resizes fully */
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    file_viewport = XtCreateManagedWidget("vport", viewportWidgetClass,
					  parent, Args, ArgCount);

    /* label for filename mask */

    FirstArg(XtNlabel, "Filename Mask");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, file_viewport);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("mask_label", labelWidgetClass, 
				parent, Args, ArgCount);

    /* text widget for the filename mask */

    FirstArg(XtNeditType, XawtextEdit);
    NextArg(XtNleftMargin, 4);
    NextArg(XtNheight, char_ht * 2);
    NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNfromHoriz, w);
    NextArg(XtNfromVert, file_viewport);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    *mask_w = XtCreateManagedWidget("mask", asciiTextWidgetClass, 
					parent, Args, ArgCount);
    XtOverrideTranslations(*mask_w, XtParseTranslationTable(mask_text_translations));

    /* get the first directory listing */

    FirstArg(XtNstring, &dirmask);
    GetValues(*mask_w);
    if (MakeFileList(dir, dirmask, &dir_list, &file_list) == False)
	file_msg("No files in directory?");

    FirstArg(XtNlabel, "  Current Dir");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, *mask_w);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("dir_label", labelWidgetClass,
			      parent, Args, ArgCount);

    FirstArg(XtNstring, dir);
    NextArg(XtNleftMargin, 4);
    NextArg(XtNinsertPosition, strlen(dir));
    NextArg(XtNheight, char_ht * 2);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
    NextArg(XtNeditType, XawtextEdit);
    NextArg(XtNfromVert, *mask_w);
    NextArg(XtNfromHoriz, w);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    *dir_w = XtCreateManagedWidget("dir_name", asciiTextWidgetClass,
				   parent, Args, ArgCount);

    XtOverrideTranslations(*dir_w, XtParseTranslationTable(dir_translations));

    /* directory alternatives */

    FirstArg(XtNlabel, "  Directories");
    NextArg(XtNborderWidth, 0);
    NextArg(XtNfromVert, *dir_w);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    dir_alt = XtCreateManagedWidget("dir_alt_label", labelWidgetClass,
			      parent, Args, ArgCount);

    /* put a Home button to the left of the list of directories */
    FirstArg(XtNlabel, "Home");
    NextArg(XtNfromVert, dir_alt);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNhorizDistance, -(char_wd * 5));
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    home = XtCreateManagedWidget("home", commandWidgetClass, parent, Args, ArgCount);
    XtAddCallback(home, XtNcallback, GoHome, (XtPointer) NULL);

    /* put a button for showing/hiding hidden files below the Home button */

    FirstArg(XtNlabel, show_hidden? "Hide Hidden": "Show Hidden");
    NextArg(XtNfromVert, home);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNhorizDistance, (int) -(char_wd * 10.5));
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    hidden = XtCreateManagedWidget("hidden", commandWidgetClass, 
				parent, Args, ArgCount);
    XtAddCallback(hidden, XtNcallback, ShowHidden, (XtPointer) NULL);

    FirstArg(XtNallowVert, True);
    NextArg(XtNforceBars, True);
    NextArg(XtNfromHoriz, dir_alt);
    NextArg(XtNfromVert, *dir_w);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNwidth, file_panel? F_FILE_WIDTH: E_FILE_WIDTH);
    NextArg(XtNheight, char_ht * 5);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainRight);
    dir_viewport = XtCreateManagedWidget("dirvport", viewportWidgetClass,
					 parent, Args, ArgCount);

    FirstArg(XtNlist, file_list);
    /* for file panel use only one column */
    if (file_panel) {
	NextArg(XtNdefaultColumns, 1);
	NextArg(XtNforceColumns, True);
    }
    *flist_w = XtCreateManagedWidget("file_list_panel", figListWidgetClass,
				     file_viewport, Args, ArgCount);
    XtAddCallback(*flist_w, XtNcallback, FileSelected, (XtPointer) NULL);
    XtOverrideTranslations(*flist_w,
			   XtParseTranslationTable(list_panel_translations));

    FirstArg(XtNlist, dir_list);
    *dlist_w = XtCreateManagedWidget("dir_list_panel", figListWidgetClass,
				     dir_viewport, Args, ArgCount);
    XtOverrideTranslations(*dlist_w,
			   XtParseTranslationTable(list_panel_translations));

    XtAddCallback(*dlist_w, XtNcallback, DirSelected, (XtPointer) NULL);

    if (!actions_added) {
	XtAppAddActions(tool_app, actionTable, XtNumber(actionTable));
	actions_added = True;
    }

    FirstArg(XtNlabel, "Rescan");
    NextArg(XtNfromVert, dir_viewport);
    NextArg(XtNvertDistance, 15);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNhorizDistance, 45);
    NextArg(XtNheight, 25);
    NextArg(XtNtop, XtChainBottom);
    NextArg(XtNbottom, XtChainBottom);
    NextArg(XtNleft, XtChainLeft);
    NextArg(XtNright, XtChainLeft);
    w = XtCreateManagedWidget("rescan", commandWidgetClass, parent,
			      Args, ArgCount);
    XtAddCallback(w, XtNcallback, CallbackRescan, (XtPointer) NULL);

    /* install accelerators so they can be used from each window */
    XtInstallAccelerators(parent, w);
    XtInstallAccelerators(*flist_w, parent);
    XtInstallAccelerators(*dlist_w, parent);

    *ret_beside = w;
    *ret_below = dir_viewport;

    return;
}