annotate simtool/pbupdate.c @ 115:0dcd666292e4

fc-simtool: pb-erase-one command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 28 Jan 2021 02:56:10 +0000
parents 5bfb5a7262c1
children 06e2d5c60cbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }