[BACK]Return to radioctl.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / radioctl

Diff for /src/usr.bin/radioctl/radioctl.c between version 1.7 and 1.8

version 1.7, 2002/01/02 19:18:55 version 1.8, 2002/01/22 22:09:28
Line 77 
Line 77 
 const char *offchar = "off";  const char *offchar = "off";
 #define OFFCHAR_LEN     3  #define OFFCHAR_LEN     3
   
 static struct radio_info ri;  struct radio_info ri;
   
 static int      parse_opt(char *, struct opt_t *);  int     parse_opt(char *, struct opt_t *);
   
 static void     print_vars(int);  void    print_vars(int);
 static void     do_ioctls(int, struct opt_t *, int);  void    do_ioctls(int, struct opt_t *, int);
   
 static void     print_value(int);  void    print_value(int);
 static void     change_value(const struct opt_t);  void    change_value(const struct opt_t);
 static void     update_value(int, u_long *, u_long);  void    update_value(int, u_long *, u_long);
   
 static void     warn_unsupported(int);  void     warn_unsupported(int);
 static void     usage(void);  void    usage(void);
   
 static void     show_verbose(const char *, int);  void    show_verbose(const char *, int);
 static void     show_int_val(u_long, const char *, char *, int);  void    show_int_val(u_long, const char *, char *, int);
 static void     show_float_val(float, const char *, char *, int);  void    show_float_val(float, const char *, char *, int);
 static void     show_char_val(const char *, const char *, int);  void    show_char_val(const char *, const char *, int);
 static int      str_to_opt(const char *);  int     str_to_opt(const char *);
 static u_long   str_to_long(char *, int);  u_long  str_to_long(char *, int);
   
 /*  /*
  * Control behavior of a FM tuner - set frequency, volume etc   * Control behavior of a FM tuner - set frequency, volume etc
Line 108 
Line 108 
   
         char *radiodev = NULL;          char *radiodev = NULL;
         int rd = -1;          int rd = -1;
   
         int optchar;          int optchar;
         char *param = NULL;  
   
         int show_vars = 0;          int show_vars = 0;
         int set_param = 0;          int set_param = 0;
         int silent = 0;          int silent = 0;
           int mode = O_RDONLY;
   
         int optv = 0;  
   
         if (argc < 2)          if (argc < 2)
                 usage();                  usage();
   
Line 125 
Line 121 
         if (radiodev == NULL)          if (radiodev == NULL)
                 radiodev = RADIODEVICE;                  radiodev = RADIODEVICE;
   
         while ((optchar = getopt(argc, argv, "af:nw:")) != -1) {          while ((optchar = getopt(argc, argv, "af:nw")) != -1) {
                 switch (optchar) {                  switch (optchar) {
                 case 'a':                  case 'a':
                         show_vars = 1;                          show_vars = 1;
                         optv = 1;  
                         break;                          break;
                 case 'f':                  case 'f':
                         radiodev = optarg;                          radiodev = optarg;
                         optv = 2;  
                         break;                          break;
                 case 'n':                  case 'n':
                         silent = 1;                          silent = 1;
                         optv = 1;  
                         break;                          break;
                 case 'w':                  case 'w':
                         set_param = 1;                          set_param = 1;
                         param = optarg;                          mode = O_RDWR;
                         optv = 2;  
                         break;                          break;
                 default:                  default:
                         usage();                          usage();
                         /* NOTREACHED */                          /* NOTREACHED */
                 }                  }
   
                 argc -= optv;  
                 argv += optv;  
         }          }
   
         rd = open(radiodev, O_RDONLY);          argc -= optind;
           argv += optind;
   
           rd = open(radiodev, mode);
         if (rd < 0)          if (rd < 0)
                 err(1, "%s open error", radiodev);                  err(1, "%s open error", radiodev);
   
         if (ioctl(rd, RIOCGINFO, &ri) < 0)          if (ioctl(rd, RIOCGINFO, &ri) < 0)
                 err(1, "RIOCGINFO");                  err(1, "RIOCGINFO");
   
         if (argc > 1)          if (!argc && show_vars && !set_param)
                 if (parse_opt(*(argv + 1), &opt)) {                  print_vars(silent);
                         show_verbose(varname[opt.option], silent);          else if (argc > 0 && !show_vars) {
                         print_value(opt.option);                  if (set_param) {
                         free(opt.string);                          for(; argc--; argv++)
                         putchar('\n');                                  if (parse_opt(*argv, &opt))
                                           do_ioctls(rd, &opt, silent);
                   } else {
                           for(; argc--; argv++)
                                   if (parse_opt(*argv, &opt)) {
                                           show_verbose(varname[opt.option],
                                               silent);
                                           print_value(opt.option);
                                           free(opt.string);
                                           putchar('\n');
                                   }
                 }                  }
           }
   
         if (set_param)  
                 if (parse_opt(param, &opt))  
                         do_ioctls(rd, &opt, silent);  
   
         if (show_vars)  
                 print_vars(silent);  
   
         if (close(rd) < 0)          if (close(rd) < 0)
                 warn("%s close error", radiodev);                  warn("%s close error", radiodev);
   
         return 0;          return 0;
 }  }
   
 static void  void
 usage(void)  usage(void)
 {  {
         fprintf(stderr, "usage:  %s [-f file] [-n] variable ...\n"          fprintf(stderr, "usage:  %s [-f file] [-n] variable ...\n"
Line 191 
Line 187 
         exit(1);          exit(1);
 }  }
   
 static void  void
 show_verbose(const char *nick, int silent)  show_verbose(const char *nick, int silent)
 {  {
         if (!silent)          if (!silent)
                 printf("%s=", nick);                  printf("%s=", nick);
 }  }
   
 static void  void
 warn_unsupported(int optval)  warn_unsupported(int optval)
 {  {
         warnx("driver does not support `%s'", varname[optval]);          warnx("driver does not support `%s'", varname[optval]);
 }  }
   
 static void  void
 do_ioctls(int fd, struct opt_t *o, int silent)  do_ioctls(int fd, struct opt_t *o, int silent)
 {  {
         int oval;          int oval;
Line 250 
Line 246 
         putchar('\n');          putchar('\n');
 }  }
   
 static void  void
 change_value(const struct opt_t o)  change_value(const struct opt_t o)
 {  {
         int unsupported = 0;          int unsupported = 0;
Line 297 
Line 293 
 /*  /*
  * Convert string to integer representation of a parameter   * Convert string to integer representation of a parameter
  */   */
 static int  int
 str_to_opt(const char *topt)  str_to_opt(const char *topt)
 {  {
         int res, toptlen, varlen, len, varsize;          int res, toptlen, varlen, len, varsize;
Line 319 
Line 315 
         return OPTION_NONE;          return OPTION_NONE;
 }  }
   
 static void  void
 update_value(int sign, u_long *value, u_long update)  update_value(int sign, u_long *value, u_long update)
 {  {
         switch (sign) {          switch (sign) {
Line 338 
Line 334 
 /*  /*
  * Convert string to unsigned integer   * Convert string to unsigned integer
  */   */
 static u_long  u_long
 str_to_long(char *str, int optval)  str_to_long(char *str, int optval)
 {  {
         u_long val;          u_long val;
Line 358 
Line 354 
  * parse string s into struct opt_t   * parse string s into struct opt_t
  * return true on success, false on failure   * return true on success, false on failure
  */   */
 static int  int
 parse_opt(char *s, struct opt_t *o) {  parse_opt(char *s, struct opt_t *o) {
         const char *badvalue = "bad value `%s'";          const char *badvalue = "bad value `%s'";
         char *topt = NULL;          char *topt = NULL;
Line 440 
Line 436 
 /*  /*
  * Print current value of the parameter.   * Print current value of the parameter.
  */   */
 static void  void
 print_value(int optval)  print_value(int optval)
 {  {
         if (optval == OPTION_NONE)          if (optval == OPTION_NONE)
Line 474 
Line 470 
         }          }
 }  }
   
 static void  void
 show_int_val(u_long val, const char *nick, char *append, int silent)  show_int_val(u_long val, const char *nick, char *append, int silent)
 {  {
         show_verbose(nick, silent);          show_verbose(nick, silent);
         printf("%lu%s\n", val, append);          printf("%lu%s\n", val, append);
 }  }
   
 static void  void
 show_float_val(float val, const char *nick, char *append, int silent)  show_float_val(float val, const char *nick, char *append, int silent)
 {  {
         show_verbose(nick, silent);          show_verbose(nick, silent);
         printf("%.2f%s\n", val, append);          printf("%.2f%s\n", val, append);
 }  }
   
 static void  void
 show_char_val(const char *val, const char *nick, int silent)  show_char_val(const char *val, const char *nick, int silent)
 {  {
         show_verbose(nick, silent);          show_verbose(nick, silent);
Line 498 
Line 494 
 /*  /*
  * Print all available parameters   * Print all available parameters
  */   */
 static void  void
 print_vars(int silent)  print_vars(int silent)
 {  {
         show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent);          show_int_val(ri.volume, varname[OPTION_VOLUME], "", silent);

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8