FreeCalypso > hg > freecalypso-hwlab
annotate simtool/pbupdate.c @ 174:4f5abad5dd40
doc/Unbuffered-FT2232x-JTAG: update for fc-usbser-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 07:23:18 +0000 |
parents | f18b87115cca |
children |
rev | line source |
---|---|
111
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the pb-update command. |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <pcsclite.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <winscard.h> |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "globals.h" |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static u_char gsm7_encode_table[256] = { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x00 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 0xFF, 0xFF, '\n', 0xFF, 0xFF, '\r', 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x10 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 ' ', '!', '"', '#', 0x02, '%', '&', 0x27, /* 0x20 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 '(', ')', '*', '+', ',', '-', '.', '/', |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 '0', '1', '2', '3', '4', '5', '6', '7', /* 0x30 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 '8', '9', ':', ';', '<', '=', '>', '?', |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 0x40 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 0x50 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 'X', 'Y', 'Z', 0xBC, 0xAF, 0xBE, 0x94, 0x11, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 0xFF, 'a', 'b', 'c', 'd', 'e', 'f', 'g', /* 0x60 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', /* 0x70 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 'x', 'y', 'z', 0xA8, 0xC0, 0xA9, 0xBD, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x80 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x90 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 0xFF, 0x40, 0xFF, 0x01, 0x24, 0x03, 0xFF, 0x5F, /* 0xA0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0xB0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 0xFF, 0xFF, 0xFF, 0xFF, 0x5B, 0x0E, 0x1C, 0x09, /* 0xC0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 0xFF, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 0xFF, 0x5D, 0xFF, 0xFF, 0xFF, 0xFF, 0x5C, 0xFF, /* 0xD0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 0x0B, 0xFF, 0xFF, 0xFF, 0x5E, 0xFF, 0xFF, 0x1E, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 0x7F, 0xFF, 0xFF, 0xFF, 0x7B, 0x0F, 0x1D, 0xFF, /* 0xE0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 0x04, 0x05, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 0xFF, 0x7D, 0x08, 0xFF, 0xFF, 0xFF, 0x7C, 0xFF, /* 0xF0 */ |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 0x0C, 0x06, 0xFF, 0xFF, 0x7E, 0xFF, 0xFF, 0xFF |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 }; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 static |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 digit_char_to_gsm(ch) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 switch (ch) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 case '0': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 case '1': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case '2': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 case '3': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 case '4': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 case '5': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case '6': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 case '7': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 case '8': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 case '9': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return (ch - '0'); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 case '*': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 return 0xA; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 case '#': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return 0xB; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 case 'a': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 case 'b': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 case 'c': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return (ch - 'a' + 0xC); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 case 'A': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 case 'B': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 case 'C': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return (ch - 'A' + 0xC); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return (-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 static void |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 pack_digit_bytes(digits, dest, num_digit_bytes) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 u_char *digits, *dest; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 unsigned num_digit_bytes; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 u_char *sp, *dp; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 unsigned n; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 sp = digits; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 dp = dest; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 for (n = 0; n < num_digit_bytes; n++) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 *dp++ = sp[0] | (sp[1] << 4); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 sp += 2; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 static char * |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 decode_qstring_alpha(cp, record, filename_for_errs, lineno_for_errs) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 char *cp, *filename_for_errs; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 u_char *record; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 unsigned maxlen, acclen, nadd; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 int c; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 maxlen = curfile_record_len - 14; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 for (acclen = 0; ; ) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 if (*cp == '\0') { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 unterm_qstring: fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 "%s line %d: unterminated quoted string\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (*cp == '"') |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 c = *cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 if (c == '\\') { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (*cp == '\0') |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 goto unterm_qstring; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 c = *cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 switch (c) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 case 'n': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 c = '\n'; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 case 'r': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 c = '\r'; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 case '"': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 case '\\': |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 default: |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 "%s line %d: non-understood backslash escape\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 c = gsm7_encode_table[c]; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 if (c == 0xFF) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 "%s line %d: character in quoted string cannot be encoded in GSM7\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if (c & 0x80) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 nadd = 2; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 else |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 nadd = 1; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (acclen + nadd > maxlen) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 "%s line %d: alpha tag string is longer than SIM limit\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 if (c & 0x80) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 record[acclen++] = 0x1B; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 record[acclen++] = c & 0x7F; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 return(cp + 1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 static char * |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 decode_hex_alpha(cp, record, filename_for_errs, lineno_for_errs) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 char *cp, *filename_for_errs; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 u_char *record; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 unsigned maxlen, acclen; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 maxlen = curfile_record_len - 14; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 for (acclen = 0; ; ) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (acclen >= maxlen) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 "%s line %d: alpha tag string is longer than SIM limit\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 record[acclen++] = (decode_hex_digit(cp[0]) << 4) | |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 decode_hex_digit(cp[1]); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 cp += 2; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 return(cp); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 static |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 process_record(line, filename_for_errs, lineno_for_errs) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 char *line, *filename_for_errs; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 unsigned recno; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 u_char record[255], *fixp; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 u_char digits[20]; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 unsigned ndigits, num_digit_bytes; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 char *cp; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 int c; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 recno = strtoul(line+1, 0, 10); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 if (recno < 1 || recno > curfile_record_count) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 fprintf(stderr, "%s line %d: record number is out of range\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 cp = line + 1; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 while (isdigit(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 if (*cp++ != ':') { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 memset(record, 0xFF, curfile_record_len); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 fixp = record + curfile_record_len - 14; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 if (digit_char_to_gsm(*cp) < 0) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 goto inv_syntax; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 for (ndigits = 0; ; ndigits++) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 c = digit_char_to_gsm(*cp); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 if (c < 0) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 break; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 if (ndigits >= 20) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 fprintf(stderr, "%s line %d: too many number digits\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 filename_for_errs, lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 digits[ndigits] = c; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 if (ndigits & 1) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 digits[ndigits++] = 0xF; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 num_digit_bytes = ndigits >> 1; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 fixp[0] = num_digit_bytes + 1; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 pack_digit_bytes(digits, fixp + 2, num_digit_bytes); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 if (*cp++ != ',') |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 goto inv_syntax; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 if (cp[0] != '0' || cp[1] != 'x' && cp[1] != 'X' || !isxdigit(cp[2]) || |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 !isxdigit(cp[3]) || !isspace(cp[4])) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 goto inv_syntax; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 fixp[1] = strtoul(cp, 0, 16); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 cp += 5; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 if (!strncasecmp(cp, "CCP=", 4)) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 cp += 4; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 fixp[12] = strtoul(cp, 0, 0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 while (*cp && !isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 if (!strncasecmp(cp, "EXT=", 4)) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 cp += 4; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 fixp[13] = strtoul(cp, 0, 0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 while (*cp && !isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 if (*cp == '"') { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 cp = decode_qstring_alpha(cp, record, filename_for_errs, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 if (!cp) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 } else if (!strncasecmp(cp, "HEX", 3)) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 cp += 3; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 cp = decode_hex_alpha(cp, record, filename_for_errs, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 lineno_for_errs); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 if (!cp) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 } else |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 goto inv_syntax; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 while (isspace(*cp)) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 cp++; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 if (*cp) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 goto inv_syntax; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 return update_rec_op(recno, 0x04, record, curfile_record_len); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 cmd_pb_update(argc, argv) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 char **argv; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 int rc; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 FILE *inf; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 int lineno; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 char linebuf[1024]; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 rc = phonebook_op_common(argv[1]); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 if (rc < 0) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 return(rc); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 inf = fopen(argv[2], "r"); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 if (!inf) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 perror(argv[2]); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 if (!index(linebuf, '\n')) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 fprintf(stderr, |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 "%s line %d: too long or missing newline\n", |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 argv[2], lineno); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 fclose(inf); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 return(-1); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 if (linebuf[0] != '#' || !isdigit(linebuf[1])) |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 continue; |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 rc = process_record(linebuf, argv[2], lineno); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 if (rc < 0) { |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 fclose(inf); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 return(rc); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 } |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 fclose(inf); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 return(0); |
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 } |
117
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
316 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
317 static |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
318 decode_number_arg(arg, fixp) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
319 char *arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
320 u_char *fixp; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
321 { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
322 u_char digits[20]; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
323 unsigned ndigits, num_digit_bytes; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
324 char *cp, *endp; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
325 int c; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
326 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
327 cp = arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
328 if (*cp == '+') { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
329 fixp[1] = 0x91; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
330 cp++; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
331 } else |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
332 fixp[1] = 0x81; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
333 if (digit_char_to_gsm(*cp) < 0) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
334 inv_arg: fprintf(stderr, "error: invalid phone number argument\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
335 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
336 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
337 for (ndigits = 0; ; ndigits++) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
338 c = digit_char_to_gsm(*cp); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
339 if (c < 0) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
340 break; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
341 cp++; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
342 if (ndigits >= 20) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
343 fprintf(stderr, "error: too many number digits\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
344 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
345 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
346 digits[ndigits] = c; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
347 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
348 if (ndigits & 1) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
349 digits[ndigits++] = 0xF; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
350 num_digit_bytes = ndigits >> 1; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
351 fixp[0] = num_digit_bytes + 1; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
352 pack_digit_bytes(digits, fixp + 2, num_digit_bytes); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
353 if (*cp == ',') { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
354 cp++; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
355 if (!isdigit(*cp)) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
356 goto inv_arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
357 fixp[1] = strtoul(cp, &endp, 0); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
358 if (*endp) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
359 goto inv_arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
360 } else if (*cp) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
361 goto inv_arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
362 return(0); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
363 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
364 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
365 static |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
366 decode_alphatag_arg(arg, record) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
367 char *arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
368 u_char *record; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
369 { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
370 unsigned maxlen, acclen, nadd; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
371 char *cp; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
372 int c; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
373 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
374 maxlen = curfile_record_len - 14; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
375 cp = arg; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
376 for (acclen = 0; *cp; ) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
377 c = *cp++; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
378 if (c == '\\') { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
379 if (*cp == '\0') { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
380 fprintf(stderr, |
126
f18b87115cca
fc-simtool: typo fix in error message
Mychaela Falconia <falcon@freecalypso.org>
parents:
120
diff
changeset
|
381 "error: dangling backslash escape\n"); |
117
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
382 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
383 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
384 c = *cp++; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
385 switch (c) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
386 case 'n': |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
387 c = '\n'; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
388 break; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
389 case 'r': |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
390 c = '\r'; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
391 break; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
392 case '"': |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
393 case '\\': |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
394 break; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
395 default: |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
396 fprintf(stderr, |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
397 "error: non-understood backslash escape\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
398 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
399 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
400 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
401 c = gsm7_encode_table[c]; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
402 if (c == 0xFF) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
403 fprintf(stderr, |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
404 "error: character in alpha tag string cannot be encoded in GSM7\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
405 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
406 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
407 if (c & 0x80) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
408 nadd = 2; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
409 else |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
410 nadd = 1; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
411 if (acclen + nadd > maxlen) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
412 fprintf(stderr, |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
413 "error: alpha tag string is longer than SIM limit\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
414 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
415 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
416 if (c & 0x80) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
417 record[acclen++] = 0x1B; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
418 record[acclen++] = c & 0x7F; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
419 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
420 return(0); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
421 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
422 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
423 cmd_pb_update_imm(argc, argv) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
424 char **argv; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
425 { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
426 int rc; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
427 unsigned recno; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
428 u_char record[255], *fixp; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
429 |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
430 rc = phonebook_op_common(argv[1]); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
431 if (rc < 0) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
432 return(rc); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
433 recno = strtoul(argv[2], 0, 0); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
434 if (recno < 1 || recno > curfile_record_count) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
435 fprintf(stderr, "error: specified record number is invalid\n"); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
436 return(-1); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
437 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
438 memset(record, 0xFF, curfile_record_len); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
439 fixp = record + curfile_record_len - 14; |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
440 rc = decode_number_arg(argv[3], fixp); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
441 if (rc < 0) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
442 return(rc); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
443 if (argv[4]) { |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
444 rc = decode_alphatag_arg(argv[4], record); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
445 if (rc < 0) |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
446 return(rc); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
447 } |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
448 return update_rec_op(recno, 0x04, record, curfile_record_len); |
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
449 } |
120
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
450 |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
451 static |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
452 decode_alphatag_arg_hex(arg, record) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
453 char *arg; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
454 u_char *record; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
455 { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
456 unsigned maxlen, acclen; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
457 |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
458 maxlen = curfile_record_len - 14; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
459 for (acclen = 0; ; acclen++) { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
460 while (isspace(*arg)) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
461 arg++; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
462 if (!*arg) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
463 break; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
464 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
465 fprintf(stderr, "error: invalid hex string input\n"); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
466 return(-1); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
467 } |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
468 if (acclen >= maxlen) { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
469 fprintf(stderr, |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
470 "error: alpha tag string is longer than SIM limit\n"); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
471 return(-1); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
472 } |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
473 record[acclen] = (decode_hex_digit(arg[0]) << 4) | |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
474 decode_hex_digit(arg[1]); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
475 arg += 2; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
476 } |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
477 return(0); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
478 } |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
479 |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
480 cmd_pb_update_imm_hex(argc, argv) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
481 char **argv; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
482 { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
483 int rc; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
484 unsigned recno; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
485 u_char record[255], *fixp; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
486 |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
487 rc = phonebook_op_common(argv[1]); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
488 if (rc < 0) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
489 return(rc); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
490 recno = strtoul(argv[2], 0, 0); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
491 if (recno < 1 || recno > curfile_record_count) { |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
492 fprintf(stderr, "error: specified record number is invalid\n"); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
493 return(-1); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
494 } |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
495 memset(record, 0xFF, curfile_record_len); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
496 fixp = record + curfile_record_len - 14; |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
497 rc = decode_number_arg(argv[3], fixp); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
498 if (rc < 0) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
499 return(rc); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
500 rc = decode_alphatag_arg_hex(argv[4], record); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
501 if (rc < 0) |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
502 return(rc); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
503 return update_rec_op(recno, 0x04, record, curfile_record_len); |
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
504 } |