20 #if defined(ALLOW_FRQS_CODE)
22 static char fchars[] =
FCHARS;
25 #define FREE_DEST_RETURN(MSG,PRI,VAL) do { \
26 msg(MSG,PRI,VAL); free(dest); return(NULL); } while(0)
28 static char *frqs_expand_notches(
char *chans,
char *master)
30 char *dest = calloc(
MAXNOTCH+1,
sizeof(
char)), *scp, *dcp;
31 msg(
"FRQS: frqs_expand_notches(%s) -- input",1,chans);
37 for (scp = chans, dcp = dest; *scp; scp++) {
40 aa = strchr(master, scp[-1]);
41 if (!aa) FREE_DEST_RETURN(
"~ at start of string or after @!",3,0);
42 else if (scp[1] ==
'\0')
43 FREE_DEST_RETURN(
"~ at end of string or followed by @!",3,0);
44 bb = strchr(master, scp[1]);
45 if (!bb) FREE_DEST_RETURN(
"Odd, %c not in codes",3,*scp);
46 while (*(++aa) != *bb && (*aa))
49 }
else if (scp[0] ==
'@' && scp[1] ==
'|') {
52 FREE_DEST_RETURN(
"@| followed by non-digit: %s!",3,scp);
54 if (nn < 9) scp += 2;
else scp += 3;
61 msg(
"FRQS: frqs_expand_notches(%s) -- output",1,dest);
64 #undef FREE_DEST_RETURN
67 #define FREE_CHANS_RETURN(MSG,PRI,VAL,XIT) do { \
69 if(chans != ochans) free(chans); return(XIT); } while(0)
71 int frqs_chan_notches(
char *chans,
char *master,
struct c_block *cb_ptr)
73 char *ochans = chans, *fcp, *ncp;
74 msg(
"FRQS: frqs_chan_notches(%s) -- input",1,chans);
76 if (strchr(chans,
'@') || strchr(chans,
'|') || strchr(chans,
'~')) {
77 chans = frqs_expand_notches(chans, master);
78 if (!chans)
return(-1);
80 if (strlen(chans) > cb_ptr->
nnotches)
81 FREE_CHANS_RETURN(
"Too many chan_notches %d",3,strlen(chans),-2);
83 for (fcp = chans, ncp = cb_ptr->
chan_notches; *fcp; fcp++, ncp++) {
84 if (*fcp !=
'@' && !strchr(master, *fcp))
85 FREE_CHANS_RETURN(
"Channel %c is not active?",3,*fcp,-3);
91 if (chans != ochans) free(chans);
94 #undef FREE_DEST_RETURN
97 static void frqs_clone_clones(
struct c_block *cond_start,
int havechid)
100 int jj, nn = strlen(cond_start->
chid);
101 for (cb_ptr=cond_start; cb_ptr!=NULL; cb_ptr=cb_ptr->
cb_chain) {
104 strcpy(cb_ptr->
chid, cond_start->
chid);
105 for (jj = 0; jj < nn; jj++)
111 static int frqs_clone_ids(
char *cinfo,
char *master,
struct c_block *cond_start)
113 int clen = strlen(cinfo), ncan = clen/2, havechid, ii, mclen;
114 char *
clones = cinfo + ncan, *cand, *copy;
116 msg(
"FRQS: frqs_clone_ids '%s' -- input",1,cinfo);
118 if (2*(ncan) != clen || ncan >=
MAXFREQ/2) {
119 msg(
"Clone string length issues (%d is not 2*%d or > %d)", 3,
124 havechid = (cond_start->
chid_rf[0] != 0.0) ? 1 : 0;
125 mclen = strlen(master);
128 if (strlen(cond_start->
chid) != mclen) {
129 msg(
"chan_ids was used but illegally (%d != %d, cannot clone", 3,
130 strlen(cond_start->
chid), mclen);
136 for (ii = 0, cand = cinfo; cand - cinfo < ncan; cand++) {
137 copy = strchr(master, *cand);
139 msg(
"clone candidate %c not in code list, cannot clone", 3, cand);
142 ndx[ii++] = copy - master;
147 if (havechid && strchr(master, *cand)) {
148 msg(
"clone alias %c is already used, cannot clone", 3, cand);
151 if (!strchr(fchars, *cand)) {
152 msg(
"clone code %c is not legal, cannot clone", 3, cand);
156 for (ii = 0; ii < ncan; ii++) {
159 cond_start->
clones[0][ii] = cinfo[ii];
160 if (havechid && mclen <
MAXFREQ) {
164 msg(
"No more room for codes starting with %c", 3,
clones[ii]);
171 cond_start->
chid[kk+1] = master[kk+1] = 0;
172 msg(
"short master code path %d\n%s: of %s (freq %f)", 1,
177 msg(
"64 fcodes in use, but clone label not found", 3);
183 msg(
"long master code path %d\n%s: of %s (freq %f)", 1,
186 msg(
"found %d for %c", 1, kk,
clones[ii]);
189 ?
"clone %c (%c -> %c) at address %d (->%d), freqs %f -> %f"
190 :
"clone %c (%c -> %c) at master address %d (->%d)",
191 1, master[kk],
clones[ii], cinfo[ii], kk, ndx[ii],
197 cond_start->
clones[1][ii] = cond_start->
clones[0][ii] =
'\0';
199 msg(
"FRQS: (master) fcode set is now %s with %s -> %s", 1,
201 frqs_clone_clones(cond_start, havechid);
206 static int frqs_CHAN_PARAM(
int toknum)
217 static int frqs_new_codes(
char *parsed_codes,
char *master,
220 static char *temp_codes, sblabels[] = {
'D',
'+',
'-' };
221 struct c_block *cb_start, *cb_ptr, *cb_tail;
222 int fc, nc, pp, tt, xx, len, sideband, sbndx, one;
224 temp_codes = calloc((len = strlen(parsed_codes))+8, 1);
225 if (!temp_codes) { perror(
"malloc");
return(-1); }
226 strcpy(temp_codes, parsed_codes);
227 memset(parsed_codes, 0,
MAXFREQ);
228 msg(
"FRQS: frqs_old_codes: '%s' with %d (cond_start: %p)", 1,
229 temp_codes, len, cond_start);
230 for (pp = tt = 0; tt < len; tt++) {
231 if (temp_codes[tt] ==
'~') {
233 one = (temp_codes[tt-1] ==
'+' || temp_codes[tt-1] ==
'-') ? 2 : 1;
235 fc =
fcode(temp_codes[tt-one], master);
237 msg(
"FRQS: bogus ~ channel expansion after '%c'", 3,
242 nc =
fcode(temp_codes[tt+1], master);
244 msg(
"FRQS: bogus ~ channel expansion before '%c'", 3,
249 parsed_codes[pp++] = master[fc];
251 msg(
"FRQS: %c accept_sbs[%d] = %d (sideband %c)", 1,
252 master[fc], fc, sideband, sblabels[0]);
253 for (cb_ptr=cond_start; cb_ptr!=NULL;
260 if (temp_codes[tt+1] ==
'+') { sideband =
USB; sbndx = 1; }
261 else if (temp_codes[tt+1] ==
'-') { sideband =
LSB; sbndx = 2; }
262 else { sideband =
DSB; sbndx = 0; }
264 fc =
fcode(temp_codes[tt], master);
265 if (fc >= 0) parsed_codes[pp++] = master[fc];
266 else msg(
"FRQS: bad freq code '%c'(%d)", 3,
267 temp_codes[tt], sbndx=-1);
268 if (sbndx > 0) { parsed_codes[pp++] = sblabels[sbndx]; tt++; }
269 if (sbndx < 0)
return(-4);
272 msg(
"FRQS: %c accept_sbs[%d] = %d (sideband %c)", 1,
273 master[fc], fc, sideband, sblabels[sbndx]);
274 for (cb_ptr=cond_start; cb_ptr!=NULL; cb_ptr=cb_ptr->
cb_chain)
279 len = strlen(parsed_codes);
281 ?
"FRQS: frqs_new_codes: '%s' with %d"
282 :
"FRQS: frqs_exp_codes: '%s' with %d",
283 1, parsed_codes, len);
288 static char *frqs_expand_codes(
char *cf_chan_string,
char *master)
290 char *newchans = calloc(268, 1);
291 msg(
"FRQS: frqs_expand_codes: '%s' (%d) -- input",1,
292 cf_chan_string, strlen(cf_chan_string));
293 strncpy(newchans, cf_chan_string, 256);
294 if (frqs_new_codes(newchans, master, NULL)) {
298 msg(
"FRQS: frqs_expand_codes: '%s' -- output",1,newchans);
303 static int frqs_display_chans(
char *chans,
char *master,
307 char *atskip = strchr(chans,
'@');
309 msg(
"FRQS: frqs_display_chans: '%s' '%s' -- input",1,
310 chans, atskip ? atskip :
"");
311 if (atskip) *atskip = 0;
312 expcodes = frqs_expand_codes(chans, master);
314 msg (
"problem expanding display_chans %s",3, chans);
317 if (atskip) { *atskip =
'@'; strcat(expcodes, atskip); }
318 for (cb_ptr=cond_start; cb_ptr!=NULL; cb_ptr=cb_ptr->
cb_chain)
320 msg(
"FRQS: frqs_display_chans: '%s' -- output",1, expcodes);
char chid[MAXFREQ+1]
Definition: control.h:108
char chan_notches[MAXNOTCH+1]
Definition: control.h:89
#define LSB
Definition: control.h:140
char clones[2][MAXFREQ/2+1]
Definition: control.h:110
#define USB
Definition: control.h:139
#define FCHARS
Definition: control.h:166
char display_chans[MAXFREQ+5]
Definition: control.h:112
int nnotches
Definition: control.h:87
#define DSB
Definition: control.h:141
#define MAXNOTCH
Definition: control.h:8
double chid_rf[MAXFREQ]
Definition: control.h:109
int accept_sbs[MAXFREQ]
Definition: control.h:42
struct c_block * cb_chain
Definition: control.h:24
char progname[]
Definition: msg.c:3
void msg(const char *string, int level,...)
Definition: msg.c:25
int token_cat[MAX_TOKENS]
Definition: parse_control_file.c:23
int fcode(char c, char *codes)
Definition: parser.c:113
#define MAX_TOKENS
Definition: parser.h:169
#define CHAN_PARAM
Definition: parser.h:195
#define MAXFREQ
Definition: sizelimits.h:1