scpi-parser, adopted from github
scpi/utils_private.h@0:d8aca47812e0, 2014-11-14 (annotated)
- Committer:
- iesensor
- Date:
- Fri Nov 14 01:07:59 2014 +0000
- Revision:
- 0:d8aca47812e0
tested on K64F
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iesensor | 0:d8aca47812e0 | 1 | /*- |
iesensor | 0:d8aca47812e0 | 2 | * Copyright (c) 2012-2013 Jan Breuer, |
iesensor | 0:d8aca47812e0 | 3 | * |
iesensor | 0:d8aca47812e0 | 4 | * All Rights Reserved |
iesensor | 0:d8aca47812e0 | 5 | * |
iesensor | 0:d8aca47812e0 | 6 | * Redistribution and use in source and binary forms, with or without |
iesensor | 0:d8aca47812e0 | 7 | * modification, are permitted provided that the following conditions are |
iesensor | 0:d8aca47812e0 | 8 | * met: |
iesensor | 0:d8aca47812e0 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
iesensor | 0:d8aca47812e0 | 10 | * this list of conditions and the following disclaimer. |
iesensor | 0:d8aca47812e0 | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
iesensor | 0:d8aca47812e0 | 12 | * notice, this list of conditions and the following disclaimer in the |
iesensor | 0:d8aca47812e0 | 13 | * documentation and/or other materials provided with the distribution. |
iesensor | 0:d8aca47812e0 | 14 | * |
iesensor | 0:d8aca47812e0 | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
iesensor | 0:d8aca47812e0 | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
iesensor | 0:d8aca47812e0 | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iesensor | 0:d8aca47812e0 | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE |
iesensor | 0:d8aca47812e0 | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
iesensor | 0:d8aca47812e0 | 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
iesensor | 0:d8aca47812e0 | 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
iesensor | 0:d8aca47812e0 | 22 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
iesensor | 0:d8aca47812e0 | 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
iesensor | 0:d8aca47812e0 | 24 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
iesensor | 0:d8aca47812e0 | 25 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iesensor | 0:d8aca47812e0 | 26 | */ |
iesensor | 0:d8aca47812e0 | 27 | |
iesensor | 0:d8aca47812e0 | 28 | /** |
iesensor | 0:d8aca47812e0 | 29 | * @file scpi_utils.h |
iesensor | 0:d8aca47812e0 | 30 | * @date Thu Nov 15 10:58:45 UTC 2012 |
iesensor | 0:d8aca47812e0 | 31 | * |
iesensor | 0:d8aca47812e0 | 32 | * @brief Conversion routines and string manipulation routines |
iesensor | 0:d8aca47812e0 | 33 | * |
iesensor | 0:d8aca47812e0 | 34 | * |
iesensor | 0:d8aca47812e0 | 35 | */ |
iesensor | 0:d8aca47812e0 | 36 | |
iesensor | 0:d8aca47812e0 | 37 | #ifndef SCPI_UTILS_H |
iesensor | 0:d8aca47812e0 | 38 | #define SCPI_UTILS_H |
iesensor | 0:d8aca47812e0 | 39 | |
iesensor | 0:d8aca47812e0 | 40 | #include <stdint.h> |
iesensor | 0:d8aca47812e0 | 41 | #include "scpi/config.h" |
iesensor | 0:d8aca47812e0 | 42 | #include "scpi/types.h" |
iesensor | 0:d8aca47812e0 | 43 | |
iesensor | 0:d8aca47812e0 | 44 | #ifdef __cplusplus |
iesensor | 0:d8aca47812e0 | 45 | extern "C" { |
iesensor | 0:d8aca47812e0 | 46 | #endif |
iesensor | 0:d8aca47812e0 | 47 | |
iesensor | 0:d8aca47812e0 | 48 | #if defined(__GNUC__) && (__GNUC__ >= 4) |
iesensor | 0:d8aca47812e0 | 49 | #define LOCAL __attribute__((visibility ("hidden"))) |
iesensor | 0:d8aca47812e0 | 50 | #else |
iesensor | 0:d8aca47812e0 | 51 | #define LOCAL |
iesensor | 0:d8aca47812e0 | 52 | #endif |
iesensor | 0:d8aca47812e0 | 53 | |
iesensor | 0:d8aca47812e0 | 54 | const char * strnpbrk(const char *str, size_t size, const char *set) LOCAL; |
iesensor | 0:d8aca47812e0 | 55 | scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; |
iesensor | 0:d8aca47812e0 | 56 | scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; |
iesensor | 0:d8aca47812e0 | 57 | size_t longToStr(int32_t val, char * str, size_t len) LOCAL; |
iesensor | 0:d8aca47812e0 | 58 | size_t doubleToStr(double val, char * str, size_t len) LOCAL; |
iesensor | 0:d8aca47812e0 | 59 | size_t strToLong(const char * str, int32_t * val) LOCAL; |
iesensor | 0:d8aca47812e0 | 60 | size_t strToDouble(const char * str, double * val) LOCAL; |
iesensor | 0:d8aca47812e0 | 61 | scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
iesensor | 0:d8aca47812e0 | 62 | scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
iesensor | 0:d8aca47812e0 | 63 | size_t skipWhitespace(const char * cmd, size_t len) LOCAL; |
iesensor | 0:d8aca47812e0 | 64 | size_t skipColon(const char * cmd, size_t len) LOCAL; |
iesensor | 0:d8aca47812e0 | 65 | scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) LOCAL; |
iesensor | 0:d8aca47812e0 | 66 | scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len) LOCAL; |
iesensor | 0:d8aca47812e0 | 67 | scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
iesensor | 0:d8aca47812e0 | 68 | |
iesensor | 0:d8aca47812e0 | 69 | #if !HAVE_STRNLEN |
iesensor | 0:d8aca47812e0 | 70 | size_t BSD_strnlen(const char *s, size_t maxlen); |
iesensor | 0:d8aca47812e0 | 71 | #endif |
iesensor | 0:d8aca47812e0 | 72 | |
iesensor | 0:d8aca47812e0 | 73 | #if !HAVE_STRNCASECMP && !HAVE_STRNICMP |
iesensor | 0:d8aca47812e0 | 74 | int OUR_strncasecmp(const char *s1, const char *s2, size_t n); |
iesensor | 0:d8aca47812e0 | 75 | #endif |
iesensor | 0:d8aca47812e0 | 76 | |
iesensor | 0:d8aca47812e0 | 77 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
iesensor | 0:d8aca47812e0 | 78 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
iesensor | 0:d8aca47812e0 | 79 | |
iesensor | 0:d8aca47812e0 | 80 | #if 0 |
iesensor | 0:d8aca47812e0 | 81 | #define max(a,b) \ |
iesensor | 0:d8aca47812e0 | 82 | ({ __typeof__ (a) _a = (a); \ |
iesensor | 0:d8aca47812e0 | 83 | __typeof__ (b) _b = (b); \ |
iesensor | 0:d8aca47812e0 | 84 | _a > _b ? _a : _b; }) |
iesensor | 0:d8aca47812e0 | 85 | |
iesensor | 0:d8aca47812e0 | 86 | #define min(a,b) \ |
iesensor | 0:d8aca47812e0 | 87 | ({ __typeof__ (a) _a = (a); \ |
iesensor | 0:d8aca47812e0 | 88 | __typeof__ (b) _b = (b); \ |
iesensor | 0:d8aca47812e0 | 89 | _a < _b ? _a : _b; }) |
iesensor | 0:d8aca47812e0 | 90 | |
iesensor | 0:d8aca47812e0 | 91 | #endif |
iesensor | 0:d8aca47812e0 | 92 | |
iesensor | 0:d8aca47812e0 | 93 | #ifdef __cplusplus |
iesensor | 0:d8aca47812e0 | 94 | } |
iesensor | 0:d8aca47812e0 | 95 | #endif |
iesensor | 0:d8aca47812e0 | 96 | |
iesensor | 0:d8aca47812e0 | 97 | #endif /* SCPI_UTILS_H */ |
iesensor | 0:d8aca47812e0 | 98 |