mpdm_t MPDM_2MBS(wchar_t * wcs);
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_t MPDM_A(int n);
Creates a new array value with n elements.
mpdm_t MPDM_ENS(wchar_t * wcs, int s);
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_t MPDM_F(FILE * f);
Creates a new file value.
mpdm_t MPDM_H(int n);
Creates a new hash value with n buckets. The number of buckets must be a prime number. If n is 0, an optimal number of buckets will be used.
mpdm_t MPDM_I(int i);
Creates a new integer value. MPDM integers are strings.
int MPDM_IS_ARRAY(mpdm_t v);
Returns non-zero if v is an array.
int MPDM_IS_EXEC(mpdm_t v);
Returns non-zero if v is executable.
int MPDM_IS_HASH(mpdm_t v);
Returns non-zero if v is a hash.
int MPDM_IS_STRING(mpdm_t v);
Returns non-zero if v is a string.
mpdm_t MPDM_LS(wchar_t * wcs);
Creates a new string value from a literal, wide character string. A pointer to the string will be stored in the value (not a copy).
mpdm_t MPDM_MBS(char * mbs);
Creates a new string value from a multibyte string, that will be
converted to wcs by mpdm_mbstowcs()
.
mpdm_t MPDM_NMBS(char * mbs, int s);
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_t MPDM_NS(wchar_t * wcs, int s);
Creates a new string value with a copy of the first s characters from the wcs string.
mpdm_t MPDM_R(double r);
Creates a new real value. MPDM integers are strings.
mpdm_t MPDM_S(wchar_t * wcs);
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_t MPDM_X(mpdm_t (* func)(mpdm_t args));
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_t mpdm_adel(mpdm_t a, int offset);
Deletes the element at offset of the a array. The array is shrinked by one. If offset is negative, is counted from the end of the array (so a value of -1 means delete the last element of the array).
Returns the deleted element.
mpdm_t mpdm_aget(const mpdm_t a, int offset);
Returns the element at offset of the array a.
mpdm_t mpdm_app_dir(void);
Returns a system-dependent directory where the applications store their private data, as components or resources.
mpdm_t mpdm_aset(mpdm_t a, mpdm_t e, int offset);
Sets the element of the array a at offset to be the e value. Returns the previous element.
int mpdm_bseek(const mpdm_t a, const mpdm_t k, int step, int *pos);
Seeks the value k 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.
int mpdm_bseek_s(const mpdm_t a, const wchar_t * k, int step, int *pos);
Seeks the value k 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.
int mpdm_chmod(const mpdm_t filename, mpdm_t perms);
Changes the permissions for a file.
int mpdm_chown(const mpdm_t filename, mpdm_t uid, mpdm_t gid);
Changes the owner and group id's for a file.
mpdm_t mpdm_clone(const mpdm_t v);
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_t mpdm_close(mpdm_t fd);
Closes the file descriptor.
int mpdm_cmp(const mpdm_t v1, const mpdm_t v2);
Compares two values. If both has the MPDM_STRING flag set,
a comparison using wcscmp()
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 pointer
comparison is done.
mpdm_t mpdm_collapse(mpdm_t a, int offset, int num);
Collapses an array value, deleting num elements at the specified offset.
void mpdm_dump(const mpdm_t v);
Dumps a value to stdin. The value can be complex. This function is for debugging purposes only.
void mpdm_dump_unref(void);
Dumps all unreferenced values.
mpdm_t mpdm_dumper(const mpdm_t v);
Returns a visual representation of a complex value.
int mpdm_encoding(mpdm_t charset);
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). Returns a negative number if charset is unsupported, or zero if no errors were found.
mpdm_t mpdm_exec(mpdm_t c, mpdm_t args);
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); 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) 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.
Returns the return value of the code. If c is NULL or not executable, returns NULL.
int mpdm_exists(const mpdm_t h, const mpdm_t k);
Returns 1 if k is defined in h, or 0 othersize.
mpdm_t mpdm_expand(mpdm_t a, int offset, int num);
Expands an array value, inserting num elements (initialized to NULL) at the specified offset.
mpdm_t mpdm_gettext(const mpdm_t str);
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.
int mpdm_gettext_domain(const mpdm_t dom, const mpdm_t data);
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_t mpdm_glob(const mpdm_t spec);
Executes a file globbing. spec is system-dependent, but usually
the * and ? metacharacters work everywhere. spec 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_t mpdm_hdel(mpdm_t h, const mpdm_t k);
Deletes the key k from the hash h. Returns the previous value, or NULL if the key was not defined.
mpdm_t mpdm_hget(const mpdm_t h, const mpdm_t k);
Gets the value from the hash h having k as key, or NULL if the key does not exist.
mpdm_t mpdm_hget_s(const mpdm_t h, const wchar_t * k);
Gets the value from the hash h having k as key, or NULL if the key does not exist.
mpdm_t mpdm_home_dir(void);
Returns a system-dependent directory where the user can write documents and create subdirectories.
mpdm_t mpdm_hset(mpdm_t h, mpdm_t k, mpdm_t v);
Sets the value v to the key k in the hash h. Returns the previous value of the key, or NULL if the key was previously undefined.
mpdm_t mpdm_hset_s(mpdm_t h, const wchar_t * k, mpdm_t v);
Sets the value v to the key k in the hash h. Returns the previous value of the key, or NULL if the key was previously undefined.
int mpdm_hsize(const mpdm_t h);
Returns the number of key-value pairs of a hash.
mpdm_t mpdm_ins(mpdm_t a, mpdm_t e, int offset);
Inserts the e value in the a array at offset. Further elements are pushed up, so the array increases its size by one. Returns the inserted element.
int mpdm_ival(mpdm_t v);
Returns a value's data as an integer. If the value is a string, it's converted via sscanf and returned; non-string values have all an ival of 0. The converted integer is cached, so costly string conversions are only done once. Values created with the MPDM_IVAL flag set have its ival cached from the beginning.
mpdm_t mpdm_new(int flags, const void *data, int size);
Creates a new value. flags is an or-ed set of flags, 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_t mpdm_open(const mpdm_t filename, const mpdm_t mode);
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.
mpdm_t mpdm_pclose(mpdm_t fd);
Closes a pipe.
mpdm_t mpdm_pop(mpdm_t a);
Pops a value from the array (i.e. deletes from the end and returns it).
mpdm_t mpdm_popen(const mpdm_t prg, const mpdm_t mode);
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_t mpdm_push(mpdm_t a, mpdm_t e);
Pushes a value into an array (i.e. inserts at the end).
mpdm_t mpdm_queue(mpdm_t a, mpdm_t e, int size);
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_t mpdm_read(const mpdm_t fd);
Reads a line from fd. Returns the line, or NULL on EOF.
mpdm_t mpdm_ref(mpdm_t v);
Increments the reference count of a value.
mpdm_t mpdm_regex(mpdm_t r, const mpdm_t v, int offset);
Matches a regular expression against a value. Valid flags are 'i', for case-insensitive matching, '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, 'l', to return the last matching instead of the first one, or 'g', to match globally; in that last case, an array containing all matches is returned instead of a string scalar.
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_t mpdm_root(void);
Returns the root hash. This hash is stored internally and can be used as a kind of global symbol table.
double mpdm_rval(mpdm_t v);
Returns a value's data as a real number (double float). If the value is a string, it's converted via sscanf and returned; non-string values have all an rval of 0. The converted double is cached, so costly string conversions are only done once. Values created with the MPDM_RVAL flag set have its rval cached from the beginning.
int mpdm_seek(const mpdm_t a, const mpdm_t k, int step);
Seeks sequentially the value k 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.
int mpdm_seek_s(const mpdm_t a, const wchar_t * k, int step);
Seeks sequentially the value k 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_t mpdm_shift(mpdm_t a);
Extracts the first element of the array. The array is shrinked by one.
Returns the deleted element.
void mpdm_shutdown(void);
Shuts down MPDM. No MPDM functions should be used from now on.
int mpdm_size(const mpdm_t v);
Returns the size of an element.
mpdm_t mpdm_sort(const mpdm_t a, int step);
Sorts the array. step is the number of elements to group together.
Returns the sorted array (the original one is left untouched).
mpdm_t mpdm_sort_cb(const mpdm_t a, int step, mpdm_t cb);
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 sorted array (the original one is left untouched).
mpdm_t mpdm_splice(const mpdm_t v, const mpdm_t i, int offset, int del);
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).
Returns a two element array, with the new string in the first element and the deleted string in the second (with a NULL value if del is 0).
mpdm_t mpdm_split(const mpdm_t s, const mpdm_t v);
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_t mpdm_sprintf(const mpdm_t fmt, const mpdm_t args);
Formats a string using the sprintf()
format taking the values from args.
mpdm_t mpdm_sregex(mpdm_t r, const mpdm_t v, const mpdm_t s, int offset);
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 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.
Returns the modified string, or the original one if no substitutions were done.
int mpdm_startup(void);
Initializes the Minimum Profit Data Manager. Returns 0 if everything went OK.
mpdm_t mpdm_stat(const mpdm_t filename);
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_t mpdm_strcat(const mpdm_t s1, const mpdm_t s2);
Returns a new string formed by the concatenation of s1 and s2.
wchar_t *mpdm_string(const mpdm_t v);
Returns a printable representation of a value. For strings, it's the value data itself; for any other type, a conversion to string is returned instead. This value should be used immediately, as it can be a pointer to a static buffer.
void mpdm_sweep(int count);
Destroys values with a reference count of 0. count is the
number of values to be checked for deletion; special values of
count are -1, that forces a check of all currently known values
(can be time-consuming) and 0, which tells mpdm_sweep()
to check a
small group of them on each call.
mpdm_t mpdm_ulc(const mpdm_t s, int u);
Converts s to uppercase (for u == 1) or to lowercase (u == 0).
int mpdm_unlink(const mpdm_t filename);
Deletes a file.
mpdm_t mpdm_unref(mpdm_t v);
Decrements the reference count of a value.