From: <ny...@us...> - 2007-02-09 01:54:50
|
Revision: 313 http://svn.sourceforge.net/pmplib/?rev=313&view=rev Author: nyaochi Date: 2007-02-08 17:54:50 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/pmplib/include/pmplib/filepath.h Removed Paths: ------------- trunk/pmplib/include/filepath.h Deleted: trunk/pmplib/include/filepath.h =================================================================== --- trunk/pmplib/include/filepath.h 2007-02-09 01:53:12 UTC (rev 312) +++ trunk/pmplib/include/filepath.h 2007-02-09 01:54:50 UTC (rev 313) @@ -1,346 +0,0 @@ -/* - * File/path utility implemented with Win32 API. - * - * Copyright (c) 2005-2006 Nyaochi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* $Id$ */ - -#ifndef __FILEPATHUTIL_H__ -#define __FILEPATHUTIL_H__ - -#include <time.h> -#include <ucs2char.h> - -#ifdef FILEPATH_EXPORTS -#define FILEPATHAPI __declspec(dllexport) -#else -#define FILEPATHAPI -#endif - - -#ifdef __cplusplus -extern "C" { -#endif/*__cplusplus*/ - -/** - * \addtogroup filepath File/Path Manupulation API - * @{ - * - * The PMPlib File/Path Manupulation API is a utility for file-systems and - * pathnames. - */ - -/** - * \addtogroup filepath_string file/path string API - * @{ - * - */ - -/** - * Add a (back)slash character to the end of a string. - * - * This function adds a (back)slash character to the end of the string if - * the resultant string is grammertical. If the string already has a trailing - * (back)slash, this function will not change it. - * - * @param path The pointer to the string. - * @retval ucs2char_t* Identical value to \a path argument. - */ -FILEPATHAPI ucs2char_t* filepath_addslash(ucs2char_t* path); - -/** - * Remove a (back)slash character from the end of a string. - * - * This function removes a (back)slash character from the end of the string if - * the resultant string is grammertical. If the string already has no trailing - * (back)slash, this function will not change it. - * - * @param path The pointer to the string. - * @retval ucs2char_t* The identical value to \a path argument. - */ -FILEPATHAPI ucs2char_t* filepath_removeslash(ucs2char_t* path); - -/** - * Concatenate two strings into one well-formed path. - * - * @param dst The pointer to a buffer to receive the resultant path. - * @param size The size, in number of UCS-2 characters, of \a dst. - * @param path The pointer to a path name. - * @param file The pointer to a file name. - * @retval const ucs2char_t* The identical value to \a dst argument. - */ -FILEPATHAPI const ucs2char_t* filepath_combinepath(ucs2char_t* dst, size_t size, const ucs2char_t* path, const ucs2char_t* file); - -/** - * Remove the path portion of a filepath name. - * - * @param path The pointer to the filepath name from which this - * function removes the path portion. The resultant string - * will contain only the file portion. - */ -FILEPATHAPI void filepath_strippath(ucs2char_t* path); - -/** - * Skip the path portion in a filepath name. - * - * @param path The pointer to the filepath name from which this - * function skips the path portion. The skipped string - * will contain only the file portion. - * @retval const ucs2char_t* The pointer at which the file portion begins. - */ -FILEPATHAPI const ucs2char_t* filepath_skippath(const ucs2char_t* path); - -/** - * Remove the file portion from a string. - * - * @param path The pointer to the string from which the file portion - * is removed. - */ -FILEPATHAPI void filepath_remove_filespec(ucs2char_t* path); - -/** - * Skip a portion in a filepath name. - * - * @param path The pointer to the filepath name from which this - * function skips the portion. - * @param root The pointer to the string representing the portion to - * be skipped. - * @retval const ucs2char_t* The pointer at the next character after the - * portion \a root ends in \a path. - */ -FILEPATHAPI const ucs2char_t* filepath_skiproot(const ucs2char_t* path, const ucs2char_t* root); - -/** - * Skip a portion in filepath name, assuming it as the root directory. - * - * The resultant string will begin with a path character. - * - * @param path The pointer to the filepath name from which this - * function skips the portion. - * @param root The pointer to the string representing the portion to - * be skipped. - * @retval const ucs2char_t* The pointer at the next character after the - * portion \a root ends in \a path. - */ -FILEPATHAPI const ucs2char_t* filepath_changeroot(const ucs2char_t* path, const ucs2char_t* root); - -/** - * Skip a directory name in filepath name. - * - * @param path The pointer to the filepath name from which this - * function skips a directory name. - * @retval const ucs2char_t* The pointer at the next character after the - * directory name ends in \a path. - */ -FILEPATHAPI const ucs2char_t* filepath_skipadirectory(const ucs2char_t* path); - -/** - * Add a file extension to the end of a string. - * - * @param path The pointer to the string. - * @param ext The pointer to the file extension. - */ -FILEPATHAPI void filepath_add_extension(ucs2char_t* path, const ucs2char_t* ext); - -/** - * Remove a file extension from the end of a string. - * - * @param path The pointer to the string from which the extension - * is removed. - */ -FILEPATHAPI void filepath_remove_extension(ucs2char_t* path); - -/** - * Convert a relative path to its corresponding absolute path. - * - * @param absolute The pointer to a buffer to receive the resultant path. - * @param base The name of the base directory where the relative path - * begins. - * @param relative The relative path to be converted. - * @retval int Reserved (0). - */ -FILEPATHAPI int filepath_relative_to_absolute(ucs2char_t* absolute, const ucs2char_t* base, const ucs2char_t* relative); - -/** - * Canonicalize a path. - * - * @param dst The pointer to a buffer to receive the resultant path. - * @param src The path to be canonicalized. - * @retval Non-zero value if successful, zero otherwise. - */ -FILEPATHAPI int filepath_path_canonicalize(ucs2char_t* dst, const ucs2char_t* src); - -/** - * Replaces all path separators with a backslash ('\') separator. - * - * This function replaces all path separators in the given path with - * Windows-style path separators (back-slashes). On POSIX systems, this means - * converting forward slash ('/') path separators into backslashes. On - * Windows, this is a no-op. The \p path is modified in place. - * - * @param path The pointer to the path string to be converted. - * @return int Reserved. - */ -FILEPATHAPI int filepath_encode(ucs2char_t* path); - -/** - * Replaces '\'-slashes in a path name with the native path separator. - * - * This function replaces all Windows-style path separators - * (back-slashes) in the given path with the native path separator. On - * POSIX systems, the replacement character is a forward slash ('/'). On - * Windows, this is a no-op. The \p path is modified in place. - * - * @param path The pointer to the path string to be converted. - * @return int Reserved. - */ -FILEPATHAPI int filepath_decode(ucs2char_t* path); - -/** @} */ - -/** - * \addtogroup filepath_filedir file/directory manupulation API - * @{ - * - */ - -/** - * Prototype for the callback function for receiving found files. - * - * @param instance The instance value. - * @param found_path The path-name portion of the found file. - * @param found_file The file-name portion of the found file. - * @retval int Reserved. - */ -typedef int (*filepath_findfile_callback)(void *instance, const ucs2char_t* found_path, const ucs2char_t* found_file); - -/** - * Find files. - * - * @param path The directory in which this function starts the search. - * @param recursive Non-zero value to search files recursively under the - * directory \p path. - * @param callback The pointer to the callback function to receive the - * names of found files. - * @param instance A user-defined instance value that will be sent to the - * callback function. - * @retval int Reserved. - */ -FILEPATHAPI int find_file(const ucs2char_t* path, int recursive, filepath_findfile_callback callback, void *instance); - -/** - * Test the existence of a file. - * - * @param path The filepath name to be tested. - * @retval int True or false. - */ -FILEPATHAPI int filepath_file_exists(const ucs2char_t* path); - -/** - * Test a file name has an extension. - * - * @param filename The file name to be tested. - * @param ext The extension. - * @retval int True or false. - */ -FILEPATHAPI int filepath_hasext(const ucs2char_t* filename, const ucs2char_t* ext); - -/** - * Test if a filepath name represents a directory. - * - * @param path The filepath name to be tested. - * @retval int True or false. - */ -FILEPATHAPI int filepath_is_dir(const ucs2char_t *path); - -/** - * Test if a filepath name represents a relative path. - * - * @param path The filepath name to be tested. - * @retval int True or false. - */ -FILEPATHAPI int filepath_is_relative(const ucs2char_t* path); - -/** - * Test if two path names has a common prefix of a directory. - * - * @param path1 A filepath name. - * @param path2 Another filepath name. - * @retval int True or false. - */ -FILEPATHAPI int filepath_is_same_root(const ucs2char_t* path1, const ucs2char_t* path2); - -/** - * Obtain the last-modified time of a file. - * - * @param filename The filepath name. - * @retval time_t The time stamp when the file was updated most recently. - */ -FILEPATHAPI time_t filepath_mtime(const ucs2char_t *filename); - -/** - * Compares the modification times of two files. - * - * This function compares the modification times of @p file1 and @p file2 - * and returns the difference between them is returned. - * - * @param file1 The name of file #1. - * @param file2 The name of file #2. - * @retval int The comparison result: - * - < 0, if file2 was modified more recently than file1; - * - = 0, if the modification times are the same; - * - > 0, if file1 was modified more recently than file2. - */ -FILEPATHAPI int filepath_compare_lastupdate(const ucs2char_t* file1, const ucs2char_t* file2); - -/** - * Obtain the size of a file. - * - * @param filename The filepath name. - * @retval uint32_t The size, in bytes, of the file. - */ -FILEPATHAPI uint32_t filepath_size(const ucs2char_t *filename); - -/** - * Remove a file. - * - * @param file The name of a file to be removed. - * @retval int True if succeeded, false otherwise. - */ -FILEPATHAPI int filepath_removefile(const ucs2char_t* file); - -/** - * Copy a file. - * - * @param src The name of a source file to be copied. - * @param dst The name of a destination to be created. - * @retval int True if succeeded, false otherwise. - */ -FILEPATHAPI int filepath_copyfile(const ucs2char_t* src, const ucs2char_t* dst); - -/** @} */ - - -/** @} */ - -#ifdef __cplusplus -} -#endif/*__cplusplus*/ - -#endif/*__FILEPATHUTIL_H__*/ Copied: trunk/pmplib/include/pmplib/filepath.h (from rev 312, trunk/pmplib/include/filepath.h) =================================================================== --- trunk/pmplib/include/pmplib/filepath.h (rev 0) +++ trunk/pmplib/include/pmplib/filepath.h 2007-02-09 01:54:50 UTC (rev 313) @@ -0,0 +1,346 @@ +/* + * File/path utility implemented with Win32 API. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __FILEPATHUTIL_H__ +#define __FILEPATHUTIL_H__ + +#include <time.h> +#include <ucs2char.h> + +#ifdef FILEPATH_EXPORTS +#define FILEPATHAPI __declspec(dllexport) +#else +#define FILEPATHAPI +#endif + + +#ifdef __cplusplus +extern "C" { +#endif/*__cplusplus*/ + +/** + * \addtogroup filepath File/Path Manupulation API + * @{ + * + * The PMPlib File/Path Manupulation API is a utility for file-systems and + * pathnames. + */ + +/** + * \addtogroup filepath_string file/path string API + * @{ + * + */ + +/** + * Add a (back)slash character to the end of a string. + * + * This function adds a (back)slash character to the end of the string if + * the resultant string is grammertical. If the string already has a trailing + * (back)slash, this function will not change it. + * + * @param path The pointer to the string. + * @retval ucs2char_t* Identical value to \a path argument. + */ +FILEPATHAPI ucs2char_t* filepath_addslash(ucs2char_t* path); + +/** + * Remove a (back)slash character from the end of a string. + * + * This function removes a (back)slash character from the end of the string if + * the resultant string is grammertical. If the string already has no trailing + * (back)slash, this function will not change it. + * + * @param path The pointer to the string. + * @retval ucs2char_t* The identical value to \a path argument. + */ +FILEPATHAPI ucs2char_t* filepath_removeslash(ucs2char_t* path); + +/** + * Concatenate two strings into one well-formed path. + * + * @param dst The pointer to a buffer to receive the resultant path. + * @param size The size, in number of UCS-2 characters, of \a dst. + * @param path The pointer to a path name. + * @param file The pointer to a file name. + * @retval const ucs2char_t* The identical value to \a dst argument. + */ +FILEPATHAPI const ucs2char_t* filepath_combinepath(ucs2char_t* dst, size_t size, const ucs2char_t* path, const ucs2char_t* file); + +/** + * Remove the path portion of a filepath name. + * + * @param path The pointer to the filepath name from which this + * function removes the path portion. The resultant string + * will contain only the file portion. + */ +FILEPATHAPI void filepath_strippath(ucs2char_t* path); + +/** + * Skip the path portion in a filepath name. + * + * @param path The pointer to the filepath name from which this + * function skips the path portion. The skipped string + * will contain only the file portion. + * @retval const ucs2char_t* The pointer at which the file portion begins. + */ +FILEPATHAPI const ucs2char_t* filepath_skippath(const ucs2char_t* path); + +/** + * Remove the file portion from a string. + * + * @param path The pointer to the string from which the file portion + * is removed. + */ +FILEPATHAPI void filepath_remove_filespec(ucs2char_t* path); + +/** + * Skip a portion in a filepath name. + * + * @param path The pointer to the filepath name from which this + * function skips the portion. + * @param root The pointer to the string representing the portion to + * be skipped. + * @retval const ucs2char_t* The pointer at the next character after the + * portion \a root ends in \a path. + */ +FILEPATHAPI const ucs2char_t* filepath_skiproot(const ucs2char_t* path, const ucs2char_t* root); + +/** + * Skip a portion in filepath name, assuming it as the root directory. + * + * The resultant string will begin with a path character. + * + * @param path The pointer to the filepath name from which this + * function skips the portion. + * @param root The pointer to the string representing the portion to + * be skipped. + * @retval const ucs2char_t* The pointer at the next character after the + * portion \a root ends in \a path. + */ +FILEPATHAPI const ucs2char_t* filepath_changeroot(const ucs2char_t* path, const ucs2char_t* root); + +/** + * Skip a directory name in filepath name. + * + * @param path The pointer to the filepath name from which this + * function skips a directory name. + * @retval const ucs2char_t* The pointer at the next character after the + * directory name ends in \a path. + */ +FILEPATHAPI const ucs2char_t* filepath_skipadirectory(const ucs2char_t* path); + +/** + * Add a file extension to the end of a string. + * + * @param path The pointer to the string. + * @param ext The pointer to the file extension. + */ +FILEPATHAPI void filepath_add_extension(ucs2char_t* path, const ucs2char_t* ext); + +/** + * Remove a file extension from the end of a string. + * + * @param path The pointer to the string from which the extension + * is removed. + */ +FILEPATHAPI void filepath_remove_extension(ucs2char_t* path); + +/** + * Convert a relative path to its corresponding absolute path. + * + * @param absolute The pointer to a buffer to receive the resultant path. + * @param base The name of the base directory where the relative path + * begins. + * @param relative The relative path to be converted. + * @retval int Reserved (0). + */ +FILEPATHAPI int filepath_relative_to_absolute(ucs2char_t* absolute, const ucs2char_t* base, const ucs2char_t* relative); + +/** + * Canonicalize a path. + * + * @param dst The pointer to a buffer to receive the resultant path. + * @param src The path to be canonicalized. + * @retval Non-zero value if successful, zero otherwise. + */ +FILEPATHAPI int filepath_path_canonicalize(ucs2char_t* dst, const ucs2char_t* src); + +/** + * Replaces all path separators with a backslash ('\') separator. + * + * This function replaces all path separators in the given path with + * Windows-style path separators (back-slashes). On POSIX systems, this means + * converting forward slash ('/') path separators into backslashes. On + * Windows, this is a no-op. The \p path is modified in place. + * + * @param path The pointer to the path string to be converted. + * @return int Reserved. + */ +FILEPATHAPI int filepath_encode(ucs2char_t* path); + +/** + * Replaces '\'-slashes in a path name with the native path separator. + * + * This function replaces all Windows-style path separators + * (back-slashes) in the given path with the native path separator. On + * POSIX systems, the replacement character is a forward slash ('/'). On + * Windows, this is a no-op. The \p path is modified in place. + * + * @param path The pointer to the path string to be converted. + * @return int Reserved. + */ +FILEPATHAPI int filepath_decode(ucs2char_t* path); + +/** @} */ + +/** + * \addtogroup filepath_filedir file/directory manupulation API + * @{ + * + */ + +/** + * Prototype for the callback function for receiving found files. + * + * @param instance The instance value. + * @param found_path The path-name portion of the found file. + * @param found_file The file-name portion of the found file. + * @retval int Reserved. + */ +typedef int (*filepath_findfile_callback)(void *instance, const ucs2char_t* found_path, const ucs2char_t* found_file); + +/** + * Find files. + * + * @param path The directory in which this function starts the search. + * @param recursive Non-zero value to search files recursively under the + * directory \p path. + * @param callback The pointer to the callback function to receive the + * names of found files. + * @param instance A user-defined instance value that will be sent to the + * callback function. + * @retval int Reserved. + */ +FILEPATHAPI int find_file(const ucs2char_t* path, int recursive, filepath_findfile_callback callback, void *instance); + +/** + * Test the existence of a file. + * + * @param path The filepath name to be tested. + * @retval int True or false. + */ +FILEPATHAPI int filepath_file_exists(const ucs2char_t* path); + +/** + * Test a file name has an extension. + * + * @param filename The file name to be tested. + * @param ext The extension. + * @retval int True or false. + */ +FILEPATHAPI int filepath_hasext(const ucs2char_t* filename, const ucs2char_t* ext); + +/** + * Test if a filepath name represents a directory. + * + * @param path The filepath name to be tested. + * @retval int True or false. + */ +FILEPATHAPI int filepath_is_dir(const ucs2char_t *path); + +/** + * Test if a filepath name represents a relative path. + * + * @param path The filepath name to be tested. + * @retval int True or false. + */ +FILEPATHAPI int filepath_is_relative(const ucs2char_t* path); + +/** + * Test if two path names has a common prefix of a directory. + * + * @param path1 A filepath name. + * @param path2 Another filepath name. + * @retval int True or false. + */ +FILEPATHAPI int filepath_is_same_root(const ucs2char_t* path1, const ucs2char_t* path2); + +/** + * Obtain the last-modified time of a file. + * + * @param filename The filepath name. + * @retval time_t The time stamp when the file was updated most recently. + */ +FILEPATHAPI time_t filepath_mtime(const ucs2char_t *filename); + +/** + * Compares the modification times of two files. + * + * This function compares the modification times of @p file1 and @p file2 + * and returns the difference between them is returned. + * + * @param file1 The name of file #1. + * @param file2 The name of file #2. + * @retval int The comparison result: + * - < 0, if file2 was modified more recently than file1; + * - = 0, if the modification times are the same; + * - > 0, if file1 was modified more recently than file2. + */ +FILEPATHAPI int filepath_compare_lastupdate(const ucs2char_t* file1, const ucs2char_t* file2); + +/** + * Obtain the size of a file. + * + * @param filename The filepath name. + * @retval uint32_t The size, in bytes, of the file. + */ +FILEPATHAPI uint32_t filepath_size(const ucs2char_t *filename); + +/** + * Remove a file. + * + * @param file The name of a file to be removed. + * @retval int True if succeeded, false otherwise. + */ +FILEPATHAPI int filepath_removefile(const ucs2char_t* file); + +/** + * Copy a file. + * + * @param src The name of a source file to be copied. + * @param dst The name of a destination to be created. + * @retval int True if succeeded, false otherwise. + */ +FILEPATHAPI int filepath_copyfile(const ucs2char_t* src, const ucs2char_t* dst); + +/** @} */ + + +/** @} */ + +#ifdef __cplusplus +} +#endif/*__cplusplus*/ + +#endif/*__FILEPATHUTIL_H__*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-02-09 04:54:36
|
Revision: 318 http://svn.sourceforge.net/pmplib/?rev=318&view=rev Author: nyaochi Date: 2007-02-08 20:54:37 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Added new Makefile.am files Added Paths: ----------- trunk/pmplib/include/Makefile.am trunk/pmplib/include/pmplib/Makefile.am Added: trunk/pmplib/include/Makefile.am =================================================================== --- trunk/pmplib/include/Makefile.am (rev 0) +++ trunk/pmplib/include/Makefile.am 2007-02-09 04:54:37 UTC (rev 318) @@ -0,0 +1,3 @@ +# $Id:$ + +SUBDIRS = pmplib Added: trunk/pmplib/include/pmplib/Makefile.am =================================================================== --- trunk/pmplib/include/pmplib/Makefile.am (rev 0) +++ trunk/pmplib/include/pmplib/Makefile.am 2007-02-09 04:54:37 UTC (rev 318) @@ -0,0 +1,9 @@ +# $Id:$ + +pmplibincludedir = $(includedir)/pmplib + +pmplibinclude_HEADERS = \ + os_types.h \ + pmp.h \ + ucs2char.h \ + filepath.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-02-09 01:55:11
|
Revision: 314 http://svn.sourceforge.net/pmplib/?rev=314&view=rev Author: nyaochi Date: 2007-02-08 17:55:12 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/pmplib/include/pmplib/pmp.h Removed Paths: ------------- trunk/pmplib/include/pmp.h Deleted: trunk/pmplib/include/pmp.h =================================================================== --- trunk/pmplib/include/pmp.h 2007-02-09 01:54:50 UTC (rev 313) +++ trunk/pmplib/include/pmp.h 2007-02-09 01:55:12 UTC (rev 314) @@ -1,826 +0,0 @@ -/* - * Digital Media Player library. - * - * Copyright (c) 2005-2006 Nyaochi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* $Id$ */ - -#ifndef __PMP_H__ -#define __PMP_H__ - -#ifdef PMP_EXPORTS -#define PMPAPI __declspec(dllexport) -#else -#define PMPAPI -#endif/*PMP_EXPORTS*/ - -#ifdef __cplusplus -extern "C" { -#endif/*__cplusplus*/ - - -/** - * @mainpage PMPlib API Documentation - * - * @section intro Introduction - * - * This is the documentation for the PMPlib API. - */ - -/** - * \addtogroup pmp PMPlib APIs - * @{ - */ - -/* - * Forward structure declarations. - */ -struct tag_pmp_t; typedef struct tag_pmp_t pmp_t; -struct tag_pmp_music_t; typedef struct tag_pmp_music_t pmp_music_t; - -/** - * Error codes. - */ -enum { - PMP_SUCCESS = 0, - PMP_DEVICENOTFOUND, - PMP_NOTSUPPORTED, - PMP_INSUFFICIENTMEMORY, - PMP_NOTIMPLIMENTED, - PMPDBE_OUTOFMEMORY, - PMPDBE_NOTFOUND, - PMPDBE_INVALIDTYPE, - PMPDBE_DBINCONSIST, - PMPDBE_NOTINITIALIZED, - PMPDBE_INVALIDLEAFID, - PMPDBE_OPENFORREAD, - PMPDBE_OPENFORWRITE, - PMPDBE_INSUFFICIENT, - PMPPLE_WRITE, -}; - -/** - * Open flags for portable media device. - * Specify one or more flags to pmp_t::open() member function. - */ -enum { - /** - * Read access to the music database. - * The member function pmp_t::open() will read the music database. - */ - PMPOF_MUSIC_DB_READ = 0x0001, - /** - * Write access to the music database. - * The member function pmp_t::close() will write the music database. - */ - PMPOF_MUSIC_DB_WRITE = 0x0002, - /** - * Read access to the music playlists. - * The member function pmp_t::open() will read the music playlists. - */ - PMPOF_MUSIC_PL_READ = 0x0004, - /** - * Write access to the music playlists. - * The member function pmp_t::close() will write the music playlists. - */ - PMPOF_MUSIC_PL_WRITE = 0x0008, -}; - -/** - * Macro to define FourCC representations of codecs. - */ -#define PMPFOURCC(a, b, c, d) \ - ((uint32_t)(a) << 24 | (uint32_t)(b) << 16 | (uint32_t)(c) << 8 | (uint32_t)(d)) - -#define PMPCODEC_NONE PMPFOURCC(' ',' ',' ',' ') /**< Unknown codec. */ -#define PMPCODEC_MPEGLAYER3 PMPFOURCC('M','P','1','3') /**< MPEG Audio Layer III */ -#define PMPCODEC_WMA PMPFOURCC('W','M','A',' ') /**< Windows Media Audio */ -#define PMPCODEC_VORBIS PMPFOURCC('O','V','1',' ') /**< Ogg Vorbis */ -#define PMPCODEC_WAV PMPFOURCC('W','A','V','E') /**< Microsoft Riff WAVE */ - -enum { - PMPPEF_NONE = 0x0000, - PMPPEF_SUPPORT = 0x0001, - PMPPEF_CONSTANT = 0x0002, - PMPPEF_RECURSIVE = 0x0004, -}; - -enum { - PMPMF_NONE = 0x0000, - PMPMF_SUPPORT = 0x0001, - PMPMF_RECURSIVE = 0x0002, -}; - -enum { - PMPPF_NONE = 0x0000, - PMPPF_SUPPORT = 0x0001, - PMPPF_RECURSIVE = 0x0002, -}; - - - -/** - * @defgroup device PMPlib Device API - * @{ - */ - -/** Maximum size, in chars, of a device description. */ -#define PMP_DECLSIZE (128) -/** Unavailable field of a device description. */ -#define PMP_DECLUNAVAIL ("***") - -/** - * PMP device decription. - * This structure stores information about a PMP device. A PMP device driver - * should fill these fields properly so that an application can obtain the - * information about the device. An empty value represents the uncertainity - * of the field value at this stage. The value ::PMP_DECLUNAVAIL (\c "***") - * implies the unavailability of the field value for the device. - */ -typedef struct { - /** Device identifier (e.g., "iriver_e10_ums_1.0-1.4"). */ - char id[PMP_DECLSIZE]; - /** Manufacturer (e.g., "iriver"). */ - char manufacturer[PMP_DECLSIZE]; - /** Model name (e.g., "E10"). */ - char name[PMP_DECLSIZE]; - /** Firmware mode (e.g., "UM"). */ - char mode[PMP_DECLSIZE]; - /** Firmware default language (e.g., "JP"). */ - char language[PMP_DECLSIZE]; - /** Firmware version (e.g., "1.4"). */ - char version[PMP_DECLSIZE]; - /** Minimum firmware version (e.g., "1.0"). */ - char min_version[PMP_DECLSIZE]; - /** Maximum firmware version (e.g., "1.4"). */ - char max_version[PMP_DECLSIZE]; -} pmp_device_description_t; - -/** - * PMP device environment. - * This structure stores information about predefined paths, capability, - */ -typedef struct { - /** Path to the root directory of the player. */ - ucs2char_t path_to_root[MAX_PATH]; - /** Relative path to the system directory from the root. */ - ucs2char_t path_to_system[MAX_PATH]; - /** Relative path to the music directory from the root. */ - ucs2char_t path_to_music[MAX_PATH]; - /** Relative path to the playlist directory from the root. */ - ucs2char_t path_to_playlist[MAX_PATH]; - - /** Music flags. */ - uint32_t music_flag; - /** Playlist flags. */ - uint32_t playlist_flag; - - /** Number of elements in \a audio_codecs array. */ - uint32_t num_audio_codecs; - /** Array of PMPFOURCC values corresponding to the supported audio codecs. */ - uint32_t* audio_codecs; - - /** Number of elements in \a audio_extensions array. */ - uint32_t num_audio_extensions; - /** Array of ucs2char_t string values for audio file extensions. */ - ucs2char_t** audio_extensions; - - /** Description about the device. */ - const pmp_device_description_t decl; -} pmp_device_information_t; - -/** - * The root interface for portable media device. - * - * This structure represents the basic interface that is common to any - * portal media devices. It defines several member variables and pure - * virtual functions to access the implementation for the target device. - * Use pmplib_create() function to obtain the instance suitable for a - * specific device. - * - * @see pmplib_create - */ -struct tag_pmp_t { - /** - * Pointer for the internal use. - * - * This member variable is reserved for the internal use of the library. - * Do not modify the value. - */ - void* instance; - - /** - * Reference counter. - * - * This member variable is reserved for the library to manage the - * reference counter. Do not modify the value directly. Call - * member functions add_ref() and release() to increase and - * decrease the reference counter. - */ - uint32_t ref_count; - - /** - * Open flags. - * - * This member variable is reserved for the library to store the - * flags specified in open() function. Do not modify the value. - */ - uint32_t flag; - - /** - * PMP device decription. - */ - pmp_device_information_t info; - - /** - * The pointer to pmp_music_t interface. - */ - pmp_music_t* music; - - /** - * Increment the reference counter. - * @param pmp The pointer to the pmp_t instance. - */ - uint32_t (*add_ref)(pmp_t* pmp); - - /** - * Decrement the reference counter. - * If the reference counter becomes zero after this decrement, - * this function will destroy the pmp_t instance. - * @param pmp The pointer to the pmp_t instance. - */ - uint32_t (*release)(pmp_t* pmp); - - /** - * Open the PMP device. - * @param pmp The pointer to the pmp_t instance. - * @param flag The open flags. - */ - result_t (*open)(pmp_t* pmp, uint32_t flag); - - /** - * Close the PMP device. - * @param pmp The pointer to the pmp_t instance. - */ - result_t (*close)(pmp_t* pmp); -}; - -/** - * @} - */ - -/** - * @defgroup music PMPlib Music API - * @{ - */ - -/** - * Structure for a music record. - */ -struct tag_pmp_music_record_t { - /** - * Relative path for the music file from the mount location of the device. - * The path character must be '\\' on all platforms (including POSIX). - * e.g., "\\Music\\Beatles\\AbbeyRoad\\01_AbbeyRoad.mp3" - * @assert @code filename != NULL @endcode - */ - ucs2char_t *filename; - - /** - * Title name. - * e.g., "Come Together" - * @assert @code title != NULL @endcode - */ - ucs2char_t *title; - - /** - * Artist name. - * e.g., "The Beatles" - * @assert @code artist != NULL @endcode - */ - ucs2char_t *artist; - - /** - * Composer. - * e.g., "John Lennon" - * @assert @code composer != NULL @endcode - */ - ucs2char_t *composer; - - /** - * Album name. - * e.g., "Abbey Road" - * @assert @code album != NULL @endcode - */ - ucs2char_t *album; - - /** - * Genre name. - * e.g., "Rock" - * @assert @code genre != NULL @endcode - */ - ucs2char_t *genre; - - /** - * Release date. - * e.g., "1969" - * @assert @code date != NULL @endcode - */ - ucs2char_t *date; - - /** - * FourCC representation of the codec. - * e.g., PMPCODEC_MPEGLAYER3 - */ - uint32_t codec; - - /** - * Track number. - * e.g., 1 - */ - uint32_t track_number; - - /** - * Sample rate in [Hz]. - * e.g., 44100 - */ - uint32_t sample_rate; - - /** - * Bitrate in [bps]. - * e.g., 128000 - */ - uint32_t bitrate; - - /** - * Duration in seconds. - * e.g., 260 - */ - uint32_t duration; - - /** - * File size in bytes. - * e.g., 4160000 - */ - uint32_t filesize; - - /** - * Timestamp of the last update of the music file. - * The value is equivalent to \c st.st_mtime after \c stat(&st, filename); - */ - uint32_t ts_update; - - /** - * Rating. - * e.g., 5 - */ - uint32_t rating; - - /** - * Play count on the device. - * e.g., 23 - */ - uint32_t play_count; - - /** - * Timestamp of the recent playback on the device. - */ - uint32_t ts_playback; - - /** - * timestamp when the track was imported. - */ - uint32_t ts_import; -}; -typedef struct tag_pmp_music_record_t pmp_music_record_t; - -typedef struct { - ucs2char_t *name; - int num_entries; - ucs2char_t **entries; -} pmp_playlist_t; - -/** - * Interface for organizing music files. - * - * This interface is responsible for several operations relevant to music - * files in a portable media device. The major operations are: - * - setting a list of music records for building a music database - * - getting a list of music records from the existing music database - * - dumping the existing music database in a text format - * - setting a list of music files for generating - * - getting a list of music playlists used by the device - * - * You cannot create an instance of this structure by yourself. Access - * pmp_t::music member to obtain this interface. - */ -struct tag_pmp_music_t { - /** - * Pointer for the internal use. - * - * This member variable is reserved for the internal use of the library. - * Do not modify the value. - */ - void* instance; - - /** - * The pointer to pmp_t interface. - * - * @assert - * @code this->pmp->music == this @endcode - */ - pmp_t* pmp; - - /** - * Set a list of music records. - * - * This function sets a list of music records that provide a complete - * information about all music files on a device. Based on this list, - * PMPlib will build a music database on the device. - * - * This function does not write out any content on the player immediately - * for the following reason. Some portable devices manage a music database - * and playlists separately, but some integrate playlist information into - * a music database. In the latter case, PMPlib cannot build a music - * database until a definitive list of playlists is obtained. In order to - * support various devices in a unified interface, this function reserves - * a future update of the music database; a database update is prolonged - * until the device is closed by pmp->close() call. - * - * @param music The pointer to the pmp_music_t interface. - * @param records An array of music records. - * @param num_records The number of elements in \a records array. - * @retval result_t The status code after this operation. - * - * @assert - * @code music != NULL @endcode - * @code records != NULL @endcode - */ - result_t (*set_records)(pmp_music_t* music, const pmp_music_record_t* records, uint32_t num_records); - - /** - * Get a list of music records. - * - * This function gets the list of music records in the existing music - * database or set by \a set_records call. - * - * If the argument \a records is NULL, this function returns the number of - * music records to the variable whose address is specified by the - * argument \a num_records. You can use this for determining the size of - * array \a records necessary to obtain all records from this function. - * - * If the argument \a records is not NULL, this function copies the - * current music records to the array whose address is specified by the - * argument \a records and whose size is specified by the variable - * pointed by the argument \a num_records. - * - * @param music The pointer to the pmp_music_t interface. - * @param records An array of music records. - * @param num_records The pointer to the variable presenting the number - * of elements in \a records array. - * @retval result_t The status code after this operation. - * - * @assert - * @code music != NULL @endcode - * @code num_records != NULL @endcode - */ - result_t (*get_records)(pmp_music_t* music, pmp_music_record_t* records, uint32_t* num_records); - - /** - * Set a list of music playlists. - * - * This function sets a list of music playlists. PMPlib will generate the - * playlists on the device based on this list. - * - * This function does not write out any content on the player immediately; - * playlist generation is prolonged until the device is closed by - * pmp->close() call. - * - * @param music The pointer to the pmp_music_t interface. - * @param playlists An array of music playlists. - * @param num_playlists The number of elements in \a playlists array. - * @retval result_t The status code after this operation. - * - * @assert - * @code music != NULL @endcode - * @code playlists != NULL @endcode - */ - result_t (*set_playlists)(pmp_music_t* music, const pmp_playlist_t* playlists, uint32_t num_playlists); - - /** - * Get a list of music playlists. - * - * This function gets the list of music playlists in the device or set by - * \a set_playlists call. - * - * If the argument \a playlists is NULL, this function returns the number - * of music playlists to the variable whose address is specified by the - * argument \a num_playlists. You can use this for determining the size of - * array \a playlists necessary to obtain all playlists. - * - * If the argument \a playlists is not NULL, this function copies the - * current music playlists to the array whose address is specified by the - * argument \a playlists and whose size is specified by the variable - * pointed by the argument \a num_playlists. - * - * @param music The pointer to the pmp_music_t interface. - * @param playlists An array of music playlists. - * @param num_playlists The pointer to the variable presenting the - * number of elements in \a playlists array. - * @retval result_t The status code after this operation. - * - * @assert - * @code music != NULL @endcode - * @code num_playlists != NULL @endcode - */ - result_t (*get_playlists)(pmp_music_t* music, pmp_playlist_t* playlists, uint32_t* num_playlists); - - /** - * Dump the music database. - * - * @param music The pointer to the pmp_music_t interface. - * @param fp The pointer to an output stream. - * @param flag The flags. - * @retval result_t The status code after this operation. - * - * @assert - * @code music != NULL @endcode - */ - result_t (*dump)(pmp_music_t* music, FILE *fp, int flag); -}; - -/** - * Initialize pmp_music_record_t structure. - * - * @param record The pointer to pmp_music_record_t instance. - */ -PMPAPI void pmplib_record_init(pmp_music_record_t* record); - -/** - * Uninitialize pmp_music_record_t structure. - * - * This function frees the memory blocks used by the \a record. - * - * @param record The pointer to pmp_music_record_t instance. - */ -PMPAPI void pmplib_record_finish(pmp_music_record_t* record); - -/** - * Clone a pmp_music_record_t record. - * - * This function copies the values in the \a src record to \a dst. - * - * @param dst The pointer to the destination. - * @param src The pointer to the source. - * @retval result_t The status code after this operation. - */ -PMPAPI result_t pmplib_record_clone(pmp_music_record_t* dst, const pmp_music_record_t* src); - -/** - * Uninitialize an array of pmp_music_record_t records. - * - * This function frees the memory blocks used by each record in the array and - * the array. - * - * @param record The pointer to pmp_music_record_t array. - * @param num_records The number of elements in the array. - */ -PMPAPI void pmplib_records_finish(pmp_music_record_t* records, int num_records); - -/** - * Clone a pmp_music_record_t array. - * - * This function copies all records in the \a src array to \a dst. - * - * @param dst The destination array. - * @param src The source array. - * @param num_records The number of elements in the source array. - * @retval result_t The status code after this operation. - */ -PMPAPI result_t pmplib_records_clone(pmp_music_record_t* dst, const pmp_music_record_t* src, int num_records); - -PMPAPI void pmplib_playlist_init(pmp_playlist_t* playlist); -PMPAPI void pmplib_playlist_finish(pmp_playlist_t* playlist); -PMPAPI void pmplib_playlist_clone(pmp_playlist_t* dst, const pmp_playlist_t* src); - -PMPAPI void pmplib_playlists_finish(pmp_playlist_t* playlist, int num_playlists); -PMPAPI void pmplib_playlists_clone(pmp_playlist_t* dst, const pmp_playlist_t* src, int num_playlists); - -/** - * @} - */ - - -typedef result_t (*pmplib_create_t)(pmp_t** pmp, const ucs2char_t* path_to_device, const char *devid); - -/** - * Prototype for the callback function for receiving device identifiers. - * - */ -typedef void (*pmplib_enumerate_devid_callback_t)(void *instance, const char *devid); -typedef result_t (*pmplib_enumerate_devid_t)(pmplib_enumerate_devid_callback_t callback, void *instance); - -PMPAPI uint32_t pmplib_interlocked_increment(uint32_t* count); -PMPAPI uint32_t pmplib_interlocked_decrement(uint32_t* count); - - - - - - -/** - * @defgroup pmplib PMPlib Helper API - * @{ - * - * The PMPlib Helper API provides the utility for choosing a suitable PMPlib - * driver from a number of installed drivers. Because the PMPlib project - * implements a number of drivers for different portable media devices, an - * application must choose a suitable driver that matches to the target - * device. By using this API, an application can query a driver suitable for - * the portable media device specified by the mount location (root directory - * of the device) and/or the string identifier of a driver. An application can - * also enumerate the string identifiers of the drivers available in the - * system. - * - * An application must call pmplib_init() function to initialize the API - * and obtain the pointer to a ::pmplib_t instance that is used for subsequent - * calls of the API. - * The application can query an interface to a PMPlib driver by using - * pmplib_create() function. A list of installed device identifiers is - * obtained by receiving callback notifications invoked by - * pmplib_enumerate_devid() function. The application must terminate this - * API by calling pmplib_finish() function. - * - * This is an example of querying an interface to the driver that matches to - * the device connected to the mount point (Win32 path "D:\"): - * - * @code - * #include <ucs2char.h> - * #include <pmp.h> - * - * int main(int argc, char *argv[]) - * { - * result_t ret = 0; - * pmp_t* pmp = NULL; - * pmplib_t* pmplib = NULL; - * static const ucs2char_t path[] = {'D',':','\\',0}; - * - * // Initialize the PMPlib Helper API. - * if ((ret = pmplib_init(&pmplib)) != 0) { - * // Failed to initialize the API. - * goto error_exit; - * } - * - * // Query an interface to the PMPlib driver suitable for the path. - * if ((ret = pmplib_create(pmplib, &pmp, path, NULL)) != 0) { - * // Failed to find a suitable driver. - * goto error_exit; - * } - * - * // Processing with the driver. - * ... - * - * // Release the driver. - * pmp->release(pmp); - * - * // Terminate the helper API. - * pmplib_finish(pmplib); - * return 0; - * - * error_exit: - * // Error handling. - * ... - * return 1; - * } - * @endcode - * - * @{ - */ - -struct tag_pmplib_t; - -/** - * The structure for the PMPlib Helper API. - * An application should use a pointer to this structure as a handle value - * for this API. Call pmplib_init() function to obtain a pointer to this - * structure and pmplib_finish() function to terminate this API. Access to - * a member in this structure is prohibited since it is reserved for the - * internal use of the library only. - */ -typedef struct tag_pmplib_t pmplib_t; - -/** - * Initialize the PMPlib helper library. - * - * This function loads the drivers installed in the system to prepare them. - * - * @retval ptr_pmplib The pointer to the buffer to receive the pointer - * to the ::pmplib_t instance initialized by this - * function. - * @retval result_t The status code. - * - * @assert - * @code ptr_pmplib != NULL @endcode - * - * @note - * Call this function before using any other functions in this API. - */ -PMPAPI result_t pmplib_init(pmplib_t** ptr_pmplib); - -/** - * Uninitialize the PMPlib helper library. - * - * This function detatch the drivers loaded by pmplib_init() function. - * - * @param pmplib The pointer to the ::pmplib_t instance. - * @retval result_t The status code. - * - * @assert - * @code ptr_pmplib != NULL @endcode - * - * @note - * Call this function to terminate this API. - */ -PMPAPI result_t pmplib_finish(pmplib_t* pmplib); - -/** - * Query a driver and create a ::pmp_t instance. - * - * This function queries the driver suitable for the portable media device - * specified by the mount location and/or identifier, and returns the - * interface to the driver (::pmp_t instance). An application must specify - * parameter \a path_to_device. If parameter \a id is not \c NULL, this - * function obtains the interface to the driver with the device identifier - * specified in \a id parameter. If the parameter \a id is \c NULL, this - * function tries to recognize the model of the device based on the content - * of the files located under \a path_to_device. If successful, the interface - * to the driver will be returned in the \a pmp argument. - * - * @param pmplib The pointer to the ::pmplib_t instance. - * @param path_to_device A UCS-2 string representing the location of the - * target device. This parameter cannot be \c NULL. - * @param id A C-string representing the device identifier of - * the target device. If this argument is \c NULL, - * this function tries to recognize the model of the - * device based on the location (\a path_to_device). - * @retval ptr_pmp The pointer to the buffer to receive the pointer - * to the driver interface (::pmp_t instance). - * @retval result_t The status code. - * - * @assert - * @code pmplib != NULL @endcode - * @code ptr_pmp != NULL @endcode - * @code path_to_device != NULL @endcode - */ -PMPAPI result_t pmplib_create(pmplib_t* pmplib, pmp_t** ptr_pmp, const ucs2char_t* path_to_device, const char *id); - -/** - * Enumerate device identifiers of the installed drivers. - * - * This function enumerates the device identifiers of the installed drivers, - * and invokes the \a callback function for each identifier. - * - * @param pmplib The pointer to the ::pmplib_t instance. - * @param callback The pointer to the callback function to receive - * device identifiers. - * @param instance A user-defined instance value. The callback - * function will receive the same value. - * @retval result_t The status code. - * - * @assert - * @code pmplib != NULL @endcode - * @code callback != NULL @endcode - */ -PMPAPI result_t pmplib_enumerate_devid(pmplib_t* pmplib, pmplib_enumerate_devid_callback_t callback, void *instance); - -/** - * @} - */ - -/** - * @} - */ - - -#ifdef __cplusplus -} -#endif/*__cplusplus*/ - -#endif/*__PMP_H__*/ - Copied: trunk/pmplib/include/pmplib/pmp.h (from rev 313, trunk/pmplib/include/pmp.h) =================================================================== --- trunk/pmplib/include/pmplib/pmp.h (rev 0) +++ trunk/pmplib/include/pmplib/pmp.h 2007-02-09 01:55:12 UTC (rev 314) @@ -0,0 +1,826 @@ +/* + * Digital Media Player library. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __PMP_H__ +#define __PMP_H__ + +#ifdef PMP_EXPORTS +#define PMPAPI __declspec(dllexport) +#else +#define PMPAPI +#endif/*PMP_EXPORTS*/ + +#ifdef __cplusplus +extern "C" { +#endif/*__cplusplus*/ + + +/** + * @mainpage PMPlib API Documentation + * + * @section intro Introduction + * + * This is the documentation for the PMPlib API. + */ + +/** + * \addtogroup pmp PMPlib APIs + * @{ + */ + +/* + * Forward structure declarations. + */ +struct tag_pmp_t; typedef struct tag_pmp_t pmp_t; +struct tag_pmp_music_t; typedef struct tag_pmp_music_t pmp_music_t; + +/** + * Error codes. + */ +enum { + PMP_SUCCESS = 0, + PMP_DEVICENOTFOUND, + PMP_NOTSUPPORTED, + PMP_INSUFFICIENTMEMORY, + PMP_NOTIMPLIMENTED, + PMPDBE_OUTOFMEMORY, + PMPDBE_NOTFOUND, + PMPDBE_INVALIDTYPE, + PMPDBE_DBINCONSIST, + PMPDBE_NOTINITIALIZED, + PMPDBE_INVALIDLEAFID, + PMPDBE_OPENFORREAD, + PMPDBE_OPENFORWRITE, + PMPDBE_INSUFFICIENT, + PMPPLE_WRITE, +}; + +/** + * Open flags for portable media device. + * Specify one or more flags to pmp_t::open() member function. + */ +enum { + /** + * Read access to the music database. + * The member function pmp_t::open() will read the music database. + */ + PMPOF_MUSIC_DB_READ = 0x0001, + /** + * Write access to the music database. + * The member function pmp_t::close() will write the music database. + */ + PMPOF_MUSIC_DB_WRITE = 0x0002, + /** + * Read access to the music playlists. + * The member function pmp_t::open() will read the music playlists. + */ + PMPOF_MUSIC_PL_READ = 0x0004, + /** + * Write access to the music playlists. + * The member function pmp_t::close() will write the music playlists. + */ + PMPOF_MUSIC_PL_WRITE = 0x0008, +}; + +/** + * Macro to define FourCC representations of codecs. + */ +#define PMPFOURCC(a, b, c, d) \ + ((uint32_t)(a) << 24 | (uint32_t)(b) << 16 | (uint32_t)(c) << 8 | (uint32_t)(d)) + +#define PMPCODEC_NONE PMPFOURCC(' ',' ',' ',' ') /**< Unknown codec. */ +#define PMPCODEC_MPEGLAYER3 PMPFOURCC('M','P','1','3') /**< MPEG Audio Layer III */ +#define PMPCODEC_WMA PMPFOURCC('W','M','A',' ') /**< Windows Media Audio */ +#define PMPCODEC_VORBIS PMPFOURCC('O','V','1',' ') /**< Ogg Vorbis */ +#define PMPCODEC_WAV PMPFOURCC('W','A','V','E') /**< Microsoft Riff WAVE */ + +enum { + PMPPEF_NONE = 0x0000, + PMPPEF_SUPPORT = 0x0001, + PMPPEF_CONSTANT = 0x0002, + PMPPEF_RECURSIVE = 0x0004, +}; + +enum { + PMPMF_NONE = 0x0000, + PMPMF_SUPPORT = 0x0001, + PMPMF_RECURSIVE = 0x0002, +}; + +enum { + PMPPF_NONE = 0x0000, + PMPPF_SUPPORT = 0x0001, + PMPPF_RECURSIVE = 0x0002, +}; + + + +/** + * @defgroup device PMPlib Device API + * @{ + */ + +/** Maximum size, in chars, of a device description. */ +#define PMP_DECLSIZE (128) +/** Unavailable field of a device description. */ +#define PMP_DECLUNAVAIL ("***") + +/** + * PMP device decription. + * This structure stores information about a PMP device. A PMP device driver + * should fill these fields properly so that an application can obtain the + * information about the device. An empty value represents the uncertainity + * of the field value at this stage. The value ::PMP_DECLUNAVAIL (\c "***") + * implies the unavailability of the field value for the device. + */ +typedef struct { + /** Device identifier (e.g., "iriver_e10_ums_1.0-1.4"). */ + char id[PMP_DECLSIZE]; + /** Manufacturer (e.g., "iriver"). */ + char manufacturer[PMP_DECLSIZE]; + /** Model name (e.g., "E10"). */ + char name[PMP_DECLSIZE]; + /** Firmware mode (e.g., "UM"). */ + char mode[PMP_DECLSIZE]; + /** Firmware default language (e.g., "JP"). */ + char language[PMP_DECLSIZE]; + /** Firmware version (e.g., "1.4"). */ + char version[PMP_DECLSIZE]; + /** Minimum firmware version (e.g., "1.0"). */ + char min_version[PMP_DECLSIZE]; + /** Maximum firmware version (e.g., "1.4"). */ + char max_version[PMP_DECLSIZE]; +} pmp_device_description_t; + +/** + * PMP device environment. + * This structure stores information about predefined paths, capability, + */ +typedef struct { + /** Path to the root directory of the player. */ + ucs2char_t path_to_root[MAX_PATH]; + /** Relative path to the system directory from the root. */ + ucs2char_t path_to_system[MAX_PATH]; + /** Relative path to the music directory from the root. */ + ucs2char_t path_to_music[MAX_PATH]; + /** Relative path to the playlist directory from the root. */ + ucs2char_t path_to_playlist[MAX_PATH]; + + /** Music flags. */ + uint32_t music_flag; + /** Playlist flags. */ + uint32_t playlist_flag; + + /** Number of elements in \a audio_codecs array. */ + uint32_t num_audio_codecs; + /** Array of PMPFOURCC values corresponding to the supported audio codecs. */ + uint32_t* audio_codecs; + + /** Number of elements in \a audio_extensions array. */ + uint32_t num_audio_extensions; + /** Array of ucs2char_t string values for audio file extensions. */ + ucs2char_t** audio_extensions; + + /** Description about the device. */ + const pmp_device_description_t decl; +} pmp_device_information_t; + +/** + * The root interface for portable media device. + * + * This structure represents the basic interface that is common to any + * portal media devices. It defines several member variables and pure + * virtual functions to access the implementation for the target device. + * Use pmplib_create() function to obtain the instance suitable for a + * specific device. + * + * @see pmplib_create + */ +struct tag_pmp_t { + /** + * Pointer for the internal use. + * + * This member variable is reserved for the internal use of the library. + * Do not modify the value. + */ + void* instance; + + /** + * Reference counter. + * + * This member variable is reserved for the library to manage the + * reference counter. Do not modify the value directly. Call + * member functions add_ref() and release() to increase and + * decrease the reference counter. + */ + uint32_t ref_count; + + /** + * Open flags. + * + * This member variable is reserved for the library to store the + * flags specified in open() function. Do not modify the value. + */ + uint32_t flag; + + /** + * PMP device decription. + */ + pmp_device_information_t info; + + /** + * The pointer to pmp_music_t interface. + */ + pmp_music_t* music; + + /** + * Increment the reference counter. + * @param pmp The pointer to the pmp_t instance. + */ + uint32_t (*add_ref)(pmp_t* pmp); + + /** + * Decrement the reference counter. + * If the reference counter becomes zero after this decrement, + * this function will destroy the pmp_t instance. + * @param pmp The pointer to the pmp_t instance. + */ + uint32_t (*release)(pmp_t* pmp); + + /** + * Open the PMP device. + * @param pmp The pointer to the pmp_t instance. + * @param flag The open flags. + */ + result_t (*open)(pmp_t* pmp, uint32_t flag); + + /** + * Close the PMP device. + * @param pmp The pointer to the pmp_t instance. + */ + result_t (*close)(pmp_t* pmp); +}; + +/** + * @} + */ + +/** + * @defgroup music PMPlib Music API + * @{ + */ + +/** + * Structure for a music record. + */ +struct tag_pmp_music_record_t { + /** + * Relative path for the music file from the mount location of the device. + * The path character must be '\\' on all platforms (including POSIX). + * e.g., "\\Music\\Beatles\\AbbeyRoad\\01_AbbeyRoad.mp3" + * @assert @code filename != NULL @endcode + */ + ucs2char_t *filename; + + /** + * Title name. + * e.g., "Come Together" + * @assert @code title != NULL @endcode + */ + ucs2char_t *title; + + /** + * Artist name. + * e.g., "The Beatles" + * @assert @code artist != NULL @endcode + */ + ucs2char_t *artist; + + /** + * Composer. + * e.g., "John Lennon" + * @assert @code composer != NULL @endcode + */ + ucs2char_t *composer; + + /** + * Album name. + * e.g., "Abbey Road" + * @assert @code album != NULL @endcode + */ + ucs2char_t *album; + + /** + * Genre name. + * e.g., "Rock" + * @assert @code genre != NULL @endcode + */ + ucs2char_t *genre; + + /** + * Release date. + * e.g., "1969" + * @assert @code date != NULL @endcode + */ + ucs2char_t *date; + + /** + * FourCC representation of the codec. + * e.g., PMPCODEC_MPEGLAYER3 + */ + uint32_t codec; + + /** + * Track number. + * e.g., 1 + */ + uint32_t track_number; + + /** + * Sample rate in [Hz]. + * e.g., 44100 + */ + uint32_t sample_rate; + + /** + * Bitrate in [bps]. + * e.g., 128000 + */ + uint32_t bitrate; + + /** + * Duration in seconds. + * e.g., 260 + */ + uint32_t duration; + + /** + * File size in bytes. + * e.g., 4160000 + */ + uint32_t filesize; + + /** + * Timestamp of the last update of the music file. + * The value is equivalent to \c st.st_mtime after \c stat(&st, filename); + */ + uint32_t ts_update; + + /** + * Rating. + * e.g., 5 + */ + uint32_t rating; + + /** + * Play count on the device. + * e.g., 23 + */ + uint32_t play_count; + + /** + * Timestamp of the recent playback on the device. + */ + uint32_t ts_playback; + + /** + * timestamp when the track was imported. + */ + uint32_t ts_import; +}; +typedef struct tag_pmp_music_record_t pmp_music_record_t; + +typedef struct { + ucs2char_t *name; + int num_entries; + ucs2char_t **entries; +} pmp_playlist_t; + +/** + * Interface for organizing music files. + * + * This interface is responsible for several operations relevant to music + * files in a portable media device. The major operations are: + * - setting a list of music records for building a music database + * - getting a list of music records from the existing music database + * - dumping the existing music database in a text format + * - setting a list of music files for generating + * - getting a list of music playlists used by the device + * + * You cannot create an instance of this structure by yourself. Access + * pmp_t::music member to obtain this interface. + */ +struct tag_pmp_music_t { + /** + * Pointer for the internal use. + * + * This member variable is reserved for the internal use of the library. + * Do not modify the value. + */ + void* instance; + + /** + * The pointer to pmp_t interface. + * + * @assert + * @code this->pmp->music == this @endcode + */ + pmp_t* pmp; + + /** + * Set a list of music records. + * + * This function sets a list of music records that provide a complete + * information about all music files on a device. Based on this list, + * PMPlib will build a music database on the device. + * + * This function does not write out any content on the player immediately + * for the following reason. Some portable devices manage a music database + * and playlists separately, but some integrate playlist information into + * a music database. In the latter case, PMPlib cannot build a music + * database until a definitive list of playlists is obtained. In order to + * support various devices in a unified interface, this function reserves + * a future update of the music database; a database update is prolonged + * until the device is closed by pmp->close() call. + * + * @param music The pointer to the pmp_music_t interface. + * @param records An array of music records. + * @param num_records The number of elements in \a records array. + * @retval result_t The status code after this operation. + * + * @assert + * @code music != NULL @endcode + * @code records != NULL @endcode + */ + result_t (*set_records)(pmp_music_t* music, const pmp_music_record_t* records, uint32_t num_records); + + /** + * Get a list of music records. + * + * This function gets the list of music records in the existing music + * database or set by \a set_records call. + * + * If the argument \a records is NULL, this function returns the number of + * music records to the variable whose address is specified by the + * argument \a num_records. You can use this for determining the size of + * array \a records necessary to obtain all records from this function. + * + * If the argument \a records is not NULL, this function copies the + * current music records to the array whose address is specified by the + * argument \a records and whose size is specified by the variable + * pointed by the argument \a num_records. + * + * @param music The pointer to the pmp_music_t interface. + * @param records An array of music records. + * @param num_records The pointer to the variable presenting the number + * of elements in \a records array. + * @retval result_t The status code after this operation. + * + * @assert + * @code music != NULL @endcode + * @code num_records != NULL @endcode + */ + result_t (*get_records)(pmp_music_t* music, pmp_music_record_t* records, uint32_t* num_records); + + /** + * Set a list of music playlists. + * + * This function sets a list of music playlists. PMPlib will generate the + * playlists on the device based on this list. + * + * This function does not write out any content on the player immediately; + * playlist generation is prolonged until the device is closed by + * pmp->close() call. + * + * @param music The pointer to the pmp_music_t interface. + * @param playlists An array of music playlists. + * @param num_playlists The number of elements in \a playlists array. + * @retval result_t The status code after this operation. + * + * @assert + * @code music != NULL @endcode + * @code playlists != NULL @endcode + */ + result_t (*set_playlists)(pmp_music_t* music, const pmp_playlist_t* playlists, uint32_t num_playlists); + + /** + * Get a list of music playlists. + * + * This function gets the list of music playlists in the device or set by + * \a set_playlists call. + * + * If the argument \a playlists is NULL, this function returns the number + * of music playlists to the variable whose address is specified by the + * argument \a num_playlists. You can use this for determining the size of + * array \a playlists necessary to obtain all playlists. + * + * If the argument \a playlists is not NULL, this function copies the + * current music playlists to the array whose address is specified by the + * argument \a playlists and whose size is specified by the variable + * pointed by the argument \a num_playlists. + * + * @param music The pointer to the pmp_music_t interface. + * @param playlists An array of music playlists. + * @param num_playlists The pointer to the variable presenting the + * number of elements in \a playlists array. + * @retval result_t The status code after this operation. + * + * @assert + * @code music != NULL @endcode + * @code num_playlists != NULL @endcode + */ + result_t (*get_playlists)(pmp_music_t* music, pmp_playlist_t* playlists, uint32_t* num_playlists); + + /** + * Dump the music database. + * + * @param music The pointer to the pmp_music_t interface. + * @param fp The pointer to an output stream. + * @param flag The flags. + * @retval result_t The status code after this operation. + * + * @assert + * @code music != NULL @endcode + */ + result_t (*dump)(pmp_music_t* music, FILE *fp, int flag); +}; + +/** + * Initialize pmp_music_record_t structure. + * + * @param record The pointer to pmp_music_record_t instance. + */ +PMPAPI void pmplib_record_init(pmp_music_record_t* record); + +/** + * Uninitialize pmp_music_record_t structure. + * + * This function frees the memory blocks used by the \a record. + * + * @param record The pointer to pmp_music_record_t instance. + */ +PMPAPI void pmplib_record_finish(pmp_music_record_t* record); + +/** + * Clone a pmp_music_record_t record. + * + * This function copies the values in the \a src record to \a dst. + * + * @param dst The pointer to the destination. + * @param src The pointer to the source. + * @retval result_t The status code after this operation. + */ +PMPAPI result_t pmplib_record_clone(pmp_music_record_t* dst, const pmp_music_record_t* src); + +/** + * Uninitialize an array of pmp_music_record_t records. + * + * This function frees the memory blocks used by each record in the array and + * the array. + * + * @param record The pointer to pmp_music_record_t array. + * @param num_records The number of elements in the array. + */ +PMPAPI void pmplib_records_finish(pmp_music_record_t* records, int num_records); + +/** + * Clone a pmp_music_record_t array. + * + * This function copies all records in the \a src array to \a dst. + * + * @param dst The destination array. + * @param src The source array. + * @param num_records The number of elements in the source array. + * @retval result_t The status code after this operation. + */ +PMPAPI result_t pmplib_records_clone(pmp_music_record_t* dst, const pmp_music_record_t* src, int num_records); + +PMPAPI void pmplib_playlist_init(pmp_playlist_t* playlist); +PMPAPI void pmplib_playlist_finish(pmp_playlist_t* playlist); +PMPAPI void pmplib_playlist_clone(pmp_playlist_t* dst, const pmp_playlist_t* src); + +PMPAPI void pmplib_playlists_finish(pmp_playlist_t* playlist, int num_playlists); +PMPAPI void pmplib_playlists_clone(pmp_playlist_t* dst, const pmp_playlist_t* src, int num_playlists); + +/** + * @} + */ + + +typedef result_t (*pmplib_create_t)(pmp_t** pmp, const ucs2char_t* path_to_device, const char *devid); + +/** + * Prototype for the callback function for receiving device identifiers. + * + */ +typedef void (*pmplib_enumerate_devid_callback_t)(void *instance, const char *devid); +typedef result_t (*pmplib_enumerate_devid_t)(pmplib_enumerate_devid_callback_t callback, void *instance); + +PMPAPI uint32_t pmplib_interlocked_increment(uint32_t* count); +PMPAPI uint32_t pmplib_interlocked_decrement(uint32_t* count); + + + + + + +/** + * @defgroup pmplib PMPlib Helper API + * @{ + * + * The PMPlib Helper API provides the utility for choosing a suitable PMPlib + * driver from a number of installed drivers. Because the PMPlib project + * implements a number of drivers for different portable media devices, an + * application must choose a suitable driver that matches to the target + * device. By using this API, an application can query a driver suitable for + * the portable media device specified by the mount location (root directory + * of the device) and/or the string identifier of a driver. An application can + * also enumerate the string identifiers of the drivers available in the + * system. + * + * An application must call pmplib_init() function to initialize the API + * and obtain the pointer to a ::pmplib_t instance that is used for subsequent + * calls of the API. + * The application can query an interface to a PMPlib driver by using + * pmplib_create() function. A list of installed device identifiers is + * obtained by receiving callback notifications invoked by + * pmplib_enumerate_devid() function. The application must terminate this + * API by calling pmplib_finish() function. + * + * This is an example of querying an interface to the driver that matches to + * the device connected to the mount point (Win32 path "D:\"): + * + * @code + * #include <ucs2char.h> + * #include <pmp.h> + * + * int main(int argc, char *argv[]) + * { + * result_t ret = 0; + * pmp_t* pmp = NULL; + * pmplib_t* pmplib = NULL; + * static const ucs2char_t path[] = {'D',':','\\',0}; + * + * // Initialize the PMPlib Helper API. + * if ((ret = pmplib_init(&pmplib)) != 0) { + * // Failed to initialize the API. + * goto error_exit; + * } + * + * // Query an interface to the PMPlib driver suitable for the path. + * if ((ret = pmplib_create(pmplib, &pmp, path, NULL)) != 0) { + * // Failed to find a suitable driver. + * goto error_exit; + * } + * + * // Processing with the driver. + * ... + * + * // Release the driver. + * pmp->release(pmp); + * + * // Terminate the helper API. + * pmplib_finish(pmplib); + * return 0; + * + * error_exit: + * // Error handling. + * ... + * return 1; + * } + * @endcode + * + * @{ + */ + +struct tag_pmplib_t; + +/** + * The structure for the PMPlib Helper API. + * An application should use a pointer to this structure as a handle value + * for this API. Call pmplib_init() function to obtain a pointer to this + * structure and pmplib_finish() function to terminate this API. Access to + * a member in this structure is prohibited since it is reserved for the + * internal use of the library only. + */ +typedef struct tag_pmplib_t pmplib_t; + +/** + * Initialize the PMPlib helper library. + * + * This function loads the drivers installed in the system to prepare them. + * + * @retval ptr_pmplib The pointer to the buffer to receive the pointer + * to the ::pmplib_t instance initialized by this + * function. + * @retval result_t The status code. + * + * @assert + * @code ptr_pmplib != NULL @endcode + * + * @note + * Call this function before using any other functions in this API. + */ +PMPAPI result_t pmplib_init(pmplib_t** ptr_pmplib); + +/** + * Uninitialize the PMPlib helper library. + * + * This function detatch the drivers loaded by pmplib_init() function. + * + * @param pmplib The pointer to the ::pmplib_t instance. + * @retval result_t The status code. + * + * @assert + * @code ptr_pmplib != NULL @endcode + * + * @note + * Call this function to terminate this API. + */ +PMPAPI result_t pmplib_finish(pmplib_t* pmplib); + +/** + * Query a driver and create a ::pmp_t instance. + * + * This function queries the driver suitable for the portable media device + * specified by the mount location and/or identifier, and returns the + * interface to the driver (::pmp_t instance). An application must specify + * parameter \a path_to_device. If parameter \a id is not \c NULL, this + * function obtains the interface to the driver with the device identifier + * specified in \a id parameter. If the parameter \a id is \c NULL, this + * function tries to recognize the model of the device based on the content + * of the files located under \a path_to_device. If successful, the interface + * to the driver will be returned in the \a pmp argument. + * + * @param pmplib The pointer to the ::pmplib_t instance. + * @param path_to_device A UCS-2 string representing the location of the + * target device. This parameter cannot be \c NULL. + * @param id A C-string representing the device identifier of + * the target device. If this argument is \c NULL, + * this function tries to recognize the model of the + * device based on the location (\a path_to_device). + * @retval ptr_pmp The pointer to the buffer to receive the pointer + * to the driver interface (::pmp_t instance). + * @retval result_t The status code. + * + * @assert + * @code pmplib != NULL @endcode + * @code ptr_pmp != NULL @endcode + * @code path_to_device != NULL @endcode + */ +PMPAPI result_t pmplib_create(pmplib_t* pmplib, pmp_t** ptr_pmp, const ucs2char_t* path_to_device, const char *id); + +/** + * Enumerate device identifiers of the installed drivers. + * + * This function enumerates the device identifiers of the installed drivers, + * and invokes the \a callback function for each identifier. + * + * @param pmplib The pointer to the ::pmplib_t instance. + * @param callback The pointer to the callback function to receive + * device identifiers. + * @param instance A user-defined instance value. The callback + * function will receive the same value. + * @retval result_t The status code. + * + * @assert + * @code pmplib != NULL @endcode + * @code callback != NULL @endcode + */ +PMPAPI result_t pmplib_enumerate_devid(pmplib_t* pmplib, pmplib_enumerate_devid_callback_t callback, void *instance); + +/** + * @} + */ + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif/*__cplusplus*/ + +#endif/*__PMP_H__*/ + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-02-09 01:55:34
|
Revision: 315 http://svn.sourceforge.net/pmplib/?rev=315&view=rev Author: nyaochi Date: 2007-02-08 17:55:34 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/pmplib/include/pmplib/ucs2char.h Removed Paths: ------------- trunk/pmplib/include/ucs2char.h Copied: trunk/pmplib/include/pmplib/ucs2char.h (from rev 314, trunk/pmplib/include/ucs2char.h) =================================================================== --- trunk/pmplib/include/pmplib/ucs2char.h (rev 0) +++ trunk/pmplib/include/pmplib/ucs2char.h 2007-02-09 01:55:34 UTC (rev 315) @@ -0,0 +1,682 @@ +/* + * UCS-2 character set library. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __UCS2CHAR_H__ +#define __UCS2CHAR_H__ + +#include <stdio.h> + +#ifdef UCS2_EXPORTS +#define UCS2API __declspec(dllexport) +#else +#define UCS2API +#endif + +#ifdef __cplusplus +extern "C" { +#endif/*__cplusplus*/ + +/** + * \addtogroup ucs2 UCS-2 Character/String API + * @{ + * + * The PMPlib UCS-2 character/string API provides a manupulation utility + * for characters/strings in UCS-2 encoding. As a number of portable media + * players support Unicode for displaying song information, PMPlib deals + * with Unicode characters/strings encoded in UCS-2. + * + * The byte order of UCS-2 character is dependent on the CPU architecture + * on which this code runs: e.g., little-endian on Intel IA-32/IA-64 and + * big-endian on IBM PowerPC. + */ + +/** + * Type definition of a UCS-2 character. + */ +typedef uint16_t ucs2char_t; + +/** + * Initialize the UCS-2 library. + * + * This function initializes internal variables used in the UCS-2 library. + * Call this function before using any other functions in this API. + * + * @retval int Zero if succeeded, otherwise non-zero value. + */ +UCS2API int ucs2init(); + + +/** + * @defgroup ucs2_conv Character encoding converter + * @{ + * + * This API subset converts the character encoding of a string from one to + * another. It supports mutual conversions between: + * UCS-2 and multi-byte character (i.e., \c char); + * UCS-2 and UTF-8. + * + * By default, this library detects the character encoding of multi-byte + * characters on the current system based on the value of LANG variable + * (for POSIX) or via GetACP() function (for Win32). + */ + +/** + * Set the encoding for multi-byte characters (for iconv/libiconv). + * + * This function change the default encoding for multi-byte characters to the + * character encoding specified by the \a encoding argument. + * + * @param encoding The pointer to the string specifying the character + * encoding. + * + * @note + * This function is effective only on environments with iconv (libiconv). + */ +UCS2API int ucs2setenc(const char *encoding); + +/** + * Get the encoding for multi-byte characters (for iconv/libiconv). + * + * This function returns the default encoding for multi-byte characters used + * in the UCS-2 API. + * + * @retval const char* The pointer to the string of the character encoding. + * + * @note + * This function is effective only on environments with iconv (libiconv). + */ +UCS2API const char *ucs2getenc(); + +/** + * Set the code page for multi-byte characters (for Win32). + * + * This function change the default encoding for multi-byte characters to the + * code page specified by the \a cp argument. + * + * @param cp The code page. + * + * @note + * This function is effective only on Win32 environments. + */ +UCS2API void ucs2setcp(int cp); + +/** + * Get the code page for multi-byte characters (for Win32). + * + * This function returns the default code page for multi-byte characters. + * + * @param cp The code page. + * + * @note + * This function is effective only on Win32 environments. + */ +UCS2API int ucs2getcp(); + +/** + * Convert a UCS-2 string to multi-byte characters. + * + * @param mbstr The pointer to the buffer for receiving multi-byte + * characters converted from the UCS-2 string. If + * \a mbs_size is zero, this argument is not be used. + * @param mbs_size The size, in bytes, of the buffer pointed to by the + * \a mbstr argument. If this value is zero, the function + * returns the number of bytes required for the buffer. + * @param ucs2str The pointer to the UCS-2 string to be converted. + * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 + * string, \a ucs2str. + * @retval size_t The number of bytes written to \a mbstr buffer if + * the conversion is successful. If \a mbs_size is zero, + * the return value is the required size, in bytes, for a + * buffer to receive the converted string. This function + * returns zero if an error occurred. + */ +UCS2API size_t ucs2tombs(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); + +/** + * Convert multi-byte characters to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the multi-byte characters. If + * \a ucs_size is zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the multi-byte characters to be + * converted. + * @param mbs_size The size, in bytes, of the multi-byte characters, + * \a mbstr. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + */ +UCS2API size_t mbstoucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); + +/** + * Convert multi-byte characters in a specific encoding to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the multi-byte characters. If + * \a ucs_size is zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the multi-byte characters to be + * converted. + * @param mbs_size The size, in bytes, of the multi-byte characters, + * \a mbstr. + * @param charset The pointer to the string specifying the encoding of + * the multi-byte characters. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + * @note + * \a charset is ignored on Win32 environments. + */ +UCS2API size_t mbstoucs2_charset(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size, const char *charset); + +/** + * Convert a UCS-2 string to multi-byte characters. + * + * @param mbstr The pointer to the buffer for receiving UTF-8 string + * converted from the UCS-2 string. If \a mbs_size is + * zero, this argument is not be used. + * @param mbs_size The size, in bytes, of the buffer pointed to by the + * \a mbstr argument. If this value is zero, the function + * returns the number of bytes required for the buffer. + * @param ucs2str The pointer to the UCS-2 string to be converted. + * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 + * string, \a ucs2str. + * @retval size_t The number of bytes written to \a mbstr buffer if + * the conversion is successful. If \a mbs_size is zero, + * the return value is the required size, in bytes, for a + * buffer to receive the converted string. This function + * returns zero if an error occurred. + */ +UCS2API size_t ucs2toutf8(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); + +/** + * Convert a UTF-8 string to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the UTF-8 string. If \a ucs_size is + * zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the UTF-8 string to be converted. + * @param mbs_size The size, in bytes, of the UTF-8 string, \a mbstr. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + */ +UCS2API size_t utf8toucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); + +/** + * Convert and duplicate a UCS-2 string to multi-byte characters. + * + * @param ucs2str The pointer to a UCS-2 string. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API char *ucs2dupmbs(const ucs2char_t *ucs2str); + +/** + * Convert and duplicate multi-byte characters to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* mbsdupucs2(const char *mbstr); + +/** + * Convert and duplicate multi-byte characters in a specific encoding + * to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @param charset The pointer to the string specifying the encoding of + * the multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* mbsdupucs2_charset(const char *mbstr, const char *charset); + +/** + * Convert and duplicate a UCS-2 string to a UTF-8 string. + * + * @param ucs2str The pointer to a UCS-2 string. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API char *ucs2duputf8(const ucs2char_t *ucs2str); + +/** + * Convert and duplicate a UTF-8 string to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* utf8dupucs2(const char *utf8str); + +/** + * @} + */ + + + +/** + * @defgroup ucs2_memory Memory manager routines + * @{ + */ + +/** + * Allocate a memory block. + * + * @param size The size, in bytes, of the memory block. + * @retval void* The pointer to the allocated memory block. + */ +UCS2API void *ucs2malloc(size_t size); + +/** + * Allocate a memory block with values initialized as zero. + * + * @param size The size, in bytes, of the memory block. + * @retval void* The pointer to the allocated memory block. + */ +UCS2API void *ucs2calloc(size_t size); + +/** + * Resize a memory block. + * + * @param ptr The pointer to the memory block to be resized. + * @param size The size, in bytes, of the new memory block. + * @retval void* The pointer to the new memory block. + */ +UCS2API void *ucs2realloc(void *ptr, size_t size); + +/** + * Free a memory block. + * + * @param ptr The pointer to the memory block to be freed. + */ +UCS2API void ucs2free(void* ptr); + +/** + * @} + */ + +/** + * @defgroup ucs2_char UCS-2 character routines + * @{ + */ + +/** + * Test whether a USC-2 character is a surrogate-pair character in UTF-16. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2issurrogate(ucs2char_t c); + +/** + * Test whether a USC-2 character is a whitespace character. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2isspace(ucs2char_t c); + +/** + * Test whether a USC-2 character is a numeric character. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2isdigit(ucs2char_t c); + +/** + * Convert a UCS-2 character to lower case. + * @param c The UCS-2 character to be coverted. + * @retval ucs2char_t The resultant UCS-2 character. + */ +UCS2API ucs2char_t ucs2lower(ucs2char_t c); + +/** + * Convert a UCS-2 character to upper case. + * @param c The UCS-2 character to be coverted. + * @retval ucs2char_t The resultant UCS-2 character. + */ +UCS2API ucs2char_t ucs2upper(ucs2char_t c); + +/** + * @} + */ + + + + + +/** + * @defgroup ucs2_string_ansi ANSI C compatible string routines + * @{ + * + * This is the subset of the UCS-2 Character/String API that corresponds + * to string manupulation routines in the ANSI C standard. The following + * ANSI C functions are not defined in this subset: + * strcoll, strerror, strtok, strxfrm. + */ + +/** + * Concatenate two strings. + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2cat(ucs2char_t* dst, const ucs2char_t* src); + +/** + * Search for the first occurrence of a character in a string. + * + * @param str The pointer to the string in which \a c is searched. + * @param c The target character. + * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL + * if \a c does not occur in \a str. + */ +UCS2API ucs2char_t* ucs2chr(const ucs2char_t* str, ucs2char_t c); + +/** + * Compare two strings. + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2cmp(const ucs2char_t* x, const ucs2char_t* y); + +/** + * Copy a string. + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2cpy(ucs2char_t* dst, const ucs2char_t* src); + +/** + * Count the number of characters not appearing in a character set. + * + * @param str The pointer to a string. + * @param charset The pointer to a character set. + * @retval size_t The number of characters from the beginning of \a str + * in which any character in \a charset appear for the + * first time, or the length of \a str if such a character + * does not exist. + */ +UCS2API size_t ucs2cspn(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Count the length of a string. + * + * @param str The pointer to a string. + * @retval size_t The number of characters in \a str. + */ +UCS2API size_t ucs2len(const ucs2char_t* str); + +/** + * Concatenate two strings (no more than the maximum length). + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @param n The number of characters to be concatenated. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2ncat(ucs2char_t *dst, const ucs2char_t *src, size_t n); + +/** + * Compare two strings (no longer than the maximum length). + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @param n The number of characters to be compared. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2ncmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); + +/** + * Copy a string (no more than the maximum length). + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @param n The number of characters to be copied. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2ncpy(ucs2char_t* dst, const ucs2char_t* src, size_t n); + +/** + * Find a character in a string that belongs to a character set. + * + * @param str The pointer to the string where \a charset is searched. + * @param charset The pointer to a character set. + * @retval ucs2char_t* The pointer to the character in \a str that belongs + * to \a charset, or \c NULL if such a character does not + * exist. + */ +UCS2API ucs2char_t* ucs2pbrk(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Search for the last occurrence of a character in a string. + * + * @param str The pointer to the string in which \a c is searched. + * @param c The target character. + * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL + * if \a c does not occur in \a str. + */ +UCS2API ucs2char_t* ucs2rchr(const ucs2char_t* string, ucs2char_t c); + +/** + * Find a character in a string that does not belong to a character set. + * + * @param str The pointer to the string where \a charset is searched. + * @param charset The pointer to a character set. + * @retval ucs2char_t* The pointer to the character in \a str that does not + * belong to \a charset, or \c NULL if such a character + * does not exist. + */ +UCS2API size_t ucs2spn(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Find a substring in a string. + * + * @param str The pointer to the string where \a substr is searched. + * @param substr The pointer to the substring. + * @retval ucs2char_t* The pointer to the character where \a substr begins + * in \a str for the first time, or \c NULL if \a str + * does not contain \a substr. + */ +UCS2API ucs2char_t* ucs2str(const ucs2char_t* str, const ucs2char_t* substr); + +/** + * @} + */ + + + + + +/** + * @defgroup ucs2_string_non_ansi Miscellaneous string routines + * @{ + */ + +/** + * Duplicate a string. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* ucs2dup(const ucs2char_t* str); + +/** + * Duplicate a string no longer than the specified length. + * + * @param str The pointer to a string. + * @param length The maximum length of the duplicated string. + * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* ucs2ndup(const ucs2char_t* src, size_t length); + +/** + * Convert a string to lowercase. + * + * Given \a str argument, this function converts uppercase letters in the + * string to lowercase and overwrites the resultant string on the same buffer + * pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2lwr(ucs2char_t* str); + +/** + * Convert a string to uppercase. + * + * Given \a str argument, this function converts lowercase letters in the + * string to uppercase and overwrites the resultant string on the same buffer + * pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2upr(ucs2char_t* str); + +/** + * Compare two strings incasesensitively. + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2icmp(const ucs2char_t* x, const ucs2char_t* y); + +/** + * Compare two strings incasesensitively (no longer than the maximum length). + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @param n The number of characters to be compared. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2incmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); + +/** + * Strip whitespace characters at the head and tail of a string. + * + * Given \a str argument, this function trims whilespace characters at the + * head and tail of the string and overwrites the resultant string on the + * same buffer pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2strip(ucs2char_t* str); + +/** + * @} + */ + + + +/** + * @defgroup ucs2_std Wrapper for stdio/stdlib routines + * @{ + */ + +/** + * Convert a UCS-2 string to integer value. + * @param str The pointer to a string. + * @retval int The corresponding integer value. + */ +UCS2API int ucs2toi(const ucs2char_t* str); + +/** + * Convert an integer value to UCS-2 string. + * @param value The integer value. + * @param string The pointer to the buffer to receive the string. + * @param radix Radix of the \a value. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* itoucs2(int value, ucs2char_t *string, int radix); + +/** + * Open a stream from a file. + * @param filename The pointer to the UCS-2 string for the file name. + * @param mode The pointer to the C string for the open mode. + * @retval FILE* The pointer to the opened stream if successful, + * NULL otherwise. + */ +UCS2API FILE *ucs2fopen(const ucs2char_t *filename, const char *mode); + +/** + * Write a UCS-2 character to a stream. + * @param c The character to be written. + * @param fp The pointer to the output stream. + * @retval int Zero if successful, non-zero otherwise. + */ +UCS2API int fputucs2c(ucs2char_t c, FILE *fp); + + + +/** @} */ + +/** @} */ + +#ifdef __cplusplus +} +#endif/*__cplusplus*/ + +#endif/*__UCS2CHAR_H__*/ Deleted: trunk/pmplib/include/ucs2char.h =================================================================== --- trunk/pmplib/include/ucs2char.h 2007-02-09 01:55:12 UTC (rev 314) +++ trunk/pmplib/include/ucs2char.h 2007-02-09 01:55:34 UTC (rev 315) @@ -1,682 +0,0 @@ -/* - * UCS-2 character set library. - * - * Copyright (c) 2005-2006 Nyaochi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* $Id$ */ - -#ifndef __UCS2CHAR_H__ -#define __UCS2CHAR_H__ - -#include <stdio.h> - -#ifdef UCS2_EXPORTS -#define UCS2API __declspec(dllexport) -#else -#define UCS2API -#endif - -#ifdef __cplusplus -extern "C" { -#endif/*__cplusplus*/ - -/** - * \addtogroup ucs2 UCS-2 Character/String API - * @{ - * - * The PMPlib UCS-2 character/string API provides a manupulation utility - * for characters/strings in UCS-2 encoding. As a number of portable media - * players support Unicode for displaying song information, PMPlib deals - * with Unicode characters/strings encoded in UCS-2. - * - * The byte order of UCS-2 character is dependent on the CPU architecture - * on which this code runs: e.g., little-endian on Intel IA-32/IA-64 and - * big-endian on IBM PowerPC. - */ - -/** - * Type definition of a UCS-2 character. - */ -typedef uint16_t ucs2char_t; - -/** - * Initialize the UCS-2 library. - * - * This function initializes internal variables used in the UCS-2 library. - * Call this function before using any other functions in this API. - * - * @retval int Zero if succeeded, otherwise non-zero value. - */ -UCS2API int ucs2init(); - - -/** - * @defgroup ucs2_conv Character encoding converter - * @{ - * - * This API subset converts the character encoding of a string from one to - * another. It supports mutual conversions between: - * UCS-2 and multi-byte character (i.e., \c char); - * UCS-2 and UTF-8. - * - * By default, this library detects the character encoding of multi-byte - * characters on the current system based on the value of LANG variable - * (for POSIX) or via GetACP() function (for Win32). - */ - -/** - * Set the encoding for multi-byte characters (for iconv/libiconv). - * - * This function change the default encoding for multi-byte characters to the - * character encoding specified by the \a encoding argument. - * - * @param encoding The pointer to the string specifying the character - * encoding. - * - * @note - * This function is effective only on environments with iconv (libiconv). - */ -UCS2API int ucs2setenc(const char *encoding); - -/** - * Get the encoding for multi-byte characters (for iconv/libiconv). - * - * This function returns the default encoding for multi-byte characters used - * in the UCS-2 API. - * - * @retval const char* The pointer to the string of the character encoding. - * - * @note - * This function is effective only on environments with iconv (libiconv). - */ -UCS2API const char *ucs2getenc(); - -/** - * Set the code page for multi-byte characters (for Win32). - * - * This function change the default encoding for multi-byte characters to the - * code page specified by the \a cp argument. - * - * @param cp The code page. - * - * @note - * This function is effective only on Win32 environments. - */ -UCS2API void ucs2setcp(int cp); - -/** - * Get the code page for multi-byte characters (for Win32). - * - * This function returns the default code page for multi-byte characters. - * - * @param cp The code page. - * - * @note - * This function is effective only on Win32 environments. - */ -UCS2API int ucs2getcp(); - -/** - * Convert a UCS-2 string to multi-byte characters. - * - * @param mbstr The pointer to the buffer for receiving multi-byte - * characters converted from the UCS-2 string. If - * \a mbs_size is zero, this argument is not be used. - * @param mbs_size The size, in bytes, of the buffer pointed to by the - * \a mbstr argument. If this value is zero, the function - * returns the number of bytes required for the buffer. - * @param ucs2str The pointer to the UCS-2 string to be converted. - * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 - * string, \a ucs2str. - * @retval size_t The number of bytes written to \a mbstr buffer if - * the conversion is successful. If \a mbs_size is zero, - * the return value is the required size, in bytes, for a - * buffer to receive the converted string. This function - * returns zero if an error occurred. - */ -UCS2API size_t ucs2tombs(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); - -/** - * Convert multi-byte characters to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the multi-byte characters. If - * \a ucs_size is zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the multi-byte characters to be - * converted. - * @param mbs_size The size, in bytes, of the multi-byte characters, - * \a mbstr. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - */ -UCS2API size_t mbstoucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); - -/** - * Convert multi-byte characters in a specific encoding to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the multi-byte characters. If - * \a ucs_size is zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the multi-byte characters to be - * converted. - * @param mbs_size The size, in bytes, of the multi-byte characters, - * \a mbstr. - * @param charset The pointer to the string specifying the encoding of - * the multi-byte characters. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - * @note - * \a charset is ignored on Win32 environments. - */ -UCS2API size_t mbstoucs2_charset(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size, const char *charset); - -/** - * Convert a UCS-2 string to multi-byte characters. - * - * @param mbstr The pointer to the buffer for receiving UTF-8 string - * converted from the UCS-2 string. If \a mbs_size is - * zero, this argument is not be used. - * @param mbs_size The size, in bytes, of the buffer pointed to by the - * \a mbstr argument. If this value is zero, the function - * returns the number of bytes required for the buffer. - * @param ucs2str The pointer to the UCS-2 string to be converted. - * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 - * string, \a ucs2str. - * @retval size_t The number of bytes written to \a mbstr buffer if - * the conversion is successful. If \a mbs_size is zero, - * the return value is the required size, in bytes, for a - * buffer to receive the converted string. This function - * returns zero if an error occurred. - */ -UCS2API size_t ucs2toutf8(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); - -/** - * Convert a UTF-8 string to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the UTF-8 string. If \a ucs_size is - * zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the UTF-8 string to be converted. - * @param mbs_size The size, in bytes, of the UTF-8 string, \a mbstr. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - */ -UCS2API size_t utf8toucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); - -/** - * Convert and duplicate a UCS-2 string to multi-byte characters. - * - * @param ucs2str The pointer to a UCS-2 string. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API char *ucs2dupmbs(const ucs2char_t *ucs2str); - -/** - * Convert and duplicate multi-byte characters to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* mbsdupucs2(const char *mbstr); - -/** - * Convert and duplicate multi-byte characters in a specific encoding - * to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @param charset The pointer to the string specifying the encoding of - * the multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* mbsdupucs2_charset(const char *mbstr, const char *charset); - -/** - * Convert and duplicate a UCS-2 string to a UTF-8 string. - * - * @param ucs2str The pointer to a UCS-2 string. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API char *ucs2duputf8(const ucs2char_t *ucs2str); - -/** - * Convert and duplicate a UTF-8 string to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* utf8dupucs2(const char *utf8str); - -/** - * @} - */ - - - -/** - * @defgroup ucs2_memory Memory manager routines - * @{ - */ - -/** - * Allocate a memory block. - * - * @param size The size, in bytes, of the memory block. - * @retval void* The pointer to the allocated memory block. - */ -UCS2API void *ucs2malloc(size_t size); - -/** - * Allocate a memory block with values initialized as zero. - * - * @param size The size, in bytes, of the memory block. - * @retval void* The pointer to the allocated memory block. - */ -UCS2API void *ucs2calloc(size_t size); - -/** - * Resize a memory block. - * - * @param ptr The pointer to the memory block to be resized. - * @param size The size, in bytes, of the new memory block. - * @retval void* The pointer to the new memory block. - */ -UCS2API void *ucs2realloc(void *ptr, size_t size); - -/** - * Free a memory block. - * - * @param ptr The pointer to the memory block to be freed. - */ -UCS2API void ucs2free(void* ptr); - -/** - * @} - */ - -/** - * @defgroup ucs2_char UCS-2 character routines - * @{ - */ - -/** - * Test whether a USC-2 character is a surrogate-pair character in UTF-16. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2issurrogate(ucs2char_t c); - -/** - * Test whether a USC-2 character is a whitespace character. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2isspace(ucs2char_t c); - -/** - * Test whether a USC-2 character is a numeric character. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2isdigit(ucs2char_t c); - -/** - * Convert a UCS-2 character to lower case. - * @param c The UCS-2 character to be coverted. - * @retval ucs2char_t The resultant UCS-2 character. - */ -UCS2API ucs2char_t ucs2lower(ucs2char_t c); - -/** - * Convert a UCS-2 character to upper case. - * @param c The UCS-2 character to be coverted. - * @retval ucs2char_t The resultant UCS-2 character. - */ -UCS2API ucs2char_t ucs2upper(ucs2char_t c); - -/** - * @} - */ - - - - - -/** - * @defgroup ucs2_string_ansi ANSI C compatible string routines - * @{ - * - * This is the subset of the UCS-2 Character/String API that corresponds - * to string manupulation routines in the ANSI C standard. The following - * ANSI C functions are not defined in this subset: - * strcoll, strerror, strtok, strxfrm. - */ - -/** - * Concatenate two strings. - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2cat(ucs2char_t* dst, const ucs2char_t* src); - -/** - * Search for the first occurrence of a character in a string. - * - * @param str The pointer to the string in which \a c is searched. - * @param c The target character. - * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL - * if \a c does not occur in \a str. - */ -UCS2API ucs2char_t* ucs2chr(const ucs2char_t* str, ucs2char_t c); - -/** - * Compare two strings. - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2cmp(const ucs2char_t* x, const ucs2char_t* y); - -/** - * Copy a string. - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2cpy(ucs2char_t* dst, const ucs2char_t* src); - -/** - * Count the number of characters not appearing in a character set. - * - * @param str The pointer to a string. - * @param charset The pointer to a character set. - * @retval size_t The number of characters from the beginning of \a str - * in which any character in \a charset appear for the - * first time, or the length of \a str if such a character - * does not exist. - */ -UCS2API size_t ucs2cspn(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Count the length of a string. - * - * @param str The pointer to a string. - * @retval size_t The number of characters in \a str. - */ -UCS2API size_t ucs2len(const ucs2char_t* str); - -/** - * Concatenate two strings (no more than the maximum length). - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @param n The number of characters to be concatenated. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2ncat(ucs2char_t *dst, const ucs2char_t *src, size_t n); - -/** - * Compare two strings (no longer than the maximum length). - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @param n The number of characters to be compared. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2ncmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); - -/** - * Copy a string (no more than the maximum length). - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @param n The number of characters to be copied. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2ncpy(ucs2char_t* dst, const ucs2char_t* src, size_t n); - -/** - * Find a character in a string that belongs to a character set. - * - * @param str The pointer to the string where \a charset is searched. - * @param charset The pointer to a character set. - * @retval ucs2char_t* The pointer to the character in \a str that belongs - * to \a charset, or \c NULL if such a character does not - * exist. - */ -UCS2API ucs2char_t* ucs2pbrk(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Search for the last occurrence of a character in a string. - * - * @param str The pointer to the string in which \a c is searched. - * @param c The target character. - * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL - * if \a c does not occur in \a str. - */ -UCS2API ucs2char_t* ucs2rchr(const ucs2char_t* string, ucs2char_t c); - -/** - * Find a character in a string that does not belong to a character set. - * - * @param str The pointer to the string where \a charset is searched. - * @param charset The pointer to a character set. - * @retval ucs2char_t* The pointer to the character in \a str that does not - * belong to \a charset, or \c NULL if such a character - * does not exist. - */ -UCS2API size_t ucs2spn(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Find a substring in a string. - * - * @param str The pointer to the string where \a substr is searched. - * @param substr The pointer to the substring. - * @retval ucs2char_t* The pointer to the character where \a substr begins - * in \a str for the first time, or \c NULL if \a str - * does not contain \a substr. - */ -UCS2API ucs2char_t* ucs2str(const ucs2char_t* str, const ucs2char_t* substr); - -/** - * @} - */ - - - - - -/** - * @defgroup ucs2_string_non_ansi Miscellaneous string routines - * @{ - */ - -/** - * Duplicate a string. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* ucs2dup(const ucs2char_t* str); - -/** - * Duplicate a string no longer than the specified length. - * - * @param str The pointer to a string. - * @param length The maximum length of the duplicated string. - * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* ucs2ndup(const ucs2char_t* src, size_t length); - -/** - * Convert a string to lowercase. - * - * Given \a str argument, this function converts uppercase letters in the - * string to lowercase and overwrites the resultant string on the same buffer - * pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2lwr(ucs2char_t* str); - -/** - * Convert a string to uppercase. - * - * Given \a str argument, this function converts lowercase letters in the - * string to uppercase and overwrites the resultant string on the same buffer - * pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2upr(ucs2char_t* str); - -/** - * Compare two strings incasesensitively. - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2icmp(const ucs2char_t* x, const ucs2char_t* y); - -/** - * Compare two strings incasesensitively (no longer than the maximum length). - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @param n The number of characters to be compared. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2incmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); - -/** - * Strip whitespace characters at the head and tail of a string. - * - * Given \a str argument, this function trims whilespace characters at the - * head and tail of the string and overwrites the resultant string on the - * same buffer pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2strip(ucs2char_t* str); - -/** - * @} - */ - - - -/** - * @defgroup ucs2_std Wrapper for stdio/stdlib routines - * @{ - */ - -/** - * Convert a UCS-2 string to integer value. - * @param str The pointer to a string. - * @retval int The corresponding integer value. - */ -UCS2API int ucs2toi(const ucs2char_t* str); - -/** - * Convert an integer value to UCS-2 string. - * @param value The integer value. - * @param string The pointer to the buffer to receive the string. - * @param radix Radix of the \a value. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* itoucs2(int value, ucs2char_t *string, int radix); - -/** - * Open a stream from a file. - * @param filename The pointer to the UCS-2 string for the file name. - * @param mode The pointer to the C string for the open mode. - * @retval FILE* The pointer to the opened stream if successful, - * NULL otherwise. - */ -UCS2API FILE *ucs2fopen(const ucs2char_t *filename, const char *mode); - -/** - * Write a UCS-2 character to a stream. - * @param c The character to be written. - * @param fp The pointer to the output stream. - * @retval int Zero if successful, non-zero otherwise. - */ -UCS2API int fputucs2c(ucs2char_t c, FILE *fp); - - - -/** @} */ - -/** @} */ - -#ifdef __cplusplus -} -#endif/*__cplusplus*/ - -#endif/*__UCS2CHAR_H__*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |