comparison simtool/smsp_erase.c @ 40:4c240a37e7c4

fc-simtool smsp-erase-* command family implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 22:05:38 +0000
parents simtool/pberase.c@c34ecbbdf05e
children 10030acba82f
comparison
equal deleted inserted replaced
39:2467b7acad1f 40:4c240a37e7c4
1 /*
2 * This module implements the smsp-erase family of commands.
3 */
4
5 #include <sys/types.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "curfile.h"
11
12 cmd_smsp_erase_all(argc, argv)
13 char **argv;
14 {
15 int rc;
16 unsigned recno;
17 u_char record[255];
18
19 rc = select_ef_smsp();
20 if (rc < 0)
21 return(rc);
22 memset(record, 0xFF, curfile_record_len);
23 for (recno = 1; recno <= curfile_record_count; recno++) {
24 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
25 if (rc < 0)
26 return(rc);
27 }
28 return(0);
29 }
30
31 cmd_smsp_erase_one(argc, argv)
32 char **argv;
33 {
34 int rc;
35 unsigned recno;
36 u_char record[255];
37
38 rc = select_ef_smsp();
39 if (rc < 0)
40 return(rc);
41 recno = strtoul(argv[1], 0, 0);
42 if (recno < 1 || recno > curfile_record_count) {
43 fprintf(stderr, "error: specified record number is invalid\n");
44 return(-1);
45 }
46 memset(record, 0xFF, curfile_record_len);
47 return update_rec_op(recno, 0x04, record, curfile_record_len);
48 }
49
50 cmd_smsp_erase_range(argc, argv)
51 char **argv;
52 {
53 int rc;
54 unsigned recno, startrec, endrec;
55 u_char record[255];
56
57 rc = select_ef_smsp();
58 if (rc < 0)
59 return(rc);
60 startrec = strtoul(argv[1], 0, 0);
61 if (startrec < 1 || startrec > curfile_record_count) {
62 fprintf(stderr,
63 "error: specified starting record number is invalid\n");
64 return(-1);
65 }
66 endrec = strtoul(argv[2], 0, 0);
67 if (endrec < 1 || endrec > curfile_record_count) {
68 fprintf(stderr,
69 "error: specified final record number is invalid\n");
70 return(-1);
71 }
72 if (startrec > endrec) {
73 fprintf(stderr, "error: reverse record range specified\n");
74 return(-1);
75 }
76 memset(record, 0xFF, curfile_record_len);
77 for (recno = startrec; recno <= endrec; recno++) {
78 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
79 if (rc < 0)
80 return(rc);
81 }
82 return(0);
83 }