~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to rib/ri2rib/inlineparse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Aqsis
2
 
// Copyright  1997 - 2001, Paul C. Gregory
3
 
//
4
 
// Contact: pgregory@aqsis.org
5
 
//
6
 
// This library is free software; you can redistribute it and/or
7
 
// modify it under the terms of the GNU Lesser General Public
8
 
// License as published by the Free Software Foundation; either
9
 
// version 2.1 of the License, or (at your option) any later version.
10
 
//
11
 
// This library 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 GNU
14
 
// General Public License for more details.
15
 
//
16
 
// You should have received a copy of the GNU General Public
17
 
// License along with this library; if not, write to the Free Software
18
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 
20
 
/** \file
21
 
 *  \brief A class to parse RiDeclare and inline parameter list definitions.
22
 
 *  \author Lionel J. Lacour (intuition01@online.fr)
23
 
 */
24
 
#include "inlineparse.h"
25
 
 
26
 
USING_NAMESPACE( libri2rib );
27
 
 
28
 
void CqInlineParse::check_syntax ()
29
 
{
30
 
        // number_of_words =0 ---> ERROR
31
 
        // number_of_words =1 ---> not an inline def
32
 
        // number_of_words =2 ---> type id
33
 
        // number_of_words =3 ---> class type id
34
 
        // number_of_words =4 ---> ERROR
35
 
        // number_of_words =5 ---> type [ size ] id
36
 
        // number_of_words =6 ---> class type [ size ] id
37
 
        // number_of_words =7 ---> ERROR
38
 
 
39
 
        switch ( number_of_words )
40
 
        {
41
 
                        case 0:
42
 
                        throw CqError ( RIE_SYNTAX, RIE_ERROR, "void parameter declaration", TqFalse );
43
 
                        case 4:
44
 
                        case 7:
45
 
                        throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
46
 
                        return ;
47
 
                        case 1:
48
 
                        inline_def = TqFalse;
49
 
                        break;
50
 
                        case 2:
51
 
                        lc( word[ 0 ] );
52
 
                        if ( is_type( word[ 0 ] ) == TqFalse )
53
 
                        {
54
 
                                throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
55
 
                        }
56
 
                        inline_def = TqTrue;
57
 
                        tc = UNIFORM;
58
 
                        tt = get_type( word[ 0 ] );
59
 
                        size = 1;
60
 
                        identifier = word[ 1 ];
61
 
                        break;
62
 
                        case 3:
63
 
                        lc( word[ 0 ] );
64
 
                        lc( word[ 1 ] );
65
 
                        if ( ( is_class( word[ 0 ] ) == TqFalse ) || ( is_type( word[ 1 ] ) == TqFalse ) )
66
 
                        {
67
 
                                throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
68
 
                        }
69
 
                        inline_def = TqTrue;
70
 
                        tc = get_class( word[ 0 ] );
71
 
                        tt = get_type( word[ 1 ] );
72
 
                        size = 1;
73
 
                        identifier = word[ 2 ];
74
 
                        break;
75
 
                        case 5:
76
 
                        lc( word[ 0 ] );
77
 
                        if ( ( is_type( word[ 0 ] ) == TqFalse ) || ( word[ 1 ] != "[" ) ||
78
 
                                ( is_int( word[ 2 ] ) == TqFalse ) || ( word[ 3 ] != "]" ) )
79
 
                        {
80
 
                                throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
81
 
                        }
82
 
                        inline_def = TqTrue;
83
 
                        tc = UNIFORM;
84
 
                        tt = get_type( word[ 0 ] );
85
 
                        size = get_size( word[ 2 ] );
86
 
                        identifier = word[ 4 ];
87
 
                        break;
88
 
                        case 6:
89
 
                        lc( word[ 0 ] );
90
 
                        lc( word[ 1 ] );
91
 
                        if ( ( is_class( word[ 0 ] ) == TqFalse ) || ( is_type( word[ 1 ] ) == TqFalse ) ||
92
 
                                ( word[ 2 ] != "[" ) || ( is_int( word[ 3 ] ) == TqFalse ) ||
93
 
                                ( word[ 4 ] != "]" ) )
94
 
                        {
95
 
                                throw CqError( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
96
 
                        }
97
 
                        inline_def = TqTrue;
98
 
                        tc = get_class( word[ 0 ] );
99
 
                        tt = get_type( word[ 1 ] );
100
 
                        size = get_size( word[ 3 ] );
101
 
                        identifier = word[ 5 ];
102
 
                        break;
103
 
        }
104
 
}
105
 
 
106
 
void CqInlineParse::parse ( std::string &str )
107
 
{
108
 
        TqUint i, j;
109
 
        size_t sp;
110
 
        size_t sz;
111
 
        TqBool start_found;
112
 
 
113
 
        sp = 0;
114
 
        sz = 1;
115
 
        j = 0;
116
 
        start_found = TqFalse;
117
 
 
118
 
        for ( i = 0;( i < str.length() ) && ( j < 7 );i++ )
119
 
        {
120
 
                switch ( str[ i ] )
121
 
                {
122
 
                                case ' ':
123
 
                                case '\t':
124
 
                                case '\n':
125
 
                                if ( start_found == TqTrue )
126
 
                                {
127
 
                                        word[ j ] = str.substr( sp, sz );
128
 
                                        j++;
129
 
                                        sz = 1;
130
 
                                }
131
 
                                start_found = TqFalse;
132
 
                                break;
133
 
                                case '#':
134
 
                                throw CqError( RIE_SYNTAX, RIE_ERROR, "'#' character not allowed in strings", TqTrue );
135
 
                                case '\"':
136
 
                                throw CqError( RIE_SYNTAX, RIE_ERROR, "'\"' character not allowed in strings", TqTrue );
137
 
                                case '[':
138
 
                                case ']':
139
 
                                if ( start_found == TqTrue )
140
 
                                {
141
 
                                        word[ j ] = str.substr( sp, sz );
142
 
                                        j++;
143
 
                                        start_found = TqFalse;
144
 
                                }
145
 
                                sp = i;
146
 
                                sz = 1;
147
 
                                word[ j ] = str.substr( sp, sz );
148
 
                                j++;
149
 
                                break;
150
 
                                default:
151
 
                                if ( start_found == TqTrue )
152
 
                                {
153
 
                                        sz += 1;
154
 
                                        break;
155
 
                                }
156
 
                                start_found = TqTrue;
157
 
                                sp = i;
158
 
                                sz = 1;
159
 
                }
160
 
        }
161
 
        // if there is no space at the end of the string,
162
 
        // the previous loop will not notice the end of the word,
163
 
        // and so will 'forget' to store it.
164
 
        if ( start_found == TqTrue )
165
 
        {
166
 
                word[ j ] = str.substr( sp, sz );
167
 
                j++;
168
 
        }
169
 
        number_of_words = j;
170
 
        check_syntax ();
171
 
}
172
 
 
173
 
TqBool CqInlineParse::is_class ( const std::string &str )
174
 
{
175
 
        if ( ( str == "constant" ) ||
176
 
                ( str == "uniform" ) ||
177
 
                ( str == "varying" ) ||
178
 
                ( str == "vertex" )  ||
179
 
                ( str == "facevarying") )
180
 
                return TqTrue;
181
 
        return TqFalse;
182
 
}
183
 
 
184
 
TqBool CqInlineParse::is_type ( const std::string &str )
185
 
{
186
 
        if ( ( str == "float" ) ||
187
 
                ( str == "point" ) ||
188
 
                ( str == "vector" ) ||
189
 
                ( str == "normal" ) ||
190
 
                ( str == "color" ) ||
191
 
                ( str == "string" ) ||
192
 
                ( str == "matrix" ) ||
193
 
                ( str == "hpoint" ) ||
194
 
                ( str == "integer" ) ||
195
 
                ( str == "int" ) )
196
 
                return TqTrue;
197
 
        return TqFalse;
198
 
}
199
 
 
200
 
// check if this int is >0 too
201
 
TqBool CqInlineParse::is_int ( const std::string &str )
202
 
{
203
 
        int i, j;
204
 
        i = sscanf( str.c_str(), "%d", &j );
205
 
        if ( ( i != 1 ) || ( j <= 0 ) )
206
 
                return TqFalse;
207
 
        return TqTrue;
208
 
}
209
 
 
210
 
EqTokenClass CqInlineParse::get_class ( const std::string &str )
211
 
{
212
 
        if ( str == "constant" )
213
 
                return CONSTANT;
214
 
        if ( str == "uniform" )
215
 
                return UNIFORM;
216
 
        if ( str == "varying" )
217
 
                return VARYING;
218
 
        if ( str == "vertex" )
219
 
                return VERTEX;
220
 
        if ( str == "facevarying" )
221
 
                return FACEVARYING;
222
 
        return ( CONSTANT );
223
 
}
224
 
 
225
 
EqTokenType CqInlineParse::get_type ( const std::string &str )
226
 
{
227
 
        if ( str == "float" )
228
 
                return FLOAT;
229
 
        if ( str == "point" )
230
 
                return POINT;
231
 
        if ( str == "vector" )
232
 
                return VECTOR;
233
 
        if ( str == "normal" )
234
 
                return NORMAL;
235
 
        if ( str == "color" )
236
 
                return COLOR;
237
 
        if ( str == "string" )
238
 
                return STRING;
239
 
        if ( str == "matrix" )
240
 
                return MATRIX;
241
 
        if ( str == "hpoint" )
242
 
                return HPOINT;
243
 
        if ( str == "integer" )
244
 
                return INTEGER;
245
 
        if ( str == "int" )
246
 
                return INTEGER;
247
 
        return ( FLOAT );
248
 
}
249
 
 
250
 
TqUint CqInlineParse::get_size ( const std::string &str )
251
 
{
252
 
        TqUint i;
253
 
        sscanf( str.c_str(), "%u", &i );
254
 
        return i;
255
 
}
256
 
 
257
 
void CqInlineParse::lc( std::string &str )
258
 
{
259
 
        for ( TqUint i = 0;i < str.length();i++ )
260
 
        {
261
 
                str[ i ] = tolower( str[ i ] );
262
 
        }
263
 
}