Ejemplo n.º 1
0
Archivo: hha.c Proyecto: maksverver/hha
int main(int argc, char *argv[])
{
    assert(sizeof(Header)     == 16);
    assert(sizeof(IndexEntry) == 24);

    parse_args(argc, argv);

    switch (arg_mode)
    {
    case LIST:
        open_archive(arg_archive);
        process_header();
        list_entries();
        close_archive();
        break;

    case EXTRACT:
        open_archive(arg_archive);
        process_header();
        extract_entries();
        close_archive();
        break;

    case CREATE:
        create_archive(arg_archive, (const char**)arg_files_begin,
                                    (const char**)arg_files_end, arg_com);
        break;
    }

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
    int i;
    node *head = NULL;

    if (!strcmp(argv[2], "-c")) {
        get_statistics(statistics, argv[1]);
//        TODO
//        statistics = get_statistics(argv[1])

//        build tree
        for (i = 0; i < 255; i++) { order[i] = i; };
        qsort(order, 256, sizeof (int), comparator);

        while (statistics[order[size]] && size < 256) { size++; }

        printf("size %d\n", size);
        if (size == 0) { return 0; };
        
        for (i = 0; i < size; i++) {
            node *n = malloc(sizeof(node));
            n -> item = order[i];
            n -> stat = statistics[order[i]];
            n -> left = NULL;
            n -> right = NULL;
            n -> next = head;
            head = n;
        };
           
        while (head -> next) { head = combine(head, head -> next); }
        
//        build map
        build_map(head, 0, 0);
        
        create_archive(argv[3]);
        
        for (i = 0; i < 256; i++)
        {
            if (map[i]){
                printf("%d - %d - %d\n", i, map[i], statistics[i]);
            };
        }
        return (EXIT_SUCCESS);
    };


    if (!strcmp(argv[2], "-x")) {
        head = extract_tree(argv[1]);
        
        printf("extracted\n");
        return (EXIT_SUCCESS);
    };
}
Ejemplo n.º 3
0
void Path::compress(const std::string& filepath,
                    const std::string& compressedfilepath)
{
    namespace fs = boost::filesystem;
    namespace fe = boost::system;

    fs::path path(filepath);

    if (fs::exists(path)) {
        create_archive(filepath.c_str(), compressedfilepath.c_str());
    }

}
Ejemplo n.º 4
0
void
open_archive (struct locarhandle *ah, bool readonly)
{
  struct stat64 st;
  struct stat64 st2;
  int fd;
  struct locarhead head;
  int retry = 0;
  size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
  char archivefname[prefix_len + sizeof (ARCHIVE_NAME)];

  if (output_prefix)
    memcpy (archivefname, output_prefix, prefix_len);
  strcpy (archivefname + prefix_len, ARCHIVE_NAME);

  while (1)
    {
      /* Open the archive.  We must have exclusive write access.  */
      fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
      if (fd == -1)
	{
	  /* Maybe the file does not yet exist.  */
	  if (errno == ENOENT)
	    {
	      if (readonly)
		{
		  static const struct locarhead nullhead =
		    {
		      .namehash_used = 0,
		      .namehash_offset = 0,
		      .namehash_size = 0
		    };

		  ah->addr = (void *) &nullhead;
		  ah->fd = -1;
		}
	      else
		create_archive (archivefname, ah);

	      return;
	    }
	  else
	    error (EXIT_FAILURE, errno, _("cannot open locale archive \"%s\""),
		   archivefname);
	}

      if (fstat64 (fd, &st) < 0)
	error (EXIT_FAILURE, errno, _("cannot stat locale archive \"%s\""),
	       archivefname);

      if (!readonly && lockf64 (fd, F_LOCK, sizeof (struct locarhead)) == -1)
	{
	  close (fd);

	  if (retry++ < max_locarchive_open_retry)
	    {
	      struct timespec req;

	      /* Wait for a bit.  */
	      req.tv_sec = 0;
	      req.tv_nsec = 1000000 * (random () % 500 + 1);
	      (void) nanosleep (&req, NULL);

	      continue;
	    }

	  error (EXIT_FAILURE, errno, _("cannot lock locale archive \"%s\""),
		 archivefname);
	}

      /* One more check.  Maybe another process replaced the archive file
	 with a new, larger one since we opened the file.  */
      if (stat64 (archivefname, &st2) == -1
	  || st.st_dev != st2.st_dev
	  || st.st_ino != st2.st_ino)
	{
	  (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
	  close (fd);
	  continue;
	}

      /* Leave the loop.  */
      break;
    }
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
	int ch;
	int ret = 0;
	bool archived = false;
	bool syndicated = false;
	bool make_news = false;
	bool news_is_home = false;

	x.program = argv[0];
	x.base_url = "";
	x.parser = "cat";

	while ((ch = getopt(argc, argv, "ab:fhnp:t:u")) != -1) {
		switch (ch) {
			case 'a':
				archived = true;
				break;
			case 'b':
				x.base_url = optarg;
				break;
			case 'f':
				syndicated = true;
				break;
			case 'h':
				make_news = true;
				news_is_home = true;
				break;
			case 'n':
				make_news = true;
				news_is_home = false;
				break;
			case 'p':
				x.parser = optarg;
				break;
			case 't':
				x.feed_title = optarg;
				break;
			case 'u':
				x.hide_user = true;
				break;
		}
	}
	argc -= optind;
	argv += optind;

	if (mkdir("./build", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
		if (errno != EEXIST) {
			perror("mkdir");
			goto error;
		}
	}

	if (ftw("./src", traverse, 8) == -1) {
		perror("ftw");
		goto error;
	}

	if (archived) {
		puts("Building archive...");
		if (create_archive() == -1) goto error;
	}

	qsort(x.pages, x.page_count, sizeof(struct page),
	    compare_page_dates);

	if (syndicated) {
		puts("Building feed...");
		if (x.feed_title == NULL) {
			fprintf(stderr,
			    "%s: no feed title specified, use -t title\n",
			    x.program);
			goto error;
		}
		if (create_feed() == -1) goto error;
	}

	if (make_news) {
		puts("Building news...");
		if (create_news(news_is_home ?
		    "./build/index.html" : "./build/news.html") == -1) {
			goto error;
		}
	}
end:
	for (size_t i = 0; i < x.page_count; ++i) {
		free_page(&x.pages[i]);
	}
	free(x.pages);
	return ret;
error:
	ret = 1;
	goto end;
}