This is my personal collection of utitlity function which I am bored of to code ever and ever again. In particular this collection contains some functions I consider so fundamental (like strtrim) that I still puzzled that they are not included in the glibc.
I publish them under the LPGL to everybody. I you have an issue with this license, please contact me. I am pretty sure we will find an approriate alternative way of licensiong
Click here to download librutic
is a whitespace.
c
is a whitespace if ws
is true.c
is a identical to sep
if ws
is false.
This function is used by split()
.
str
and returns the pointer to the
first char in str
that is not a whitespace
str
or the
pointer to the end of the string. If str
already points to a white space
str
itself is returned.
str
that is not a white space or the
pointer to the end of the string. If str
already points to a character that is not a
white space than str
itself is returned.
nextWS()
and nextNonWS()
.
That means if str
points to one argument in an white space separated list
(like with command line arguments) the return value of the function points to the next one.
If nothing is left in str
a pointer to '\0' is returned.
txt
into (at most) max
segments.
The segements can be acced using the elem[]
array. The segment are cut
at whitespaces (ws=true
) or at sep
(ws=false
).elem[]
must be an array with at least max
allocated.
split()
does not allocate any memory.txt
is modified by split()
.
split()
(see above) with ws=false
.
Basically this version cuts at sep
.
split()
(see above) with ws=true
and sep
neglected. Basically this version cuts at whitespaces.
src
with all alpha-characters turned to upper case.
src
with all alpha-characters turned to lower case.
src
.
file
exists.
path
exists and if it is a directory.
path
and all its parents as required.
src
to another file nameddest
.
FILE *fp
and to stdout
.
This is useful to print diagnostic messages both to a log file and stdout.
For all files create by one instances of RutiFiles
the components
base path
and base name
are the same. Only the third individual
part differs. However, this might be more than just different extension.
The rational behind this class is the following. If one has a program which creates a couple of files
(log files, data files, result files etc.) all files belonging to one run shall be named similar
differing only by a part indicating its diffenrent contents. Thie can be achieved with this class.
Different runs shall have at least different base names
but with in a run the file
names differ only by the individual part.
RutiFiles
with empty
base path
and base name
.
RutiFiles
with
base path
and base name
given byp
and n
,
respectively.
base path
and base name
to
p
and n
, respectively.
Useful if the instance was created by the simple constructor.
file
as the individual part of the file name and in mode mode
.
file
as the individual part of the file name.
b
to the power of e
. The value of e
must be
greater zero.
b
to the power of e
. The value of e
must be
greater zero.
b
to the power of e
. The value of e
must be
greater zero.
The purpose of the class is to allocate (and free) array with multiple indices dynamically. This is implemented for up to 4 indices yet, but might extended further in future versions.
The allocation is done but allocation arrays of pointer for each index but the last. This arrays point into an array responsable for the consequitive index. Therefore arrays of this type can be used like C-style arrays with multiple indices, altough they are created dynamically. However, there is some extra memory required for the pointer arrays.
All methods in this template class are static.
n1
.
A[n1][n2]
.
static TYPE ** alloc(int n1, int n2)
but the dimesions are given in
the array *n
.
A[n1][n2][n3]
.
static TYPE ** alloc(int n1, int n2,int n3)
but the dimesions are given in
the array *n
.
A[n1][n2][n3][n4]
.
static TYPE ** alloc(int n1, int n2,int n3,int n4)
but the dimesions are given in
the array *n
.
This class is meant to measure run times of parts of your programs internally.
Time for TASK : CPUTIME CPU-seconds,REALTIME s real time
The idea of this class is to have a simple option to start multithreading of independeant tasks. Each task is defined by a class or struct an function. A thread is started by calling the function with a pointer to the class or struct as (void *) argument. The scheduler takes care that the requested amount of threads is running until all tasks are done
The class has the follwoing methods:
The task-functions must follow this definition:
typedef void * (*RutiThreadFunction) (void *);In order to use the Thread Scheduler, you must add
#include <ruti/scheduler.h>