X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Fdissect-sysfile.c;h=d5994b3b845f484aa6f6d6e1371488056137304e;hb=51c3424bf88d0fa110683fbcdd208d0fa5c98179;hp=3d26a0fb0275c448faa728d529c8ed72022dbd92;hpb=78b2280e4d75fc07ce0f17c3607c0707f7ccb819;p=pspp diff --git a/tests/dissect-sysfile.c b/tests/dissect-sysfile.c index 3d26a0fb02..d5994b3b84 100644 --- a/tests/dissect-sysfile.c +++ b/tests/dissect-sysfile.c @@ -102,6 +102,7 @@ static void sys_error (struct sfm_reader *, const char *, ...) NO_RETURN; static void read_bytes (struct sfm_reader *, void *, size_t); +static bool try_read_bytes (struct sfm_reader *, void *, size_t); static int read_int (struct sfm_reader *); static int64_t read_int64 (struct sfm_reader *); static double read_float (struct sfm_reader *); @@ -126,7 +127,7 @@ main (int argc, char *argv[]) r.file_name = argv[i]; r.file = fopen (r.file_name, "rb"); if (r.file == NULL) - error (EXIT_FAILURE, errno, "error opening \"%s\"", r.file_name); + error (EXIT_FAILURE, errno, "error opening `%s'", r.file_name); r.n_variable_records = 0; r.n_variables = 0; r.n_var_widths = 0; @@ -688,7 +689,7 @@ read_mrsets (struct sfm_reader *r, size_t size, size_t count) if (!text_match (text, ' ')) { - sys_warn (r, _("Missing space following 'E' at offset %zu " + sys_warn (r, _("Missing space following `E' at offset %zu " "in MRSETS record"), text_pos (text)); break; } @@ -697,14 +698,14 @@ read_mrsets (struct sfm_reader *r, size_t size, size_t count) if (!strcmp (number, "11")) label_from_var_label = true; else if (strcmp (number, "1")) - sys_warn (r, _("Unexpected label source value \"%s\" " - "following 'E' at offset %zu in MRSETS record"), + sys_warn (r, _("Unexpected label source value `%s' " + "following `E' at offset %zu in MRSETS record"), number, text_pos (text)); } else { - sys_warn (r, "missing 'C', 'D', or 'E' at offset %zu " + sys_warn (r, "missing `C', `D', or `E' at offset %zu " "in mrsets record", text_pos (text)); break; } @@ -1079,12 +1080,13 @@ read_compressed_data (struct sfm_reader *r) printf ("\n%08llx: compressed data:\n", (long long int) ftello (r->file)); opcode_idx = N_OPCODES; + opcode_ofs = 0; case_num = 0; for (case_num = 0; ; case_num++) { printf ("%08llx: case %d's uncompressible data begins\n", (long long int) ftello (r->file), case_num); - for (i = 0; i < r->n_var_widths; i++) + for (i = 0; i < r->n_var_widths; ) { int width = r->var_widths[i]; char raw_value[8]; @@ -1093,7 +1095,13 @@ read_compressed_data (struct sfm_reader *r) if (opcode_idx >= N_OPCODES) { opcode_ofs = ftello (r->file); - read_bytes (r, opcodes, 8); + if (i == 0) + { + if (!try_read_bytes (r, opcodes, 8)) + return; + } + else + read_bytes (r, opcodes, 8); opcode_idx = 0; } opcode = opcodes[opcode_idx]; @@ -1107,6 +1115,11 @@ read_compressed_data (struct sfm_reader *r) if (width != 0) printf (", but this is a string variable (width=%d)", width); printf ("\n"); + i++; + break; + + case 0: + printf ("ignored padding\n"); break; case 252: @@ -1118,6 +1131,7 @@ read_compressed_data (struct sfm_reader *r) printf ("uncompressible data: "); print_untyped_value (r, raw_value); printf ("\n"); + i++; break; case 254: @@ -1125,14 +1139,15 @@ read_compressed_data (struct sfm_reader *r) if (width == 0) printf (", but this is a numeric variable"); printf ("\n"); + i++; break; case 255: printf ("SYSMIS"); if (width != 0) printf (", but this is a string variable (width=%d)", width); - printf ("\n"); + i++; break; } @@ -1353,6 +1368,16 @@ read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) read_bytes_internal (r, false, buf, byte_cnt); } +/* Reads BYTE_CNT bytes into BUF. + Returns true if exactly BYTE_CNT bytes are successfully read. + Returns false if an immediate end-of-file is encountered. + Aborts if an I/O error or a partial read occurs. */ +static bool +try_read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +{ + return read_bytes_internal (r, true, buf, byte_cnt); +} + /* Reads a 32-bit signed integer from R and returns its value in host format. */ static int