annotate simtool/smsp_restore.c @ 83:07e395fddfe1

lnd-write command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 06:08:28 +0000
parents 8cb269f5a902
children 9c10afbb745a
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);
41
8cb269f5a902 fc-simtool smsp-restore: forgot to set parameter indicator bits
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
151 fixp[0] &= 0xFB;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 while (*cp && !isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
157 if (!strncasecmp(cp, "DCS=", 4)) {
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 cp += 4;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
159 if (!isdigit(*cp)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
160 fprintf(stderr,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
161 "%s line %d: DCS= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
162 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
163 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
164 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
165 fixp[26] = strtoul(cp, 0, 0);
41
8cb269f5a902 fc-simtool smsp-restore: forgot to set parameter indicator bits
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
166 fixp[0] &= 0xF7;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
167 while (*cp && !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 while (isspace(*cp))
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
170 cp++;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
171 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
172 if (!strncasecmp(cp, "VP=", 3)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
173 cp += 3;
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
174 if (!isdigit(*cp)) {
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
175 fprintf(stderr,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
176 "%s line %d: VP= parameter invalid syntax\n",
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
177 filename_for_errs, lineno_for_errs);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
178 return(-1);
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
179 }
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
180 fixp[27] = strtoul(cp, 0, 0);
41
8cb269f5a902 fc-simtool smsp-restore: forgot to set parameter indicator bits
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
181 fixp[0] &= 0xEF;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 while (*cp && !isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 if (*cp == '"') {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 cp++;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
189 cp = alpha_from_file_qstring(cp, record,
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
190 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
191 filename_for_errs,
2ef261371347 alpha tag from file parsing functions factored out of pb-update
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
192 lineno_for_errs);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (!cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 } else if (!strncasecmp(cp, "HEX", 3)) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 cp += 3;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 cp++;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
199 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
200 filename_for_errs, lineno_for_errs);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 if (!cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 } else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 goto inv_syntax;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 while (isspace(*cp))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 cp++;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 if (*cp)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 goto inv_syntax;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
209 return update_rec_op(recno, 0x04, record, curfile_record_len);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
212 cmd_smsp_restore(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 FILE *inf;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 int lineno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 char linebuf[1024];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
220 rc = select_ef_smsp();
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 return(rc);
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
223 inf = fopen(argv[1], "r");
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if (!inf) {
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
225 perror(argv[1]);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 if (!index(linebuf, '\n')) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 "%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
232 argv[1], lineno);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 if (linebuf[0] != '#' || !isdigit(linebuf[1]))
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 continue;
39
2467b7acad1f fc-simtool smsp-restore implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 18
diff changeset
238 rc = process_record(linebuf, argv[1], lineno);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 if (rc < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 fclose(inf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 }