FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pbupd_imm.c @ 13:d4f8c511affe
simtool: pbupdate.c split into separate modules for each command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 01:28:53 +0000 |
parents | simtool/pbupdate.c@8a34f5b7c812 |
children | b8d27c72747a |
comparison
equal
deleted
inserted
replaced
12:8a34f5b7c812 | 13:d4f8c511affe |
---|---|
1 /* | |
2 * This module implements the pb-update-imm 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 "curfile.h" | |
11 | |
12 extern u_char gsm7_encode_table[256]; | |
13 | |
14 static | |
15 decode_alphatag_arg(arg, record, maxlen) | |
16 char *arg; | |
17 u_char *record; | |
18 unsigned maxlen; | |
19 { | |
20 unsigned acclen, nadd; | |
21 char *cp; | |
22 int c; | |
23 | |
24 cp = arg; | |
25 for (acclen = 0; *cp; ) { | |
26 c = *cp++; | |
27 if (c == '\\') { | |
28 if (*cp == '\0') { | |
29 fprintf(stderr, | |
30 "error: dangling backslash escape\n"); | |
31 return(-1); | |
32 } | |
33 c = *cp++; | |
34 switch (c) { | |
35 case 'n': | |
36 c = '\n'; | |
37 break; | |
38 case 'r': | |
39 c = '\r'; | |
40 break; | |
41 case '"': | |
42 case '\\': | |
43 break; | |
44 default: | |
45 fprintf(stderr, | |
46 "error: non-understood backslash escape\n"); | |
47 return(-1); | |
48 } | |
49 } | |
50 c = gsm7_encode_table[c]; | |
51 if (c == 0xFF) { | |
52 fprintf(stderr, | |
53 "error: character in alpha tag string cannot be encoded in GSM7\n"); | |
54 return(-1); | |
55 } | |
56 if (c & 0x80) | |
57 nadd = 2; | |
58 else | |
59 nadd = 1; | |
60 if (acclen + nadd > maxlen) { | |
61 fprintf(stderr, | |
62 "error: alpha tag string is longer than SIM limit\n"); | |
63 return(-1); | |
64 } | |
65 if (c & 0x80) | |
66 record[acclen++] = 0x1B; | |
67 record[acclen++] = c & 0x7F; | |
68 } | |
69 return(0); | |
70 } | |
71 | |
72 cmd_pb_update_imm(argc, argv) | |
73 char **argv; | |
74 { | |
75 int rc; | |
76 unsigned recno; | |
77 u_char record[255], *fixp; | |
78 | |
79 rc = phonebook_op_common(argv[1]); | |
80 if (rc < 0) | |
81 return(rc); | |
82 recno = strtoul(argv[2], 0, 0); | |
83 if (recno < 1 || recno > curfile_record_count) { | |
84 fprintf(stderr, "error: specified record number is invalid\n"); | |
85 return(-1); | |
86 } | |
87 memset(record, 0xFF, curfile_record_len); | |
88 fixp = record + curfile_record_len - 14; | |
89 rc = encode_phone_number_arg(argv[3], fixp); | |
90 if (rc < 0) | |
91 return(rc); | |
92 if (argv[4]) { | |
93 rc = decode_alphatag_arg(argv[4], record, | |
94 curfile_record_len - 14); | |
95 if (rc < 0) | |
96 return(rc); | |
97 } | |
98 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
99 } |