00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (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 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 /*! 00019 * @defgroup argv Argument vector conversion 00020 * 00021 * The command line arguments are the whitespace-separated tokens given in the 00022 * shell command used to invoke the program; thus, in `cat foo bar', the 00023 * arguments are `foo' and `bar'. For the command `cat foo bar', argc is 3 and 00024 * argv has three elements, "cat", "foo" and "bar". 00025 * 00026 * The argv_from_str() and argv_to_str() functions convert an argument vector 00027 * (as in main()) from and to a string (as seen in the shell), respectively. 00028 * 00029 * @{ 00030 */ 00031 00032 #ifndef _LUCID_ARGV_H 00033 #define _LUCID_ARGV_H 00034 00035 /*! 00036 * @brief convert string to argument vector 00037 * 00038 * @param[in] str space seperated string to convert 00039 * @param[out] argv argument vector to fill 00040 * @param[in] argc size of argv 00041 * 00042 * @return number of arguments that (would) have been converted 00043 * 00044 * @note the caller has to allocate memory for argv 00045 * @note this function modifies its first argument, use with caution 00046 */ 00047 int argv_from_str(char *str, char ** const argv, int argc); 00048 00049 /*! 00050 * @brief convert argument vector to string 00051 * 00052 * @param[in] argc size of argv 00053 * @param[in] argv argument vector to convert 00054 * 00055 * @return space seperated string (obtained by malloc(3)) 00056 * 00057 * @note The caller should free obtained memory using free(3) 00058 * 00059 * @see malloc(3) 00060 * @see free(3) 00061 */ 00062 char *argv_to_str(int argc, const char ** const argv); 00063 00064 #endif 00065 00066 /*! @} argv */