annotate simtool/smsp_restore.c @ 39:2467b7acad1f

fc-simtool smsp-restore implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 21:54:01 +0000
parents simtool/pbupd_file.c@2ef261371347
children 8cb269f5a902
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
2 * This module implements the smsp-restore command.
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
18
2ef261371347 alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
13 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
14 extern char *alpha_from_file_hex();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
16 static char *
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
17 parse_da(cp, bina, filename_for_errs, lineno_for_errs)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
18 char *cp, *filename_for_errs;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
19 u_char *bina;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
20 {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
21 u_char digits[20];
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
22 unsigned ndigits, num_digit_bytes;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
23 int c;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
24
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
25 if (digit_char_to_gsm(*cp) < 0) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
26 inv_syntax: fprintf(stderr, "%s line %d: DA= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
27 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
28 return(0);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
29 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
30 for (ndigits = 0; ; ndigits++) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
31 c = digit_char_to_gsm(*cp);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
32 if (c < 0)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
33 break;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
34 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
35 if (ndigits >= 20) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
36 fprintf(stderr, "%s line %d: too many number digits\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
37 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
38 return(0);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
39 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
40 digits[ndigits] = c;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
41 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
42 bina[0] = ndigits;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
43 if (ndigits & 1)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
44 digits[ndigits++] = 0xF;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
45 num_digit_bytes = ndigits >> 1;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
46 pack_digit_bytes(digits, bina + 2, num_digit_bytes);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
47 if (*cp++ != ',')
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
48 goto inv_syntax;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
49 if (cp[0] != '0' || cp[1] != 'x' && cp[1] != 'X' || !isxdigit(cp[2]) ||
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
50 !isxdigit(cp[3]) || !isspace(cp[4]))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
51 goto inv_syntax;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
52 bina[1] = strtoul(cp, 0, 16);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
53 cp += 5;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
54 while (isspace(*cp))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
55 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
56 return(cp);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
57 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
58
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
59 static char *
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
60 parse_sc(cp, bina, filename_for_errs, lineno_for_errs)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
61 char *cp, *filename_for_errs;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
62 u_char *bina;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
63 {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
64 u_char digits[20];
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
65 unsigned ndigits, num_digit_bytes;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
66 int c;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
67
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
68 if (digit_char_to_gsm(*cp) < 0) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
69 inv_syntax: fprintf(stderr, "%s line %d: SC= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
70 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
71 return(0);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
72 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
73 for (ndigits = 0; ; ndigits++) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
74 c = digit_char_to_gsm(*cp);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
75 if (c < 0)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
76 break;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
77 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
78 if (ndigits >= 20) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
79 fprintf(stderr, "%s line %d: too many number digits\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
80 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
81 return(0);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
82 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
83 digits[ndigits] = c;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
84 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
85 if (ndigits & 1)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
86 digits[ndigits++] = 0xF;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
87 num_digit_bytes = ndigits >> 1;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
88 bina[0] = num_digit_bytes + 1;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
89 pack_digit_bytes(digits, bina + 2, num_digit_bytes);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
90 if (*cp++ != ',')
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
91 goto inv_syntax;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
92 if (cp[0] != '0' || cp[1] != 'x' && cp[1] != 'X' || !isxdigit(cp[2]) ||
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
93 !isxdigit(cp[3]) || !isspace(cp[4]))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
94 goto inv_syntax;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
95 bina[1] = strtoul(cp, 0, 16);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
96 cp += 5;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
97 while (isspace(*cp))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
98 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
99 return(cp);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
100 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
101
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 static
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
103 process_record(line, filename_for_errs, lineno_for_errs)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 char *line, *filename_for_errs;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 unsigned recno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 u_char record[255], *fixp;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 char *cp;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 recno = strtoul(line+1, 0, 10);
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
111 if (recno < 1 || recno > curfile_record_count) {
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 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
113 filename_for_errs, lineno_for_errs);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 cp = line + 1;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 while (isdigit(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (*cp++ != ':') {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n",
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 filename_for_errs, lineno_for_errs);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 cp++;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
126 memset(record, 0xFF, curfile_record_len);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
127 fixp = record + curfile_record_len - 28;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
128 if (!strncasecmp(cp, "DA=", 3)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
129 cp += 3;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
130 cp = parse_da(cp, fixp + 1, filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
131 if (!cp)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
132 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
133 fixp[0] &= 0xFE;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
134 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
135 if (!strncasecmp(cp, "SC=", 3)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
136 cp += 3;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
137 cp = parse_sc(cp, fixp+13, filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
138 if (!cp)
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
139 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
140 fixp[0] &= 0xFD;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
141 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
142 if (!strncasecmp(cp, "PID=", 4)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
143 cp += 4;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
144 if (!isdigit(*cp)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
145 fprintf(stderr,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
146 "%s line %d: PID= parameter invalid syntax\n",
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 filename_for_errs, lineno_for_errs);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
150 fixp[25] = strtoul(cp, 0, 0);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 while (*cp && !isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
156 if (!strncasecmp(cp, "DCS=", 4)) {
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 cp += 4;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
158 if (!isdigit(*cp)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
159 fprintf(stderr,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
160 "%s line %d: DCS= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
161 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
162 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
163 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
164 fixp[26] = strtoul(cp, 0, 0);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
165 while (*cp && !isspace(*cp))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
166 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
167 while (isspace(*cp))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
168 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
169 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
170 if (!strncasecmp(cp, "VP=", 3)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
171 cp += 3;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
172 if (!isdigit(*cp)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
173 fprintf(stderr,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
174 "%s line %d: VP= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
175 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
176 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
177 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
178 fixp[27] = strtoul(cp, 0, 0);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 while (*cp && !isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 if (*cp == '"') {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 cp++;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
186 cp = alpha_from_file_qstring(cp, record,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
187 curfile_record_len - 28,
18
2ef261371347 alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
188 filename_for_errs,
2ef261371347 alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
189 lineno_for_errs);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 if (!cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 } else if (!strncasecmp(cp, "HEX", 3)) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 cp += 3;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 cp++;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
196 cp = alpha_from_file_hex(cp, record, curfile_record_len - 28,
18
2ef261371347 alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
197 filename_for_errs, lineno_for_errs);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 if (!cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 } else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 goto inv_syntax;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 if (*cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 goto inv_syntax;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
206 return update_rec_op(recno, 0x04, record, curfile_record_len);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
209 cmd_smsp_restore(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 FILE *inf;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 int lineno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 char linebuf[1024];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
217 rc = select_ef_smsp();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 return(rc);
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
220 inf = fopen(argv[1], "r");
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 if (!inf) {
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
222 perror(argv[1]);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 if (!index(linebuf, '\n')) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 "%s line %d: too long or missing newline\n",
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
229 argv[1], lineno);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 if (linebuf[0] != '#' || !isdigit(linebuf[1]))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 continue;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
235 rc = process_record(linebuf, argv[1], lineno);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 if (rc < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 }