Move comments documenting functions from the function definitions (.c
files) to the function declarations (.h files).  This convention means
that any installed headers (which describe the public API) will
include API documentaiton.  (The .c files are never installed, so
users won't see the documentation of public APIs if the comments are
in the .c files, unless the comments are converted to Doxygen and the
Doxygen documentation is compiled and installed.)
---
 lib/util/stringutils.c | 88 ---------------------------------------------
 lib/util/stringutils.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 88 deletions(-)

diff --git a/lib/util/stringutils.c b/lib/util/stringutils.c
index bcc046c..bb86318 100644
--- a/lib/util/stringutils.c
+++ b/lib/util/stringutils.c
@@ -12,9 +12,6 @@
 #include <errno.h>
 
 
-/*
- * Does string s end with suffix?
- */
 int endswith(
     const char *s,
     const char *suffix)
@@ -37,9 +34,6 @@ int endswith(
 }
 
 
-/*
- * Does string s start with prefix?
- */
 int startswith(
     const char *s,
     const char *prefix)
@@ -63,9 +57,6 @@ int startswith(
 }
 
 
-/*
- * Return true if the string contains at least one non-delimiter character.
- */
 int exists_non_delimiter(
     const char *s,
     const char *delimiters)
@@ -82,9 +73,6 @@ int exists_non_delimiter(
 }
 
 
-/*
- * Strip all leftmost delimiter characters from input string (in place).
- */
 void lstrip(
     char *s,
     const char *delimiters)
@@ -103,9 +91,6 @@ void lstrip(
 }
 
 
-/*
- * Strip all rightmost delimiter characters from input string (in place).
- */
 void rstrip(
     char *s,
     const char *delimiters)
@@ -120,9 +105,6 @@ void rstrip(
 }
 
 
-/*
- * Strip all leftmost and rightmost delimiter characters (in place).
- */
 void strip(
     char *s,
     const char *delimiters)
@@ -132,12 +114,6 @@ void strip(
 }
 
 
-/*
- * Return the next field, i.e. pointer to the beginning of the next contiguous
- * string of non-delimiter characters.  Note that this skips the current
- * contiguous string of non-delimiter characters. Returns NULL if there are no
- * more non-delimiter characters in the string.
- */
 char *start_of_next_field(
     const char *s,
     const char *delimiters)
@@ -164,12 +140,6 @@ char *start_of_next_field(
 }
 
 
