FreeCalypso > hg > fc-pcsc-tools
annotate simtool/pbrestore.c @ 197:3ddbc3fea5f0
encode_plmn_3bytes() error handling change
in preparation for PLMN list reading addition
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 02:36:27 +0000 |
parents | 9c10afbb745a |
children |
rev | line source |
---|---|
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
2 * This module implements pb-restore and pb-update commands. |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "curfile.h" |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
130
9c10afbb745a
fc-simtool: search added to file-reading commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
13 extern FILE *open_script_input_file(); |
9c10afbb745a
fc-simtool: search added to file-reading commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
14 |
18
2ef261371347
alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
15 extern char *alpha_from_file_qstring(); |
2ef261371347
alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
16 extern char *alpha_from_file_hex(); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
19 process_record(line, bin_file_buf, filename_for_errs, lineno_for_errs) |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *line, *filename_for_errs; |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
21 u_char *bin_file_buf; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned recno; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 u_char record[255], *fixp; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 u_char digits[20]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned ndigits, num_digit_bytes; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char *cp; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int c; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 recno = strtoul(line+1, 0, 10); |
85
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
31 if (recno < 1 || recno > curfile_record_count) { |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, "%s line %d: record number is out of range\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 filename_for_errs, lineno_for_errs); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 cp = line + 1; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 while (isdigit(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (*cp++ != ':') { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 filename_for_errs, lineno_for_errs); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 cp++; |
85
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
46 memset(record, 0xFF, curfile_record_len); |
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
47 fixp = record + curfile_record_len - 14; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (digit_char_to_gsm(*cp) < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 goto inv_syntax; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 for (ndigits = 0; ; ndigits++) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 c = digit_char_to_gsm(*cp); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (c < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (ndigits >= 20) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fprintf(stderr, "%s line %d: too many number digits\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 filename_for_errs, lineno_for_errs); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 digits[ndigits] = c; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (ndigits & 1) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 digits[ndigits++] = 0xF; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 num_digit_bytes = ndigits >> 1; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fixp[0] = num_digit_bytes + 1; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 pack_digit_bytes(digits, fixp + 2, num_digit_bytes); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (*cp++ != ',') |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 goto inv_syntax; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (cp[0] != '0' || cp[1] != 'x' && cp[1] != 'X' || !isxdigit(cp[2]) || |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 !isxdigit(cp[3]) || !isspace(cp[4])) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 goto inv_syntax; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fixp[1] = strtoul(cp, 0, 16); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 cp += 5; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (!strncasecmp(cp, "CCP=", 4)) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 cp += 4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fixp[12] = strtoul(cp, 0, 0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 while (*cp && !isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (!strncasecmp(cp, "EXT=", 4)) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 cp += 4; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fixp[13] = strtoul(cp, 0, 0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 while (*cp && !isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (*cp == '"') { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 cp++; |
85
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
94 cp = alpha_from_file_qstring(cp, record, |
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
95 curfile_record_len - 14, |
18
2ef261371347
alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
96 filename_for_errs, |
2ef261371347
alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
97 lineno_for_errs); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (!cp) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } else if (!strncasecmp(cp, "HEX", 3)) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 cp += 3; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 cp++; |
85
51167ee0151b
pb-update implementation: rm vestiges of uicc unification attempt
Mychaela Falconia <falcon@freecalypso.org>
parents:
18
diff
changeset
|
104 cp = alpha_from_file_hex(cp, record, curfile_record_len - 14, |
18
2ef261371347
alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
105 filename_for_errs, lineno_for_errs); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (!cp) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } else |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 goto inv_syntax; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 while (isspace(*cp)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 cp++; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (*cp) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 goto inv_syntax; |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
114 if (bin_file_buf) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
115 bcopy(record, bin_file_buf + (recno - 1) * curfile_record_len, |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
116 curfile_record_len); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
117 return(0); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
118 } else |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
119 return update_rec_op(recno, 0x04, record, curfile_record_len); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
120 } |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
121 |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
122 cmd_pb_restore(argc, argv) |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
123 char **argv; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
124 { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
125 int rc; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
126 FILE *inf; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
127 int lineno; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
128 char linebuf[1024]; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
129 u_char *databuf; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
130 |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
131 rc = phonebook_op_common(argv[1]); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
132 if (rc < 0) |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
133 return(rc); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
134 databuf = malloc(curfile_total_size); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
135 if (!databuf) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
136 perror("malloc for full phonebook EF"); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
137 return(-1); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
138 } |
130
9c10afbb745a
fc-simtool: search added to file-reading commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
139 inf = open_script_input_file(argv[2]); |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
140 if (!inf) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
141 perror(argv[2]); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
142 free(databuf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
143 return(-1); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
144 } |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
145 memset(databuf, 0xFF, curfile_total_size); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
146 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
147 if (!index(linebuf, '\n')) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
148 fprintf(stderr, |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
149 "%s line %d: too long or missing newline\n", |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
150 argv[2], lineno); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
151 fclose(inf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
152 free(databuf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
153 return(-1); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
154 } |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
155 if (linebuf[0] != '#' || !isdigit(linebuf[1])) |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
156 continue; |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
157 rc = process_record(linebuf, databuf, argv[2], lineno); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
158 if (rc < 0) { |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
159 fclose(inf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
160 free(databuf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
161 return(rc); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
162 } |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
163 } |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
164 fclose(inf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
165 rc = restore_bin_records(databuf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
166 free(databuf); |
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
167 return(rc); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 cmd_pb_update(argc, argv) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 FILE *inf; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 int lineno; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 char linebuf[1024]; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 rc = phonebook_op_common(argv[1]); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 return(rc); |
130
9c10afbb745a
fc-simtool: search added to file-reading commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
181 inf = open_script_input_file(argv[2]); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 if (!inf) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 perror(argv[2]); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (!index(linebuf, '\n')) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 fprintf(stderr, |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 "%s line %d: too long or missing newline\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 argv[2], lineno); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 fclose(inf); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 if (linebuf[0] != '#' || !isdigit(linebuf[1])) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 continue; |
87
bc862d41f96b
pb-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
196 rc = process_record(linebuf, 0, argv[2], lineno); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 if (rc < 0) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 fclose(inf); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 fclose(inf); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 } |
88
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
205 |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
206 cmd_lnd_restore(argc, argv) |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
207 char **argv; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
208 { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
209 int rc; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
210 FILE *inf; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
211 int lineno; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
212 char linebuf[1024]; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
213 u_char *databuf; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
214 |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
215 rc = select_ef_lnd(); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
216 if (rc < 0) |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
217 return(rc); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
218 databuf = malloc(curfile_total_size); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
219 if (!databuf) { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
220 perror("malloc for full EF_LND"); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
221 return(-1); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
222 } |
130
9c10afbb745a
fc-simtool: search added to file-reading commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
223 inf = open_script_input_file(argv[1]); |
88
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
224 if (!inf) { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
225 perror(argv[1]); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
226 free(databuf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
227 return(-1); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
228 } |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
229 memset(databuf, 0xFF, curfile_total_size); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
230 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
231 if (!index(linebuf, '\n')) { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
232 fprintf(stderr, |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
233 "%s line %d: too long or missing newline\n", |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
234 argv[1], lineno); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
235 fclose(inf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
236 free(databuf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
237 return(-1); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
238 } |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
239 if (linebuf[0] != '#' || !isdigit(linebuf[1])) |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
240 continue; |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
241 rc = process_record(linebuf, databuf, argv[1], lineno); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
242 if (rc < 0) { |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
243 fclose(inf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
244 free(databuf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
245 return(rc); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
246 } |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
247 } |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
248 fclose(inf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
249 rc = restore_bin_cyclic(databuf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
250 free(databuf); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
251 return(rc); |
ae831b21ef77
lnd-restore command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
252 } |