Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

gtcutils.h File Reference

Small functions, prototypes and so on needed here and there in the library. More...

#include <config.h>
#include <sys/time.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define gtc_max(a, b)   ((a)>(b)?(a):(b))
 min of a and b.

#define gtc_min(a, b)   ((a)<(b)?(a):(b))
 max of a and b.

#define gtc_must_malloc(x)   _gtc_must_malloc(x,__FILE__,__PRETTY_FUNCTION__, __LINE__)
#define gtc_free(x)   _gtc_free(x,__FILE__,__PRETTY_FUNCTION__, __LINE__)
#define GTCERROR
 Prints an error message and abort. More...

#define GTCWARN
 Print a warning message. More...

#define GTCDEBUG
 Debug message. More...

#define GTCPRINT   printf
#define GTCINFO
 Like GTCWARN but claims to be an information instead of a warning. More...

#define GTC_ASSERT_REFCOUNT(x)   ((x)->refcount>0||gtc_assert(__FILE__,__PRETTY_FUNCTION__,__LINE__,"refcount of " #x ">0"))
#define GTCASSERT(x)   ((x)||gtc_assert(__FILE__,__PRETTY_FUNCTION__,__LINE__,"(" #x ")"))
 A gtc version of assert; aborts is x is zero.

#define GTC_INCREF(x)   (x)->refcount++
#define GTC_DECREF(x, destructor)   GTC_ASSERT_REFCOUNT(x)&&((--(x)->refcount)||destructor(x))

Typedefs

typedef float gtcReal
 This was so I could easily switch to doubles if I so chose. Of course now I'd have to make big changes because of OpenGL.


Functions

double gtc_time ()
 Returns the current time in seconds.

void gtc_time_convert (double t, struct timeval *tv)
 Converts a time returned by gtc_time() to a timeval structure.

void gtc_stream_int (unsigned char *destination, int foo)
 encodes an int in a binary neutral format.

int degtc_stream_int (unsigned char *destination)
 decodes an int from the binary neutral format.

void* _gtc_must_malloc (int size, char *file, char *function, int line)
 Allocate memory, abort() if it can't find memory.

char* gtc_strdup (char *s)
 Attempts to strdup s, if it fails, abort().

void* gtc_memdup (void *buffer, int size)
void _gtc_free (void *x, char *file, char *function, int line)
void gtc_init_tokens (void)
 Search path and other configuration information for GTC. More...

char* gtc_get_token (char *id)
 Fetches a token from the configuration file.

int gtc_tokenize (char *s, char *tok, int n, int maxsize)
 Tokenize a string. More...

int gtc_count_tokens (char *s)
 Gives the number of tokens in a string.

FILE* gtc_fopen (char *filename, char *mode)
 Replacement for fopen. More...

FILE* gtc_open (char *filename, char *mode)
 Similar to fopen(). More...

int gtc_internal_error_prefix (char *file, char *function, int line, char *prefix)
int gtc_internal_error (const char *format,...)
int gtc_debug_msg (const char *format,...)
int gtc_assert (char *file, char *f, int line, char *assertion)
void gtc_init (void)
 GTC initialization. More...


Variables

int GTCDEBUGLEVEL = 0
 Set this to one if you want debug output.

const char* LEGAL
 The GPL license/disclaimer. More...

const char* gtcBuildTime = "Sat Jul 14 18:37:37 PDT 2001"
const char* gtcVersion = VER
char* (* gtcTokens )[2] = 0
 Tokens read from the configuration file, see gtc_init_tokens().

int gtcNumTokens = 0
 Total number of tokens in the configuration file.


Detailed Description

Small functions, prototypes and so on needed here and there in the library.


Define Documentation

#define GTCDEBUG
 

Value:

  GTCDEBUGLEVEL && gtc_internal_error_prefix(__FILE__, \
  __PRETTY_FUNCTION__, __LINE__, "DEBUG") && gtc_debug_msg
Debug message.

