Debian Codegraph @

libs/picomodel/picointernal.h

raw symbols SCIP
1 /* -----------------------------------------------------------------------------
2
3 PicoModel Library
4
5 Copyright (c) 2002, Randy Reddig & seaw0lf
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10
11 Redistributions of source code must retain the above copyright notice, this list
12 of conditions and the following disclaimer.
13
14 Redistributions in binary form must reproduce the above copyright notice, this
15 list of conditions and the following disclaimer in the documentation and/or
16 other materials provided with the distribution.
17
18 Neither the names of the copyright holders nor the names of its contributors may
19 be used to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 ----------------------------------------------------------------------------- */
34
35
36
37 /* marker */
38 #ifndef PICOINTERNAL_H
39 #define PICOINTERNAL_H
40
41 #include "globaldefs.h"
42
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47
48
49 /* dependencies */
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <stdarg.h>
53 #include <string.h>
54 #include <ctype.h>
55 #include <math.h>
56
57 #include "picomodel.h"
58
59
60 /* os dependent replacements */
61 #if GDEF_OS_WINDOWS
62 #define _pico_stricmp stricmp
63 #define _pico_strnicmp strnicmp
64 #else
65 #define _pico_stricmp strcasecmp
66 #define _pico_strnicmp strncasecmp
67 #endif
68
69
70 /* constants */
71 #define PICO_PI 3.14159265358979323846
72
73 #define PICO_SEEK_SET 0
74 #define PICO_SEEK_CUR 1
75 #define PICO_SEEK_END 2
76
77 #define PICO_IOEOF 1
78 #define PICO_IOERR 2
79
80 extern const picoColor_t picoColor_white;
81
82 /* types */
83 #ifndef byte
84 typedef unsigned char byte;
85 #endif
86
87 typedef struct picoParser_s
88 {
89 const char *buffer;
90 int bufSize;
91 char *token;
92 int tokenSize;
93 int tokenMax;
94 const char *cursor;
95 const char *max;
96 int curLine;
97 }
98 picoParser_t;
99
100 typedef struct picoMemStream_s
101 {
102 const picoByte_t *buffer;
103 int bufSize;
104 const picoByte_t *curPos;
105 int flag;
106 }
107 picoMemStream_t;
108
109
110 /* variables */
111 extern const picoModule_t *picoModules[];
112
113 extern void *( *_pico_ptr_malloc )( size_t );
114 extern void ( *_pico_ptr_free )( void* );
115 extern void ( *_pico_ptr_load_file )( const char*, unsigned char**, int* );
116 extern void ( *_pico_ptr_free_file )( void* );
117 extern int ( *_pico_ptr_save_file )( const char*, const unsigned char*, int );
118 extern void ( *_pico_ptr_print )( int, const char* );
119
120
121
122 /* prototypes */
123
124 /* memory */
125 void *_pico_alloc( size_t size );
126 void *_pico_calloc( size_t num, size_t size );
127 void *_pico_realloc( void **ptr, size_t oldSize, size_t newSize );
128 char *_pico_clone_alloc( const char *str );
129 void _pico_free( void *ptr );
130
131 /* files */
132 void _pico_load_file( const char *name, unsigned char **buffer, int *bufSize );
133 void _pico_free_file( void *buffer );
134 int _pico_save_file( const char *name, const unsigned char *buffer, int bufSize );
135
136 /* strings */
137 void _pico_first_token( char *str );
138 char *_pico_strltrim( char *str );
139 char *_pico_strrtrim( char *str );
140 int _pico_strchcount( char *str, int ch );
141 void _pico_printf( int level, const char *format, ... );
142 const char *_pico_stristr( const char *str, const char *substr );
143 void _pico_unixify( char *path );
144 int _pico_nofname( const char *path, char *dest, int destSize );
145 const char *_pico_nopath( const char *path );
146 char *_pico_setfext( char *path, const char *ext );
147 int _pico_getline( char *buf, int bufsize, char *dest, int destsize );
148 char *_pico_strlwr( char *str );
149 void _pico_deduce_shadernames( picoModel_t *model );
150
151 /* vectors */
152 void _pico_zero_bounds( picoVec3_t mins, picoVec3_t maxs );
153 void _pico_expand_bounds( picoVec3_t p, picoVec3_t mins, picoVec3_t maxs );
154 void _pico_zero_vec( picoVec3_t vec );
155 void _pico_zero_vec2( picoVec2_t vec );
156 void _pico_zero_vec4( picoVec4_t vec );
157 void _pico_set_vec( picoVec3_t v, float a, float b, float c );
158 void _pico_set_vec4( picoVec4_t v, float a, float b, float c, float d );
159 void _pico_set_color( picoColor_t c, int r, int g, int b, int a );
160 void _pico_copy_color( const picoColor_t src, picoColor_t dest );
161 void _pico_copy_vec( picoVec3_t src, picoVec3_t dest );
162 void _pico_copy_vec2( picoVec2_t src, picoVec2_t dest );
163 picoVec_t _pico_normalize_vec( picoVec3_t vec );
164 void _pico_add_vec( picoVec3_t a, picoVec3_t b, picoVec3_t dest );
165 void _pico_subtract_vec( picoVec3_t a, picoVec3_t b, picoVec3_t dest );
166 picoVec_t _pico_dot_vec( picoVec3_t a, picoVec3_t b );
167 void _pico_cross_vec( picoVec3_t a, picoVec3_t b, picoVec3_t dest );
168 picoVec_t _pico_calc_plane( picoVec4_t plane, picoVec3_t a, picoVec3_t b, picoVec3_t c );
169 void _pico_scale_vec( picoVec3_t v, float scale, picoVec3_t dest );
170 void _pico_scale_vec4( picoVec4_t v, float scale, picoVec4_t dest );
171
172 /* endian */
173 int _pico_big_long( int src );
174 short _pico_big_short( short src );
175 float _pico_big_float( float src );
176
177 int _pico_little_long( int src );
178 short _pico_little_short( short src );
179 float _pico_little_float( float src );
180
181 /* pico ascii parser */
182 picoParser_t *_pico_new_parser( const picoByte_t *buffer, int bufSize );
183 void _pico_free_parser( picoParser_t *p );
184 int _pico_parse_ex( picoParser_t *p, int allowLFs, int handleQuoted );
185 char *_pico_parse_first( picoParser_t *p );
186 char *_pico_parse( picoParser_t *p, int allowLFs );
187 void _pico_parse_skip_rest( picoParser_t *p );
188 int _pico_parse_skip_braced( picoParser_t *p );
189 int _pico_parse_check( picoParser_t *p, int allowLFs, char *str );
190 int _pico_parse_checki( picoParser_t *p, int allowLFs, char *str );
191 int _pico_parse_int( picoParser_t *p, int *out );
192 int _pico_parse_int_def( picoParser_t *p, int *out, int def );
193 int _pico_parse_float( picoParser_t *p, float *out );
194 int _pico_parse_float_def( picoParser_t *p, float *out, float def );
195 int _pico_parse_vec( picoParser_t *p, picoVec3_t out );
196 int _pico_parse_vec_def( picoParser_t *p, picoVec3_t out, picoVec3_t def );
197 int _pico_parse_vec2( picoParser_t *p, picoVec2_t out );
198 int _pico_parse_vec2_def( picoParser_t *p, picoVec2_t out, picoVec2_t def );
199 int _pico_parse_vec4( picoParser_t *p, picoVec4_t out );
200 int _pico_parse_vec4_def( picoParser_t *p, picoVec4_t out, picoVec4_t def );
201
202 /* pico memory stream */
203 picoMemStream_t *_pico_new_memstream( const picoByte_t *buffer, int bufSize );
204 void _pico_free_memstream( picoMemStream_t *s );
205 int _pico_memstream_read( picoMemStream_t *s, void *buffer, int len );
206 int _pico_memstream_getc( picoMemStream_t *s );
207 int _pico_memstream_seek( picoMemStream_t *s, long offset, int origin );
208 long _pico_memstream_tell( picoMemStream_t *s );
209 #define _pico_memstream_eof( _pico_memstream ) ( ( _pico_memstream )->flag & PICO_IOEOF )
210 #define _pico_memstream_error( _pico_memstream ) ( ( _pico_memstream )->flag & PICO_IOERR )
211
212 /* end marker */
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif