This reference documents version 2.72 of the C API. <->
sprintf()
-like string.
sscanf()
.
MPDM_2MBS - Creates a multibyte string value from a wide char string.
mpdm_t MPDM_2MBS(wchar_t * wcs);
wcs | the wide char string |
Creates a multibyte string value from the wcs wide char string,
converting it by mpdm_wcstombs()
. Take note that multibyte string values
are not properly strings, so they cannot be used for string comparison
and such.
MPDM_A - Creates an array value.
mpdm_t MPDM_A(int n);
n | Number of elements |
Creates a new array value with n elements.
MPDM_C - Creates a new value with a copy of a buffer.
mpdm_t MPDM_C(mpdm_type_t type, void *ptr, int size);
type | data type |
ptr | pointer to data |
size | data size |
Create a new value with a copy of a buffer. The value will store a copy of ptr and have the specified type.
MPDM_ENS - Creates a string value from an external string, with size.
mpdm_t MPDM_ENS(wchar_t * wcs, int s);
wcs | the external wide character string |
s | the size in chars the string will hold |
Creates a new string value with size s. The wcs string must be
a dynamic value (i.e. allocated by malloc()
) that will be freed on
destruction.
MPDM_F - Creates a file value.
mpdm_t MPDM_F(FILE * f);
f | the file descriptor |
Creates a new file value.
MPDM_I - Creates an integer value.
mpdm_t MPDM_I(int i);
i | the integer |
Creates a new integer value. MPDM integers are strings.
MPDM_MBS - Creates a string value from a multibyte string.
mpdm_t MPDM_MBS(char * mbs);
mbs | the multibyte string |
Creates a new string value from a multibyte string, that will be
converted to wcs by mpdm_mbstowcs()
.
MPDM_NMBS - Creates a string value from a multibyte string, with size.
mpdm_t MPDM_NMBS(char * mbs, int s);
mbs | the multibyte string |
s | the size |
Creates a new string value with the first s characters from the mbs
multibyte string, that will be converted to wcs by mpdm_mbstowcs()
.
MPDM_NS - Creates a string value from a string, with size.
mpdm_t MPDM_NS(wchar_t * wcs, int s);
wcs | the wide character string |
s | the size in chars the string will hold |
Creates a new string value with a copy of the first s characters from the wcs string.
MPDM_O - Creates an object value.
mpdm_t MPDM_O(void);
Creates a new object value.
MPDM_R - Creates a real value.
mpdm_t MPDM_R(double r);
r | the real number |
Creates a new real value. MPDM integers are strings.
MPDM_S - Creates a string value from a string.
mpdm_t MPDM_S(wchar_t * wcs);
wcs | the wide character string |
Creates a new string value from a wide character string. The value will store a copy of the string that will be freed on destruction.
MPDM_X - Creates a new executable value.
mpdm_t MPDM_X(mpdm_t (* func)(mpdm_t args));
func | the C code function |
Creates a new executable value given a pointer to the func C code function. The function must receive an mpdm_t array value (that will hold their arguments) and return another one.
mpdm_app_dir - Returns the applications directory.
mpdm_t mpdm_app_dir(void);
Returns a system-dependent directory where the applications store their private data, as components or resources.
If the global APPID MPDM variable is set, it's used to search for the specific application installation folder (on MS Windows' registry) and / or appended as the final folder.
mpdm_bool - Returns a boolean value.
mpdm_t mpdm_bool(int b);
b | true or false |
Returns the stored values for TRUE or FALSE.
mpdm_bseek - Seeks a value in an array (binary).
int mpdm_bseek(const mpdm_t a, const mpdm_t v, int step, int *pos);
a | the ordered array |
v | the value |
step | number of elements to step |
pos | the position where the element should be, if it's not found |
Seeks the value v in the a array in increments of step. The array should be sorted to work correctly. A complete search should use a step of 1.
If the element is found, returns the offset of the element as a positive number; otherwise, -1 is returned and the position where the element should be is stored in pos. You can set pos to NULL if you don't mind.
mpdm_bseek_wcs - Seeks a value in an array (binary, string version).
int mpdm_bseek_wcs(const mpdm_t a, const wchar_t *v, int step, int *pos);
a | the ordered array |
v | the value |
step | number of elements to step |
pos | the position where the element should be, if it's not found |
Seeks the value v in the a array in increments of step. The array should be sorted to work correctly. A complete search should use a step of 1.
If the element is found, returns the offset of the element as a positive number; otherwise, -1 is returned and the position where the element should be is stored in pos. You can set pos to NULL if you don't mind.
mpdm_chdir - Changes the working directory
int mpdm_chdir(const mpdm_t dir);
dir | the new path |
Changes the working directory
mpdm_chmod - Changes a file's permissions.
int mpdm_chmod(const mpdm_t filename, mpdm_t perms);
filename | the file name |
perms | permissions (element 2 from mpdm_stat() )
|
Changes the permissions for a file.
mpdm_chomp - Deletes end of line characters at the end of a string.
mpdm_t mpdm_chomp(mpdm_t s);
s | the value |
Returns a new string value like the original one but without any possible \n or \r at the end.
mpdm_chown - Changes a file's owner.
int mpdm_chown(const mpdm_t filename, mpdm_t uid, mpdm_t gid);
filename | the file name |
uid | user id (element 4 from mpdm_stat() )
|
gid | group id (element 5 from mpdm_stat() )
|
Changes the owner and group id's for a file.
mpdm_clone - Creates a clone of a value.
mpdm_t mpdm_clone(const mpdm_t v);
v | the value |
Creates a clone of a value. If the value is multiple, a new value will be created containing clones of all its elements; otherwise, the same unchanged value is returned.
mpdm_close - Closes a file descriptor.
int mpdm_close(mpdm_t fd);
fd | the value containing the file descriptor |
Closes the file descriptor.
mpdm_cmp - Compares two values.
int mpdm_cmp(const mpdm_t v1, const mpdm_t v2);
v1 | the first value |
v2 | the second value |
Compares two values. If both has the MPDM_STRING flag set,
a comparison using wcscoll()
is returned; if both are arrays,
the size is compared first and, if they have the same number
elements, each one is compared; otherwise, a simple visual
representation comparison is done.
mpdm_cmp_wcs - Compares two values (string version).
int mpdm_cmp_wcs(const mpdm_t v1, const wchar_t *v2);
v1 | the first value |
v2 | the second value |
Compares the v2 string against the stringified view of v1.
mpdm_collapse - Collapses an array.
mpdm_t mpdm_collapse(mpdm_t a, int index, int num);
a | the array |
index | deletion index |
num | number of elements to collapse |
Collapses an array value, deleting num elements at the specified index.
mpdm_del_i - Deletes an element by integer subscript.
mpdm_t mpdm_del_i(const mpdm_t s, int index);
s | the set |
index | subscript of the element to be deleted |
Deletes the element at index of the s set.
mpdm_dump - Dumps a value to stdin.
void mpdm_dump(const mpdm_t v);
v | The value |
Dumps a value to stdin. The value can be complex. This function is for debugging purposes only.
mpdm_dumper - Returns a visual representation of a complex value.
mpdm_t mpdm_dumper(const mpdm_t v);
v | The value |
Returns a visual representation of a complex value.
mpdm_encoding - Sets the current charset encoding for files.
int mpdm_encoding(mpdm_t charset);
charset | the charset name. |
Sets the current charset encoding for files. Future opened files will be assumed to be encoded with charset, which can be any of the supported charset names (utf-8, iso-8859-1, etc.), and converted on each read / write. If charset is NULL, it is reverted to default charset conversion (i.e. the one defined in the locale).
This function stores the charset value into the ENCODING item
of the mpdm_root()
hash.
Returns a negative number if charset is unsupported, or zero if no errors were found.
mpdm_escape - Escapes sets of characters in a string.
mpdm_t mpdm_escape(mpdm_t v, wchar_t low, wchar_t high, mpdm_t f);
v | the string |
low | lower character limit |
high | higher character limit |
f | format to apply |
Escapes characters from the v string that are lower than
low or higher than high, applying the f format, that can
be a string for a fmt()
/ sprintf()
format or an executable
value.
mpdm_exec - Executes an executable value.
mpdm_t mpdm_exec(mpdm_t c, mpdm_t args, mpdm_t ctxt);
c | the code value |
args | the arguments |
ctxt | the context |
Executes an executable value. If c is a scalar value, its data should be a pointer to a directly executable C function with a prototype of mpdm_t func(mpdm_t args, mpdm_t ctxt); if it's a multiple one, the first value's data should be a pointer to a directly executable C function with a prototype of mpdm_t func(mpdm_t b, mpdm_t args, mpdm_t ctxt) and the second value will be passed as the b argument. This value is used to store bytecode or so when implementing virtual machines or compilers. The ctxt is meant to be used as a special context to implement local symbol tables and such. Its meaning is free and can be NULL. If c is a file descriptor, a line is read from it if the call has no arguments or otherwise all of them are written into it.
Returns the return value of the code. If c is NULL or not executable, returns NULL.
mpdm_exec_thread - Runs an executable value in a new thread.
mpdm_t mpdm_exec_thread(mpdm_t c, mpdm_t args, mpdm_t ctxt);
c | the executable value |
args | executable arguments |
ctxt | the context |
Runs the c executable value in a new thread. The code starts executing immediately. The args and ctxt arguments are sent to the executable value as arguments.
Returns a handle for the thread.
mpdm_exists - Tests if there is a value available by index.
int mpdm_exists(const mpdm_t o, const mpdm_t i);
o | the object |
i | the index |
Returns 1 if exists a value indexable by i in h, or 0 othersize.
mpdm_expand - Expands an array.
mpdm_t mpdm_expand(mpdm_t a, int index, int num);
a | the array |
index | insertion index |
num | number of elements to insert |
Expands an array value, inserting num elements (initialized to NULL) at the specified index.
mpdm_get - Gets an element by index.
mpdm_t mpdm_get(const mpdm_t s, mpdm_t index);
s | the set |
index | the index |
Returns the element at index of the set s.
mpdm_get_i - Gets an element by integer subscript.
mpdm_t mpdm_get_i(const mpdm_t s, int index);
s | the set |
index | the subscript of the element |
Returns the element at index of the set s.
mpdm_get_wcs - Gets the value from an object by string index (string version).
mpdm_t mpdm_get_wcs(const mpdm_t o, const wchar_t *i);
o | the object |
i | the index |
Returns the value from o by index i, or NULL if there is no value addressable by that index.
mpdm_getcwd - Get current working directory
mpdm_t mpdm_getcwd(void);
Returns the current working directory.
mpdm_gettext - Translates a string to the current language.
mpdm_t mpdm_gettext(const mpdm_t str);
str | the string |
Translates the str string to the current language.
This function can still be used even if there is no real gettext
support()
by manually filling the I18N hash.
If the string is found in the current table, the translation is returned; otherwise, the same str value is returned.
mpdm_gettext_domain - Sets domain and data directory for translations.
int mpdm_gettext_domain(const mpdm_t dom, const mpdm_t data);
dom | the domain (application name) |
data | directory contaning the .mo files |
Sets the domain (application name) and translation data for translating
strings that will be returned by mpdm_gettext()
.data must point to a
directory containing the .mo (compiled .po) files.
If there is no gettext support, returns 0, or 1 otherwise.
mpdm_glob - Executes a file globbing.
mpdm_t mpdm_glob(mpdm_t spec, mpdm_t base);
spec | Globbing spec |
base | Optional base directory |
Executes a file globbing. spec is system-dependent, but usually
the * and ? metacharacters work everywhere. base can contain a
directory; if that's the case, the output strings will include it.
In any case, each returned value will be suitable for a call to
mpdm_open()
.
Returns an array of files that match the globbing (can be an empty array if no file matches), or NULL if globbing is unsupported.
mpdm_hdel - Deletes a key from a hash.
mpdm_t mpdm_hdel(mpdm_t h, const mpdm_t k);
h | the hash |
k | the key |
Deletes the key k from the hash h. Returns NULL (versions prior to 1.0.10 returned the deleted value).
mpdm_hget - Gets a value from a hash.
mpdm_t mpdm_hget(const mpdm_t h, const mpdm_t k);
h | the hash |
k | the key |
Gets the value from the hash h having k as key, or NULL if the key does not exist.
mpdm_hget_s - Gets the value from a hash (string version).
mpdm_t mpdm_hget_s(const mpdm_t h, const wchar_t *k);
h | the hash |
k | the key |
Gets the value from the hash h having k as key, or NULL if the key does not exist.
mpdm_home_dir - Returns the home user directory.
mpdm_t mpdm_home_dir(void);
Returns a system-dependent directory where the user can write documents and create subdirectories.
mpdm_hset - Sets a value in a hash.
mpdm_t mpdm_hset(mpdm_t h, mpdm_t k, mpdm_t v);
h | the hash |
k | the key |
v | the value |
Sets the value v to the key k in the hash h. Returns the new value (versions prior to 1.0.10 returned the old value).
mpdm_hset_s - Sets a value in a hash (string version).
mpdm_t mpdm_hset_s(mpdm_t h, const wchar_t *k, mpdm_t v);
h | the hash |
k | the key |
v | the value |
Sets the value v to the key k in the hash h. Returns the new value (versions prior to 1.0.10 returned the old value).
mpdm_hsize - Returns the number of pairs of a hash.
int mpdm_hsize(const mpdm_t h);
h | the hash |
Returns the number of key-value pairs of a hash.
mpdm_ins - Insert an element in an array.
mpdm_t mpdm_ins(mpdm_t a, mpdm_t e, int index);
a | the array |
e | the element to be inserted |
index | subscript where the element is going to be inserted |
Inserts the e value in the a array at index. Further elements are pushed up, so the array increases its size by one. Returns the inserted element.
mpdm_is_null - Returns 1 if a value is NULL.
int mpdm_is_null(mpdm_t v);
v | the value |
Returns 1 if a value is NULL. The reference count is touched.
mpdm_is_true - Returns 1 if a value is true.
int mpdm_is_true(mpdm_t v);
v | the value |
Returns 1 if v is true. False values are: NULL, integers with value 0, reals with value 0.0, empty strings and the special string "0". The reference count is touched.
mpdm_iterator - Iterates through the content of a set.
int mpdm_iterator(mpdm_t set, int *context, mpdm_t *v, mpdm_t *i);
set | the set (hash, array, file or scalar) |
context | A pointer to an opaque context |
v | a pointer to a value to store the key |
i | a pointer to a value to store the index |
Iterates through the set. If it's a hash, every value/index pair is returned on each call. If it's an array, v contains the element and i the index number on each call. If it's a file, v contains the line read and i the index number. Otherwise, it's assumed to be a string containing a numeral and v and i are filled with values from 0 to set - 1 on each call.
Any of v and i pointers can be NULL if the value is not of interest.
The context pointer to integer is opaque and should be initialized to zero on the first call.
Returns 0 if no more data is left in set.
mpdm_ival - Returns a value's data as an integer.
int mpdm_ival(mpdm_t v);
v | the value |
Returns a value's data as an integer.
mpdm_join - Joins two values.
mpdm_t mpdm_join(const mpdm_t a, const mpdm_t b);
a | first value |
b | second value |
Joins two values. If both are hashes, a new hash containing the pairs in a overwritten with the keys in b is returned; if both are arrays, a new array is returned with all elements in a followed by all elements in b; if a is an array and b is a string, a new string is returned with all elements in a joined using b as a separator; and if a is a hash and b is a string, a new array is returned containing all pairs in a joined using b as a separator.
mpdm_join_wcs - Joins all elements of an array into a string (string version).
mpdm_t mpdm_join_wcs(const mpdm_t a, const wchar_t *s);
a | array to be joined |
s | joiner string |
Joins all elements from a into one string, using s as a glue.
mpdm_keys - Returns the keys of a hash.
mpdm_t mpdm_keys(const mpdm_t h);
h | the hash |
Returns an array containing all the keys of the h hash.
mpdm_mutex_lock - Locks a mutex.
void mpdm_mutex_lock(mpdm_t mutex);
mutex | the mutex to be locked |
Locks a mutex. If the mutex is not already locked, it waits until it is.
mpdm_mutex_unlock - Unlocks a mutex.
void mpdm_mutex_unlock(mpdm_t mutex);
mutex | the mutex to be unlocked |
Unlocks a previously locked mutex. The thread unlocking the mutex must be the one who locked it.
mpdm_new - Creates a new value.
mpdm_t mpdm_new(mpdm_type_t type, const void *data, int size);
type | data type |
data | pointer to real data |
size | size of data |
Creates a new value. type is the data type, data is a pointer to the data the value will store and size the size of these data (if value is to be a multiple one, size is a number of elements, or a number of bytes otherwise).
This function is normally not directly used; use any of the type creation macros instead.
mpdm_new_mutex - Creates a new mutex.
mpdm_t mpdm_new_mutex(void);
Creates a new mutex.
mpdm_new_semaphore - Creates a new semaphore.
mpdm_t mpdm_new_semaphore(int init_value);
init_value | the initial value of the semaphore. |
Creates a new semaphore with an init_value.
mpdm_open - Opens a file.
mpdm_t mpdm_open(mpdm_t filename, mpdm_t mode);
filename | the file name |
mode | an fopen-like mode string |
Opens a file. If filename can be open in the specified mode, an mpdm_t value will be returned containing the file descriptor, or NULL otherwise. If mode is NULL, "r" is assumed.
If the file is open for reading, some charset detection methods are
used. If any of them is successful, its name is stored in the
DETECTED_ENCODING element of the mpdm_root()
hash. This value is
suitable to be copied over ENCODING or TEMP_ENCODING.
If the file is open for writing, the encoding to be used is read from
the ENCODING element of mpdm_root()
and, if not set, from the
TEMP_ENCODING one. The latter will always be deleted afterwards.
mpdm_pclose - Closes a pipe.
int mpdm_pclose(mpdm_t fd);
fd | the value containing the file descriptor |
Closes a pipe.
mpdm_pop - Pops a value from an array.
mpdm_t mpdm_pop(mpdm_t a);
a | the array |
Pops a value from the array (i.e. deletes from the end and returns it).
mpdm_popen - Opens a pipe.
mpdm_t mpdm_popen(const mpdm_t prg, const mpdm_t mode);
prg | the program to pipe |
mode | an fopen-like mode string |
Opens a pipe to a program. If prg can be open in the specified mode, an mpdm_t value will be returned containing the file descriptor, or NULL otherwise.
mpdm_popen2 - Opens a pipe and returns 2 descriptors.
mpdm_t mpdm_popen2(const mpdm_t prg);
prg | the program to pipe |
Opens a read-write pipe and returns an array of two descriptors, one for reading and one for writing. If prg could not be piped to, returns NULL.
mpdm_push - Pushes a value into an array.
mpdm_t mpdm_push(mpdm_t a, mpdm_t e);
a | the array |
e | the value |
Pushes a value into an array (i.e. inserts at the end).
mpdm_queue - Implements a queue in an array.
mpdm_t mpdm_queue(mpdm_t a, mpdm_t e, int size);
a | the array |
e | the element to be pushed |
size | maximum size of array |
Pushes the e element into the a array. If the array already has size elements, the first (oldest) element is deleted from the queue and returned.
Returns the deleted element, or NULL if the array doesn't have size elements yet.
mpdm_read - Reads a line from a file descriptor.
mpdm_t mpdm_read(const mpdm_t fd);
fd | the value containing the file descriptor |
Reads a line from fd. Returns the line, or NULL on EOF.
mpdm_ref - Increments the reference count of a value.
mpdm_t mpdm_ref(mpdm_t v);
v | the value |
Increments the reference count of a value.
mpdm_regex - Matches a regular expression.
mpdm_t mpdm_regex(const mpdm_t v, const mpdm_t r, int offset);
v | the value to be matched |
r | the regular expression |
offset | offset from the start of v->data |
Matches a regular expression against a value. Valid flags are 'i', for case-insensitive matching, or 'm', to treat the string as a multiline string (i.e., one containing newline characters), so that ^ and $ match the boundaries of each line instead of the whole string.
If r is a string, an ordinary regular expression matching is tried over the v string. If the matching is possible, the match result is returned, or NULL otherwise.
If r is an array (of strings), each element is tried sequentially as an individual regular expression over the v string, each one using the offset returned by the previous match. All regular expressions must match to be successful. If this is the case, an array (with the same number of arguments) is returned containing the matched strings, or NULL otherwise.
If r is NULL, the result of the previous regex matching is returned as a two element array. The first element will contain the character offset of the matching and the second the number of characters matched. If the previous regex was unsuccessful, NULL is returned.
mpdm_rename - Renames a file.
int mpdm_rename(const mpdm_t o, const mpdm_t n);
o | old path |
n | new path |
Renames a file.
mpdm_root - Returns the root hash.
mpdm_t mpdm_root(void);
Returns the root hash. This hash is stored internally and can be used as a kind of global symbol table.
mpdm_rval - Returns a value's data as a real number (double).
double mpdm_rval(mpdm_t v);
v | the value |
Returns a value's data as a real number (double float).
mpdm_seek - Seeks a value in an array (sequential).
int mpdm_seek(const mpdm_t a, const mpdm_t v, int step);
a | the array |
v | the value |
step | number of elements to step |
Seeks sequentially the value v in the a array in increments of step. A complete search should use a step of 1. Returns the offset of the element if found, or -1 otherwise.
mpdm_seek_wcs - Seeks a value in an array (sequential, string version).
int mpdm_seek_wcs(const mpdm_t a, const wchar_t *v, int step);
a | the array |
v | the value |
step | number of elements to step |
Seeks sequentially the value v in the a array in increments of step. A complete search should use a step of 1. Returns the offset of the element if found, or -1 otherwise.
mpdm_semaphore_post - Increments the value of a semaphore.
void mpdm_semaphore_post(mpdm_t sem);
sem | the semaphore to increment |
Increments by 1 the value of a semaphore.
mpdm_semaphore_wait - Waits for a semaphore to be ready.
void mpdm_semaphore_wait(mpdm_t sem);
sem | the semaphore to wait onto |
Waits for the value of a semaphore to be > 0. If it's not, the thread waits until it is.
mpdm_set_wcs - Sets a value in an object (string version).
mpdm_t mpdm_set_wcs(mpdm_t o, mpdm_t v, const wchar_t *i);
o | the object |
v | the value |
i | the index |
Sets the value v inside the object o, accesible by index i. Returns v.
mpdm_shift - Extracts the first element of an array.
mpdm_t mpdm_shift(mpdm_t a);
a | the array |
Extracts the first element of the array. The array is shrinked by one.
Returns the element.
mpdm_shutdown - Shuts down MPDM.
void mpdm_shutdown(void);
Shuts down MPDM. No MPDM functions should be used from now on.
mpdm_size - Returns the size of an element.
int mpdm_size(const mpdm_t v);
v | the element |
Returns the size of an element. It does not change the reference count of the value.
mpdm_sleep - Sleeps a number of milliseconds.
void mpdm_sleep(int msecs);
msecs | the milliseconds to sleep |
Sleeps a number of milliseconds.
mpdm_sort - Sorts an array.
mpdm_t mpdm_sort(const mpdm_t a, int step);
a | the array |
step | increment step |
Sorts the array. step is the number of elements to group together.
Returns the same array, sorted (versions prior to 1.0.10 returned a new array).
mpdm_sort_cb - Sorts an array with a special sorting function.
mpdm_t mpdm_sort_cb(mpdm_t a, int step, mpdm_t cb);
a | the array |
step | increment step |
asort_cb | sorting function |
Sorts the array. step is the number of elements to group together. For each pair of elements being sorted, the executable mpdm_t value sort_cb is called with an array containing the two elements as argument. It must return a signed numerical mpdm_t value indicating the sorting order.
Returns the same array, sorted (versions prior to 1.0.10 returned a new array).
mpdm_splice_s - Creates a new string value from another.
mpdm_t mpdm_splice_s(const mpdm_t v, const mpdm_t i, int offset, int del, mpdm_t *n, mpdm_t *d)/* do not use this;
v | the original value |
i | the value to be inserted |
offset | offset where the substring is to be inserted |
del | number of characters to delete |
n | an optional pointer to the new string |
d | an optional pointer to the deleted string |
Creates a new string value from v, deleting del chars at offset and substituting them by i. If del is 0, no deletion is done. both offset and del can be negative; if this is the case, it's assumed as counting from the end of v. If v is NULL, i will become the new string, and both offset and del will be ignored. If v is not NULL and i is, no insertion process is done (only deletion, if applicable).
Fills n (in not NULL) with the new string, and d (if not NULL) with the deleted portion.
Returns the new value (if created) or the deleted value (if created).
mpdm_split - Separates a string into an array of pieces.
mpdm_t mpdm_split(const mpdm_t v, const mpdm_t s);
v | the value to be separated |
s | the separator |
Separates the v string value into an array of pieces, using s as a separator.
If the separator is NULL, the string is splitted by characters.
If the string does not contain the separator, an array holding the complete string is returned.
mpdm_split_wcs - Separates a string into an array of pieces (string version).
mpdm_t mpdm_split_wcs(const mpdm_t v, const wchar_t *s);
v | the value to be separated |
s | the separator |
Separates the v string value into an array of pieces, using s as a separator.
If the separator is NULL, the string is splitted by characters.
If the string does not contain the separator, an array holding the complete string is returned.
mpdm_sprintf - Formats a sprintf()
-like string.
mpdm_t mpdm_sprintf(const mpdm_t fmt, const mpdm_t args);
fmt | the string format |
args | an array of values |
Formats a string using the sprintf()
format taking the values from args.
mpdm_sregex - Matches and substitutes a regular expression.
mpdm_t mpdm_sregex(mpdm_t v, const mpdm_t r, const mpdm_t s, int offset);
v | the value to be matched |
r | the regular expression |
s | the substitution string, hash or code |
offset | offset from the start of v->data |
Matches a regular expression against a value, and substitutes the found substring with s. Valid flags are 'i', for case-insensitive matching, and 'g', for global replacements (all ocurrences in v will be replaced, instead of just the first found one).
If s is executable, it's executed with the matched part as the only argument and its return value is used as the substitution string.
If s is a hash, the matched string is used as a key to it and its value used as the substitution. If this value itself is executable, it's executed with the matched string as its only argument and its return value used as the substitution.
If r is NULL, returns the number of substitutions made in the
previous call to mpdm_sregex()
(can be zero if none was done).
The global variables mpdm_regex_offset and mpdm_regex_size are set to the offset of the matched string and the size of the replaced string, respectively.
Always returns a new string (either modified or an exact copy).
mpdm_sscanf - Extracts data like sscanf()
.
mpdm_t mpdm_sscanf(const mpdm_t str, const mpdm_t fmt, int offset);
str | the string to be parsed |
fmt | the string format |
offset | the character offset to start scanning |
Extracts data from a string using a special format pattern, very
much like the scanf()
series of functions in the C library. Apart
from the standard percent-sign-commands (s, u, d, i, f, x,
n, [; with optional size and * to ignore), it implements S,
to match a string of characters upto what follows in the format
string; w, to match an alphabetic word (taking locale
into account); W, to match the inverse; and r, to return the rest
of the string. Also, the [ set of characters can include
other % formats.
Returns an array with the extracted values. If n is used, the position in the scanned string is returned as the value.
mpdm_startup - Initializes MPDM.
int mpdm_startup(void);
Initializes the Minimum Profit Data Manager. Returns 0 if everything went OK.
mpdm_stat - Gives status from a file.
mpdm_t mpdm_stat(const mpdm_t filename);
filename | file name to get the status from |
Returns a 14 element array of the status (permissions, onwer, etc.) from the desired filename, or NULL if the file cannot be accessed. (man 2 stat).
The values are: 0, device number of filesystem; 1, inode number; 2, file mode; 3, number of hard links to the file; 4, uid; 5, gid; 6, device identifier; 7, total size of file in bytes; 8, atime; 9, mtime; 10, ctime; 11, preferred block size for system I/O; 12, number of blocks allocated and 13, canonicalized file name. Not all elements have necesarily meaningful values, as most are system-dependent.
mpdm_strcat - Concatenates two strings.
mpdm_t mpdm_strcat(const mpdm_t s1, const mpdm_t s2);
s1 | the first string |
s2 | the second string |
Returns a new string formed by the concatenation of s1 and s2.
mpdm_strcat_wcs - Concatenates two strings (string version).
mpdm_t mpdm_strcat_wcs(const mpdm_t s1, const wchar_t *s2);
s1 | the first string |
s2 | the second string |
Returns a new string formed by the concatenation of s1 and s2.
mpdm_strcat_wcsn - Concatenates two strings (string with size version).
mpdm_t mpdm_strcat_wcsn(const mpdm_t s1, const wchar_t *s2, int size);
s1 | the first string |
s2 | the second string |
size | the size of the second string |
Returns a new string formed by the concatenation of s1 and s2.
mpdm_string - Returns a string representation of a value.
wchar_t *mpdm_string(const mpdm_t v);
v | the value |
Returns a string representation of a value. For strings, it's the value data itself; for any other type, a conversion to string is returned instead. These values can be used for printing but they are mostly oriented to being used as indexes in objects.
The reference count value in v is not touched.
mpdm_tr - Transliterates a string.
mpdm_t mpdm_tr(mpdm_t str, mpdm_t s1, mpdm_t s2);
str | the strnig |
s1 | characters to be changed |
s2 | characters to replace those in s1 |
Creates a copy of str, which will have all characters in s1 replaced by those in s2 matching their position.
mpdm_ulc - Converts a string to uppercase or lowecase.
mpdm_t mpdm_ulc(const mpdm_t s, int u);
s | the string |
u | convert to uppercase (1) or to lowercase (0). |
Converts s to uppercase (for u == 1) or to lowercase (u == 0).
mpdm_unlink - Deletes a file.
int mpdm_unlink(const mpdm_t filename);
filename | file name to be deleted |
Deletes a file.
mpdm_unref - Decrements the reference count of a value.
mpdm_t mpdm_unref(mpdm_t v);
v | the value |
Decrements the reference count of a value. If the reference count of the value reaches 0, it's destroyed.
mpdm_unrefnd - Decrements the reference count of a value, without destroy.
mpdm_t mpdm_unrefnd(mpdm_t v);
v | the value |
Decrements the reference count of a value, without destroying the value if it's unreferenced.
mpdm_utf8_to_wc - Converts from utf8 to wchar (streaming).
int mpdm_utf8_to_wc(wchar_t *w, int *s, char c);
w | convert wide char |
s | temporal state |
c | char read from stream |
Converts a stream of utf8 characters to wide char ones. The input stream is read one byte at a time from c and composed into w until a Unicode codepoint is ready. The s integer keeps an internal state change and must be set to 0 before the stream is read. It detects encoding errors; in this case, the special Unicode char U+FFFD is returned.
When 0 is returned, a new wide char is available into w. If the stream is interrupted in the middle of a multibyte character, the s state variable will not be 0.
mpdm_void - Refs then unrefs a value.
mpdm_t mpdm_void(mpdm_t v);
v | the value |
References and unreferences a value. To be used to receive
the output of mpdm_exec()
in case of it being void (i.e.
its return value ignored).
mpdm_write - Writes a value into a file.
int mpdm_write(const mpdm_t fd, const mpdm_t v);
fd | the file descriptor. |
v | the value to be written. |
Writes the v value into fd, using the current encoding. If v is an array or file, it's iterated and its elements written into fd.