wayne roberts / libscpi

Dependents:   scpi_sx127x scpi_sx127x_firstTest MLX90418_I2C_master

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utils_private.h Source File

utils_private.h

00001 /*-
00002  * Copyright (c) 2012-2013 Jan Breuer,
00003  *
00004  * All Rights Reserved
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are
00008  * met:
00009  * 1. Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00017  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00018  * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00019  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00022  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00023  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00025  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 /**
00029  * @file   scpi_utils.h
00030  * @date   Thu Nov 15 10:58:45 UTC 2012
00031  * 
00032  * @brief  Conversion routines and string manipulation routines
00033  * 
00034  * 
00035  */
00036 
00037 #ifndef SCPI_UTILS_PRIVATE_H
00038 #define SCPI_UTILS_PRIVATE_H
00039 
00040 #include <stdint.h>
00041 #include "scpi/config.h"
00042 #include "scpi/types.h"
00043 
00044 #ifdef  __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 #if defined(__GNUC__) && (__GNUC__ >= 4)
00049     #define LOCAL __attribute__((visibility ("hidden")))
00050 #else
00051     #define LOCAL
00052 #endif
00053 
00054     char * strnpbrk(const char *str, size_t size, const char *set) LOCAL;
00055     scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL;
00056     scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) LOCAL;
00057     size_t strToLong(const char * str, int32_t * val, int8_t base) LOCAL;
00058     size_t strToDouble(const char * str, double * val) LOCAL;
00059     scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
00060     scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
00061     size_t skipWhitespace(const char * cmd, size_t len) LOCAL;
00062     scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) LOCAL;
00063     scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len, int32_t *numbers, size_t numbers_len) LOCAL;
00064     scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
00065 
00066 #if !HAVE_STRNLEN
00067     size_t BSD_strnlen(const char *s, size_t maxlen) LOCAL;
00068 #endif
00069 
00070 #if !HAVE_STRNCASECMP && !HAVE_STRNICMP
00071     int OUR_strncasecmp(const char *s1, const char *s2, size_t n) LOCAL;
00072 #endif
00073 
00074 #ifndef min
00075     #define min(a, b)  (((a) < (b)) ? (a) : (b))
00076 #endif
00077 
00078 #ifndef max
00079     #define max(a, b)  (((a) > (b)) ? (a) : (b))
00080 #endif
00081 
00082 #if 0
00083 #define max(a,b) \
00084    ({ __typeof__ (a) _a = (a); \
00085        __typeof__ (b) _b = (b); \
00086      _a > _b ? _a : _b; })
00087 
00088 #define min(a,b) \
00089    ({ __typeof__ (a) _a = (a); \
00090        __typeof__ (b) _b = (b); \
00091      _a < _b ? _a : _b; })
00092 
00093 #endif
00094 
00095 #ifdef  __cplusplus
00096 }
00097 #endif
00098 
00099 #endif  /* SCPI_UTILS_PRIVATE_H */