Exemple #1
0
void	check_file(char *av, t_args *args)
{
	struct stat	*stats;

	stats = malloc(sizeof(*stats));
	if (!lstat(av, stats))
	{
		if (S_ISDIR(stats->st_mode))
			add_file(&(args->dirs), new_file(ft_strdup(av)));
		else if (S_ISREG(stats->st_mode))
			add_file(&(args->files), new_file(ft_strdup(av)));
		else if (S_ISLNK(stats->st_mode))
		{
			if (args->opt->l)
				add_file(&(args->files), new_file(ft_strdup(av)));
			else
				add_file(&(args->dirs), new_file(ft_strdup(av)));
		}
	}
	else
	{
		ft_error2(av);
		args->error = 1;
	}
	free(stats);
}
Exemple #2
0
static void create_cab_file(void)
{
    CCAB cabParams;
    HFCI hfci;
    ERF erf;
    static CHAR a_txt[] = "a.txt",
                b_txt[] = "b.txt",
                testdir_c_txt[] = "testdir\\c.txt",
                testdir_d_txt[] = "testdir\\d.txt";
    BOOL res;

    set_cab_parameters(&cabParams);

    hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
                      fci_read, fci_write, fci_close, fci_seek, fci_delete,
                      get_temp_file, &cabParams, NULL);

    ok(hfci != NULL, "Failed to create an FCI context\n");

    add_file(hfci, a_txt);
    add_file(hfci, b_txt);
    add_file(hfci, testdir_c_txt);
    add_file(hfci, testdir_d_txt);

    res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
    ok(res, "Failed to flush the cabinet\n");

    res = FCIDestroy(hfci);
    ok(res, "Failed to destroy the cabinet\n");
}
Exemple #3
0
int
main(int argc, char *argv[])
{
    int c, fflag;

    fflag = 0;
    while ((c = getopt(argc, argv, "Eae:f:nru")) != -1)
        switch (c) {
        case 'E':
        case 'r':
            Eflag = 1;
            break;
        case 'a':
            aflag = 1;
            break;
        case 'e':
            eflag = 1;
            add_compunit(CU_STRING, optarg);
            break;
        case 'f':
            fflag = 1;
            add_compunit(CU_FILE, optarg);
            break;
        case 'n':
            nflag = 1;
            break;
        case 'u':
            setlinebuf(stdout);
            break;
        default:
        case '?':
            (void)fprintf(stderr,
                          "usage: sed [-aEnru] command [file ...]\n"
                          "       sed [-aEnru] [-e command] [-f command_file] [file ...]\n");
            exit(1);
        }
    argc -= optind;
    argv += optind;

    /* First usage case; script is the first arg */
    if (!eflag && !fflag && *argv) {
        add_compunit(CU_STRING, *argv);
        argv++;
    }

    compile();

    /* Continue with first and start second usage */
    if (*argv)
        for (; *argv; argv++)
            add_file(*argv);
    else
        add_file(NULL);
    process();
    cfclose(prog, NULL);
    if (fclose(stdout))
        err(FATAL, "stdout: %s", strerror(errno));
    exit (0);
}
Exemple #4
0
int
main(int argc, char *argv[])
{
	int c, fflag;

	setprogname(*argv);
	fflag = 0;
	while ((c = getopt(argc, argv, "ae:f:nE")) != -1)
		switch (c) {
		case 'a':
			aflag = 1;
			break;
		case 'e':
			eflag = 1;
			add_compunit(CU_STRING, optarg);
			break;
		case 'f':
			fflag = 1;
			add_compunit(CU_FILE, optarg);
			break;
		case 'n':
			nflag = 1;
			break;
		case 'E':
			ere = REG_EXTENDED;
			break;
		default:
		case '?':
			(void)fprintf(stderr,
"usage:\t%s [-aEn] script [file ...]\n\t%s [-aEn] [-e script] ... [-f script_file] ... [file ...]\n",
			    getprogname(), getprogname());
			exit(1);
		}
	argc -= optind;
	argv += optind;

	/* First usage case; script is the first arg */
	if (!eflag && !fflag && *argv) {
		add_compunit(CU_STRING, *argv);
		argv++;
	}

	compile();

	/* Continue with first and start second usage */
	if (*argv)
		for (; *argv; argv++)
			add_file(*argv);
	else
		add_file(NULL);
	process();
	cfclose(prog, NULL);
	if (fclose(stdout))
		err(FATAL, "stdout: %s", strerror(errno));
	exit (0);
}
Exemple #5
0
static void max_file_size(void)
{
	add_dir(     FOUND, "");
	add_file(    FOUND, "a", 1);
	add_file(    FOUND, "b", 2);
	add_file(NOT_FOUND, "c", 3);
	add_dir (    FOUND, "d");
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\nmax_file_size=2", fullpath);
}
Exemple #6
0
static void exclude_dir(void)
{
	add_dir(     FOUND, "");
	add_file(    FOUND, "a",   1);
	add_dir (NOT_FOUND, "d");
	add_file(NOT_FOUND, "d/x", 1);
	add_file(    FOUND, "e",   3);
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\n"
		"exclude=%s/d\n",
		fullpath, fullpath);
}
Exemple #7
0
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_prepend_config_files(const char *filelist, char **pq, char ***ret_pp)
{
    krb5_error_code ret;
    const char *p, *q;
    char **pp;
    int len;
    char *fn;

    pp = NULL;

    len = 0;
    p = filelist;
    while(1) {
	ssize_t l;
	q = p;
	l = strsep_copy(&q, PATH_SEP, NULL, 0);
	if(l == -1)
	    break;
	fn = malloc(l + 1);
	if(fn == NULL) {
	    krb5_free_config_files(pp);
	    return ENOMEM;
	}
	(void)strsep_copy(&p, PATH_SEP, fn, l + 1);
	ret = add_file(&pp, &len, fn);
	if (ret) {
	    krb5_free_config_files(pp);
	    return ret;
	}
    }

    if (pq != NULL) {
	int i;

	for (i = 0; pq[i] != NULL; i++) {
	    fn = strdup(pq[i]);
	    if (fn == NULL) {
		krb5_free_config_files(pp);
		return ENOMEM;
	    }
	    ret = add_file(&pp, &len, fn);
	    if (ret) {
		krb5_free_config_files(pp);
		return ret;
	    }
	}
    }

    *ret_pp = pp;
    return 0;
}
Exemple #8
0
static void exclude_extension(void)
{
	add_dir(     FOUND, "");
	add_file(NOT_FOUND, "a.c", 1);
	add_file(NOT_FOUND, "a.h", 2);
	add_file(    FOUND, "b",   2);
	add_file(    FOUND, "b.x", 2);
	add_file(NOT_FOUND, "c.c", 3);
	add_dir (    FOUND, "d");
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\n"
		"exclude_ext=c\n"
		"exclude_ext=h\n", fullpath);
}
Exemple #9
0
static void simple_entries(void)
{
	add_dir( FOUND, "");
	add_file(FOUND, "a", 1);
	add_file(FOUND, "b", 2);
	add_file(FOUND, "c", 3);
	add_dir (FOUND, "d");
	add_slnk(FOUND, "e", "a");
	add_hlnk(FOUND, "f", "a");
	add_hlnk(FOUND, "g", "a");
	add_fifo_special(FOUND, "h");
	add_sock(FOUND, "i");
	snprintf(extra_config, sizeof(extra_config), "include=%s", fullpath);
}
Exemple #10
0
int create_file(struct simple_directory *dir, const char *path, mode_t mode)
{

	/* implementation will be something like this, but path strings will
	 * need to be handled better
	 */
	char *tmp_path = strdup(path);
	const char *dn = dirname(tmp_path);


	/* Debug */
	printf("\n\n");
	printf("create_file()\n");
	printf("Path is: %s\n", path);
	printf("dirname is: %s\n", dn);

	if (strcmp(dn, "/") == 0) {
		printf("Create file\n");
		add_file(dir, create_file_struct(path, mode, 1, "", 0));
		
		printf("\n\n");

		return 0;
	} else {
		printf("Find directory\n");
		struct simple_directory *d = find_directory(dir, dn);

		int dir_len = strlen(dn);
		char *new_path = strdup(path + dir_len);
		
		printf("\n\n");

		return create_file(d, new_path, mode);
	}
}
Exemple #11
0
/* The main logic of the public svn_client_add4;  the only difference
   is that this function uses an existing access baton.
   (svn_client_add4 just generates an access baton and calls this func.) */
