int main(){
	auto t0 = clock();
	FileComparer cmp(L"g:/Backup/000/version1.zip", std::shared_ptr<RsyncableFile>(new RsyncableFile(L"g:/Backup/000/version0.zip")));
	auto t1 = clock();
	cmp.process();
	auto t2 = clock();
	std::cout << "Building rsync table: " << double(t1 - t0) / CLOCKS_PER_SEC << " s.\n"
		"Comparing files: " << double(t2 - t1) / CLOCKS_PER_SEC << " s.\n";

	std::cout
		<< "Old SHA1: " << PrintableBuffer(cmp.get_old_digest(), 20) << "\n"
		"New SHA1: " << PrintableBuffer(cmp.get_new_digest(), 20) << std::endl;
	return 0;
}
Exemple #2
0
/* main program loop */
void mux_loop(int pf) {
  fd_set  ready;        /* used for select */
  int     i = 0;        /* used in the multiplex loop */
  int     done = 0;
  char    buf[BUFSIZE];
  struct timeval tv;
  
  tv.tv_sec = SCRIPT_DELAY;
  tv.tv_usec = 0;

  if (script) {
    script_init(scr_name);
  }

  do { /* forever */
    FD_ZERO(&ready);
    FD_SET(STDIN_FILENO, &ready);
    FD_SET(pf, &ready);

    if (script) {
      if (!select(pf+1, &ready, NULL, NULL, &tv)) {
	i = script_process(S_TIMEOUT, buf, BUFSIZE);
	if (i > 0) {
	   cook_buf(pf, buf, i);
	}
	/* restart timer */
	tv.tv_sec = SCRIPT_DELAY;
	tv.tv_usec = 0;
      }
    } /* if */
    else {
      select(pf+1, &ready, NULL, NULL, NULL);
    }

    if (FD_ISSET(pf, &ready)) {
      /* pf has characters for us */
      i = read(pf, buf, BUFSIZE);
      if (i > 0) {
	if (options & OPTION_LOG_FILTER) {
	  /* only printable characters */
	  size_t size = 0;
	  char *printable = PrintableBuffer(buf,i,&size);
	  DEBUG_MSG("received printable buffer = %s",printable);
	  if (flog != NULL) {
	    printable[size] = '\n';
	    printable[size+1] = '\0';
	    const size_t written = fwrite(printable, 1, size, flog);
	    if (written != size) {
	      const int error = errno;
	      DEBUG_MSG("error writing log file, only %u characters written, errno = %d",written,error);
	    }
	  }	  
	} else {
	  /* raw memory dump */
	  DEBUG_DUMP_MEMORY(buf,i);
	  if (flog != 0) {
	    fwrite(buf, 1, i, flog);
	  }
	}
	write(STDOUT_FILENO, buf, i);		
	if (script) {
	  i = script_process(S_DCE, buf, i);
	  if (i > 0) {
	     cook_buf(pf, buf, i);
	  }
	}
      } else {
	done = 1;
      }
    } /* if */

    if (FD_ISSET(STDIN_FILENO, &ready)) {
      /* standard input has characters for us */
      i = read(STDIN_FILENO, buf, BUFSIZE);
      if (i > 0) {
	 cook_buf(pf, buf, i);
      } else {
	 done = 1;
      }
    } /* if */
  } while (!done); /* do */
}