helper.h File Reference

Just some helper functions and macros. More...

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "config.h"

Include dependency graph for helper.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define CHAR   int64_t
#define STRLEN(a)   ustrlen(a);
#define U8_LENGTH(a)
#define FLUSH
#define VPRINTF(...)   if(0<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
 Macro used for normal output.
#define WPRINTF(...)   if(1<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
 Macro used for verbose output.
#define VWPRINTF(...)   if(2<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
 Macro used for extremely verbose output.
#define CHECK_PTR(a)   if(NULL==(a)) { fprintf(stderr,"LOW MEMORY!!!\n"); exit(5); }
 Emergency exit in case of low memory.

Functions

char * getword (FILE *input, unsigned int *occurrences=NULL)
 Function that reads one word from input file.
int ustrlen (const char *arg)
 Gets one character from string.
int sgetch (CHAR *where, const char *from)

Variables

int verbose
 Global variable controlling verbosity of output.


Detailed Description

Just some helper functions and macros.


Define Documentation

#define U8_LENGTH (  ) 

Value:

( ( (*(char*)(a)) & 0b10000000 ) ?  /* More then one byte?                */ \
                        ( ( (*(char*)(a)) & 0b01000000 ) ?  /* Is this really only the beginning? */ \
                        ( ( (*(char*)(a)) & 0b00100000 ) ?  /* More then two bytes?               */ \
                        ( ( (*(char*)(a)) & 0b00010000 ) ?  /* More then three bytes?             */ \
                        ( ( (*(char*)(a)) & 0b00001000 ) ?  /* More then four bytes?              */ \
                        ( ( (*(char*)(a)) & 0b00000100 ) ?  /* More then five bytes?              */ \
                            6 : 5 )                         /* 5 or 6 bytes                       */ \
                              : 4 )                         /* 4 bytes                            */ \
                              : 3 )                         /* 3 bytes                            */ \
                              : 2 )                         /* 2 bytes                            */ \
                              :-1 )                         /* In the middle of sequence          */ \
                              : 1 )

#define VPRINTF ( ...   )     if(0<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)

Macro used for normal output.

This macro uses normal printf syntax. Only difference is, that it's executed only if program has verbosity above certain level.

See also:
verbose WPRINTF(), VWPRINTF()

Referenced by compute_stats(), evaluate(), find_it(), find_it_thread(), init_db(), print_it(), and wait_for_empty().

#define VWPRINTF ( ...   )     if(2<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)

Macro used for extremely verbose output.

This macro uses normal printf syntax. Only difference is, that it's executed only if program has verbosity above certain level.

See also:
verbose VPRINTF(), VWPRINTF()

Referenced by add_task(), bsqrs(), compute_stats(), evaluate(), expand_other_ending(), fill_squares(), find_it_thread(), for_each_segment_helper(), fsqrs(), getword(), lock_let(), print_it(), and wait_for_empty().

#define WPRINTF ( ...   )     if(1<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)

Macro used for verbose output.

This macro uses normal printf syntax. Only difference is, that it's executed only if program has verbosity above certain level.

See also:
verbose VPRINTF(), VWPRINTF()

Referenced by compute_stats(), find_it(), find_it_thread(), and print_it().


Function Documentation

char* getword ( FILE *  input,
unsigned int *  occurrences = NULL 
)

Function that reads one word from input file.

It returns pointer to that word. Be aware! This pointer points to static buffer inside the function, so you shouldn't care about it's deallocation. It's little bit weird, but I never need two words in memory, so why to bother with some allocation and deallocation ;-)

References CHECK_PTR, ISALPHA, ISBLANK, ISDIGIT, MAXWORD, numbered, and VWPRINTF.

Referenced by compute_stats(), and find_it_thread().

int ustrlen ( const char *  arg  ) 

Gets one character from string.

Reason why is this function important is utf-8. Because in case of utf-8 one character does not necessary means one byte.


Variable Documentation

int verbose

Global variable controlling verbosity of output.

It is used by outputting macros. Possible values are:

  • 0 Suppress all output.
  • 1 Normal amount of informations.
  • 2 Verbose output.
  • 3 Extremely verbose output.

See also:
VPRINTF(), WPRINTF(), VWPRINTF()

Referenced by main(), and print_it().


Generated on Sat Dec 20 11:32:18 2008 for Affisix by  doxygen 1.5.7.1