Esempio n. 1
0
File: output.c Progetto: rhash/RHash
/**
 * Output one-line percents by printing them after file path.
 * If the total file length is unknow (i.e. hashing stdin),
 * then output a rotating stick.
 *
 * @param info pointer to the file-info structure
 * @param offset the number of hashed bytes
 */
static void p_update_percents(struct file_info *info, uint64_t offset)
{
	static const char rot[4] = {'-', '\\', '|', '/'};
	int perc = 0;
	unsigned ticks;

	if (info->size > 0) {
		offset -= info->msg_offset;
		/* use only two digits to display percents: 0%-99% */
		perc = (int)( offset * 99.9 / (uint64_t)info->size );
		if (percents.points == perc) return;
	}

	/* update percents no more than 20 times per second */
	ticks = rhash_get_ticks(); /* clock ticks count in milliseconds */
	if ((unsigned)(ticks - percents.ticks) < 50) return;

	/* output percents or rotated bar */
	if (info->size > 0) {
		rsh_fprintf(rhash_data.log, "%u%%", perc);
		percents.points = perc;
	} else {
		rsh_fprintf(rhash_data.log, "%c", rot[(percents.points++) & 3]);
	}

	rsh_fprintf(rhash_data.log, "\r%-51s ", info->print_path);
	fflush(rhash_data.log);
	percents.ticks  = ticks;
}
Esempio n. 2
0
/**
 * Output one-line percents by printing them after file path.
 * In the case the total file length is unknow (i.e. hashing stdin)
 * output a rotating stick.
 *
 * @param info pointer to the file-info structure
 * @param offset current file offset in bytes
 */
static void p_update_percents(struct file_info *info, uint64_t offset)
{
	static const char rot[4] = {'-', '\\', '|', '/'};
	int perc = 0;
	unsigned ticks;

#ifdef WIN32_USE_CURSOR
	COORD dwCursorPosition;
	if(percents.use_cursor && percents.hOut == NULL) return;
#endif

	if(info->size > 0) {
		/* use only two digits to display percents: 0%-99% */
		perc = (int)( offset * 99.9 / (uint64_t)info->size );
		if(percents.points == perc) return;
	}

	/* update percents no more than 20 times per second */
	ticks = rhash_get_ticks(); /* clock ticks count in milliseconds */
	if((unsigned)(ticks - percents.ticks) < 50) return;

	/* output percents or rotated bar */
	if(info->size > 0) {
		fprintf(rhash_data.log, "%u%%", perc);
		percents.points = perc;
	} else {
		fprintf(rhash_data.log, "%c", rot[(percents.points++) & 3]);
	}

#ifdef WIN32_USE_CURSOR
	if(percents.use_cursor) {
		fflush(rhash_data.log);

		/* rewind the cursor position */
		dwCursorPosition.X = percents.cur_x;
		dwCursorPosition.Y = percents.cur_y;
		SetConsoleCursorPosition(percents.hOut, dwCursorPosition);
	} else
#endif
	{
		fprintf(rhash_data.log, "\r%-51s ", info->print_path);
		fflush(rhash_data.log);
	}
	percents.ticks  = ticks;
}
Esempio n. 3
0
File: output.c Progetto: rhash/RHash
/**
 * Initialize one-line percent mode.
 *
 * @param info pointer to the file-info structure
 * @return non-zero if the output method successfully initialized
 */
static int p_init_percents(struct file_info *info)
{
	(void)info;
	percents.points      = 0;
	percents.same_output = 0;
	percents.use_cursor  = 0;

	fflush(rhash_data.out);
	fflush(rhash_data.log);
	assert(rhash_data.log == stderr);

	/* note: this output differs from print_check_result() by file handle */
	rsh_fprintf(rhash_data.log, "%-51s ", info->print_path);

	percents.same_output = (rhash_data.out == stdout && isatty(0));
	percents.ticks = rhash_get_ticks();
	return 1;
}
Esempio n. 4
0
/**
 * Initialize one-line percent mode.
 *
 * @param info pointer to the file-info structure
 * @return non-zero if the output method successfully initialized
 */
static int p_init_percents(struct file_info *info)
{
#ifdef WIN32_USE_CURSOR
	CONSOLE_SCREEN_BUFFER_INFO csbInfo;
	percents.hOut = NULL;
#endif

	(void)info;
	percents.points      = 0;
	percents.same_output = 0;
	percents.use_cursor  = 0;

	fflush(rhash_data.out);
	fflush(rhash_data.log);
	assert(rhash_data.log == stderr);

	/* note: this output differs from print_check_result() by file handle */
	fprintf(rhash_data.log, "%-51s ", info->print_path);

#ifdef WIN32_USE_CURSOR
	if(percents.use_cursor) {
		/* store cursor coordinates */
		percents.hOut = GetStdHandle(STD_ERROR_HANDLE);
		if(percents.hOut == INVALID_HANDLE_VALUE ||
			!GetConsoleScreenBufferInfo(percents.hOut, &csbInfo)) {
				percents.hOut = NULL;
				return 0;
		} else {
			percents.cur_x = csbInfo.dwCursorPosition.X;
			percents.cur_y = csbInfo.dwCursorPosition.Y;
		}
	}
#endif

	percents.same_output = (rhash_data.out == stdout && isatty(0));
	percents.ticks = rhash_get_ticks();
	return 1;
}