Explorar o código

Update faux/ctype files

Serj Kalichev %!s(int64=4) %!d(string=hai) anos
pai
achega
ebf0742663
Modificáronse 9 ficheiros con 175 adicións e 254 borrados
  1. 1 1
      Doxyfile
  2. 23 23
      faux/Makefile.am
  3. 0 49
      faux/c_decl.h
  4. 16 119
      faux/ctype.h
  5. 3 0
      faux/ctype/Makefile.am
  6. 59 24
      faux/ctype/ctype.c
  7. 0 2
      faux/ctype/module.am
  8. 23 21
      faux/str/str.c
  9. 50 15
      faux/types.h

+ 1 - 1
Doxyfile

@@ -790,7 +790,7 @@ WARN_LOGFILE           =
 # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = faux/str
+INPUT                  = faux
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

+ 23 - 23
faux/Makefile.am

@@ -3,39 +3,39 @@ libfaux_la_SOURCES =
 libfaux_la_LIBADD =
 
 nobase_include_HEADERS += \
+	faux/types.h \
+	faux/ctype.h \
 	faux/str.h
 
-#    faux/argv.h \
-#    faux/bintree.h \
-#    faux/list.h \
-#    faux/ctype.h \
-#    faux/c_decl.h \
-#    faux/dump.h \
-#    faux/types.h \
-#    faux/system.h \
-#    faux/db.h \
-#    faux/ini.h \
-#    faux/log.h \
-#    faux/conv.h
+#	faux/argv.h \
+#	faux/list.h \
+#	faux/c_decl.h \
+#	faux/dump.h \
+#	faux/system.h \
+#	faux/db.h \
+#	faux/ini.h \
+#	faux/log.h \
+#	faux/conv.h
 
 EXTRA_DIST += \
+	faux/ctype/Makefile.am \
 	faux/str/Makefile.am
 
-#    faux/argv/module.am \
-#    faux/list/module.am \
-#    faux/ctype/module.am \
-#    faux/dump/module.am \
-#    faux/system/module.am \
-#    faux/db/module.am \
-#    faux/ini/module.am \
-#    faux/log/module.am \
-#    faux/conv/module.am \
-#    faux/README
+#	faux/argv/module.am \
+#	faux/list/module.am \
+#	faux/dump/module.am \
+#	faux/system/module.am \
+#	faux/db/module.am \
+#	faux/ini/module.am \
+#	faux/log/module.am \
+#	faux/conv/module.am \
+#	faux/README
 
+include $(top_srcdir)/faux/ctype/Makefile.am
 include $(top_srcdir)/faux/str/Makefile.am
+
 #include $(top_srcdir)/faux/argv/module.am
 #include $(top_srcdir)/faux/list/module.am
-#include $(top_srcdir)/faux/ctype/module.am
 #include $(top_srcdir)/faux/dump/module.am
 #include $(top_srcdir)/faux/system/module.am
 #include $(top_srcdir)/faux/db/module.am

+ 0 - 49
faux/c_decl.h

@@ -1,49 +0,0 @@
-/*
- * c_decl.h
- *
- * a simple set of macros to ease declaration of C interfaces.
- */
-
-///@{
-/**
-\ingroup lub
-\defgroup lub_c_decl C linkage macros
-
-These two macros are used to simplify the declaration of C-linkage code.
-Rather than worry about preprocessor directives similar to
-\code
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int foobar(void);
-
-#ifdef __cplusplus
-}
-#endif
-\endcode
-you simply need to use the _BEGIN_C_DECL and _END_C_DECL macros instead.
-
-\code
-#include "lub/c_decl.h"
-_BEGIN_C_DECL
-
-int foobar(void);
-
-_END_C_DECL
-\endcode
-*/
-
-#ifndef _lub_c_decl_h
-#define _lub_c_decl_h
-
-#ifdef __cplusplus
-#define _BEGIN_C_DECL extern "C" {
-#define _END_C_DECL   }
-#else				/* not __cplusplus */
-#define _BEGIN_C_DECL
-#define _END_C_DECL
-#endif				/* not __cplusplus */
-
-/// /** @} */
-#endif				/* _lub_c_decl_h */

+ 16 - 119
faux/ctype.h

@@ -1,128 +1,25 @@
-/*
- * ctype.h
+/** @file ctype.h
+ * @brief Public interface for faux ctype functions.
  */
