Skip to content

Commit

Permalink
Errors are now printed to stderr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald de Man committed Mar 15, 2015
1 parent 80e475c commit 5df99c1
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Expand Up @@ -25,10 +25,10 @@ CFLAGS = -g -O3 -march=corei7 -msse4.2 -pipe -D_GNU_SOURCE -Wall -std=c99 -Wstri

export FLAGS CC CFLAGS

all: rtbgen rtbgenp rtbver rtbverp tbcheck

rtbgen rtbgenp rtbver rtbverp tbcheck clean:
@$(MAKE) -f Makefile.regular $@

all: rtbgen rtbgenp rtbver rtbverp tbcheck

.PHONY: rtbgen rtbgenp rtbver rtbverp tbcheck clean

10 changes: 5 additions & 5 deletions src/checksum.c
Expand Up @@ -59,7 +59,7 @@ static void calc_checksum(char *name)
checksum_found = 1;
} else {
if (size & 0x3f) {
printf("Size of %s is not a multiple of 64.\n", name);
fprintf(stderr, "Size of %s is not a multiple of 64.\n", name);
exit(1);
}
checksum_found = 0;
Expand All @@ -84,7 +84,7 @@ void print_checksum(char *name, char *sum)
if ((size & 0x3f) == 0x10) {
memcpy(checksum1, data + (size & ~0x3fULL), 16);
} else {
printf("No checksum found.\n");
fprintf(stderr, "No checksum found.\n");
exit(1);
}
unmap_file(data, size);
Expand All @@ -105,12 +105,12 @@ void add_checksum(char *name)
{
calc_checksum(name);
if (checksum_found) {
printf("%s checksum already present.\n", checksum_match ? "Matching" : "Non-matching");
fprintf(stderr, "%s checksum already present.\n", checksum_match ? "Matching" : "Non-matching");
exit(1);
}
FILE *F = fopen(name, "ab");
if (!F) {
printf("Could not open %s for appending.\n", name);
fprintf(stderr, "Could not open %s for appending.\n", name);
exit(1);
}
fwrite(checksum2, 16, 1, F);
Expand All @@ -122,7 +122,7 @@ void verify_checksum(char *name)
printf("%s: ", name);
calc_checksum(name);
if (!checksum_found) {
printf("No checksum present.\n");
fprintf(stderr, "No checksum present.\n");
exit(1);
}
if (!checksum_match)
Expand Down
10 changes: 5 additions & 5 deletions src/compress.c
Expand Up @@ -993,7 +993,7 @@ struct HuffCode *construct_pairs_dtz(unsigned char *restrict data, long64 size,
pairfreq[i][j] = 0;

if (num_syms > 255) {
printf("error\n");
fprintf(stderr, "error\n");
exit(1);
}
for (t = 0; t < numthreads; t++)
Expand Down Expand Up @@ -1107,7 +1107,7 @@ struct HuffCode *construct_pairs_dtz(unsigned char *restrict data, long64 size,
}

if (i != num) {
printf("Ran short of symbols.\n");
printf("Ran short of symbols.\n"); // not an error
num = i;
num_ctrl--;
}
Expand Down Expand Up @@ -1738,7 +1738,7 @@ void compress_tb(struct tb_handle *F, ubyte *restrict data,
strcat(name, F->wdl ? WDLSUFFIX : DTZSUFFIX);
strcat(name, ext);
if (!(G = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

Expand All @@ -1760,7 +1760,7 @@ void merge_tb(struct tb_handle *F)
strcpy(name, F->name);
strcat(name, F->wdl ? WDLSUFFIX : DTZSUFFIX);
if (!(G = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

Expand All @@ -1771,7 +1771,7 @@ void merge_tb(struct tb_handle *F)
strcat(name, F->wdl ? WDLSUFFIX : DTZSUFFIX);
strcat(name, ext);
if (!(F->H[i] = fopen(name, "rb"))) {
printf("Could not open %s for reading.\n", name);
fprintf(stderr, "Could not open %s for reading.\n", name);
exit(1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/decompress.c
Expand Up @@ -273,7 +273,7 @@ void decomp_init_table(struct tb_handle *H)
magic = 0;
fread(&magic, 1, 4, F);
if (magic != (H->wdl ? WDL_MAGIC : DTZ_MAGIC)) {
printf("Corrupted table.\n");
fprintf(stderr, "Corrupted table.\n");
exit(1);
}

Expand Down Expand Up @@ -468,7 +468,7 @@ static void decompress_worker(struct thread_data *thread)
while (idx + size > idx2) {
if (*((uint32 *)(d->indextable + 6 * mainidx)) != block
|| *((ushort *)(d->indextable + 6 * mainidx + 4)) != idx2 - idx) {
printf("ERROR in main index!!\n");
fprintf(stderr, "ERROR in main index!!\n");
exit(1);
}
idx2 += 1ULL << d->idxbits;
Expand Down Expand Up @@ -536,7 +536,7 @@ struct tb_handle *open_tb(char *tablename, int wdl)
strcat(name, tablename);
strcat(name, wdl ? WDLSUFFIX : DTZSUFFIX);
if (!(H->F = fopen(name, "rb"))) {
printf("Could not open %s for reading.\n", name);
fprintf(stderr, "Could not open %s for reading.\n", name);
exit(1);
}
H->data = (ubyte *)map_file(name, 1, &(H->data_size));
Expand Down
4 changes: 2 additions & 2 deletions src/permute.c
Expand Up @@ -1000,7 +1000,7 @@ ubyte *init_permute_piece(int *pcs, int *pt, ubyte *tb_table)

generate_test_list(tb_size, entry_piece.num);
if (!tb_table && !(tb_table = malloc(tb_size + 1))) {
printf("Out of memory.\n");
fprintf(stderr, "Out of memory.\n");
exit(1);
}

Expand Down Expand Up @@ -1193,7 +1193,7 @@ ubyte *init_permute_file(int *pcs, int file, ubyte *tb_table)
generate_test_list(tb_size, entry_pawn.num);

if (!tb_table && !(tb_table = malloc(tb_size + 1))) {
printf("Out of memory.\n");
fprintf(stderr, "Out of memory.\n");
exit(1);
}

Expand Down
10 changes: 5 additions & 5 deletions src/probe.c
Expand Up @@ -116,7 +116,7 @@ void add_to_hash(struct TBEntry *ptr, long64 key)
while (i < HSHMAX && TB_hash[hshidx][i].ptr)
i++;
if (i == HSHMAX) {
printf("HSHMAX too low!\n");
fprintf(stderr, "HSHMAX too low!\n");
exit(1);
} else {
TB_hash[hshidx][i].key = key;
Expand Down Expand Up @@ -180,13 +180,13 @@ static void init_tb(char *str)
}
if (pcs[WPAWN] + pcs[BPAWN] == 0) {
if (TBnum_piece == TBMAX_PIECE) {
printf("TBMAX_PIECE limit too low!\n");
fprintf(stderr, "TBMAX_PIECE limit too low!\n");
exit(1);
}
entry = (struct TBEntry *)&TB_piece[TBnum_piece++];
} else {
if (TBnum_pawn == TBMAX_PAWN) {
printf("TBMAX_PAWN limit too low!\n");
fprintf(stderr, "TBMAX_PAWN limit too low!\n");
exit(1);
}
entry = (struct TBEntry *)&TB_pawn[TBnum_pawn++];
Expand Down Expand Up @@ -2126,7 +2126,7 @@ static void init_table(struct TBEntry *entry, long64 key)
entry->data = map_file(file, 1, &dummy);
ubyte *data = (ubyte *)entry->data;
if (((uint32 *)data)[0] != WDL_MAGIC) {
printf("Corrupted table.\n");
fprintf(stderr, "Corrupted table.\n");
exit(1);
}

Expand Down Expand Up @@ -3030,7 +3030,7 @@ static __attribute__ ((noinline)) void probe_failed(int *pieces)
if (pieces[j] == BKING - i)
str[k++] = pchr[i];
str[k] = 0;
printf("Missing table: %s\n", str);
fprintf(stderr, "Missing table: %s\n", str);
exit(1);
}

28 changes: 15 additions & 13 deletions src/reduce.c
Expand Up @@ -20,16 +20,16 @@ void save_table(ubyte *table, char color)
if (!lz4_buf) {
lz4_buf = malloc(4 + LZ4_compressBound(COPYSIZE));
if (!lz4_buf) {
printf("Out of memory.\n");
exit(0);
fprintf(stderr, "Out of memory.\n");
exit(1);
}
}

sprintf(name, "%s.%c.%d", tablename, color, num_saves);

if (!(F = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

for (i = 0; i < 256; i++)
Expand Down Expand Up @@ -99,8 +99,8 @@ void reconstruct_table_pass(ubyte *table, char color, int k, ubyte *v)
sprintf(name, "%s.%c.%d", tablename, color, k);

if (!(F = fopen(name, "rb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand Down Expand Up @@ -185,8 +185,10 @@ void verify_stats(ubyte *table, long64 *tot_stats, struct dtz_map *map)
verify_ok = 0;
}

if (!verify_ok)
if (!verify_ok) {
fprintf(stderr, "Verification of reconstructed table failed.\n");
exit(1);
}
}

void reconstruct_table(ubyte *table, char color, struct dtz_map *map)
Expand Down Expand Up @@ -413,16 +415,16 @@ void store_table(ubyte *table, char color)
if (!lz4_buf) {
lz4_buf = malloc(4 + LZ4_compressBound(COPYSIZE));
if (!lz4_buf) {
printf("Out of memory.\n");
exit(0);
fprintf(stderr, "Out of memory.\n");
exit(1);
}
}

sprintf(name, "%s.%c", tablename, color);

if (!(F = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand All @@ -448,8 +450,8 @@ void load_table(ubyte *table, char color)
sprintf(name, "%s.%c", tablename, color);

if (!(F = fopen(name, "rb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand Down
28 changes: 15 additions & 13 deletions src/reducep.c
Expand Up @@ -29,16 +29,16 @@ void save_table(ubyte *table, char color, int local, long64 begin, long64 size)
if (!lz4_buf) {
lz4_buf = malloc(8 + LZ4_compressBound(COPYSIZE));
if (!lz4_buf) {
printf("Out of memory.\n");
exit(0);
fprintf(stderr, "Out of memory.\n");
exit(1);
}
}

if (local == num_saves) {
sprintf(name, "%s.%c.%d", tablename, color, num_saves);
if (!(F = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}
tmp_table[num_saves][color == 'w' ? 0 : 1] = F;
} else {
Expand Down Expand Up @@ -113,8 +113,8 @@ void reconstruct_table_pass(ubyte *table, char color, int k, ubyte *v)
sprintf(name, "%s.%c.%d", tablename, color, k);

if (!(F = fopen(name, "rb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand Down Expand Up @@ -184,8 +184,10 @@ void verify_stats(ubyte *table, long64 *tot_stats, struct dtz_map *map)
verify_ok = 0;
}

if (!verify_ok)
if (!verify_ok) {
fprintf(stderr, "Verification of reconstructed table failed.\n");
exit(1);
}
}

void reconstruct_table(ubyte *table, char color, struct dtz_map *map)
Expand Down Expand Up @@ -441,16 +443,16 @@ void store_table(ubyte *table, char color)
if (!lz4_buf) {
lz4_buf = malloc(8 + LZ4_compressBound(COPYSIZE));
if (!lz4_buf) {
printf("Out of memory.\n");
exit(0);
fprintf(stderr, "Out of memory.\n");
exit(1);
}
}

sprintf(name, "%s.%c", tablename, color);

if (!(F = fopen(name, "wb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand All @@ -476,8 +478,8 @@ void load_table(ubyte *table, char color)
sprintf(name, "%s.%c", tablename, color);

if (!(F = fopen(name, "rb"))) {
printf("Could not open %s for writing.\n", name);
exit(-1);
fprintf(stderr, "Could not open %s for writing.\n", name);
exit(1);
}

ubyte *ptr = table;
Expand Down
6 changes: 3 additions & 3 deletions src/rtbver.c
Expand Up @@ -823,7 +823,7 @@ void load_wdl(struct thread_data *thread)
if (unlikely(v2 > 4)) table[idx_p] = WDL_ERROR;
else table[idx_p] = wdl_matrix[v2][v1_p];
if(unlikely(table[idx_p]==WDL_ERROR))
printf("WDL_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx_p, v2, v1_p);
error("WDL_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx_p, v2, v1_p);
v1_p = v1;
idx_p = idx;
idx2_p = idx2;
Expand All @@ -833,7 +833,7 @@ printf("WDL_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx_p, v2, v1_p);
if (unlikely(v2 > 4)) table[idx_p] = WDL_ERROR;
else table[idx_p] = wdl_matrix[v2][v1_p];
if(unlikely(table[idx_p]==WDL_ERROR))
printf("WDL_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx_p, v2, v1_p);
error("WDL_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx_p, v2, v1_p);
}
#else
void load_wdl(struct thread_data *thread)
Expand Down Expand Up @@ -1094,7 +1094,7 @@ void wdl_load_wdl(struct thread_data *thread)
if (unlikely(v2 > 4)) table[idx] = W_ERROR;
else table[idx] = w_wdl_matrix[v2][v1];
if(unlikely(table[idx]==W_ERROR))
printf("W_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx, v2, v1);
error("W_ERROR: idx = %"PRIu64", v2 = %d, v1 = %d\n", idx, v2, v1);
}
}

2 changes: 1 addition & 1 deletion src/stats.c
Expand Up @@ -81,7 +81,7 @@ static long64 find_val(ubyte *table, ubyte v)
run_threaded(find_loop, work_g, 0);

if (found_idx == 0xffffffffffffffffULL)
printf("find_val: not found!\n");
fprintf(stderr, "find_val: not found!\n");

return found_idx;
}
Expand Down
2 changes: 1 addition & 1 deletion src/statsp.c
Expand Up @@ -83,7 +83,7 @@ long64 find_val(ubyte *table, ubyte v, long64 *work)
run_threaded(find_loop, work, 0);

if (found_idx == 0xffffffffffffffffULL)
printf("find_val: not found!\n");
fprintf(stderr, "find_val: not found!\n");

return found_idx;
}
Expand Down

0 comments on commit 5df99c1

Please sign in to comment.