1 |
schoenebeck |
35 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
schoenebeck |
56 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
35 |
* * |
7 |
|
|
* This program is free software; you can redistribute it and/or modify * |
8 |
|
|
* it under the terms of the GNU General Public License as published by * |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
10 |
|
|
* (at your option) any later version. * |
11 |
|
|
* * |
12 |
|
|
* This program is distributed in the hope that it will be useful, * |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
|
|
* GNU General Public License for more details. * |
16 |
|
|
* * |
17 |
|
|
* You should have received a copy of the GNU General Public License * |
18 |
|
|
* along with this program; if not, write to the Free Software * |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
|
|
* MA 02111-1307 USA * |
21 |
|
|
***************************************************************************/ |
22 |
|
|
|
23 |
|
|
#ifndef __LSCPPARSER_H__ |
24 |
|
|
#define __LSCPPARSER_H__ |
25 |
|
|
|
26 |
|
|
#include <sys/types.h> |
27 |
|
|
#include <sys/socket.h> |
28 |
|
|
|
29 |
|
|
#include <stdlib.h> |
30 |
|
|
#include <iostream> |
31 |
|
|
#include <sstream> |
32 |
|
|
#include <string> |
33 |
|
|
|
34 |
schoenebeck |
53 |
#include "../common/global.h" |
35 |
|
|
#include "../Sampler.h" |
36 |
schoenebeck |
35 |
|
37 |
|
|
/// Will be returned by the parser in case of syntax errors. |
38 |
|
|
#define LSCP_SYNTAX_ERROR -69 |
39 |
|
|
|
40 |
schoenebeck |
53 |
using namespace LinuxSampler; |
41 |
|
|
|
42 |
schoenebeck |
35 |
/** |
43 |
|
|
* How the fill states of disk stream buffers should be reflected. |
44 |
|
|
*/ |
45 |
|
|
enum fill_response_t { |
46 |
|
|
fill_response_bytes, ///< The returned values are meant in bytes. |
47 |
|
|
fill_response_percentage ///< The returned values are meant in percentage. |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Semantic value of the lookahead symbol. |
52 |
|
|
* |
53 |
|
|
* Structure that is used by the parser to process and return values from the |
54 |
|
|
* input text. The lexical analyzer for example returns a number for |
55 |
|
|
* recognized number strings in the input text and the parser might return a |
56 |
|
|
* value for each of it's rules. |
57 |
|
|
*/ |
58 |
|
|
struct YYSTYPE { |
59 |
|
|
union { |
60 |
schoenebeck |
123 |
char Char; |
61 |
|
|
unsigned int Number; |
62 |
|
|
double Dotnum; |
63 |
|
|
fill_response_t FillResponse; |
64 |
schoenebeck |
35 |
}; |
65 |
schoenebeck |
123 |
std::string String; |
66 |
|
|
std::map<std::string,std::string> KeyValList; |
67 |
schoenebeck |
35 |
}; |
68 |
|
|
#define yystype YYSTYPE ///< For backward compatibility. |
69 |
|
|
#define YYSTYPE_IS_DECLARED ///< We tell the lexer / parser that we use our own data structure as defined above. |
70 |
|
|
|
71 |
|
|
// just symbol prototyping |
72 |
|
|
class LSCPServer; |
73 |
|
|
|
74 |
|
|
// pointer to an (reentrant) scanner / lexical analyzer |
75 |
|
|
typedef void* yyscan_t; |
76 |
|
|
|
77 |
|
|
/** |
78 |
|
|
* Parameters given to the parser on every yyparse() call. |
79 |
|
|
*/ |
80 |
|
|
struct yyparse_param_t { |
81 |
|
|
LSCPServer* pServer; |
82 |
|
|
yyscan_t pScanner; |
83 |
|
|
}; |
84 |
|
|
#define YYPARSE_PARAM yyparse_param |
85 |
|
|
|
86 |
|
|
/** |
87 |
|
|
* Prototype of the main scanner function (lexical analyzer). |
88 |
|
|
*/ |
89 |
|
|
#define YY_DECL int yylex(YYSTYPE* yylval, yyscan_t yyscanner) |
90 |
|
|
|
91 |
|
|
/** |
92 |
|
|
* Override lex's input function which just reads from stdin by default. |
93 |
|
|
* We read from a socket instead. |
94 |
|
|
*/ |
95 |
|
|
#define YY_INPUT(buf,result,max_size) \ |
96 |
|
|
errno=0; \ |
97 |
|
|
while ( (result = recv(hSession, buf, max_size, 0)) < 0 ) \ |
98 |
|
|
{ \ |
99 |
|
|
if(errno != EINTR) \ |
100 |
|
|
{ \ |
101 |
|
|
switch(errno) { \ |
102 |
|
|
case EBADF: \ |
103 |
|
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); \ |
104 |
|
|
break; \ |
105 |
|
|
case ECONNREFUSED: \ |
106 |
|
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); \ |
107 |
|
|
break; \ |
108 |
|
|
case ENOTCONN: \ |
109 |
|
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); \ |
110 |
|
|
break; \ |
111 |
|
|
case ENOTSOCK: \ |
112 |
|
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); \ |
113 |
|
|
break; \ |
114 |
|
|
case EAGAIN: \ |
115 |
|
|
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); \ |
116 |
|
|
break; \ |
117 |
|
|
case EINTR: \ |
118 |
|
|
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); \ |
119 |
|
|
break; \ |
120 |
|
|
case EFAULT: \ |
121 |
|
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); \ |
122 |
|
|
break; \ |
123 |
|
|
case EINVAL: \ |
124 |
|
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); \ |
125 |
|
|
break; \ |
126 |
|
|
case ENOMEM: \ |
127 |
|
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); \ |
128 |
|
|
break; \ |
129 |
|
|
default: \ |
130 |
|
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); \ |
131 |
|
|
break; \ |
132 |
|
|
} \ |
133 |
|
|
YY_FATAL_ERROR( "input in flex scanner failed" ); \ |
134 |
|
|
break; \ |
135 |
|
|
} \ |
136 |
|
|
errno=0; \ |
137 |
|
|
clearerr(yyin); \ |
138 |
|
|
}\ |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
#endif // __LSCPPARSER_H__ |