annotate simtool/smsp_erase.c @ 229:ed8cb3c0d312 default tip

new README, indicating repository move
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 18:26:13 +0000
parents 10030acba82f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
2 * This module implements the smsp-erase family of commands.
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <string.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <strings.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "curfile.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
12 cmd_smsp_erase_all(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned recno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char record[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
19 rc = select_ef_smsp();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 memset(record, 0xFF, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 for (recno = 1; recno <= curfile_record_count; recno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
31 cmd_smsp_erase_one(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 unsigned recno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 u_char record[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
38 rc = select_ef_smsp();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(rc);
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
41 recno = strtoul(argv[1], 0, 0);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (recno < 1 || recno > curfile_record_count) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr, "error: specified record number is invalid\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 memset(record, 0xFF, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return update_rec_op(recno, 0x04, record, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
50 cmd_smsp_erase_range(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 unsigned recno, startrec, endrec;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 u_char record[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
57 rc = select_ef_smsp();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(rc);
40
4c240a37e7c4 fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 14
diff changeset
60 startrec = strtoul(argv[1], 0, 0);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (startrec < 1 || startrec > curfile_record_count) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 "error: specified starting record number is invalid\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
57
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
66 if (!strcmp(argv[2], "end"))
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
67 endrec = curfile_record_count;
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
68 else {
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
69 endrec = strtoul(argv[2], 0, 0);
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
70 if (endrec < 1 || endrec > curfile_record_count) {
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
71 fprintf(stderr,
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 "error: specified final record number is invalid\n");
57
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
73 return(-1);
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
74 }
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
75 if (startrec > endrec) {
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
76 fprintf(stderr,
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
77 "error: reverse record range specified\n");
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
78 return(-1);
10030acba82f fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
79 }
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 memset(record, 0xFF, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 for (recno = startrec; recno <= endrec; recno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }