Miscellaneous utilities header. More...
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
Go to the source code of this file.
Classes | |
struct | Random |
struct | Log |
LogFile. More... | |
Macros | |
#define | MAX(a, b) ((a) > (b) ? (a) : (b)) |
#define | MIN(a, b) ((a) < (b) ? (a) : (b)) |
#define | BOUND(var, min, max, name) |
#define | fatal_error(...) |
Display an error message as "FATAL_ERROR : file name : function name : line number : ..." and abort the program. More... | |
#define | error(...) |
Display an error message as "ERROR : filename : funcname : line number : ...". More... | |
#define | warn(...) |
Display a warning message as "WARNING : ... ". More... | |
#define | info(...) |
Display a message. More... | |
#define | cassio_debug(...) |
Display a message in cassio's "fenetre de rapport" . More... | |
#define | trace(...) |
trace indicate if a piece of code is visited More... | |
#define | debug(...) |
Display a debuging message as "DEBUG : ... ". More... | |
#define | log_open(l, file) |
open a log file if allowed. More... | |
#define | log_close(l) |
Close an opened log file. More... | |
#define | log_print(l, ...) |
Print into the log file. More... | |
#define | log_is_open(l) ((l)->f != NULL) |
Check if the log stream can be used. More... | |
#define | log_receive(l, title, ...) |
log a reception More... | |
#define | log_send(l, title, ...) |
log a sending More... | |
Typedefs | |
typedef struct Random | Random |
typedef struct Log | Log |
LogFile. More... | |
Functions | |
long long | real_clock (void) |
long long | cpu_clock (void) |
void | time_print (long long, bool, FILE *) |
Print time as "D:HH:MM:SS.CC". More... | |
long long | time_read (FILE *) |
read time as "D:HH:MM:SS.C". More... | |
void | time_stamp (FILE *) |
Print local time. More... | |
void | relax (int) |
sleep for t ms. More... | |
char * | format_scientific (double, const char *, char *) |
Format a value with a unit. More... | |
void | print_scientific (double, const char *, FILE *) |
Print a value with a unit. More... | |
char * | string_duplicate (const char *) |
Duplicate a string. More... | |
long long | string_to_time (const char *) |
Read time as "D:HH:MM:SS.C". More... | |
char * | string_read_line (FILE *) |
Read a line. More... | |
char * | string_copy_line (FILE *) |
void | string_to_lowercase (char *) |
Change all char of a string to lowercase. More... | |
void | string_to_uppercase (char *) |
Change all char of a string to uppercase. More... | |
int | string_to_coordinate (const char *) |
Convert the two first chars of a string into a coordinate. More... | |
char * | string_to_word (char *) |
remove spaces from a string. More... | |
bool | string_to_boolean (const char *) |
Convert a string into a boolean. More... | |
int | string_to_int (const char *, const int) |
Convert a string into an integer. More... | |
double | string_to_real (const char *, const double) |
Convert a string into a real number. More... | |
char * | parse_word (const char *, char *, unsigned int) |
Parse a word. More... | |
char * | parse_field (const char *, char *, unsigned int, char) |
Parse a field. More... | |
char * | parse_line (const char *, char *, unsigned int) |
Parse a line. More... | |
char * | parse_board (const char *, struct Board *, int *) |
Parse a board. More... | |
char * | parse_move (const char *, const struct Board *, struct Move *) |
char * | parse_game (const char *, const struct Board *, struct Line *) |
char * | parse_boolean (const char *, bool *) |
Parse a boolean. More... | |
char * | parse_int (const char *, int *) |
Parse an integer. More... | |
char * | parse_real (const char *, double *) |
Parse a real number (as a double floating point). More... | |
char * | parse_command (const char *, char *, char *, const unsigned int) |
Parse a command. More... | |
char * | parse_find (const char *, const int) |
Find a char. More... | |
char * | parse_skip_spaces (const char *) |
Skip spaces. More... | |
char * | parse_skip_word (const char *) |
Skip word. More... | |
void | path_get_dir (const char *, char *) |
Extract the directory of a file path. More... | |
char * | file_add_ext (const char *, const char *, char *) |
Add an extension to a string. More... | |
bool | is_stdin_keyboard (void) |
unsigned long long | random_get (Random *) |
Pseudo-random number generator. More... | |
void | random_seed (Random *, const unsigned long long) |
Pseudo-random number seed. More... | |
void | thread_create2 (Thread *, void *(*f)(void *), void *) |
Create a thread. More... | |
void | thread_join (Thread) |
Join a thread. More... | |
void | thread_set_cpu (Thread, int) |
Choose a single core or cpu to run on, under linux systems, to avoid context changes. More... | |
Thread | thread_self (void) |
Current thread. More... | |
static void | atomic_add (volatile unsigned long long *value, long long i) |
void | cpu (void) |
int | get_cpu_number (void) |
Get the number of cpus or cores on the machine. More... | |
Variables | |
long long(* | time_clock )(void) |
Time clock. More... | |
Miscellaneous utilities header.
#define BOUND | ( | var, | |
min, | |||
max, | |||
name | |||
) |
Constrain a variable to a range of values.
#define cassio_debug | ( | ... | ) |
Display a message in cassio's "fenetre de rapport" .
#define debug | ( | ... | ) |
Display a debuging message as "DEBUG : ... ".
#define error | ( | ... | ) |
Display an error message as "ERROR : filename : funcname : line number : ...".
#define fatal_error | ( | ... | ) |
Display an error message as "FATAL_ERROR : file name : function name : line number : ..." and abort the program.
#define info | ( | ... | ) |
Display a message.
#define log_close | ( | l | ) |
Close an opened log file.
#define log_is_open | ( | l | ) | ((l)->f != NULL) |
Check if the log stream can be used.
#define log_open | ( | l, | |
file | |||
) |
open a log file if allowed.
#define log_print | ( | l, | |
... | |||
) |
Print into the log file.
#define log_receive | ( | l, | |
title, | |||
... | |||
) |
log a reception
#define log_send | ( | l, | |
title, | |||
... | |||
) |
log a sending
#define MAX | ( | a, | |
b | |||
) | ((a) > (b) ? (a) : (b)) |
Maximum of two values
#define MIN | ( | a, | |
b | |||
) | ((a) < (b) ? (a) : (b)) |
Minimum of two values
#define trace | ( | ... | ) |
trace indicate if a piece of code is visited
#define warn | ( | ... | ) |
Display a warning message as "WARNING : ... ".
|
inlinestatic |
atomic addition
void cpu | ( | void | ) |
long long cpu_clock | ( | void | ) |
char* file_add_ext | ( | const char * | base, |
const char * | ext, | ||
char * | file | ||
) |
Add an extension to a string.
base | Base name. |
ext | Extension (.dat, .ext, .bin, etc.) |
file | Output file name. |
char* format_scientific | ( | double | v, |
const char * | unit, | ||
char * | f | ||
) |
Format a value with a unit.
v | Value to print. |
unit | Unit. |
f | Output string. |
int get_cpu_number | ( | void | ) |
Get the number of cpus or cores on the machine.
bool is_stdin_keyboard | ( | void | ) |
char* parse_board | ( | const char * | string, |
Board * | board, | ||
int * | player | ||
) |
Parse a board.
string | String to parse |
board | Board. |
player | Player to move color. |
char* parse_boolean | ( | const char * | string, |
bool * | result | ||
) |
Parse a boolean.
string | String to parse |
result | Boolean output value. |
char* parse_command | ( | const char * | string, |
char * | cmd, | ||
char * | param, | ||
const unsigned int | size | ||
) |
Parse a command.
string | String to parse. |
cmd | Output command string (first word of the input string). |
param | Output parameters (remaining of the line). |
size | cmd string capacity. |
char* parse_field | ( | const char * | string, |
char * | word, | ||
unsigned int | n, | ||
char | separator | ||
) |
Parse a field.
string | String to parse |
word | String receiving a copy of the parsed word. |
n | word string capacity. |
separator | field separator. NOTE: It is assumed that w is big enough to contains the word copy. |
char* parse_find | ( | const char * | string, |
const int | c | ||
) |
Find a char.
string | String to parse. |
c | Seeked char. |
char* parse_int | ( | const char * | string, |
int * | result | ||
) |
Parse an integer.
string | String to parse |
result | Integer output value. |
char* parse_line | ( | const char * | string, |
char * | line, | ||
unsigned int | n | ||
) |
Parse a line.
string | string to parse |
line | string receiving a copy of the parsed line. |
n | line string capacity. NOTE: It is assumed that line is big enough to contains 'n' characters. if the line to be parsed contains more than 'n' characters, only 'n' caracters will be copied, but the whole line will be parsed. |
char* parse_real | ( | const char * | string, |
double * | result | ||
) |
Parse a real number (as a double floating point).
string | String to parse. |
result | Real number (double) output value. |
char* parse_skip_spaces | ( | const char * | string | ) |
Skip spaces.
string | String to parse. |
char* parse_skip_word | ( | const char * | string | ) |
Skip word.
string | String to parse. |
char* parse_word | ( | const char * | string, |
char * | word, | ||
unsigned int | n | ||
) |
Parse a word.
string | String to parse |
word | String receiving a copy of the parsed word. |
n | word string capacity. NOTE: It is assumed that w is big enough to contains the word copy. |
void path_get_dir | ( | const char * | path, |
char * | dir | ||
) |
Extract the directory of a file path.
path | Full path. |
dir | directory part of the path. |
void print_scientific | ( | double | v, |
const char * | unit, | ||
FILE * | f | ||
) |
Print a value with a unit.
v | Value to print. |
unit | Unit. |
f | Output stream. |
unsigned long long random_get | ( | Random * | random | ) |
Pseudo-random number generator.
A good pseudo-random generator (derived from rand48 or Java's one) to set the hash codes.
random | Pseudo-Random generator state. |
void random_seed | ( | Random * | random, |
const unsigned long long | seed | ||
) |
Pseudo-random number seed.
random | Pseudo-Random generator state. |
seed | a 64-bits integer used as seed. |
long long real_clock | ( | void | ) |
void relax | ( | int | t | ) |
sleep for t ms.
t | time in ms. |
char* string_copy_line | ( | FILE * | ) |
char* string_duplicate | ( | const char * | s | ) |
Duplicate a string.
s | string to duplicate. |
char* string_read_line | ( | FILE * | f | ) |
Read a line.
Read a line from an input string. The needed memory is allocated.
f | Input stream. |
bool string_to_boolean | ( | const char * | s | ) |
Convert a string into a boolean.
Parse a string into a boolean (false/true).
s | String. |
int string_to_coordinate | ( | const char * | s | ) |
Convert the two first chars of a string into a coordinate.
s | String. |
int string_to_int | ( | const char * | s, |
const int | default_value | ||
) |
Convert a string into an integer.
Parse a string into an int.
s | String. |
default_value | default value if parsing failed. |
void string_to_lowercase | ( | char * | s | ) |
Change all char of a string to lowercase.
s | string. |
double string_to_real | ( | const char * | s, |
const double | default_value | ||
) |
Convert a string into a real number.
Parse a string into a double.
s | String. |
default_value | default value if parsing failed. |
long long string_to_time | ( | const char * | string | ) |
Read time as "D:HH:MM:SS.C".
string | Time as a string. |
void string_to_uppercase | ( | char * | s | ) |
Change all char of a string to uppercase.
s | Input string. |
char* string_to_word | ( | char * | s | ) |
remove spaces from a string.
s | string. |
void thread_create2 | ( | Thread * | thread, |
void *(*)(void *) | function, | ||
void * | data | ||
) |
Create a thread.
thread | Thread. |
function | Function to run in parallel. |
data | Data for the function. |
void thread_join | ( | Thread | thread | ) |
Join a thread.
Wait for the thread termination. this function also frees the resources allocated by a thread that has not been detached.
thread | Thread. |
Thread thread_self | ( | void | ) |
Current thread.
void thread_set_cpu | ( | Thread | , |
int | |||
) |
Choose a single core or cpu to run on, under linux systems, to avoid context changes.
void time_print | ( | long long | t, |
bool | justified, | ||
FILE * | f | ||
) |
Print time as "D:HH:MM:SS.CC".
t | Time in milliseconds. |
justified | add spaces or not before the text. |
f | Stream. |
long long time_read | ( | FILE * | f | ) |
read time as "D:HH:MM:SS.C".
f | Input stream. |
void time_stamp | ( | FILE * | f | ) |
Print local time.
f | Output stream. |
long long(* time_clock) (void) |
Time clock.
Can be set as a real_clock or a cpu_clock.