-/*
- * Copy the current field (contiguous string of non-delimiter characters) into
- * the destination buffer, up to dest_length-1 bytes. Append '\0' to terminate
- * the C string.  If the buffer size is insufficient, safely null-terminate
- * the destination buffer and return NULL.
- */
 char *this_field(
     char *dest,
     int dest_length,
@@ -203,10 +173,6 @@ char *this_field(
 }
 
 
-/*
- * Return the length of the current field (contiguous string of non-delimiter
- * characters).  Returns -1 on error cases.
- */
 int field_length(
     const char *s,
     const char *delimiters)
@@ -223,29 +189,6 @@ int field_length(
 }
 
 
-/*
- * Split a string on given delimiters.
- *
- * This modifies the original string by terminating each field with a NULL
- * character.  The function also allocates an array of char* and populates it
- * with pointers back into the original string, each pointer indicating the
- * start of a field.  The caller is responsible for freeing the memory
- * allocated at address *pfields.
- *
- * Intuitively, if the delimiters are whitespace, this function parses a
- * command line string into char *argv[] and sets argc.  Strictly speaking,
- * this is not a complete replica of command line parsing because quoting is
- * not supported.
- *
- * Inputs: s - string to be split delimiters - list of characters to split on
- * (field delimiters)
- *
- * Outputs: s - string is modified in place pfields - address of char** that
- * will store the array of fields pnumfields - address of int that will store
- * the number of fields
- *
- * Returns: 0 on success, -1 on failure and sets errno accordingly.
- */
 int split_string(
     char *s,
     const char *delimiters,
@@ -308,30 +251,6 @@ int split_string(
 }
 
 
-/*
- * Expand an array by doubling the amount of elements allocated. Behaves much
- * like realloc(), and so the following two paragraphs are copied from the
- * realloc() man page for reference: realloc() changes the size of the memory
- * block pointed to by ptr to size bytes.  The contents will be unchanged to
- * the minimum of the old and new sizes; newly allocated memory will be
- * uninitialized.  If ptr is NULL, the call is equivalent to malloc(size); if
- * size is equal to zero, the call is equivalent to free(ptr).  Unless ptr is
- * NULL, it must have been returned by an earlier call to malloc(), calloc()
- * or realloc().  Returns a pointer to the newly allocated memory, which is
- * suitably aligned for any kind of variable and may be different from ptr, or
- * NULL if the request fails. If size was equal to 0, either NULL or a pointer
- * suitable to be passed to free() is returned.  If realloc() fails the
- * original block is left untouched - it is not freed or moved. Inputs: ptr
- * - address of pointer to array of members (*ptr may be NULL). current_nmemb
- * - current number of members allocated for the array min_nmemb - minimum
- * number of members requested for the output array Outputs: If the
- * realloc_by_doubling() was successful, *ptr is updated to the new pointer,
- * and *current_nmemb is updated to the new number of members.  Note that you
- * won't get the expected exponential reallocation if you call this more than
- * about 30 times, since size_t is often 32 bits. Returns: 0 on success; -1
- * and sets errno on failure.
- */
-
 int expand_by_doubling(
     void **ptr,
     size_t size,
@@ -377,13 +296,6 @@ int expand_by_doubling(
     return 0;
 }
 
-/**=============================================================================
- * @brief Replace questionable chars from string for printing.
- *
- * @note Caller handles memory for dst.
- * @note Output might be truncated, compared to input.
- * @note dst will be null terminated, at or before index dst_sz-1.
-------------------------------------------------------------------------------*/
 char *scrub_for_print(
     char *dst,
     char const *src,
diff --git a/lib/util/stringutils.h b/lib/util/stringutils.h
index 207e6c1..61030b3 100644
--- a/lib/util/stringutils.h
+++ b/lib/util/stringutils.h
@@ -7,45 +7,143 @@
 
 #include <stddef.h>
 
+/*
+ * Does string s end with suffix?
+ */
 int endswith(
     const char *s,
     const char *suffix);
+
+/*
+ * Does string s start with prefix?
+ */
 int startswith(
     const char *s,
     const char *prefix);
+
+/*
+ * Strip all leftmost delimiter characters from input string (in place).
+ */
 void lstrip(
     char *s,
     const char *delimiters);
+
+/*
+ * Strip all rightmost delimiter characters from input string (in place).
+ */
 void rstrip(
     char *s,
     const char *delimiters);
+
+/*
+ * Strip all leftmost and rightmost delimiter characters (in place).
+ */
 void strip(
     char *s,
     const char *delimiters);
+
+/*
+ * Return true if the string contains at least one non-delimiter character.
+ */
 int exists_non_delimiter(
     const char *s,
     const char *delimiters);
+
+/*
+ * Return the next field, i.e. pointer to the beginning of the next contiguous
+ * string of non-delimiter characters.  Note that this skips the current
+ * contiguous string of non-delimiter characters. Returns NULL if there are no
+ * more non-delimiter characters in the string.
+ */
 char *start_of_next_field(
     const char *s,
     const char *delimiters);
+
+/*
+ * Copy the current field (contiguous string of non-delimiter characters) into
+ * the destination buffer, up to dest_length-1 bytes. Append '\0' to terminate
+ * the C string.  If the buffer size is insufficient, safely null-terminate
+ * the destination buffer and return NULL.
+ */
 char *this_field(
     char *dest,
     int dest_length,
     const char *src,
     const char *delimiters);
+
+/*
+ * Return the length of the current field (contiguous string of non-delimiter
+ * characters).  Returns -1 on error cases.
+ */
 int field_length(
     const char *s,
     const char *delimiters);
+
+/*
+ * Split a string on given delimiters.
+ *
+ * This modifies the original string by terminating each field with a NULL
+ * character.  The function also allocates an array of char* and populates it
+ * with pointers back into the original string, each pointer indicating the
+ * start of a field.  The caller is responsible for freeing the memory
+ * allocated at address *pfields.
+ *
+ * Intuitively, if the delimiters are whitespace, this function parses a
+ * command line string into char *argv[] and sets argc.  Strictly speaking,
+ * this is not a complete replica of command line parsing because quoting is
+ * not supported.
+ *
+ * Inputs: s - string to be split delimiters - list of characters to split on
+ * (field delimiters)
+ *
+ * Outputs: s - string is modified in place pfields - address of char** that
+ * will store the array of fields pnumfields - address of int that will store
+ * the number of fields
+ *
+ * Returns: 0 on success, -1 on failure and sets errno accordingly.
+ */
 int split_string(
     char *s,
     const char *delimiters,
     char ***pfields,
     int *pnumfields);
+
+/*
+ * Expand an array by doubling the amount of elements allocated. Behaves much
+ * like realloc(), and so the following two paragraphs are copied from the
+ * realloc() man page for reference: realloc() changes the size of the memory
+ * block pointed to by ptr to size bytes.  The contents will be unchanged to
+ * the minimum of the old and new sizes; newly allocated memory will be
+ * uninitialized.  If ptr is NULL, the call is equivalent to malloc(size); if
+ * size is equal to zero, the call is equivalent to free(ptr).  Unless ptr is
+ * NULL, it must have been returned by an earlier call to malloc(), calloc()
+ * or realloc().  Returns a pointer to the newly allocated memory, which is
+ * suitably aligned for any kind of variable and may be different from ptr, or
+ * NULL if the request fails. If size was equal to 0, either NULL or a pointer
+ * suitable to be passed to free() is returned.  If realloc() fails the
+ * original block is left untouched - it is not freed or moved. Inputs: ptr
+ * - address of pointer to array of members (*ptr may be NULL). current_nmemb
+ * - current number of members allocated for the array min_nmemb - minimum
+ * number of members requested for the output array Outputs: If the
+ * realloc_by_doubling() was successful, *ptr is updated to the new pointer,
+ * and *current_nmemb is updated to the new number of members.  Note that you
+ * won't get the expected exponential reallocation if you call this more than
+ * about 30 times, since size_t is often 32 bits. Returns: 0 on success; -1
+ * and sets errno on failure.
+ */
 int expand_by_doubling(
     void **ptr,
     size_t size,
     size_t * current_nmemb,
     size_t min_nmemb);
+
+/**=============================================================================
+ * @brief Replace questionable chars from string for printing.
+ *
+ * @note Caller handles memory for dst.
+ * @note Output might be truncated, compared to input.
+ * @note dst will be null terminated, at or before index dst_sz-1.
+------------------------------------------------------------------------------*/
 char *scrub_for_print(
     char *dst,
     char const *src,
-- 
2.4.3


------------------------------------------------------------------------------
_______________________________________________
rpstir-devel mailing list
rpstir-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpstir-devel

Reply via email to