static svn_error_t *
add(const char *path,
    svn_depth_t depth,
    svn_boolean_t force,
    svn_boolean_t no_ignore,
    svn_wc_adm_access_t *adm_access,
    svn_client_ctx_t *ctx,
    apr_pool_t *pool)
{
  svn_node_kind_t kind;
  svn_error_t *err;

  SVN_ERR(svn_io_check_path(path, &kind, pool));
  if (kind == svn_node_dir && depth >= svn_depth_files)
    err = add_dir_recursive(path, adm_access, depth,
                            force, no_ignore, ctx, pool);
  else if (kind == svn_node_file)
    err = add_file(path, ctx, adm_access, pool);
  else
    err = svn_wc_add2(path, adm_access, NULL, SVN_INVALID_REVNUM,
                      ctx->cancel_func, ctx->cancel_baton,
                      ctx->notify_func2, ctx->notify_baton2, pool);

  /* Ignore SVN_ERR_ENTRY_EXISTS when FORCE is set.  */
  if (err && err->apr_err == SVN_ERR_ENTRY_EXISTS && force)
    {
      svn_error_clear(err);
      err = SVN_NO_ERROR;
    }
  return err;
}
Exemple #12
0
int
main(int argc, char **argv)
{
    /*int i;*/
    char db_dir[256];           /* the directory where the db file is */
    char dbfilename[256];       /* the database filename */
    char *filenames[1000];      /* the files to be added */
    char **fnames = filenames;
    short flag;                 /* flag for deleting or adding */

    parse_args(argv, db_dir, filenames, &flag);

    if (!filenames[0]) {
        fprintf(stderr, "%s\n", usage);
        return -1;
    }

    parser_init();

    build_db_filename(flag, db_dir, dbfilename);

    if (fresh)
        unlink(dbfilename);

    if (flag & Delete)
        while (*fnames)
            delete_file(dbfilename, *fnames++);
    else
        while (*fnames)
            add_file(dbfilename, *fnames++, fresh);
    return 0;
}
Exemple #13
0
  PathMan::LookUp PathMan::add_file(const char * path, uint8_t mode)
  {
    LookUp lu = {FAILURE, State(), 0, 0};
    uint32_t len;
    const char * basename;

    if (trie.root)
      lu.err = _check_path(path, len);

    basename = NULL;
    if (len > 1) {
      for (uint16_t k = 0; k < len; k++) {
        if (path[k] == '/') {
          if (len > 1 && k < len - 1) {
            basename = path + k + 1;
            lu.err = SUCCESS;
          }
        }
      }
    } else {
      lu.err = MALFORMED_PATH;
    }

    if (lu.err == SUCCESS) {
      size_t dlen = basename - path;
      char dirname[dlen + 1];
      memcpy(dirname, path, dlen); dirname[dlen] = 0;

      lu = lookup(dirname);
      if (lu.err == SUCCESS) {
        lu = add_file(lu.dir, basename, 0);
      }
    }
    return lu;
  }
