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

Diff for /src/usr.bin/mixerctl/mixerctl.c between version 1.19 and 1.20

version 1.19, 2005/02/02 08:08:33 version 1.20, 2005/02/07 14:29:10
Line 45 
Line 45 
 #include <sys/audioio.h>  #include <sys/audioio.h>
   
 #include <err.h>  #include <err.h>
   #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
   #include <limits.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 void catstr(char *, char *, char *);  
 struct field *findfield(char *);  struct field *findfield(char *);
   void adjlevel(char **, u_char *, int);
   void catstr(char *, char *, char *);
 void prfield(struct field *, char *, int);  void prfield(struct field *, char *, int);
 void rdfield(int, struct field *, char *);  void rdfield(int, struct field *, char *);
 __dead void usage(void);  __dead void usage(void);
Line 139 
Line 142 
 }  }
   
 void  void
   adjlevel(char **p, u_char *olevel, int more)
   {
           char *ep, *cp = *p;
           long inc;
           u_char level;
   
           if (*cp != '+' && *cp != '-')
                   *olevel = 0;            /* absolute setting */
   
           errno = 0;
           inc = strtol(cp, &ep, 10);
           if (*cp == '\0' || (*ep != '\0' && *ep != ',') ||
               (errno == ERANGE && (inc == LONG_MAX || inc == LONG_MIN)))
                   errx(1, "Bad number %s", cp);
           if (*ep == ',' && !more)
                   errx(1, "Too many values");
           *p = ep;
   
           if (inc < AUDIO_MIN_GAIN - *olevel)
                   level = AUDIO_MIN_GAIN;
           else if (inc > AUDIO_MAX_GAIN - *olevel)
                   level = AUDIO_MAX_GAIN;
           else
                   level = *olevel + inc;
           *olevel = level;
   }
   
   void
 rdfield(int fd, struct field *p, char *q)  rdfield(int fd, struct field *p, char *q)
 {  {
         mixer_ctrl_t *m, oldval;          mixer_ctrl_t *m, oldval;
         int v, v0, v1, mask;          int i, mask;
         int i;  
         char *s;          char *s;
   
         oldval = *p->valp;          oldval = *p->valp;
Line 161 
Line 191 
                 break;                  break;
         case AUDIO_MIXER_SET:          case AUDIO_MIXER_SET:
                 mask = 0;                  mask = 0;
                 for (v = 0; q && *q; q = s) {                  for (; q && *q; q = s) {
                         if ((s = strchr(q, ',')) != NULL)                          if ((s = strchr(q, ',')) != NULL)
                                 *s++ = 0;                                  *s++ = 0;
                         for (i = 0; i < p->infp->un.s.num_mem; i++)                          for (i = 0; i < p->infp->un.s.num_mem; i++)
Line 176 
Line 206 
                 break;                  break;
         case AUDIO_MIXER_VALUE:          case AUDIO_MIXER_VALUE:
                 if (m->un.value.num_channels == 1) {                  if (m->un.value.num_channels == 1) {
                         if (sscanf(q, "%d", &v) == 1) {                          adjlevel(&q, &m->un.value.level[0], 0);
                                 switch (*q) {  
                                 case '+':  
                                 case '-':  
                                         m->un.value.level[0] += v;  
                                         break;  
                                 default:  
                                         m->un.value.level[0] = v;  
                                         break;  
                                 }  
                         } else  
                                 errx(1, "Bad number %s", q);  
                 } else {                  } else {
                         if (sscanf(q, "%d,%d", &v0, &v1) == 2) {                          adjlevel(&q, &m->un.value.level[0], 1);
                                 switch (*q) {                          if (*q++ == ',')
                                 case '+':                                  adjlevel(&q, &m->un.value.level[1], 0);
                                 case '-':                          else
                                         m->un.value.level[0] += v0;                                  m->un.value.level[1] = m->un.value.level[0];
                                         break;  
                                 default:  
                                         m->un.value.level[0] = v0;  
                                         break;  
                                 }  
                                 s = strchr(q, ',') + 1;  
                                 switch (*s) {  
                                 case '+':  
                                 case '-':  
                                         m->un.value.level[1] += v1;  
                                         break;  
                                 default:  
                                         m->un.value.level[1] = v1;  
                                         break;  
                                 }  
                         } else if (sscanf(q, "%d", &v) == 1) {  
                                 switch (*q) {  
                                 case '+':  
                                 case '-':  
                                         m->un.value.level[0] += v;  
                                         m->un.value.level[1] += v;  
                                         break;  
                                 default:  
                                         m->un.value.level[0] = v;  
                                         m->un.value.level[1] = v;  
                                         break;  
                                 }  
                         } else  
                                 errx(1, "Bad numbers %s", q);  
                 }                  }
                 break;                  break;
         default:          default:

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20