annotate simtool/smsp_restore.c @ 215:3a2f43460582

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