Convert printf_errf in common.h
And remove some unused functions. And improve some error messages. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
833eb966f1
commit
2af0b48c7b
69
src/common.h
69
src/common.h
|
@ -1095,7 +1095,7 @@ parse_vsync(session_t *ps, const char *str) {
|
|||
return true;
|
||||
}
|
||||
|
||||
printf_errf("(\"%s\"): Invalid vsync argument.", str);
|
||||
log_error("Invalid vsync argument: %s", str);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1119,7 +1119,7 @@ parse_backend(session_t *ps, const char *str) {
|
|||
ps->o.backend = BKEND_XR_GLX_HYBRID;
|
||||
return true;
|
||||
}
|
||||
printf_errf("(\"%s\"): Invalid backend argument.", str);
|
||||
log_error("Invalid backend argument: %s", str);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1154,18 +1154,18 @@ parse_glx_swap_method(session_t *ps, const char *str) {
|
|||
char *pc = NULL;
|
||||
int age = strtol(str, &pc, 0);
|
||||
if (!pc || str == pc) {
|
||||
printf_errf("(\"%s\"): Invalid number.", str);
|
||||
log_error("glx-swap-method is an invalid number: %s", str);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (; *pc; ++pc)
|
||||
if (!isspace(*pc)) {
|
||||
printf_errf("(\"%s\"): Trailing characters.", str);
|
||||
log_error("Trailing characters in glx-swap-method option: %s", str);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (age > CGLX_MAX_BUFFER_AGE + 1 || age < -1) {
|
||||
printf_errf("(\"%s\"): Number too large / too small.", str);
|
||||
log_error("Number for glx-swap-method is too large / too small: %s", str);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1495,7 +1495,7 @@ xr_sync(session_t *ps, Drawable d, XSyncFence *pfence) {
|
|||
assert(!XSyncQueryFence(ps->dpy, *pfence, &triggered) || triggered);
|
||||
}
|
||||
else {
|
||||
printf_errf("(%#010lx): Failed to create X Sync fence.", d);
|
||||
log_error("Failed to create X Sync fence for %#010lx", d);
|
||||
}
|
||||
free_fence(ps, &tmp_fence);
|
||||
if (*pfence)
|
||||
|
@ -1561,63 +1561,6 @@ opts_set_no_fading_openclose(session_t *ps, bool newval);
|
|||
//!@}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Dump the given data to a file.
|
||||
*/
|
||||
static inline bool
|
||||
write_binary_data(const char *path, const unsigned char *data, int length) {
|
||||
if (!data)
|
||||
return false;
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) {
|
||||
printf_errf("(\"%s\"): Failed to open file for writing.", path);
|
||||
return false;
|
||||
}
|
||||
int wrote_len = fwrite(data, sizeof(unsigned char), length, f);
|
||||
fclose(f);
|
||||
if (wrote_len != length) {
|
||||
printf_errf("(\"%s\"): Failed to write all blocks: %d / %d", path,
|
||||
wrote_len, length);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump raw bytes in HEX format.
|
||||
*
|
||||
* @param data pointer to raw data
|
||||
* @param len length of data
|
||||
*/
|
||||
static inline void
|
||||
hexdump(const char *data, int len) {
|
||||
static const int BYTE_PER_LN = 16;
|
||||
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
// Print header
|
||||
printf("%10s:", "Offset");
|
||||
for (int i = 0; i < BYTE_PER_LN; ++i)
|
||||
printf(" %2d", i);
|
||||
putchar('\n');
|
||||
|
||||
// Dump content
|
||||
for (int offset = 0; offset < len; ++offset) {
|
||||
if (!(offset % BYTE_PER_LN))
|
||||
printf("0x%08x:", offset);
|
||||
|
||||
printf(" %02hhx", data[offset]);
|
||||
|
||||
if ((BYTE_PER_LN - 1) == offset % BYTE_PER_LN)
|
||||
putchar('\n');
|
||||
}
|
||||
if (len % BYTE_PER_LN)
|
||||
putchar('\n');
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a <code>bool</code> array of all wintypes to true.
|
||||
*/
|
||||
|
|
|
@ -4046,7 +4046,28 @@ session_destroy(session_t *ps) {
|
|||
log_deinit_tls();
|
||||
}
|
||||
|
||||
/*
|
||||
#if 0
|
||||
/**
|
||||
* @brief Dump the given data to a file.
|
||||
*/
|
||||
static inline bool
|
||||
write_binary_data(const char *path, const unsigned char *data, int length) {
|
||||
if (!data)
|
||||
return false;
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) {
|
||||
log_error("Failed to open \"%s\" for writing.", path);
|
||||
return false;
|
||||
}
|
||||
int wrote_len = fwrite(data, sizeof(unsigned char), length, f);
|
||||
fclose(f);
|
||||
if (wrote_len != length) {
|
||||
printf_errf("(\"%s\"): Failed to write all blocks: %d / %d", path,
|
||||
wrote_len, length);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static inline void
|
||||
dump_img(session_t *ps) {
|
||||
int len = 0;
|
||||
|
@ -4054,7 +4075,7 @@ dump_img(session_t *ps) {
|
|||
write_binary_data("/tmp/dump.raw", d, len);
|
||||
free(d);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Do the actual work.
|
||||
|
|
Loading…
Reference in New Issue