FreeCalypso > hg > fc-sim-tools
comparison simtool/pnnprog.c @ 10:ddd767f6e15b
fc-simtool ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:11:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:c9ef9e91dd8e | 10:ddd767f6e15b |
---|---|
1 /* | |
2 * This module implements functions for admin programming of EF_PNN. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include "curfile.h" | |
11 | |
12 static u_char * | |
13 add_field(dp, bytes_avail, namearg, type) | |
14 u_char *dp; | |
15 char *namearg; | |
16 unsigned bytes_avail, type; | |
17 { | |
18 u_char gsm7_buf[289]; | |
19 unsigned nsept, noct; | |
20 int rc; | |
21 | |
22 if (bytes_avail < 4) { | |
23 fprintf(stderr, | |
24 "error: PNN record is too short for name element\n"); | |
25 return(0); | |
26 } | |
27 rc = qstring_arg_to_gsm7(namearg, gsm7_buf, (bytes_avail-3) * 8 / 7); | |
28 if (rc < 0) | |
29 return(0); | |
30 nsept = rc; | |
31 gsm7_buf[nsept] = 0; | |
32 noct = (nsept * 7 + 7) / 8; | |
33 *dp++ = type; | |
34 *dp++ = noct + 1; | |
35 *dp++ = 0x80 | (nsept & 7); | |
36 gsm7_pack(gsm7_buf, dp, noct); | |
37 dp += noct; | |
38 return dp; | |
39 } | |
40 | |
41 cmd_pnn_write(argc, argv) | |
42 char **argv; | |
43 { | |
44 int rc; | |
45 unsigned recno; | |
46 u_char record[255], *dp, *endp; | |
47 | |
48 rc = select_ef_pnn(); | |
49 if (rc < 0) | |
50 return(rc); | |
51 recno = strtoul(argv[1], 0, 0); | |
52 if (recno < 1 || recno > curfile_record_count) { | |
53 fprintf(stderr, "error: specified record number is invalid\n"); | |
54 return(-1); | |
55 } | |
56 dp = record; | |
57 endp = record + curfile_record_len; | |
58 dp = add_field(dp, endp - dp, argv[2], 0x43); | |
59 if (!dp) | |
60 return(-1); | |
61 if (argv[3]) { | |
62 dp = add_field(dp, endp - dp, argv[3], 0x45); | |
63 if (!dp) | |
64 return(-1); | |
65 } | |
66 while (dp < endp) | |
67 *dp++ = 0xFF; | |
68 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
69 } | |
70 | |
71 cmd_pnn_erase(argc, argv) | |
72 char **argv; | |
73 { | |
74 int rc; | |
75 unsigned recno, startrec, endrec; | |
76 u_char record[255]; | |
77 | |
78 rc = select_ef_pnn(); | |
79 if (rc < 0) | |
80 return(rc); | |
81 startrec = strtoul(argv[1], 0, 0); | |
82 if (startrec < 1 || startrec > curfile_record_count) { | |
83 fprintf(stderr, | |
84 "error: specified starting record number is invalid\n"); | |
85 return(-1); | |
86 } | |
87 if (!argv[2]) | |
88 endrec = startrec; | |
89 else if (!strcmp(argv[2], "end")) | |
90 endrec = curfile_record_count; | |
91 else { | |
92 endrec = strtoul(argv[2], 0, 0); | |
93 if (endrec < 1 || endrec > curfile_record_count) { | |
94 fprintf(stderr, | |
95 "error: specified final record number is invalid\n"); | |
96 return(-1); | |
97 } | |
98 if (startrec > endrec) { | |
99 fprintf(stderr, | |
100 "error: reverse record range specified\n"); | |
101 return(-1); | |
102 } | |
103 } | |
104 memset(record, 0xFF, curfile_record_len); | |
105 for (recno = startrec; recno <= endrec; recno++) { | |
106 rc = update_rec_op(recno, 0x04, record, curfile_record_len); | |
107 if (rc < 0) | |
108 return(rc); | |
109 } | |
110 return(0); | |
111 } |