-/**
-\ingroup lub
-\defgroup lub_ctype ctype
-@{
 
-\brief The ANSI-C standard <ctype.h> interface works fine for strings 
-containing characters encoded with the ASCII 7-bit coding. However 
-when you use characters outside this range things start to get ambiguous. 
+#ifndef _faux_ctype_h
+#define _faux_ctype_h
 
-The default manner in which to represent a string in C is to use a 
-"char *". (NB. this is a signed type) The interfaces presented 
-in <ctype.h> take signed integers. When a character greater than 128 is
-passed as a "char" to isspace() (e.g. the british pound sign "£") then 
-a negative value is passed into the function/macro. A typical
-implementation (e.g. VxWorks) may use the passed argument as an offset
-into a lookup table, negative values in this case cause problems...
-
-This utility provides an interface which avoids this ambiguity by passing 
-"char" characters directly rather than converting to "int".
+#include <ctype.h>
 
-This component currently only contains those operations which are required
-by the current CLISH/LUB implementations. It can be extended on an as needed 
-basis.
+#include "faux/types.h"
+#include "faux/c_decl.h"
 
-*/
-/*---------------------------------------------------------------
- * HISTORY
- * 4-Sep-2006		Graeme McKerrell	
- *    Initial Version
- *---------------------------------------------------------------
- * Copyright (C) 2006 Newport Networks. All Rights Reserved.
- *--------------------------------------------------------------- */
-#ifndef _lub_ctype_h
-#define _lub_ctype_h
+C_DECL_BEGIN
 
-#include <ctype.h>
+// Classify functions
+bool_t faux_ctype_isdigit(char c);
+bool_t faux_ctype_isspace(char c);
 
-#include "lub/types.h"
-#include "lub/c_decl.h"
+// Convert functions
+char faux_ctype_tolower(char c);
+char faux_ctype_toupper(char c);
 
-_BEGIN_C_DECL
-/**
- * This operation identifies whether a character is a decimal digit
- * or not.
- *
- * \pre 
- * - none
- * 
- * \return 
- * BOOL_TRUE  - if the character is a decimal digit
- * BOOL_FALSE - if the character is not a decimal digit
- *
- * \post 
- * - none
- */
-bool_t lub_ctype_isdigit(
-	/** 
-         * The character to check
-         */
-				char c);
-/**
- * This operation identifies whether a character is a standard white space
- * character. (space, tab, carriage-return, vertical tab, form-feed)
- *
- * \pre 
- * - none
- * 
- * \return 
- * BOOL_TRUE  - if the character is white space
- * BOOL_FALSE - if the character is not white space
- *
- * \post 
- * - none
- */
-bool_t lub_ctype_isspace(
-	/** 
-         * The character to check
-         */
-				char c);
-/**
- * This operation converts an uppercase letter to the corresponding 
- * lowercase letter.
- *
- * \pre 
- * - none
- * 
- * \return 
- * If the parameter is a character for which lub_ctype_isupper() is true 
- * and there is a corresponding character for which lub_ctype_islower() is true
- * then the corresponding character is returned. Otherwise the parameter is 
- * returned unchanged.
- *
- * \post 
- * - none
- */
-char lub_ctype_tolower(
-	/** 
-         * The character to convert
-         */
-			      char c);
-/**
- * This operation converts a lowercase letter to the corresponding 
- * uppercase letter.
- *
- * \pre 
- * - none
- * 
- * \return 
- * If the parameter is a character for which lub_ctype_islower() is true 
- * and there is a corresponding character for which lub_ctype_isupper() is true
- * then the corresponding character is returned. Otherwise the parameter is 
- * returned unchanged.
- *
- * \post 
- * - none
- */
-char lub_ctype_toupper(
-	/** 
-         * The character to convert
-         */
-			      char c);
+C_DECL_END
 
-_END_C_DECL
-#endif				/* _lub_ctype_h */
-/** @} */
+#endif /* _faux_ctype_h */

+ 3 - 0
faux/ctype/Makefile.am

@@ -0,0 +1,3 @@
+libfaux_la_SOURCES += \
+	faux/ctype/ctype.c
+

+ 59 - 24
faux/ctype/ctype.c

@@ -1,35 +1,70 @@
-/*
- * ctype.c
+/** @file ctype.c
+ * @brief The ctype functions
+ *
+ * Some ctype functions are not compatible among different OSes.
+ * So faux library functions use their own versions of some
+ * ctype functions to unify the behaviour. Really the most of the
+ * faux ctype functions are only a wrappers for standard functions.
  */
-#include "lub/ctype.h"
+
 #include <ctype.h>
 
