Beispiel #1
0
int
main (int argc, char **argv)
{
  int exclude_options = 0;
  struct exclude *exclude = new_exclude ();

  set_program_name (argv[0]);

  if (argc == 1)
    error (1, 0, "usage: %s file -- words...", argv[0]);

  while (--argc)
    {
      char *opt = *++argv;
      if (opt[0] == '-')
        {
          int neg = 0;
          int flag;
          char *s = opt + 1;

          if (opt[1] == '-' && opt[2] == 0)
            {
              argc--;
              break;
            }
          if (strlen (s) > 3 && memcmp (s, "no-", 3) == 0)
            {
              neg = 1;
              s += 3;
            }
          flag = XARGMATCH (opt, s, exclude_keywords, exclude_flags);
          if (neg)
            exclude_options &= ~flag;
          else
            exclude_options |= flag;
        }
      else if (add_exclude_file (add_exclude, exclude, opt,
                                 exclude_options, '\n') != 0)
        error (1, errno, "error loading %s", opt);
    }

  for (; argc; --argc)
    {
      char *word = *++argv;

      printf ("%s: %d\n", word, excluded_file_name (exclude, word));
    }
  return 0;
}
Beispiel #2
0
void
info_attach_exclist (struct tar_stat_info *dir)
{
  struct excfile *file;
  struct exclist *head = NULL, *tail = NULL, *ent;
  struct vcs_ignore_file *vcsfile;

  if (dir->exclude_list)
    return;
  for (file = excfile_head; file; file = file->next)
    {
      if (faccessat (dir ? dir->fd : chdir_fd, file->name, F_OK, 0) == 0)
	{
	  FILE *fp;
	  struct exclude *ex = NULL;
	  int fd = subfile_open (dir, file->name, O_RDONLY);
	  if (fd == -1)
	    {
	      open_error (file->name);
	      continue;
	    }
	  fp = fdopen (fd, "r");
	  if (!fp)
	    {
	      ERROR ((0, errno, _("%s: fdopen failed"), file->name));
	      close (fd);
	      continue;
	    }

	  if (!ex)
	    ex = new_exclude ();

	  vcsfile = get_vcs_ignore_file (file->name);

	  if (vcsfile->initfn)
	    vcsfile->data = vcsfile->initfn (vcsfile->data);

	  if (add_exclude_fp (vcsfile->addfn, ex, fp,
			      EXCLUDE_WILDCARDS|EXCLUDE_ANCHORED, '\n',
			      vcsfile->data))
	    {
	      int e = errno;
	      FATAL_ERROR ((0, e, "%s", quotearg_colon (file->name)));
	    }
	  fclose (fp);

	  ent = xmalloc (sizeof (*ent));
	  ent->excluded = ex;
	  ent->flags = file->flags == EXCL_DEFAULT
	               ? file->flags : vcsfile->flags;
	  ent->prev = tail;
	  ent->next = NULL;

	  if (tail)
	    tail->next = ent;
	  else
	    head = ent;
	  tail = ent;
	}
    }
  dir->exclude_list = head;
}
Beispiel #3
0
struct exclude *
new_exclude (void)
{
  return xzalloc (sizeof *new_exclude ());
}