picointernal.h

Go to the documentation of this file.
00001 /* -----------------------------------------------------------------------------
00002 
00003  PicoModel Library
00004 
00005  Copyright (c) 2002, Randy Reddig & seaw0lf
00006  All rights reserved.
00007 
00008  Redistribution and use in source and binary forms, with or without modification,
00009  are permitted provided that the following conditions are met:
00010 
00011  Redistributions of source code must retain the above copyright notice, this list
00012  of conditions and the following disclaimer.
00013 
00014  Redistributions in binary form must reproduce the above copyright notice, this
00015  list of conditions and the following disclaimer in the documentation and/or
00016  other materials provided with the distribution.
00017 
00018  Neither the names of the copyright holders nor the names of its contributors may
00019  be used to endorse or promote products derived from this software without
00020  specific prior written permission.
00021 
00022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00026  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00027  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00029  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 
00033  ----------------------------------------------------------------------------- */
00034 
00035 /* marker */
00036 #ifndef PICOINTERNAL_H
00037 #define PICOINTERNAL_H
00038 
00039 #ifdef __cplusplus
00040 extern "C"
00041 {
00042 #endif
00043 
00044     /* dependencies */
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <stdarg.h>
00048 #include <string.h>
00049 #include <ctype.h>
00050 #include <math.h>
00051 
00052 #include "picomodel.h"
00053 
00054     /* os dependent replacements */
00055 #if defined(WIN32)
00056 #define _pico_stricmp stricmp
00057 #define _pico_strnicmp strnicmp
00058 #else
00059 #define _pico_stricmp strcasecmp
00060 #define _pico_strnicmp strncasecmp
00061 #endif
00062 
00063     /* constants */
00064 #define PICO_PI 3.14159265358979323846
00065 
00066 #define PICO_SEEK_SET    0
00067 #define PICO_SEEK_CUR    1
00068 #define PICO_SEEK_END    2
00069 
00070 #define PICO_IOEOF  1
00071 #define PICO_IOERR  2
00072 
00073     /* types */
00074     typedef struct picoParser_s
00075     {
00076             char *buffer;
00077             int bufSize;
00078             char *token;
00079             int tokenSize;
00080             int tokenMax;
00081             char *cursor;
00082             char *max;
00083             int curLine;
00084     } picoParser_t;
00085 
00086     typedef struct picoMemStream_s
00087     {
00088             picoByte_t *buffer;
00089             int bufSize;
00090             picoByte_t *curPos;
00091             int flag;
00092     } picoMemStream_t;
00093 
00094     /* variables */
00095     extern const picoModule_t *picoModules[];
00096 
00097     extern void *(*_pico_ptr_malloc) (size_t);
00098     extern void (*_pico_ptr_free) (void*);
00099     extern void (*_pico_ptr_load_file) (char*, unsigned char**, int*);
00100     extern void (*_pico_ptr_free_file) (void*);
00101     extern void (*_pico_ptr_print) (int, const char*);
00102 
00103     /* prototypes */
00104 
00105     /* memory */
00106     void *_pico_alloc (size_t size);
00107     void *_pico_calloc (size_t num, size_t size);
00108     void *_pico_realloc (void **ptr, size_t oldSize, size_t newSize);
00109     char *_pico_clone_alloc (const char *str);
00110     void _pico_free (void *ptr);
00111 
00112     /* files */
00113     void _pico_load_file (char *name, unsigned char **buffer, int *bufSize);
00114     void _pico_free_file (void *buffer);
00115 
00116     /* strings */
00117     void _pico_first_token (char *str);
00118     char *_pico_strltrim (char *str);
00119     char *_pico_strrtrim (char *str);
00120     int _pico_strchcount (char *str, int ch);
00121     void _pico_printf (int level, const char *format, ...);
00122     const char *_pico_stristr (const char *str, const char *substr);
00123     void _pico_unixify (char *path);
00124     int _pico_nofname (const char *path, char *dest, int destSize);
00125     const char *_pico_nopath (const char *path);
00126     char *_pico_setfext (char *path, const char *ext);
00127     int _pico_getline (char *buf, int bufsize, char *dest, int destsize);
00128     char *_pico_strlwr (char *str);
00129 
00130     /* vectors */
00131     void _pico_zero_bounds (picoVec3_t mins, picoVec3_t maxs);
00132     void _pico_expand_bounds (picoVec3_t p, picoVec3_t mins, picoVec3_t maxs);
00133     void _pico_zero_vec (picoVec3_t vec);
00134     void _pico_zero_vec2 (picoVec2_t vec);
00135     void _pico_zero_vec4 (picoVec4_t vec);
00136     void _pico_set_vec (picoVec3_t v, float a, float b, float c);
00137     void _pico_set_vec4 (picoVec4_t v, float a, float b, float c, float d);
00138     void _pico_set_color (picoColor_t c, int r, int g, int b, int a);
00139     void _pico_copy_color (picoColor_t src, picoColor_t dest);
00140     void _pico_copy_vec (picoVec3_t src, picoVec3_t dest);
00141     void _pico_copy_vec2 (picoVec2_t src, picoVec2_t dest);
00142     picoVec_t _pico_normalize_vec (picoVec3_t vec);
00143     void _pico_add_vec (picoVec3_t a, picoVec3_t b, picoVec3_t dest);
00144     void _pico_subtract_vec (picoVec3_t a, picoVec3_t b, picoVec3_t dest);
00145     picoVec_t _pico_dot_vec (picoVec3_t a, picoVec3_t b);
00146     void _pico_cross_vec (picoVec3_t a, picoVec3_t b, picoVec3_t dest);
00147     picoVec_t _pico_calc_plane (picoVec4_t plane, picoVec3_t a, picoVec3_t b, picoVec3_t c);
00148     void _pico_scale_vec (picoVec3_t v, float scale, picoVec3_t dest);
00149     void _pico_scale_vec4 (picoVec4_t v, float scale, picoVec4_t dest);
00150 
00151     /* endian */
00152     int _pico_big_long (int src);
00153     short _pico_big_short (short src);
00154     float _pico_big_float (float src);
00155 
00156     int _pico_little_long (int src);
00157     short _pico_little_short (short src);
00158     float _pico_little_float (float src);
00159 
00160     /* pico ascii parser */
00161     picoParser_t *_pico_new_parser (picoByte_t *buffer, int bufSize);
00162     void _pico_free_parser (picoParser_t *p);
00163     int _pico_parse_ex (picoParser_t *p, int allowLFs, int handleQuoted);
00164     char *_pico_parse_first (picoParser_t *p);
00165     char *_pico_parse (picoParser_t *p, int allowLFs);
00166     void _pico_parse_skip_rest (picoParser_t *p);
00167     int _pico_parse_skip_braced (picoParser_t *p);
00168     int _pico_parse_check (picoParser_t *p, int allowLFs, char *str);
00169     int _pico_parse_checki (picoParser_t *p, int allowLFs, char *str);
00170     int _pico_parse_int (picoParser_t *p, int *out);
00171     int _pico_parse_int_def (picoParser_t *p, int *out, int def);
00172     int _pico_parse_float (picoParser_t *p, float *out);
00173     int _pico_parse_float_def (picoParser_t *p, float *out, float def);
00174     int _pico_parse_vec (picoParser_t *p, picoVec3_t out);
00175     int _pico_parse_vec_def (picoParser_t *p, picoVec3_t out, picoVec3_t def);
00176     int _pico_parse_vec2 (picoParser_t *p, picoVec2_t out);
00177     int _pico_parse_vec2_def (picoParser_t *p, picoVec2_t out, picoVec2_t def);
00178     int _pico_parse_vec4 (picoParser_t *p, picoVec4_t out);
00179     int _pico_parse_vec4_def (picoParser_t *p, picoVec4_t out, picoVec4_t def);
00180 
00181     /* pico memory stream */
00182     picoMemStream_t *_pico_new_memstream (picoByte_t *buffer, int bufSize);
00183     void _pico_free_memstream (picoMemStream_t *s);
00184     int _pico_memstream_read (picoMemStream_t *s, void *buffer, int len);
00185     int _pico_memstream_getc (picoMemStream_t *s);
00186     int _pico_memstream_seek (picoMemStream_t *s, long offset, int origin);
00187     long _pico_memstream_tell (picoMemStream_t *s);
00188 #define         _pico_memstream_eof( _pico_memstream )      ((_pico_memstream)->flag & PICO_IOEOF)
00189 #define         _pico_memstream_error( _pico_memstream )    ((_pico_memstream)->flag & PICO_IOERR)
00190 
00191 /* end marker */
00192 #ifdef __cplusplus
00193 }
00194 #endif
00195 
00196 #endif

Generated by  doxygen 1.6.2