Пример #1
0
/*
 * Read a file from the File->Open dialog.
 */
gboolean
ggcov_read_file(const char *filename)
{
    if (file_is_directory(filename) == 0)
    {
	if (!cov_read_directory(filename, /*recursive*/FALSE))
	    return FALSE;
    }
    else if (errno != ENOTDIR)
    {
	perror(filename);
    }
    else if (file_is_regular(filename) == 0)
    {
	if (cov_is_source_filename(filename))
	{
	    if (!cov_read_source_file(filename))
		return FALSE;
	}
	else
	{
	    if (!cov_read_object_file(filename))
		return FALSE;
	}
    }
    else
    {
	_log.error("%s: don't know how to handle this filename\n", filename);
	return FALSE;
    }

    return TRUE;
}
Пример #2
0
void DirectoryArchive::forEachFile (VisitorFunc visitor, const std::string& root)
{
	std::vector<Directory*> dirs;
	UnixPath path(m_root);
	path.push(root);
	dirs.push_back(directory_open(path));

	while (!dirs.empty() && directory_good(dirs.back())) {
		const char *name = directory_read_and_increment(dirs.back());

		if (name == 0) {
			directory_close(dirs.back());
			dirs.pop_back();
			path.pop();
		} else if (!string_equal(name, ".") && !string_equal(name, "..")) {
			path.push_filename(name);

			bool is_directory = file_is_directory(path);

			if (!is_directory)
				visitor.file(os::makeRelative(path, m_root));

			path.pop();

			if (is_directory) {
				path.push(name);

				if (!visitor.directory(os::makeRelative(path, m_root), dirs.size()))
					dirs.push_back(directory_open(path));
				else
					path.pop();
			}
		}
	}
}
Пример #3
0
int
heap_init (
    const char *heappath)
{
    int
        rc = HEAP_OK;

    if (file_exists (heappath))
      {
        if (!file_is_directory (heappath))
            rc = HEAP_INVALID_PATH;
      }
    else
      {
        if (make_dir (heappath) != 0)
            rc = HEAP_CANNOT_CREATE_PATH;
      }

    if (! rc)
      {
        path = mem_strdup (heappath);
        if (!path)
            rc = HEAP_MEMORY_ERROR;
      }

    return rc;
}
Пример #4
0
/* Writes SIZE bytes from BUFFER into FILE,
   starting at the file's current position.
   Returns the number of bytes actually written,
   which may be less than SIZE if end of file is reached.
   (Normally we'd grow the file in that case, but file growth is
   not yet implemented.)
   Advances FILE's position by the number of bytes read. */