Exemple #14
0
void compiler::add_code(std::istream & in, std::string const & name) {

	token_iterator i{in};

	this->code_ += "// --------------------";
	if (!name.empty()) this->code_ += "// " + name;
	this->code_ +="\n\n";

	while (i) {

		if (i->second == token_type::other && i->first == "#") {
			++i;
			i.skip_whitespace();
			if (i->second == token_type::word) {
				if (i->first == "import") {
					std::string filename;
					std::getline(in, filename);
					filename.erase(0, filename.find_first_not_of(" \t"));
					this->code_ += "//#import " + filename + "\n";
					if (!used_files_.count(filename)) add_file(filename);
					++i;
					continue;
				} else if (i->first == "version") {
					unsigned int version;
					in >> version;
					if (version > this->glsl_version_) this->glsl_version_ = version;
					++i;
					continue;
				} else {
					this->code_ += '#';
				}
			}
void *seeki_alloc(char *str)
{
    struct seeki *sip = malloc(sizeof(struct seeki));

    sip->rfp = seek_open(str, 'r');
    sip->wfp = seek_open(str, 'w');
    sip->cfp = seek_open(str, 'c');
    sip->tot_seeks = 0;
    sip->total_sectors = 0.0;
    sip->last_start = sip->last_end = 0;
    memset(&sip->root, 0, sizeof(sip->root));

    if (sps_name) {
        char *oname;

        memset(&sip->sps, 0, sizeof(sip->sps));

        oname = malloc(strlen(sps_name) + strlen(str) + 32);
        sprintf(oname, "%s_%s.dat", sps_name, str);
        if ((sip->sps_fp = my_fopen(oname, "w")) == NULL)
            perror(oname);
        else
            add_file(sip->sps_fp, oname);
    } else
        sip->sps_fp = NULL;

    return sip;
}
Exemple #16
0
int			check_link(t_lem_env *env, char *s)
{
	int		i;
	int		j;
	int		k;
	int		a;

	env->r.nolink = 0;
	if (matrice_visit0(env, &i, &j, &k) == 0)
		return (ft_error(env, 1));
	a = -1;
	if (!is_link(s) || (a = check_link2(env, s, &i, &j)) != 0)
		return (ft_error(env, 2));
	while (++k < env->nbroom)
	{
		if ((a = ft_strcmp(env->room[k], &s[i + 1])) == 0)
			break ;
	}
	if (a != 0 || j == k)
		return (ft_error(env, 2));
	if (env->matrice[j][k] == 1)
		return (ft_error(env, 2));
	env->matrice[k][j] += 1;
	env->matrice[j][k] += 1;
	env->r.nbline += add_file(env, s);
	return (1);
}
Exemple #17
0
int
main(int argc, char **argv)
{
    handle_common_asf_args(&argc, &argv, "ASF CEOS Metadata Viewer");

    gchar *glade_xml_file;

    gtk_init(&argc, &argv);

    // glade_xml_file = (gchar *) find_in_path("mdv.glade");
    glade_xml_file = (gchar *) find_in_share("mdv.glade");
    glade_xml = glade_xml_new(glade_xml_file, NULL, NULL);

    g_free(glade_xml_file);

    set_app_title();
    set_font();

    if (argc > 1)
        add_file(argv[1]);

    glade_xml_signal_autoconnect(glade_xml);
    gtk_main ();

    exit (EXIT_SUCCESS);
}
Exemple #18
0
int main(int argc, char *argv[]){
	int i;
	struct file *head = NULL;
	for (i = 1; i < argc; i++){
		head = add_file(head, scan_c(argv[i]));	/*only handle C language right now*/
	}
	FILE * template = fopen("/etc/code-insight/template.html", "r");
Exemple #19
0
int archive_files( char *names[], int count, char *out_file_name )
{
	int f_out = open(out_file_name, O_CREAT | O_TRUNC | O_WRONLY), i;

	if (f_out < 0)
		return -1;

	write(f_out, &count, sizeof(int));

	for (i = 0; i < count; i++)
	{	
		int res;

		printf("%s", names[i]);

		res = add_file(names[i], f_out);

		if (res == -1)
			printf("... Failed, skipped.\n");
		else
			printf("... Complete.\n");		
	}

	fchmod(f_out, S_IRUSR | S_IROTH | S_IRGRP);
	close(f_out);

	return 0;
}
void			get_directory_content(t_list *dir, t_list **files, int options)
{
	DIR			*pdir;
	t_dir		*pdirent;
	char		*tmp;

	pdir = NULL;
	pdirent = NULL;
	if (!(tmp = set_file_path(NAME(dir), PATH(dir))))
		print_mem_error(errno);
	if ((pdir = opendir(tmp)))
	{
		while ((pdirent = readdir(pdir)))
		{
			if (pdirent)
				add_file(pdirent->d_name, files, tmp, options);
			else
				print_mem_error(errno);
		}
		closedir(pdir);
	}
	else
		print_opendir_error(tmp, errno);
	ft_strdel(&tmp);
	sort(*files, options);
}
Exemple #21
0
	void file_storage::add_file(std::wstring const& file, size_type size, int flags
		, std::time_t mtime, std::string const& symlink_path)
	{
		std::string utf8;
		wchar_utf8(file, utf8);
		add_file(utf8, size, flags, mtime, symlink_path);
	}
void
ObjectSettings::add_level(const std::string& text, std::string* value_ptr, const std::string& key,
                          const std::string& basedir,
                          unsigned int flags)
{
  add_file(text, value_ptr, key, {}, {".stl"}, basedir, flags);
}
void accept_file_dialog(GtkWidget *widget, gpointer data)
{
  add_file(gtk_file_selection_get_filename(GTK_FILE_SELECTION(filew)));

  update_list();
  gtk_widget_destroy(filew);
}
Exemple #24
0
void gnode_to_gui(GNode * root,
		  GtkCTreeNode * a_node)
{

    GNode *tmp;
    GtkCTreeNode *new_node;

    NE_DEBUG(DEBUG_GNOME, "Building GUI tree from GNode hierarchy... \n");

    if (!root)
	return;

    tmp = g_node_first_child(root);

    while (tmp) {
	new_node = add_file(name(tmp),
			    file(tmp),
			    a_node);

	gnode_to_gui(tmp, new_node);
	tmp = g_node_next_sibling(tmp);
    }

    gnode_to_gui(tmp, a_node);

}
Exemple #25
0
int main(int argc, char *argv[])
{
	struct m_inode *mip;
	FILE *fp;
	
	if(argc != 5)
	{
		panic(__FILE__, __LINE__, 
				"Usage: %s Image super_block_id pathname filename\n", 
				argv[0]);
	}
	
	fp = fopen(argv[4], "rb");
	if(!fp)
	{
		panic(__FILE__, __LINE__, "Can't open %s\n", argv[4]);
	}
	
	constructor(argv[1]);
	
	add_file(fp, atoi(argv[2]), argv[3]);
	
	destructor();
	return 0;
}
Exemple #26
0
static void exclude_regex(void)
{
	add_dir(     FOUND, "");
	add_file(    FOUND, "a", 1);
	add_file(    FOUND, "b", 1);
	add_file(    FOUND, "c", 1);
	add_file(NOT_FOUND, "dnotthisone", 1);
	add_dir (    FOUND, "e");
	add_dir (NOT_FOUND, "e/fexc");
	add_file(NOT_FOUND, "fnotthisone", 1);
	snprintf(extra_config, sizeof(extra_config),
		"include=%s\n"
		"exclude_regex=not\n"
		"exclude_regex=exc\n",
		fullpath);
}
Exemple #27
0
SIGNAL_CALLBACK void
on_file_selection_dialog_ok_button_clicked(GtkWidget *w)
{
    GtkWidget *file_selection_dialog;

    gchar **selections;
    gchar **current;

    file_selection_dialog =
        glade_xml_get_widget(glade_xml, "file_selection_dialog");

    selections = gtk_file_selection_get_selections(
        GTK_FILE_SELECTION(file_selection_dialog));

    current = selections;

    while (*current)
    {
        add_file(*current);
        ++current;
    }

    g_strfreev(selections);
    gtk_widget_hide(file_selection_dialog);

    execute();
}
Exemple #28
0
static BOOL add_directory( HFCI fci, WCHAR *dir )
{
    static const WCHAR wildcardW[] = {'*',0};
    WCHAR *p, *buffer;
    HANDLE handle;
    WIN32_FIND_DATAW data;
    BOOL ret = TRUE;

    if (!(buffer = cab_alloc( (strlenW(dir) + MAX_PATH + 2) * sizeof(WCHAR) ))) return FALSE;
    strcpyW( buffer, dir );
    p = buffer + strlenW( buffer );
    if (p > buffer && p[-1] != '\\') *p++ = '\\';
    strcpyW( p, wildcardW );

    if ((handle = FindFirstFileW( buffer, &data )) != INVALID_HANDLE_VALUE)
    {
        do
        {
            if (data.cFileName[0] == '.' && !data.cFileName[1]) continue;
            if (data.cFileName[0] == '.' && data.cFileName[1] == '.' && !data.cFileName[2]) continue;
            if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) continue;

            strcpyW( p, data.cFileName );
            if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                ret = add_directory( fci, buffer );
            else
                ret = add_file( fci, buffer );
            if (!ret) break;
        } while (FindNextFileW( handle, &data ));
        FindClose( handle );
    }
    cab_free( buffer );
    return TRUE;
}
EditorSectorMenu::EditorSectorMenu() :
  sector(Editor::current()->currentsector),
  sector_name_ptr(sector->get_name_ptr()),
  original_name(*sector_name_ptr),
  size(sector->get_editor_size()),
  new_size(size)
{
  add_label(_("Sector") + " " + sector->get_name());
  add_hl();
  add_textfield(_("Name"), sector_name_ptr);
  add_script(_("Initialization script"), sector->get_init_script_ptr());
  add_color(_("Ambient light"), sector->get_ambient_light_ptr());
  add_numfield(_("Gravity"), &sector->gravity);

  std::vector<std::string> music_formats;
  music_formats.push_back(".ogg");
  music_formats.push_back(".music");
  add_file(_("Music"), &sector->music, music_formats);

  add_hl();
  add_intfield(_("Width"), &(new_size.width));
  add_intfield(_("Height"), &(new_size.height));
  add_entry(MNID_RESIZESECTOR, _("Resize"));

  add_hl();
  add_back(_("OK"));
}
Exemple #30
0
int retrieve_common(struct file_system_info *fsinfo, struct stats *stats, int repo){

#define retrieve_common_finish(value){								\
			unlock(file_mutex[repo][stats->rev]);			\
			gstrdel(file);									\
			gstrdel(revision);								\
            free(temp);                                     \
			return value;									\
		}

	char *file = NULL;
	char *revision = calloc(20, sizeof(char));
	struct stat *temp = single(struct stat);

	debug(2, "Received file %s from repo %d;\n", stats->path, repo);
	lock(file_mutex[repo][stats->rev]);
    node_t *node = add_file(open_files, stats->path, stats->rev);
	if (node->count > 0){
		node->count++;
		retrieve_common_finish(0);
	};
	if (create_tmp_file(stats, node) == -1)
		retrieve_common_finish(-1);
	if (gmstrcpy(&file, fsinfo->repos[repo], "/", stats->internal, 0) == -1)
		retrieve_common_finish(-1);
	sprintf(revision, "%dB", stats->rev);
	if (retrieve_rdiff(revision, file, node->tmp_path) != 0)
		retrieve_common_finish(-1);
	if (stat(node->tmp_path, temp) != 0 || temp->st_size != stats->size)
		retrieve_common_finish(-1);
	node->count = 1;
	retrieve_common_finish(0);

};