strtok.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org>
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00016 
00017 /*!
00018  * @defgroup strtok String tokenizer
00019  *
00020  * @{
00021  */
00022 
00023 #ifndef _LUCID_STRTOK_H
00024 #define _LUCID_STRTOK_H
00025 
00026 #ifdef _LUCID_BUILD_
00027 #include "list.h"
00028 #else
00029 #include <lucid/list.h>
00030 #endif
00031 
00032 typedef struct {
00033         list_t list;
00034         char *token;
00035 } strtok_t;
00036 
00037 
00038 /*!
00039  * @brief initialize string tokenizer from argument vector
00040  *
00041  * @param[out] st    tokenizer to initialize
00042  * @param[in]  argv  argument vector
00043  * @param[in]  argc  argument vector size
00044  *
00045  * @return A pointer to st.
00046  */
00047 strtok_t *strtok_init_argv(strtok_t *st, char *argv[], int argc, int empty);
00048 
00049 /*!
00050  * @brief initialize string tokenizer from character array
00051  *
00052  * @param[out] st    tokenizer to initialize
00053  * @param[in]  str   pointer to a string
00054  * @param[in]  delim token delimiter
00055  * @param[in]  empty convert empty tokens
00056  *
00057  * @return A pointer to st.
00058  */
00059 strtok_t *strtok_init_str(strtok_t *st, const char *str, char *delim, int empty);
00060 
00061 /*!
00062  * @brief deallocate string tokenizer
00063  *
00064  * @param[out] st    tokenizer to free
00065  */
00066 void strtok_free(strtok_t *st);
00067 
00068 
00069 /*!
00070  * @brief count number of tokens
00071  *
00072  * @param[out] st    tokenizer to initialize
00073  *
00074  * @return Number of tokens in st.
00075  */
00076 int strtok_count(strtok_t *st);
00077 
00078 
00079 /*!
00080  * @brief append a token
00081  *
00082  * @param[out] st    tokenizer to append to
00083  * @param[in]  token token to append
00084  *
00085  * @return 0 on success, -1 on error with errno set.
00086  */
00087 int strtok_append(strtok_t *st, const char *token);
00088 
00089 /*!
00090  * @brief delete one or more tokens
00091  *
00092  * @param[out] st    tokenizer to delete from
00093  * @param[in]  token token to delete
00094  */
00095 void strtok_delete(strtok_t *st, const char *token);
00096 
00097 /*!
00098  * @brief Go to the previous token
00099  *
00100  * @param[in] st tokenizer to iterate
00101  */
00102 char *strtok_prev(strtok_t **st);
00103 
00104 /*!
00105  * @brief Go to the previous token
00106  *
00107  * @param[in] st tokenizer to iterate
00108  */
00109 char *strtok_next(strtok_t **st);
00110 
00111 /*! @brief interate through tokens */
00112 #define strtok_for_each(st, p) list_for_each_entry(p, &(st->list), list)
00113 
00114 
00115 /*!
00116  * @brief convert string tokenizer to argument vector
00117  *
00118  * @param[out] st   tokenizer to convert
00119  * @param[in]  argv pointer to an argument vector
00120  * @param[in]  argc pointer to number of elements stored in argv
00121  *
00122  * @param 0 on success, -1 on error with errno set.
00123  */
00124 int strtok_toargv(strtok_t *st, char **argv);
00125 
00126 /*!
00127  * @brief convert string tokenizer to character array
00128  *
00129  * @param[out] st  tokenizer to convert
00130  * @param[in]  str pointer to a string
00131  *
00132  * @param 0 on success, -1 on error with errno set.
00133  */
00134 int strtok_tostr(strtok_t *st, char **str, char *delim);
00135 
00136 #endif
00137 
00138 /*! @} strtok */

Generated on Tue Jun 19 20:38:27 2007 for lucid by  doxygen 1.5.2