OSDN Git Service

0.3.1; fix for pack
[android-x86/external-alsa-utils.git] / alsactl / alsactl_lexer.l
1 /*
2  *  Advanced Linux Sound Architecture Control Program
3  *  Copyright (c) 1998 by Perex, APS, University of South Bohemia
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21
22 %{
23
24 #include "alsactl.h"
25
26 struct bytearray {
27   unsigned char *data;
28   size_t datalen;
29 };
30
31 #include "alsactl_parser.h"
32
33 #define YY_NO_UNPUT
34 #undef YY_CDECL
35 #define YY_CDECL int YY_PROTO(yylex( void ));
36
37 int linecount;
38
39 %}
40
41 %%
42
43         /* special characters */
44
45 "{"|"}"                 return yytext[0];
46 "("|")"                 return yytext[0];
47 "["|"]"                 return yytext[0];
48 ")"[ \t]*"{"            return L_DOUBLE1;
49 ","                     return yytext[0];
50 "="                     return yytext[0];
51
52         /* tokens */
53
54 soundcard               return L_SOUNDCARD;
55 control                 return L_CONTROL;
56 mixer                   return L_MIXER;
57 element                 return L_ELEMENT;
58 switch                  return L_SWITCH;
59 rawdata                 return L_RAWDATA;
60 pcm                     return L_PCM;
61 rawmidi                 return L_RAWMIDI;
62 playback                return L_PLAYBACK;
63 record                  return L_RECORD;
64 output                  return L_OUTPUT;
65 input                   return L_INPUT;
66 iec958ocs               return L_IEC958OCS;
67 3d                      return L_3D;
68 reset                   return L_RESET;
69 user                    return L_USER;
70 valid                   return L_VALID;
71 data                    return L_DATA;
72 protect                 return L_PROTECT;
73 pre2                    return L_PRE2;
74 fsunlock                return L_FSUNLOCK;
75 type                    return L_TYPE;
76 gstatus                 return L_GSTATUS;
77 enable                  return L_ENABLE;
78 disable                 return L_DISABLE;
79 sw                      return L_SW;
80 mono_sw                 return L_MONO_SW;
81 wide                    return L_WIDE;
82 volume                  return L_VOLUME;
83 center                  return L_CENTER;
84 space                   return L_SPACE;
85 depth                   return L_DEPTH;
86 delay                   return L_DELAY;
87 feedback                return L_FEEDBACK;
88 bass                    return L_BASS;
89 treble                  return L_TREBLE;
90
91         /* element types */
92
93 Switch1                 return L_SWITCH1;
94 Switch2                 return L_SWITCH2;
95 Switch3                 return L_SWITCH3;
96 Volume1                 return L_VOLUME1;
97 Accu3                   return L_ACCU3;
98 Mux1                    return L_MUX1;
99 Mux2                    return L_MUX2;
100 ToneControl1            return L_TONE_CONTROL1;
101 _3D_Effect1             return L_3D_EFFECT1;
102
103         /* boolean */
104
105 false|off|no            return L_FALSE;
106 true|on|yes             return L_TRUE;
107
108         /* integers */
109
110 [0-9]+                  { yylval.i_value = atoi(yytext); return L_INTEGER; }
111 0x[0-9a-f]+             { char *end;
112                           yylval.i_value = strtol(yytext, &end, 0);
113                           return L_INTEGER; }
114
115         /* byte array */
116
117 "@"([0-9a-f]{2}:){0,31}([0-9a-f]{2})"@" {
118                           char *p = yytext + 1, x[3];
119                           unsigned char *d;
120                           int val;
121                           yylval.a_value.data = d = (unsigned char *)malloc( 32 );
122                           yylval.a_value.datalen = 0;
123                           while (p) {
124                             strncpy(x, p, 2); x[2] = '\0';
125                             sscanf(x, "%02x", &val);
126                             *d++ = val; 
127                             ++yylval.a_value.datalen;
128                           }
129                           return L_BYTEARRAY; }
130
131         /* strings */
132
133 \"[^\"]*\"              { yytext[strlen(yytext) - 1] = 0;
134                           yylval.s_value = strdup(&yytext[1]);
135                           return L_STRING; }
136 \'[^\']*\'              { yytext[strlen(yytext) - 1] = 0;
137                           yylval.s_value = strdup(&yytext[1]);
138                           return L_STRING; }
139 [a-z0-9/\~@-Za-z_]+     { yylval.s_value = strdup(yytext);
140                           return L_STRING; }
141 $[a-z0-9/\~@-Za-z_]+    { yylval.s_value = strdup(getenv(&yytext[1]));
142                           return L_STRING; }
143
144         /* comments & whitespaces */
145
146 [#\;][^\n]*\n           { linecount++; }
147 [ \t]+                  ;
148 \n                      { linecount++; }
149 .                       fprintf( stderr, "alsactl: discarding char '%c' - line %i\n", yytext[0], linecount + 1 );
150
151 %%
152
153 #ifndef yywrap
154 int yywrap(void)        /* do this avoid to do -lfl */
155 {
156   return 1;
157 }
158 #endif