1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
|
/*
* memcsv.c - (C) Stephane Fillod 2003-2005
*
* This program exercises the backup and restore of a radio
* using Hamlib. CSV primitives
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hamlib/rig.h>
#include "misc.h"
/*
* external prototype
*/
extern int all;
char csv_sep = ','; /* CSV separator */
/*
* Prototypes
*/
static int dump_csv_chan(RIG *rig,
vfo_t vfo,
channel_t **chan,
int channel_num,
const chan_t *chan_list,
rig_ptr_t arg);
static void dump_csv_name(const channel_cap_t *mem_caps, FILE *f);
static int set_channel_data(RIG *rig,
channel_t *chan,
char **line_key,
char **line_data);
static char *mystrtok(char *s, char delim);
static int tokenize_line(char *line,
char **token_list,
size_t siz,
char delim);
static int find_on_list(char **list, const char *what);
int csv_save(RIG *rig, const char *outfilename);
int csv_load(RIG *rig, const char *infilename);
int csv_parm_save(RIG *rig, const char *outfilename);
int csv_parm_load(RIG *rig, const char *infilename);
int csv_save(RIG *rig, const char *outfilename)
{
int status;
FILE *f;
f = fopen(outfilename, "w");
if (!f)
{
return -1;
}
if (rig->caps->clone_combo_get)
{
printf("About to save data, enter cloning mode: %s\n",
rig->caps->clone_combo_get);
}
status = rig_get_chan_all_cb(rig, RIG_VFO_NONE, dump_csv_chan, f);
fclose(f);
return status;
}
/** csv_load assumes the first line in a csv file is a key line,
defining entries and their number. First line should not
contain 'empty column', i.e. two adjacent commas.
Each next line should contain the same number of entries.
However, empty columns (two adjacent commas) are allowed.
\param rig - a pointer to the rig
\param infilename - a string with a file name to write to
*/
int csv_load(RIG *rig, const char *infilename)
{
int status = RIG_OK;
FILE *f;
char *key_list[ 64 ];
char *value_list[ 64 ];
char keys[ 256 ];
char line[ 256 ];
channel_t chan;
f = fopen(infilename, "r");
if (!f)
{
return -1;
}
/* First read the first line, containing the key */
if (fgets(keys, sizeof(keys), f) != NULL)
{
/* fgets stores '\n' in a buffer, get rid of it */
keys[ strlen(keys) - 1 ] = '\0';
printf("Read the key: %s\n", keys);
/* Tokenize the key list */
if (!tokenize_line(keys,
key_list,
sizeof(key_list) / sizeof(char *),
','))
{
fprintf(stderr,
"Invalid (possibly too long or empty) key line, cannot continue.\n");
fclose(f);
return -1;
}
}
else
{
/* File exists, but is empty */
fclose(f);
return -1;
}
/* Next, read the file line by line */
while (fgets(line, sizeof line, f) != NULL)
{
/* Tokenize the line */
if (!tokenize_line(line,
value_list,
sizeof(value_list) / sizeof(char *),
','))
{
fprintf(stderr, "Invalid (possibly too long or empty) line ignored\n");
continue;
}
/* Parse a line, write channel data into chan */
set_channel_data(rig, &chan, key_list, value_list);
/* Write a rig memory */
status = rig_set_channel(rig, RIG_VFO_NONE, &chan);
if (status != RIG_OK)
{
fprintf(stderr, "rig_get_channel: error = %s \n", rigerror(status));
fclose(f);
return status;
}
}
fclose(f);
return status;
}
/** Function to break a line into a list of tokens. Delimiters are
replaced by end-of-string characters ('\0'), and a list of pointers
to thus created substrings is created.
\param line (input) - a line to be tokenized, the line will be modified!
\param token_list (output) - a resulting table containing pointers to
tokens, or NULLs (the table will be initially nulled )
all the pointers should point to addresses within the line
\param siz (input) - size of the table
\param delim (input) - delimiter character
\return number of tokens on success, 0 if \param token_list is too small to contain all the tokens,
or if line was empty.
*/
static int tokenize_line(char *line, char **token_list, size_t siz, char delim)
{
size_t i;
char *tok;
/* Erase the table */
for (i = 0; i < siz; i++)
{
token_list[i] = NULL;
}
/* Empty line passed? */
if (line == NULL)
{
return 0;
}
/* Reinitialize, find the first token */
i = 0;
tok = mystrtok(line, delim);
/* Line contains no delim */
if (tok == NULL)
{
return 0;
}
token_list[ i++ ] = tok;
/* Find the remaining tokens */
while (i < siz)
{
tok = mystrtok(NULL, delim);
/* If NULL, no more tokens left */
if (tok == NULL)
{
break;
}
/* Add token to the list */
token_list[ i++ ] = tok;
}
/* Any tokens left? */
if (i == siz)
{
return 0;
}
else
{
return i;
}
}
/** Tokenizer that handles two delimiters by returning an empty string.
First param (input) is a string to be tokenized, second is a delimiter (input)
This tokenizer accepts only one delimiter!
\param s - string to divide on first run, NULL on each next
\param delim - delimiter
\return pointer to token, or NULL if there are no more tokens
\sa "man strtok"
*/
static char *mystrtok(char *s, char delim)
{
static size_t pos = 0, length = 0;
static char *str = 0;
size_t i, ent_pos;
if (s != NULL)
{
str = s;
pos = 0;
length = strlen(str);
}
else
{
return NULL;
}
if (str && str[ pos + 1 ] == '\0')
{
return NULL;
}
ent_pos = pos;
for (i = pos; i < length;)
{
if (str[i] == delim)
{
str[i] = '\0';
pos = i + 1;
return str + ent_pos;
}
else
{
i++;
}
}
return str + ent_pos;
}
static int print_parm_name(RIG *rig,
const struct confparams *cfp,
rig_ptr_t ptr)
{
fprintf((FILE *)ptr, "%s%c", cfp->name, csv_sep);
return 1; /* process them all */
}
static int print_parm_val(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr)
{
value_t val;
FILE *f = (FILE *)ptr;
rig_get_ext_parm(rig, cfp->token, &val);
switch (cfp->type)
{
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
fprintf(f, "%d%c", val.i, csv_sep);
break;
case RIG_CONF_NUMERIC:
fprintf(f, "%f%c", val.f, csv_sep);
break;
case RIG_CONF_STRING:
fprintf(f, "%s%c", val.s, csv_sep);
break;
default:
fprintf(f, "unknown%c", csv_sep);
}
return 1; /* process them all */
}
int csv_parm_save(RIG *rig, const char *outfilename)
{
int i, ret;
FILE *f;
setting_t get_parm = all ? 0x7fffffff : STATE(rig)->has_get_parm;
f = fopen(outfilename, "w");
if (!f)
{
return -1;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rig_strparm(get_parm & rig_idx2setting(i));
if (!ms || !ms[0])
{
continue;
}
fprintf(f, "%s%c", ms, csv_sep);
}
rig_ext_parm_foreach(rig, print_parm_name, f);
fprintf(f, "\n");
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
value_t val;
setting_t parm;
parm = get_parm & rig_idx2setting(i);
ms = rig_strparm(parm);
if (!ms || !ms[0])
{
continue;
}
ret = rig_get_parm(rig, parm, &val);
if (ret != RIG_OK)
{
return ret;
}
if (RIG_PARM_IS_FLOAT(parm))
{
fprintf(f, "%f%c", val.f, csv_sep);
}
else
{
fprintf(f, "%d%c", val.i, csv_sep);
}
}
rig_ext_parm_foreach(rig, print_parm_val, f);
fprintf(f, "\n");
fclose(f);
return 0;
}
int csv_parm_load(RIG *rig, const char *infilename)
{
return -RIG_ENIMPL;
/* for every parm/ext_parm, fscanf, parse, set_parm's */
}
/* *********************** */
/* Caution! Keep the function consistent with dump_csv_chan and set_channel_data! */
void dump_csv_name(const channel_cap_t *mem_caps, FILE *f)
{
fprintf(f, "num%c", csv_sep);
if (mem_caps->bank_num)
{
fprintf(f, "bank_num%c", csv_sep);
}
if (mem_caps->channel_desc)
{
fprintf(f, "channel_desc%c", csv_sep);
}
if (mem_caps->vfo)
{
fprintf(f, "vfo%c", csv_sep);
}
if (mem_caps->ant)
{
fprintf(f, "ant%c", csv_sep);
}
if (mem_caps->freq)
{
fprintf(f, "freq%c", csv_sep);
}
if (mem_caps->mode)
{
fprintf(f, "mode%c", csv_sep);
}
if (mem_caps->width)
{
fprintf(f, "width%c", csv_sep);
}
if (mem_caps->tx_freq)
{
fprintf(f, "tx_freq%c", csv_sep);
}
if (mem_caps->tx_mode)
{
fprintf(f, "tx_mode%c", csv_sep);
}
if (mem_caps->tx_width)
{
fprintf(f, "tx_width%c", csv_sep);
}
if (mem_caps->split)
{
fprintf(f, "split%c", csv_sep);
}
if (mem_caps->tx_vfo)
{
fprintf(f, "tx_vfo%c", csv_sep);
}
if (mem_caps->rptr_shift)
{
fprintf(f, "rptr_shift%c", csv_sep);
}
if (mem_caps->rptr_offs)
{
fprintf(f, "rptr_offs%c", csv_sep);
}
if (mem_caps->tuning_step)
{
fprintf(f, "tuning_step%c", csv_sep);
}
if (mem_caps->rit)
{
fprintf(f, "rit%c", csv_sep);
}
if (mem_caps->xit)
{
fprintf(f, "xit%c", csv_sep);
}
if (mem_caps->funcs)
{
fprintf(f, "funcs%c", csv_sep);
}
if (mem_caps->ctcss_tone)
{
fprintf(f, "ctcss_tone%c", csv_sep);
}
if (mem_caps->ctcss_sql)
{
fprintf(f, "ctcss_sql%c", csv_sep);
}
if (mem_caps->dcs_code)
{
fprintf(f, "dcs_code%c", csv_sep);
}
if (mem_caps->dcs_sql)
{
fprintf(f, "dcs_sql%c", csv_sep);
}
if (mem_caps->scan_group)
{
fprintf(f, "scan_group%c", csv_sep);
}
if (mem_caps->flags)
{
fprintf(f, "flags%c", csv_sep);
}
if (mem_caps->tag)
{
fprintf(f, "tag%c", csv_sep);
}
fprintf(f, "\n");
}
/* Caution! Keep the function consistent with dump_csv_name and set_channel_data! */
int dump_csv_chan(RIG *rig,
vfo_t vfo,
channel_t **chan_pp,
int channel_num,
const chan_t *chan_list,
rig_ptr_t arg)
{
FILE *f = arg;
static channel_t chan;
static int first_time = 1;
const channel_cap_t *mem_caps = &chan_list->mem_caps;
if (first_time)
{
dump_csv_name(mem_caps, f);
first_time = 0;
}
if (*chan_pp == NULL)
{
/*
* Hamlib frontend demand application an allocated
* channel_t pointer for next round.
*/
*chan_pp = &chan;
return RIG_OK;
}
fprintf(f, "%d%c", chan.channel_num, csv_sep);
if (mem_caps->bank_num)
{
fprintf(f, "%d%c", chan.bank_num, csv_sep);
}
if (mem_caps->channel_desc)
{
fprintf(f, "%s%c", chan.channel_desc, csv_sep);
}
if (mem_caps->vfo)
{
fprintf(f, "%s%c", rig_strvfo(chan.vfo), csv_sep);
}
if (mem_caps->ant)
{
fprintf(f, "%u%c", chan.ant, csv_sep);
}
if (mem_caps->freq)
{
fprintf(f, "%"PRIfreq"%c", chan.freq, csv_sep);
}
if (mem_caps->mode)
{
fprintf(f, "%s%c", rig_strrmode(chan.mode), csv_sep);
}
if (mem_caps->width)
{
fprintf(f, "%d%c", (int)chan.width, csv_sep);
}
if (mem_caps->tx_freq)
{
fprintf(f, "%"PRIfreq"%c", chan.tx_freq, csv_sep);
}
if (mem_caps->tx_mode)
{
fprintf(f, "%s%c", rig_strrmode(chan.tx_mode), csv_sep);
}
if (mem_caps->tx_width)
{
fprintf(f, "%d%c", (int)chan.tx_width, csv_sep);
}
if (mem_caps->split)
{
fprintf(f, "%s%c", chan.split == RIG_SPLIT_ON ? "on" : "off", csv_sep);
}
if (mem_caps->tx_vfo)
{
fprintf(f, "%s%c", rig_strvfo(chan.tx_vfo), csv_sep);
}
if (mem_caps->rptr_shift)
{
fprintf(f, "%s%c", rig_strptrshift(chan.rptr_shift), csv_sep);
}
if (mem_caps->rptr_offs)
{
fprintf(f, "%d%c", (int)chan.rptr_offs, csv_sep);
}
if (mem_caps->tuning_step)
{
fprintf(f, "%d%c", (int)chan.tuning_step, csv_sep);
}
if (mem_caps->rit)
{
fprintf(f, "%d%c", (int)chan.rit, csv_sep);
}
if (mem_caps->xit)
{
fprintf(f, "%d%c", (int)chan.xit, csv_sep);
}
if (mem_caps->funcs)
{
fprintf(f, "%"PRXll"%c", chan.funcs, csv_sep);
}
if (mem_caps->ctcss_tone)
{
fprintf(f, "%u%c", chan.ctcss_tone, csv_sep);
}
if (mem_caps->ctcss_sql)
{
fprintf(f, "%u%c", chan.ctcss_sql, csv_sep);
}
if (mem_caps->dcs_code)
{
fprintf(f, "%u%c", chan.dcs_code, csv_sep);
}
if (mem_caps->dcs_sql)
{
fprintf(f, "%u%c", chan.dcs_sql, csv_sep);
}
if (mem_caps->scan_group)
{
fprintf(f, "%d%c", chan.scan_group, csv_sep);
}
if (mem_caps->flags)
{
if (chan.tag[0] != 0) // then we need the separator
{
fprintf(f, "%x%c", chan.flags, csv_sep);
}
else
{
fprintf(f, "%x", chan.flags);
}
}
if (chan.tag[0] != 0)
{
fprintf(f, "%s", chan.tag);
}
fprintf(f, "\n");
/*
* keep the same *chan_pp for next round, thanks
* to chan being static
*/
return RIG_OK;
}
/** Function to parse a line read from csv file and store the data into
appropriate fields of channel_t. The function must be consistent
with dump_csv_name and dump_csv_chan.
\param rig - a pointer to the rig
\param chan - a pointer to channel_t structure with channel data
\param line_key_list - a pointer to a table of strings with "keys"
\param line_data_list - a pointer to a table of strings with values
\return 0 on success, negative value on error
*/
int set_channel_data(RIG *rig,
channel_t *chan,
char **line_key_list,
char **line_data_list)
{
int i, j, n;
const channel_cap_t *mem_caps;
struct rig_state *rs = STATE(rig);
memset(chan, 0, sizeof(channel_t));
chan->vfo = RIG_VFO_CURR;
i = find_on_list(line_key_list, "num");
if (i < 0)
{
fprintf(stderr, "No channel number\n");
return -1;
}
n = chan->channel_num = atoi(line_data_list[ i ]);
/* find channel caps of appropriate memory group? */
for (j = 0; j < HAMLIB_CHANLSTSIZ; j++)
{
if (rs->chan_list[j].startc <= n && rs->chan_list[j].endc >= n)
{
break;
}
}
if (j == HAMLIB_CHANLSTSIZ)
{
return -RIG_EINVAL;
}
printf("Requested channel number %d, list number %d\n", n, j);
mem_caps = &rs->chan_list[j].mem_caps;
if (mem_caps->bank_num)
{
i = find_on_list(line_key_list, "bank_num");
if (i >= 0)
{
chan->bank_num = atoi(line_data_list[ i ]);
}
}
if (mem_caps->channel_desc)
{
i = find_on_list(line_key_list, "channel_desc");
if (i >= 0)
{
strncpy(chan->channel_desc, line_data_list[ i ], rig->caps->chan_desc_sz - 1);
chan->channel_desc[ rig->caps->chan_desc_sz ] = '\0';
}
}
if (mem_caps->ant)
{
i = find_on_list(line_key_list, "ant");
if (i >= 0)
{
chan->ant = atoi(line_data_list[ i ]);
}
}
if (mem_caps->freq)
{
i = find_on_list(line_key_list, "freq");
if (i >= 0)
{
chan->freq = atoi(line_data_list[ i ]);
}
}
if (mem_caps->mode)
{
i = find_on_list(line_key_list, "mode");
if (i >= 0)
{
chan->mode = rig_parse_mode(line_data_list[ i ]);
}
}
if (mem_caps->width)
{
i = find_on_list(line_key_list, "width");
if (i >= 0)
{
chan->width = atoi(line_data_list[ i ]);
}
}
if (mem_caps->tx_freq)
{
i = find_on_list(line_key_list, "tx_freq");
if (i >= 0)
{
sscanf(line_data_list[i], "%"SCNfreq, &chan->tx_freq);
}
}
if (mem_caps->tx_mode)
{
i = find_on_list(line_key_list, "tx_mode");
if (i >= 0)
{
chan->tx_mode = rig_parse_mode(line_data_list[ i ]);
}
}
if (mem_caps->tx_width)
{
i = find_on_list(line_key_list, "tx_width");
if (i >= 0)
{
chan->tx_width = atoi(line_data_list[ i ]);
}
}
if (mem_caps->split)
{
chan->split = RIG_SPLIT_OFF;
i = find_on_list(line_key_list, "split");
if (i >= 0)
{
if (strcmp(line_data_list[i], "on") == 0)
{
chan->split = RIG_SPLIT_ON;
if (mem_caps->tx_vfo)
{
i = find_on_list(line_key_list, "tx_vfo");
if (i >= 0)
{
sscanf(line_data_list[i], "%x", &chan->tx_vfo);
}
}
}
}
}
if (mem_caps->rptr_shift)
{
i = find_on_list(line_key_list, "rptr_shift");
if (i >= 0)
{
switch (line_data_list[i][0])
{
case '=':
chan->rptr_shift = RIG_RPT_SHIFT_NONE;
break;
case '+':
chan->rptr_shift = RIG_RPT_SHIFT_PLUS;
break;
case '-':
chan->rptr_shift = RIG_RPT_SHIFT_MINUS;
break;
}
if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
i = find_on_list(line_key_list, "rptr_offs");
if (i >= 0)
{
chan->rptr_offs = atoi(line_data_list[ i ]);
}
}
}
}
if (mem_caps->tuning_step)
{
i = find_on_list(line_key_list, "tuning_step");
if (i >= 0)
{
chan->tuning_step = atoi(line_data_list[ i ]);
}
}
if (mem_caps->rit)
{
i = find_on_list(line_key_list, "rit");
if (i >= 0)
{
chan->rit = atoi(line_data_list[ i ]);
}
}
if (mem_caps->xit)
{
i = find_on_list(line_key_list, "xit");
if (i >= 0)
{
chan->xit = atoi(line_data_list[ i ]);
}
}
if (mem_caps->funcs)
{
i = find_on_list(line_key_list, "funcs");
if (i >= 0)
{
sscanf(line_data_list[i], "%"SCNXll, &chan->funcs);
}
}
if (mem_caps->ctcss_tone)
{
i = find_on_list(line_key_list, "ctcss_tone");
if (i >= 0)
{
chan->ctcss_tone = atoi(line_data_list[ i ]);
}
}
if (mem_caps->ctcss_sql)
{
i = find_on_list(line_key_list, "ctcss_sql");
if (i >= 0)
{
chan->ctcss_sql = atoi(line_data_list[ i ]);
}
}
if (mem_caps->dcs_code)
{
i = find_on_list(line_key_list, "dcs_code");
if (i >= 0)
{
chan->dcs_code = atoi(line_data_list[ i ]);
}
}
if (mem_caps->dcs_sql)
{
i = find_on_list(line_key_list, "dcs_sql");
if (i >= 0)
{
chan->dcs_sql = atoi(line_data_list[ i ]);
}
}
if (mem_caps->scan_group)
{
i = find_on_list(line_key_list, "scan_group");
if (i >= 0)
{
chan->scan_group = atoi(line_data_list[ i ]);
}
}
if (mem_caps->flags)
{
i = find_on_list(line_key_list, "flags");
if (i >= 0)
{
sscanf(line_data_list[i], "%x", &chan->flags);
}
}
return 0;
}
/** Find a string on the list. Assumes the last element on the list is NULL
\param list - a list
\param what - a string to find
\return string position on the list on success,
-1 if string not found or if string is empty
*/
int find_on_list(char **list, const char *what)
{
int i = 0;
if (!what)
{
return -1;
}
if (!list[i])
{
return -1;
}
while (list[i] != NULL)
{
if (strcmp(list[i], what) == 0)
{
return i;
}
else
{
i++;
}
}
return i;
}
|