comparison simtool/pberase.c @ 1:2071b28cd0c7

simtool: first refactored version
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:04:28 +0000
parents
children c34ecbbdf05e
comparison
equal deleted inserted replaced
0:f7145c77b7fb 1:2071b28cd0c7
1 /*
2 * This module implements the pb-erase command.
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 "simresp.h"
11 #include "curfile.h"
12
13 cmd_pb_erase(argc, argv)
14 char **argv;
15 {
16 int rc;
17 unsigned recno;
18 u_char record[255];
19
20 rc = phonebook_op_common(argv[1]);
21 if (rc < 0)
22 return(rc);
23 memset(record, 0xFF, curfile_record_len);
24 for (recno = 1; recno <= curfile_record_count; recno++) {
25 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
26 if (rc < 0)
27 return(rc);
28 }
29 return(0);
30 }
31
32 cmd_pb_erase_one(argc, argv)
33 char **argv;
34 {
35 int rc;
36 unsigned recno;
37 u_char record[255];
38
39 rc = phonebook_op_common(argv[1]);
40 if (rc < 0)
41 return(rc);
42 recno = strtoul(argv[2], 0, 0);
43 if (recno < 1 || recno > curfile_record_count) {
44 fprintf(stderr, "error: specified record number is invalid\n");
45 return(-1);
46 }
47 memset(record, 0xFF, curfile_record_len);
48 return update_rec_op(recno, 0x04, record, curfile_record_len);
49 }
50
51 cmd_pb_erase_range(argc, argv)
52 char **argv;
53 {
54 int rc;
55 unsigned recno, startrec, endrec;
56 u_char record[255];
57
58 rc = phonebook_op_common(argv[1]);
59 if (rc < 0)
60 return(rc);
61 startrec = strtoul(argv[2], 0, 0);
62 if (startrec < 1 || startrec > curfile_record_count) {
63 fprintf(stderr,
64 "error: specified starting record number is invalid\n");
65 return(-1);
66 }
67 endrec = strtoul(argv[3], 0, 0);
68 if (endrec < 1 || endrec > curfile_record_count) {
69 fprintf(stderr,
70 "error: specified final record number is invalid\n");
71 return(-1);
72 }
73 if (startrec > endrec) {
74 fprintf(stderr, "error: reverse record range specified\n");
75 return(-1);
76 }
77 memset(record, 0xFF, curfile_record_len);
78 for (recno = startrec; recno <= endrec; recno++) {
79 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
80 if (rc < 0)
81 return(rc);
82 }
83 return(0);
84 }