- refactored to modular structure

This commit is contained in:
2017-02-27 07:28:38 +00:00
parent ba8c750b75
commit 05dd972ec7
9 changed files with 478 additions and 271 deletions

75
src/ext/xstring.c Normal file
View File

@@ -0,0 +1,75 @@
/*!
* @file xstring.c
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 27.02.2017
* @author SESA354004
*/
#include "xstring.h"
#include "ctype.h"
char* gnu_basename(char *path)
{
char *base = strrchr(path, '/');
return base ? base + 1 : path;
}
/*!
* @brief Trim leading and trailing whitespaces
* @param [in] *str Input string
* @retval char* pointer to the trimmed substring
*
* @details
* This function returns a pointer to a substring of the original string.
* If the given string was allocated dynamically, the caller must not overwrite
* that pointer with the returned value, since the original pointer must be
* deallocated using the same allocator with which it was allocated. The return
* value must NOT be deallocated using free() etc.
*/
char* strntrimStatic(char *aStr, size_t aMaxLength)
{
char *end;
// Trim leading space
while (isspace((unsigned char)*aStr) && 0 < aMaxLength)
{
if (--aMaxLength > 0)
{
++aStr;
}
}
// All spaces at termination or end of max length
if (*aStr == '\0' || 0 == aMaxLength)
{
return aStr;
}
// Trim trailing space
if (strlen(aStr) >= aMaxLength)
{
end = aStr + aMaxLength - 1;
}
else
{
end = aStr + strlen(aStr) - 1;
}
while (end > aStr && isspace((unsigned char)*end))
{
end--;
}
// Write new null terminator (if length is enough)
if (end < (aStr + aMaxLength - 1))
{
*(end + 1) = '\0';
}
return aStr;
}

21
src/ext/xstring.h Normal file
View File

@@ -0,0 +1,21 @@
/*!
* @file xstring.h
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 27.02.2017
* @author SESA354004
*/
#ifndef XSTRING_H_
#define XSTRING_H_
#include <string.h>
char* gnu_basename(char *path);
char* strntrimStatic(char *aStr, size_t aMaxLength);
#endif /* XSTRING_H_ */

32
src/ext/xtime.h Normal file
View File

@@ -0,0 +1,32 @@
/*!
* @file xtime.h
* @brief Provides additional definitions for working with delays
*
* Project: \n
* Subsystem: \n
* Module: mst\n
* Code: GNU-C\n
*
* @date 08.06.2016
* @author SESA354004
*/
#ifndef XTIME_H_
#define XTIME_H_
#include <time.h>
/*! @brief Convert milliseconds to nanoseconds */
#define XTIME_MSTONS(milliseconds) (milliseconds * 1000000L)
/*! @brief Convert microseconds to nanoseconds */
#define XTIME_USTONS(microseconds) (microseconds * 1000L)
/*! @brief Convert nanoseconds to milliseconds*/
#define XTIME_NSTOMS(nanoseconds) (nanoseconds / 1000000L)
/*! @brief Convert nanoseconds to microseconds*/
#define XTIME_NSTOUS(nanoseconds) (nanoseconds / 1000L)
/*! @brief Only microseconds up to 1000000 are supported */
#define XTIME_TIMESPEC_US(seconds, microseconds) (const struct timespec[]){{seconds, XTIME_USTONS(microseconds)}}
/*! @brief Only milliseconds up to 1000 are supported */
#define XTIME_TIMESPEC_MS(seconds, milliseconds) (const struct timespec[]){{seconds, XTIME_MSTONS(milliseconds)}}
#endif /* XTIME_H_ */

41
src/ext/xtypes.h Normal file
View File

@@ -0,0 +1,41 @@
/*!
* @file xtypes.h
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 27.02.2017
* @author SESA354004
*/
#ifndef XTYPES_H_
#define XTYPES_H_
#include <stddef.h> // definition of NULL
#include <stdint.h> // fixed width types
#include <stdbool.h> // definition of bool
#define STRINGIZE_2(s) #s
/*!
* @brief Stringify the content of a definition
* @details
* Usage example:
* @code
#define VERSION_MAJOR 4
#define VERSION_MINOR 47
#define VERSION_STRING "v" STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR)
@endcode
*/
#define STRINGIZE(s) STRINGIZE_2(s)
#if defined(UNIT_TEST) || defined(_DEBUG)
#define STATIC
#else
#define STATIC static
#endif
#endif /* XTYPES_H_ */