comparison simtool/plmnsel.c @ 100:a75c0aafb367

plmnsel-erase command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 22:54:35 +0000
parents d2e800abd257
children 63c76f9d678a
comparison
equal deleted inserted replaced
99:d2e800abd257 100:a75c0aafb367
3 */ 3 */
4 4
5 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
8 #include "simresp.h" 10 #include "simresp.h"
9 #include "curfile.h" 11 #include "curfile.h"
10 #include "file_id.h" 12 #include "file_id.h"
11 13
12 static 14 static
108 rc = encode_plmn_3bytes(argv[2], rec); 110 rc = encode_plmn_3bytes(argv[2], rec);
109 if (rc < 0) 111 if (rc < 0)
110 return(rc); 112 return(rc);
111 return update_bin_op(idx * 3, rec, 3); 113 return update_bin_op(idx * 3, rec, 3);
112 } 114 }
115
116 cmd_plmnsel_erase(argc, argv)
117 char **argv;
118 {
119 int rc;
120 unsigned idx, start, end, nrec;
121 u_char rec[3];
122
123 rc = select_ef_plmnsel();
124 if (rc < 0)
125 return(rc);
126 nrec = curfile_total_size / 3;
127 start = strtoul(argv[1], 0, 0);
128 if (start >= nrec) {
129 fprintf(stderr,
130 "error: specified starting index is out of range\n");
131 return(-1);
132 }
133 if (!argv[2])
134 end = start;
135 else if (!strcmp(argv[2], "end"))
136 end = nrec - 1;
137 else {
138 end = strtoul(argv[1], 0, 0);
139 if (end >= nrec) {
140 fprintf(stderr,
141 "error: specified ending index is out of range\n");
142 return(-1);
143 }
144 if (start > end) {
145 fprintf(stderr,
146 "error: reverse index range specified\n");
147 return(-1);
148 }
149 }
150 memset(rec, 0xFF, 3);
151 for (idx = start; idx <= end; idx++) {
152 rc = update_bin_op(idx * 3, rec, 3);
153 if (rc < 0)
154 return(rc);
155 }
156 return(0);
157 }