changeset 148:db43bc57ecf7

fc-simtool bfsearch: better reporting of EF structure
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 25 Feb 2021 07:00:51 +0000
parents dcbabc398c6a
children 26d7a8815515
files simtool/bfsearch.c
diffstat 1 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/bfsearch.c	Thu Feb 25 06:22:22 2021 +0000
+++ b/simtool/bfsearch.c	Thu Feb 25 07:00:51 2021 +0000
@@ -28,6 +28,39 @@
 	return(0);
 }
 
+static void
+report_ef_struct(outf)
+	FILE *outf;
+{
+	unsigned total_size, record_len;
+
+	fputs("EF, ", outf);
+	total_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
+	switch (sim_resp_data[13]) {
+	case 0x00:
+		fprintf(outf, "transparent, length %u\n", total_size);
+		return;
+	case 0x01:
+		fputs("linear fixed, ", outf);
+		break;
+	case 0x03:
+		fputs("cyclic, ", outf);
+		break;
+	default:
+		fprintf(outf, "struct 0x%02X\n", sim_resp_data[13]);
+		return;
+	}
+	if (sim_resp_data_len < 15) {
+		fprintf(outf, "response struct cut off\n");
+		return;
+	}
+	record_len = sim_resp_data[14];
+	fprintf(outf, "record length %u", record_len);
+	if (record_len && total_size % record_len == 0)
+		fprintf(outf, ", %u records", total_size / record_len);
+	putc('\n', outf);
+}
+
 cmd_bfsearch(argc, argv, outf)
 	char **argv;
 	FILE *outf;
@@ -63,23 +96,23 @@
 		rc = get_response_op();
 		if (rc < 0)
 			return(rc);
+		fprintf(outf, "%04X: ", bfs);
 		if (sim_resp_data_len < 14)
-			fprintf(outf, "%04X: too-short response struct\n", bfs);
+			fprintf(outf, "too-short response struct\n");
 		else {
 			switch (sim_resp_data[6]) {
 			case 0x01:
-				fprintf(outf, "%04X: MF\n", bfs);
+				fprintf(outf, "MF\n");
 				break;
 			case 0x02:
-				fprintf(outf, "%04X: DF\n", bfs);
+				fprintf(outf, "DF\n");
 				break;
 			case 0x04:
-				fprintf(outf, "%04X: EF (struct %02X)\n", bfs,
-					sim_resp_data[13]);
+				report_ef_struct(outf);
 				break;
 			default:
-				fprintf(outf, "%04X: unknown file type %02X\n",
-					bfs, sim_resp_data[6]);
+				fprintf(outf, "unknown file type %02X\n",
+					sim_resp_data[6]);
 			}
 		}
 		rc = elem_select_op(skip_ids[0]);