=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/radioctl/radioctl.c,v retrieving revision 1.11 retrieving revision 1.12 diff -c -r1.11 -r1.12 *** src/usr.bin/radioctl/radioctl.c 2005/07/28 17:15:11 1.11 --- src/usr.bin/radioctl/radioctl.c 2005/12/05 16:30:24 1.12 *************** *** 1,4 **** ! /* $OpenBSD: radioctl.c,v 1.11 2005/07/28 17:15:11 robert Exp $ */ /* $RuOBSD: radioctl.c,v 1.4 2001/10/20 18:09:10 pva Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: radioctl.c,v 1.12 2005/12/05 16:30:24 robert Exp $ */ /* $RuOBSD: radioctl.c,v 1.4 2001/10/20 18:09:10 pva Exp $ */ /* *************** *** 29,34 **** --- 29,36 ---- #include #include + #include + #include #include #include *************** *** 54,61 **** #define OPTION_MONO 0x05 "stereo", #define OPTION_STEREO 0x06 ! "sensitivity" #define OPTION_SENSITIVITY 0x07 }; #define OPTION_NONE ~0u --- 56,67 ---- #define OPTION_MONO 0x05 "stereo", #define OPTION_STEREO 0x06 ! "sensitivity", #define OPTION_SENSITIVITY 0x07 + "channel", + #define OPTION_CHANNEL 0x08 + "chnlset" + #define OPTION_CHNLSET 0x09 }; #define OPTION_NONE ~0u *************** *** 71,76 **** --- 77,98 ---- u_int32_t value; }; + struct chansets { + int value; + char *name; + } chansets[] = { + { CHNLSET_NABCST, "nabcst", }, + { CHNLSET_CABLEIRC, "cableirc", }, + { CHNLSET_CABLEHRC, "cablehrc", }, + { CHNLSET_WEUROPE, "weurope", }, + { CHNLSET_JPNBCST, "jpnbcst", }, + { CHNLSET_JPNCABLE, "jpncable", }, + { CHNLSET_XUSSR, "xussr", }, + { CHNLSET_AUSTRALIA, "australia", }, + { CHNLSET_FRANCE, "france", }, + { 0, NULL } + }; + extern char *__progname; const char *onchar = "on"; #define ONCHAR_LEN 2 *************** *** 78,90 **** #define OFFCHAR_LEN 3 struct radio_info ri; int parse_opt(char *, struct opt_t *); ! void print_vars(int); void do_ioctls(int, struct opt_t *, int); ! void print_value(int); void change_value(const struct opt_t); void update_value(int, int *, int); --- 100,113 ---- #define OFFCHAR_LEN 3 struct radio_info ri; + unsigned int i = 0; int parse_opt(char *, struct opt_t *); ! void print_vars(int, int); void do_ioctls(int, struct opt_t *, int); ! void print_value(int, int); void change_value(const struct opt_t); void update_value(int, int *, int); *************** *** 111,116 **** --- 134,140 ---- int rd = -1; int optchar; int show_vars = 0; + int show_choices = 0; int silent = 0; int mode = O_RDONLY; *************** *** 121,127 **** if (radiodev == NULL) radiodev = RADIODEVICE; ! while ((optchar = getopt(argc, argv, "af:nw")) != -1) { switch (optchar) { case 'a': show_vars = 1; --- 145,151 ---- if (radiodev == NULL) radiodev = RADIODEVICE; ! while ((optchar = getopt(argc, argv, "af:nvw")) != -1) { switch (optchar) { case 'a': show_vars = 1; *************** *** 132,137 **** --- 156,164 ---- case 'n': silent = 1; break; + case 'v': + show_choices = 1; + break; case 'w': /* backwards compatibility */ break; *************** *** 162,168 **** err(1, "RIOCGINFO"); if (!argc && show_vars) ! print_vars(silent); else if (argc > 0 && !show_vars) { if (mode == O_RDWR) { for(; argc--; argv++) --- 189,195 ---- err(1, "RIOCGINFO"); if (!argc && show_vars) ! print_vars(silent, show_choices); else if (argc > 0 && !show_vars) { if (mode == O_RDWR) { for(; argc--; argv++) *************** *** 173,179 **** if (parse_opt(*argv, &opt)) { show_verbose(varname[opt.option], silent); ! print_value(opt.option); free(opt.string); putchar('\n'); } --- 200,206 ---- if (parse_opt(*argv, &opt)) { show_verbose(varname[opt.option], silent); ! print_value(opt.option, show_choices); free(opt.string); putchar('\n'); } *************** *** 190,198 **** usage(void) { fprintf(stderr, ! "usage: %s [-f file] [-n] variable ...\n" " %s [-f file] [-n] variable=value ...\n" ! " %s [-f file] [-n] -a\n", __progname, __progname, __progname); exit(1); } --- 217,225 ---- usage(void) { fprintf(stderr, ! "usage: %s [-f file] [-nv] variable ...\n" " %s [-f file] [-n] variable=value ...\n" ! " %s [-f file] [-nv] -a\n", __progname, __progname, __progname); exit(1); } *************** *** 227,233 **** if (!silent) printf("%s: ", varname[oval]); ! print_value(o->option); printf(" -> "); if (o->option == OPTION_SEARCH) { --- 254,260 ---- if (!silent) printf("%s: ", varname[oval]); ! print_value(o->option, 0); printf(" -> "); if (o->option == OPTION_SEARCH) { *************** *** 252,258 **** return; } ! print_value(o->option); putchar('\n'); } --- 279,285 ---- return; } ! print_value(o->option, 0); putchar('\n'); } *************** *** 294,299 **** --- 321,332 ---- case OPTION_MUTE: ri.mute = o.value; break; + case OPTION_CHANNEL: + update_value(o.sign, &ri.chan, o.value); + break; + case OPTION_CHNLSET: + ri.chnlset = o.value; + break; } if (unsupported) *************** *** 369,375 **** const char *badvalue = "bad value `%s'"; char *topt = NULL; int slen, optlen; ! if (s == NULL || *s == '\0' || o == NULL) return 0; --- 402,408 ---- const char *badvalue = "bad value `%s'"; char *topt = NULL; int slen, optlen; ! if (s == NULL || *s == '\0' || o == NULL) return 0; *************** *** 407,412 **** --- 440,460 ---- o->string = topt; topt = &s[optlen]; + + if (strcmp(o->string, "chnlset") == 0) { + for (i = 0; chansets[i].name; i++) + if (strncmp(chansets[i].name, topt, + strlen(chansets[i].name)) == 0) + break; + if (chansets[i].name != NULL) { + o->value = chansets[i].value; + return 1; + } else { + warnx(badvalue, topt); + return 0; + } + } + switch (*topt) { case '+': case '-': *************** *** 447,453 **** * Print current value of the parameter. */ void ! print_value(int optval) { if (optval == OPTION_NONE) return; --- 495,501 ---- * Print current value of the parameter. */ void ! print_value(int optval, int show_choices) { if (optval == OPTION_NONE) return; *************** *** 473,478 **** --- 521,541 ---- case OPTION_STEREO: printf(ri.stereo ? onchar : offchar); break; + case OPTION_CHANNEL: + printf("%u", ri.chan); + break; + case OPTION_CHNLSET: + for (i = 0; chansets[i].name; i++) { + if (chansets[i].value == ri.chnlset) + printf("%s", chansets[i].name); + } + if (show_choices) { + printf("\n\t["); + for (i = 0; chansets[i].name; i++) + printf("%s ", chansets[i].name); + printf("]"); + } + break; case OPTION_VOLUME: default: printf("%u", ri.volume); *************** *** 505,513 **** * Print all available parameters */ void ! print_vars(int silent) { show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent); show_float_val((float)ri.freq / 1000., varname[OPTION_FREQUENCY], "MHz", silent); show_char_val(ri.mute ? onchar : offchar, varname[OPTION_MUTE], silent); --- 568,587 ---- * Print all available parameters */ void ! print_vars(int silent, int show_choices) { show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent); + show_int_val(ri.chan, varname[OPTION_CHANNEL], "", silent); + for (i = 0; chansets[i].name; i++) { + if (chansets[i].value == ri.chnlset) + show_char_val(chansets[i].name, varname[OPTION_CHNLSET], silent); + } + if (show_choices) { + printf("\t[ "); + for (i = 0; chansets[i].name; i++) + printf("%s ", chansets[i].name); + printf("]\n"); + } show_float_val((float)ri.freq / 1000., varname[OPTION_FREQUENCY], "MHz", silent); show_char_val(ri.mute ? onchar : offchar, varname[OPTION_MUTE], silent);