If DEBUGLEVEL is nonzero then this will print a debug message to standard out then return. Like GTCERROR, it is a single expression so it can be used in ifs without {}. It takes a variable number of parameters printf style. Also prints file, line number and function name.

#define GTCERROR
 

Value:

  gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
  __LINE__, "ERROR") && gtc_internal_error
Prints an error message and abort.

You can pass it a printf formatted string and variable number of parameters. It will printf the stuff then abort. For instance, you could do GTCERROR("no such integer i
",k); It's a single expression so it can be used without {} in ifs. Also prints file, line number and function name.

#define GTCINFO
 

Value:

  gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
  __LINE__, "INFO") && gtc_info_msg
Like GTCWARN but claims to be an information instead of a warning.

#define GTCWARN
 

Value:

  gtc_internal_error_prefix(__FILE__,__PRETTY_FUNCTION__, \
  __LINE__, "WARNING") && gtc_debug_msg
Print a warning message.

It takes a variable number of parameters, just like print, and prints a warning message to stdout, then returns. It is a single expression so it can be used in ifs without using {}. Also prints file, line number and function name.


Function Documentation

FILE * gtc_fopen ( char * filename,
char * mode )
 

Replacement for fopen.

This works exactly like fopen except that it searches for the filename first with the name as is given, then through a configuration file given path. The path in the configuration file should look like this:

path=directory1 directory2/directory3

As usual, if the file is not found, a zero is returned.

void gtc_init ( void )
 

GTC initialization.

You can call this to initialize GTC. At the moment, this call is mostly optional. All it does is set GTCDEBUGLEVEL properly. Other parts of GTC who require initialization are smart enough to initialize on the first call.

void gtc_init_tokens ( void )
 

Search path and other configuration information for GTC.

The first need for configuration files for GTC is being felt. I need to be able to search for data files in various directories, so a data file search path is needed. The functions in here will read, parse and make available configuration in a seamless fashion. You can call this before making calls to the other GTC functions. Alternately, you can just ignore it, gtc_get_token() will call it the first time you try to get a token.

A configuration file shall be as follows. Blank lines or lines beginning with # shall be ignored. All other lines shall be meaningful. A meaningful line will start with a token. Tokens are strings of characters. The = sign may not be used. Following the token, there may be whitespace or not. An equal sign shall follow. Then, the remainder of the line, including whitespace, will become the value of the token.

These will be stored in the global array gtcTokens[]. You will never write to the tokens for fear of pthread related death.

The configuration file is searched for in the following locations, in that order: the $GTC_CONFIG environment variable, ~/.gtcrc and lastly, the datadir directory (a configure-time option, by /usr/local/share by default.)

The first of these things to be a valid file will be the configuration file that is read.

If a token appears more than once in the configuration file, you will die.

At this time, lines are limited to about 18000 characters and there can't be more than 900 token definitions.

FILE * gtc_open ( char * filename,
char * mode )
 

Similar to fopen().

Does the same as gtc_fopen() but copies the actual name of the opened file onto the filename parameter. WARNING: filename parameter must be able to accomodate for 2000 characters.

int gtc_tokenize ( char * s,
char * tok,
int n,
int maxsize )
 

Tokenize a string.

Given a string, gets the nth token in the string, where tokens are separated by whitespace. Returns 0 on success, nonzero if no such token. The resulting token is put in the string pointed to by tok, up to maxsize characters, counting the terminating zero character. If the token is longer, it is truncated to length maxsize-1 and a zero terminating character is appended. If tok or maxsize is zero, the token is looked for but not copied.


Variable Documentation

const char * LEGAL
 

Initial value:

"    Sebastien Loisel's Toolchest\n"
"    Copyright (C) 1998 Sebastien Loisel\n"
"\n"
"    This software is distributed under the terms of the GNU GPL.\n"
"\n"
"    You should have received a copy of the GNU General Public\n"
"    License along with this software; if not, write to the Free\n"
"    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
The GPL license/disclaimer.


Generated at Sat Jul 14 18:53:52 2001 for GTC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001