off_t
file_write (struct file *file, const void *buffer, off_t size) 
{
  if (file_is_directory (file)) return -1;
  off_t bytes_written = inode_write_at (file->inode, buffer, size, file->pos);
  file->pos += bytes_written;
  return bytes_written;
}
Пример #5
0
int
file_build_tree(const char *dirname, mode_t mode)
{
    char *p, *dir = g_strdup(dirname);
    int ret = 0;
    char oldc;

    /* skip leading /s */
    for (p = dir ; *p && *p == '/' ; p++)
	;

    /* check and make each directory part in turn */
    for (;;)
    {
	/* skip p to next / */
	for ( ; *p && *p != '/' ; p++)
	    ;

	oldc = *p;
	*p = '\0';

	if (file_exists(dir) < 0)
	{
	    if (mkdir(dir, mode) < 0)
	    {
		ret = -1;
		break;
	    }
	}

	if (file_is_directory(dir) < 0)
	{
	    ret = -1;
	    break;
	}

	if (!oldc)
	    break;
	*p = '/';

	/* skip possible multiple / */
	for ( ; *p && *p == '/' ; p++)
	    ;
	if (!*p)
	    break;
    }

    g_free(dir);
    return ret;
}
void Doom3MapCompiler::runDmap(const std::string& mapFile)
{
	if (!os::fileOrDirExists(mapFile) || file_is_directory(mapFile.c_str()))
	{
		rError() << "Can't dmap, file doesn't exist: " << mapFile << std::endl;
		return;
	}

	TextFileInputStream file(mapFile);
	std::istream mapStream(&file);

	boost::shared_ptr<BasicNode> root(new BasicNode);

	RawImporter importFilter(root);

	try
	{
		// Parse our map file
		Doom3MapReader reader(importFilter);
		reader.readFromStream(mapStream);
	}
	catch (IMapReader::FailureException& e)
	{
		rError() << 
			(boost::format("Failure reading map file:\n%s\n\n%s") % mapFile % e.what()).str() << std::endl;
		return;
	}

	// Start the sequence
	runDmap(root);

	if (_procFile->hasLeak())
	{
		std::string ext = "." + os::getExtension(mapFile);
		std::string leakFileName = boost::algorithm::replace_last_copy(mapFile, ext, LeakFile::Extension());

		_procFile->leakFile->writeToFile(leakFileName);

		return;
	}

	std::string ext = "." + os::getExtension(mapFile);
	std::string procFileName = boost::algorithm::replace_last_copy(mapFile, ext, ProcFile::Extension());

	_procFile->saveToFile(procFileName);
}
Пример #7
0
int
heap_recover (
    const char *heappath)
{
    int
        rc = HEAP_OK;

    if (file_exists (heappath))
      {
        if (!file_is_directory (heappath))
            rc = HEAP_INVALID_PATH;
      }
    else
      {
        if (make_dir (heappath) != 0)
            rc = HEAP_CANNOT_CREATE_PATH;
      }

    if (! rc)
      {
        path = mem_strdup (heappath);
        if (!path)
            rc = HEAP_MEMORY_ERROR;
      }
    if (! rc)
      {
        file_list = load_dir_list (path, "t");
        if (!file_list)
            rc = HEAP_MEMORY_ERROR;
      }
    for (file_info  = (FILEINFO *) file_list-> next;
         file_info != (FILEINFO *) file_list;
         file_info  = file_info-> next)
      {
        rc = file_recover (file_info);
        if (rc)
            break;
      }
    free_dir_list (file_list);

    return rc;
}
Пример #8
0
static void
ui_create(ggcov_params_t &params, const char *full_argv0, int successes)
{
    /*
     * If we're being run from the source directory, fiddle the
     * glade search path to point to ../ui first.  This means
     * we can run ggcov before installation without having to
     * compile with UI_DEBUG=1.
     */
    estring dir = file_make_absolute(full_argv0);
    const char *p = strrchr(dir, '/');
    if (p != 0 &&
	(p -= 4) >= dir.data() &&
	!strncmp(p, "/src/", 5))
    {
	dir.truncate_to(p - dir);
	dir.append_string("/ui");
	if (!file_is_directory(dir))
	{
	    _log.info("running from source directory, "
		      "so prepending %s to glade search path\n",
		      dir.data());
	    ui_prepend_glade_path(dir);
	}
    }

    const struct window *wp;
    for (wp = windows ; wp->name ; wp++)
	ui_register_windows_entry(_(wp->label), wp->create, 0);

    ui_set_default_icon(ggcov32_xpm);

    prefs.load();

    if (!successes)
    {
	/* No files discovered from commandline...show the File->Open dialog to get some */
	on_file_open_activate(0, 0);
	while (!*cov_file_t::first())
	    gtk_main_iteration();
    }

    /* Possibly have files from commandline or dialog...show initial windows */
    tok_t tok(params.get_initial_windows(), ", \n\r");
    const char *name;
    int nwindows = 0;
    while ((name = tok.next()) != 0)
    {
	for (wp = windows ; wp->name ; wp++)
	{
	    if (!strcmp(name, wp->name))
	    {
		wp->create(0, 0);
		nwindows++;
		break;
	    }
	}
	if (!wp->name)
	    _log.warning("unknown window name \"%s\"\n", name);
    }

    if (!nwindows)
	on_windows_new_summarywin_activated(0, 0);

    if (params.get_profile_mode())
    {
	while (g_main_context_iteration(NULL, FALSE))
	    ;
	exit(0);
    }
}
Пример #9
0
static gboolean
copy_one(const char *filename, void *userdata)
{
    copy_task_t *ct = (copy_task_t *)userdata;
    const char *fromfile;
    string_var tofile, mappedfile;
    
    // TODO: WTF
        
    /* construct the target filename */
    if (ct->flatten_)
    	fromfile = file_basename_c(filename);
    else
    	fromfile = filename;
	
    if (ct->tofile_ != 0)
    	tofile = ct->expand(ct->tofile_);
    else if (ct->exp_todir_ != 0)
	tofile = g_strconcat(ct->exp_todir_, "/", filename, 0);
    else
    {
	ct->result_ = FALSE; 	/* failed */
	return FALSE;	    	/* stop iteration */
    }
    if ((mappedfile = ct->mapper_->map(tofile)) == 0)
	return TRUE;	    	/* keep going */
        
    log::infof("%s -> %s\n", filename, mappedfile.data());
	
    /* TODO: apply proj->basedir */

    if (file_is_directory(filename) == 0)
    {
    	int r;
	unsigned ncopied = ct->ncopied_;
	
	r = file_apply_children(filename, copy_one, userdata);
	
	if (r < 0)
	{
	    log::perror(filename);
	}
	else if (ncopied == ct->ncopied_ && ct->include_empty_dirs_)
	{
	    /* no files copied underneath this directory -- it must be empty */
	    /* TODO: sensible mode from original directory */
	    /* TODO: control uid,gid */
	    if (file_build_tree(mappedfile, 0755))
	    {
		log::perror(filename);
		ct->result_ = FALSE;
    	    }
	}
    }
    else
    {
	if (!do_copy_file(filename, mappedfile))
	    ct->result_ = FALSE;
    }
        
    return ct->result_;    /* keep going if we didn't fail */
}