-/*--------------------------------------------------------- */
-bool_t lub_ctype_isdigit(char c)
-{
-	unsigned char tmp = (unsigned char)c;
-	return isdigit(tmp) ? BOOL_TRUE : BOOL_FALSE;
+#include "faux/ctype.h"
+
+/** @brief Checks for a digit
+ *
+ * The function is same as standard isdigit() but gets char type
+ * as an argument.
+ *
+ * @param [in] c Character to classify.
+ * @return BOOL_TRUE if char is digit and BOOL_FALSE else.
+ */
+bool_t faux_ctype_isdigit(char c) {
+
+	// isdigit() man says that argument must be unsigned char
+	return isdigit((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
 }
 
-/*--------------------------------------------------------- */
-bool_t lub_ctype_isspace(char c)
-{
-	unsigned char tmp = (unsigned char)c;
-	return isspace(tmp) ? BOOL_TRUE : BOOL_FALSE;
+
+/** @brief Checks for a white space
+ *
+ * The function is same as standard isspace() but gets char type
+ * as an argument.
+ *
+ * @param [in] c Character to classify.
+ * @return BOOL_TRUE if char is space and BOOL_FALSE else.
+ */
+bool_t faux_ctype_isspace(char c) {
+
+	// isspace() man says that argument must be unsigned char
+	return isspace((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
 }
 
-/*--------------------------------------------------------- */
-char lub_ctype_tolower(char c)
-{
-	unsigned char tmp = (unsigned char)c;
-	return tolower(tmp);
+
+/** @brief Converts uppercase characters to lowercase
+ *
+ * The function is same as standard tolower() but gets char type
+ * as an argument.
+ *
+ * @param [in] c Character to convert.
+ * @return Converted character.
+ */
+char faux_ctype_tolower(char c) {
+
+	// tolower() man says that argument must be unsigned char
+	return tolower((unsigned char)c);
 }
 
-/*--------------------------------------------------------- */
-char lub_ctype_toupper(char c)
+/** @brief Converts lowercase characters to uppercase
+ *
+ * The function is same as standard toupper() but gets char type
+ * as an argument.
+ *
+ * @param [in] c Character to convert.
+ * @return Converted character.
+ */
+char faux_ctype_toupper(char c)
 {
-	unsigned char tmp = (unsigned char)c;
-	return toupper(tmp);
+	// toupper() man says that argument must be unsigned char
+	return toupper((unsigned char)c);
 }
-
-/*--------------------------------------------------------- */

+ 0 - 2
faux/ctype/module.am

@@ -1,2 +0,0 @@
-liblub_la_SOURCES += lub/ctype/ctype.c
-

+ 23 - 21
faux/str/str.c

@@ -36,6 +36,29 @@ void faux_str_free(char **str) {
 }
 
 
+/*--------------------------------------------------------- */
+char *lub_string_dup(const char *string)
+{
+	if (!string)
+		return NULL;
+	return strdup(string);
+}
+
+/*--------------------------------------------------------- */
+char *lub_string_dupn(const char *string, unsigned int len)
+{
+	char *res = NULL;
+
+	if (!string)
+		return res;
+	res = malloc(len + 1);
+	strncpy(res, string, len);
+	res[len] = '\0';
+
+	return res;
+}
+
+
 /*--------------------------------------------------------- */
 char *lub_string_ndecode(const char *string, unsigned int len)
 {
@@ -154,27 +177,6 @@ void lub_string_cat(char **string, const char *text)
 	lub_string_catn(string, text, len);
 }
 
-/*--------------------------------------------------------- */
-char *lub_string_dup(const char *string)
-{
-	if (!string)
-		return NULL;
-	return strdup(string);
-}
-
-/*--------------------------------------------------------- */
-char *lub_string_dupn(const char *string, unsigned int len)
-{
-	char *res = NULL;
-
-	if (!string)
-		return res;
-	res = malloc(len + 1);
-	strncpy(res, string, len);
-	res[len] = '\0';
-
-	return res;
-}
 
 /*--------------------------------------------------------- */
 int lub_string_nocasecmp(const char *cs, const char *ct)

+ 50 - 15
faux/types.h

@@ -1,24 +1,59 @@
-/*
- * types.h
+/** @file types.h
+ * @brief Additional usefull data types
  */
-/**
-\ingroup  lub
-\defgroup lub_types types
 
-\brief This provides some primative types not found in ANSI-C.
-@{
-*/
+#ifndef _faux_types_h
+#define _faux_types_h
 
-#ifndef _lub_types_h
-#define _lub_types_h
 
 /**
- * A boolean type for ANSI-C
+ * A standard boolean type. The possible values are
+ * BOOL_FALSE and BOOL_TRUE.
  */
 typedef enum {
-	BOOL_FALSE,
-	BOOL_TRUE
+	BOOL_FALSE = 0,
+	BOOL_TRUE = 1
 } bool_t;
 
-/** @} */
-#endif				/* _lub_types_h */
+
+/** @def C_DECL_BEGIN
+ * This macro can be used instead standard preprocessor
+ * directive like this:
+ * @code
+ * #ifdef __cplusplus
+ * extern "C" {
+ * #endif
+ *
+ * int foobar(void);
+ *
+ * #ifdef __cplusplus
+ * }
+ * #endif
+ * @endcode
+ * It make linker to use C-style linking for functions.
+ * Use C_DECL_BEGIN before functions declaration and C_DECL_END
+ * after declaration:
+ * @code
+ * C_DECL_BEGIN
+ *
+ * int foobar(void);
+ *
+ * C_DECL_END
+ * @endcode
+ */
+
+/** @def C_DECL_END
+ * See the macro C_DECL_BEGIN.
+ * @sa C_DECL_BEGIN
+ */
+
+#ifdef __cplusplus
+#define C_DECL_BEGIN extern "C" {
+#define C_DECL_END }
+#else
+#define C_DECL_BEGIN
+#define C_DECL_END
+#endif
+
+
+#endif /* _faux_types_h */