common.c File Reference

Implementations for bare-necessities FASTlib programming in C. More...

Include dependency graph for common.c:

Go to the source code of this file.

Functions

void fl_abort (void)
 Terminates with an error, flushing all streams.
void fl_pause (void)
 Waits for the user to press return.
void fl_print_fatal_msg (const char *file, const char *func, int line, const char *format,...)
 Implementation for FATAL.
void fl_print_msg (const char *file, const char *func, int line, fl_msg_t msg_type, const char *format,...)
 Implementation for NONFATAL, NOTIFY_STAR, and NOTIFY.
void fl_print_msg_header (char marker, const char *color)
 Prints a colored message header.
void fl_print_msg_loc (const char *file, const char *func, int line)
 Print a location in code.
void fl_print_progress (const char *desc, int prec)
 Prints a progress bar using ANSI commands to stay in place.
void hex_to_stream (FILE *stream, const char *src, const char *ok_char)
 Writes a string to a stream, converting non-alphanumeric characters other than those found in ok_char to format 'XX', where XX is the hexadecimal ASCII value.
char * hex_to_string (char *dest, const char *src, const char *ok_char)
 Writes a source string to a given destination, converting non-alphanumeric characters other than those found in ok_char to format 'XX', where XX is the hexadecimal ASCII value.
char * unhex_in_place (char *str)
 Replaces substrings 'XX' with the ASCII character represented by hexadecimal XX.

Variables

int abort_on_nonfatal = 0
 Whether to treat nonfatal warnings as fatal.
const char * fl_msg_color []
 Default colors for FASTlib message markers.
char fl_msg_marker [] = {'X', '!', '*', '.'}
 Default markers for FASTlib messages.
int pause_on_nonfatal = 0
 Whether to wait for user input after nonfatal warnings.
int print_notify_locs = 0
 Whether to print call locations for notifications.
int segfault_on_abort = 0
 Whether to segfault instead of calling C's abort().

Detailed Description

Implementations for bare-necessities FASTlib programming in C.

Definition in file common.c.


Function Documentation

void fl_abort ( void   ) 

Terminates with an error, flushing all streams.

Behavior adjustable with segfault_on_abort, which may be handy for valgrind or other debuggers.

Definition at line 52 of file common.c.

References segfault_on_abort.

Referenced by fl_print_fatal_msg(), and fl_print_msg().

void fl_pause ( void   ) 

Waits for the user to press return.

This function will obliterate anything in the stdin buffer.

Definition at line 61 of file common.c.

Referenced by fl_print_msg().

void fl_print_fatal_msg ( const char *  file,
const char *  func,
int  line,
const char *  format,
  ... 
)

Implementation for FATAL.

Definition at line 92 of file common.c.

References fl_abort(), fl_msg_color, fl_msg_marker, fl_print_msg_header(), and fl_print_msg_loc().

void fl_print_msg ( const char *  file,
const char *  func,
int  line,
fl_msg_t  msg_type,
const char *  format,
  ... 
)

Implementation for NONFATAL, NOTIFY_STAR, and NOTIFY.

Definition at line 110 of file common.c.

References abort_on_nonfatal, fl_abort(), fl_msg_color, fl_msg_marker, fl_pause(), fl_print_msg_header(), fl_print_msg_loc(), pause_on_nonfatal, and print_notify_locs.

void fl_print_msg_header ( char  marker,
const char *  color 
)

Prints a colored message header.

Definition at line 73 of file common.c.

Referenced by fl_print_fatal_msg(), and fl_print_msg().

void fl_print_msg_loc ( const char *  file,
const char *  func,
int  line 
)

Print a location in code.

Definition at line 78 of file common.c.

Referenced by fl_print_fatal_msg(), and fl_print_msg().

void fl_print_progress ( const char *  name,
int  perc 
)

Prints a progress bar using ANSI commands to stay in place.

For proper formatting, desc should be 22 characters or fewer and the program should avoid output of other text while emitting a progress bar. When finished with a progress bar, emit a newline ('
') to keep the bar on screen or a line of spaces followed by a carriage return ('') to clear it.

Parameters:
name printed next to the progress bar; max 22 characters
perc percentage of bar filled; should range from 0 to 100

Definition at line 135 of file common.c.

void hex_to_stream ( FILE *  stream,
const char *  src,
const char *  ok_char 
)

Writes a string to a stream, converting non-alphanumeric characters other than those found in ok_char to format 'XX', where XX is the hexadecimal ASCII value.

Parameters:
stream an output stream
src the string to be written, hexed
ok_char characters not converted to 'XX'

Definition at line 166 of file common.c.

Referenced by datanode_write().

char* hex_to_string ( char *  dest,
const char *  src,
const char *  ok_char 
)

Writes a source string to a given destination, converting non-alphanumeric characters other than those found in ok_char to format 'XX', where XX is the hexadecimal ASCII value.

The destination is assumed large enough to store the hexed string, which may at most tripple in size. The destination should not overlap with the source.

Parameters:
dest a memory location to receive the copy
src the string to be copied, hexed
ok_char characters not converted to 'XX'
Returns:
a pointer to the null-character terminating dest

Definition at line 179 of file common.c.

char* unhex_in_place ( char *  str  ) 

Replaces substrings 'XX' with the ASCII character represented by hexadecimal XX.

Percent signs with non-hexadecimal trailing characters are unchanged.

This function may be paired with fgets or other stream input to invert the hex_to_stream operation.

Parameters:
str the string to be modified
Returns:
a pointer to the null-character terminating str

Definition at line 196 of file common.c.

Referenced by datanode_read().


Variable Documentation

Whether to treat nonfatal warnings as fatal.

Definition at line 44 of file common.c.

Referenced by fl_print_msg().

const char* fl_msg_color[]
Initial value:
  {ANSI_HRED, ANSI_YELLOW, ANSI_HGREEN, ANSI_HBLUE}

Default colors for FASTlib message markers.

Definition at line 49 of file common.c.

Referenced by fl_print_fatal_msg(), and fl_print_msg().

char fl_msg_marker[] = {'X', '!', '*', '.'}

Default markers for FASTlib messages.

Definition at line 48 of file common.c.

Referenced by fl_print_fatal_msg(), and fl_print_msg().

Whether to wait for user input after nonfatal warnings.

Definition at line 45 of file common.c.

Referenced by fl_print_msg().

Whether to print call locations for notifications.

Definition at line 46 of file common.c.

Referenced by fl_print_msg().

Whether to segfault instead of calling C's abort().

Definition at line 43 of file common.c.

Referenced by fl_abort().

Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3