You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
9.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/util/backends/arguments.h
  3. *
  4. * Purpose: Pantheios back end API
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2009, Matthew Wilson and Synesis Software
  12. * Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/util/backends/arguments.h
  42. *
  43. * [C, C++] Definition of the back-end parsing functions.
  44. */
  45. #ifndef PANTHEIOS_INCL_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS
  46. #define PANTHEIOS_INCL_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS
  47. /* /////////////////////////////////////////////////////////////////////////
  48. * Version information
  49. */
  50. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  51. # define PANTHEIOS_VER_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS_MAJOR 2
  52. # define PANTHEIOS_VER_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS_MINOR 1
  53. # define PANTHEIOS_VER_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS_REVISION 1
  54. # define PANTHEIOS_VER_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS_EDIT 22
  55. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  60. # include <pantheios/pantheios.h>
  61. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Parsing functions
  64. */
  65. /** Parses a single boolean back-end argument
  66. *
  67. * \ingroup group__backend
  68. *
  69. * Searches the argument slices list for an argument of the given name. If
  70. * it has one of the values ['yes', 'true', 'no', 'false'] the flags
  71. * parameter is adjusted to either set or remove the flagValue value, as
  72. * directed by the flagSuppressesAction parameter, and the argument is
  73. * marked as having been processed by setting its length to 0.
  74. *
  75. * \param numArgs Number of elements in the argument array. May be 0
  76. * \param args Pointer to the base of the argument array. May only be NULL
  77. * if numArgs is 0
  78. * \param argName The name of the value to look for. May not be NULL
  79. * \param flagSuppressesAction Indicates whether the flagValue is a
  80. * suppression flag, such as PANTHEIOS_BE_INIT_F_NO_SEVERITY, rather than
  81. * an activation flag, such as PANTHEIOS_BE_INIT_F_USE_SYSTEM_TIME.
  82. * \param flagValue A flag value, such as PANTHEIOS_BE_INIT_F_NO_SEVERITY
  83. * \param flags A pointer to a flags variable whose value may be modified
  84. * upon a successful match. May not be NULL.
  85. *
  86. * \return An indication of whether a valid argument was found
  87. * \retval 0 No matching arguments were found, or the argument was found but
  88. * did not have boolean values
  89. * \retval 1 An argument with the given name, and with values interpretable as
  90. * boolean, was found.
  91. *
  92. * \pre NULL != args || 0 == numArgs
  93. * \pre NULL != argName
  94. * \pre NULL != flags
  95. */
  96. PANTHEIOS_CALL(int) pantheios_be_parseBooleanArg(size_t numArgs
  97. #ifdef PANTHEIOS_NO_NAMESPACE
  98. , pan_slice_t* const args
  99. , pan_char_t const* argName
  100. , int flagSuppressesAction
  101. , pan_uint32_t flagValue
  102. , pan_uint32_t* flags);
  103. #else /* ? PANTHEIOS_NO_NAMESPACE */
  104. , pantheios::pan_slice_t* const args
  105. , pantheios::pan_char_t const* argName
  106. , int flagSuppressesAction
  107. , pantheios::pan_uint32_t flagValue
  108. , pantheios::uint32_t* flags);
  109. #endif /* PANTHEIOS_NO_NAMESPACE */
  110. /** Parses a single string back-end argument
  111. *
  112. * \ingroup group__backend
  113. *
  114. * Searches the argument slices list for an argument of the given name. If
  115. * found, it transfers the slice (i.e. copies the pointers) to the given
  116. * argument value parameter.
  117. *
  118. * \param numArgs Number of elements in the argument array. May be 0
  119. * \param args Pointer to the base of the argument array. May only be NULL
  120. * if numArgs is 0
  121. * \param argName The name of the value to look for. May not be NULL
  122. * \param argValue A pointer to a slice that will receive the value part of
  123. * an argument if successfully matched. May not be NULL.
  124. *
  125. * \pre NULL != args || 0 == numArgs
  126. * \pre NULL != argName
  127. * \pre NULL != argValue
  128. */
  129. PANTHEIOS_CALL(int) pantheios_be_parseStringArg(size_t numArgs
  130. #ifdef PANTHEIOS_NO_NAMESPACE
  131. , pan_slice_t* const args
  132. , pan_char_t const* argName
  133. , pan_slice_t* argValue);
  134. #else /* ? PANTHEIOS_NO_NAMESPACE */
  135. , pantheios::pan_slice_t* const args
  136. , pantheios::pan_char_t const* argName
  137. , pantheios::pan_slice_t* argValue);
  138. #endif /* PANTHEIOS_NO_NAMESPACE */
  139. /** Parses the stock back-end arguments
  140. *
  141. * \ingroup group__backend
  142. *
  143. * Searches the argument slices list for the arguments associated with all
  144. * stock \ref group__backend__init__flags. For each argument found (and
  145. * having an appropriate value; see pantheios_be_parseBooleanArg()) its
  146. * value is processed, the flags parameter's value is adjusted
  147. * accordingly, and the argument slice's length is set to 0 to indicate
  148. * that it has been successfully processed. Returns the number of arguments
  149. * successfully matched.
  150. *
  151. * Recognises the following argument names:
  152. * - "showProcessId" (Boolean)
  153. * - "showTime" (Boolean)
  154. * - "showSeverity" (Boolean)
  155. * - "useSystemTime" (Boolean)
  156. * - "showDetailsAtStart" (Boolean)
  157. * - "useUnixFormat" (Boolean)
  158. * - "showDate" (Boolean)
  159. * - "showTime" (Boolean)
  160. * - "highResolution" (Boolean)
  161. * - "lowResolution" (Boolean)
  162. *
  163. * \param numArgs Number of elements in the argument array. May be 0
  164. * \param args Pointer to the base of the argument array. May only be NULL
  165. * if numArgs is 0
  166. * \param flags A pointer to a flags variable whose value may be modified
  167. * upon a successful matches. May not be NULL.
  168. *
  169. * \return The number of arguments successfully matched
  170. *
  171. * \pre NULL != args || 0 == numArgs
  172. * \pre NULL != flags
  173. */
  174. PANTHEIOS_CALL(int) pantheios_be_parseStockArgs(size_t numArgs
  175. #ifdef PANTHEIOS_NO_NAMESPACE
  176. , pan_slice_t* const args
  177. , pan_uint32_t* flags);
  178. #else /* ? PANTHEIOS_NO_NAMESPACE */
  179. , pantheios::pan_slice_t* const args
  180. , pantheios::uint32_t* flags);
  181. #endif /* PANTHEIOS_NO_NAMESPACE */
  182. /* ////////////////////////////////////////////////////////////////////// */
  183. #endif /* !PANTHEIOS_INCL_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS */
  184. /* ///////////////////////////// end of file //////////////////////////// */