AMU Library 3.0
C/C++ library for communicating with AMU (Aerospace Measurement Unit) devices
Loading...
Searching...
No Matches
utils_private.h
Go to the documentation of this file.
1/*-
2 * Copyright (c) 2012-2013 Jan Breuer,
3 *
4 * All Rights Reserved
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
36
37#ifndef SCPI_UTILS_PRIVATE_H
38#define SCPI_UTILS_PRIVATE_H
39
40#include <stdint.h>
41#include "config.h"
42#include "types.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#if defined(__GNUC__) && (__GNUC__ >= 4)
49#define LOCAL __attribute__((visibility ("hidden")))
50#else
51#define LOCAL
52#endif
53
54 char * strnpbrk(const char *str, size_t size, const char *set) LOCAL;
55 scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL;
56 scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) LOCAL;
57 size_t UInt32ToStrBaseSign(uint32_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
58 size_t UInt64ToStrBaseSign(uint64_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
59 size_t strBaseToInt32(const char * str, int32_t * val, int8_t base) LOCAL;
60 size_t strBaseToUInt32(const char * str, uint32_t * val, int8_t base) LOCAL;
61 size_t strBaseToInt64(const char * str, int64_t * val, int8_t base) LOCAL;
62 size_t strBaseToUInt64(const char * str, uint64_t * val, int8_t base) LOCAL;
63 size_t strToFloat(const char * str, float * val) LOCAL;
64 size_t strToDouble(const char * str, double * val) LOCAL;
65 scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
66 scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
67 size_t skipWhitespace(const char * cmd, size_t len) LOCAL;
68 scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) LOCAL;
69 scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value, bool *query) LOCAL;
70 scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
71
72#define SCPI_DTOSTRE_UPPERCASE 1
73#define SCPI_DTOSTRE_ALWAYS_SIGN 2
74#define SCPI_DTOSTRE_PLUS_SIGN 4
75 char * SCPI_dtostre(double __val, char * __s, size_t __ssize, unsigned char __prec, unsigned char __flags);
76
78 uint16_t SCPI_Swap16(uint16_t val);
79 uint32_t SCPI_Swap32(uint32_t val);
80 uint64_t SCPI_Swap64(uint64_t val);
81
82#if !HAVE_STRNLEN
83 size_t BSD_strnlen(const char *s, size_t maxlen) LOCAL;
84#endif
85
86#if !HAVE_STRNCASECMP && !HAVE_STRNICMP
87 int OUR_strncasecmp(const char *s1, const char *s2, size_t n) LOCAL;
88#endif
89
90#if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
91 void scpiheap_init(scpi_error_info_heap_t * heap, char * error_info_heap, size_t error_info_heap_length);
92 char * scpiheap_strndup(scpi_error_info_heap_t * heap, const char *s, size_t n) LOCAL;
93 void scpiheap_free(scpi_error_info_heap_t * heap, char *s, scpi_bool_t rollback) LOCAL;
94 scpi_bool_t scpiheap_get_parts(scpi_error_info_heap_t * heap, const char *s1, size_t * len1, const char ** s2, size_t * len2) LOCAL;
95#endif
96
97#if !HAVE_STRNDUP
98 char *OUR_strndup(const char *s, size_t n);
99#endif
100
101#ifndef min
102#define min(a, b) (((a) < (b)) ? (a) : (b))
103#endif
104
105#ifndef max
106#define max(a, b) (((a) > (b)) ? (a) : (b))
107#endif
108
109#if 0
110#define max(a,b) \
111 ({ __typeof__ (a) _a = (a); \
112 __typeof__ (b) _b = (b); \
113 _a > _b ? _a : _b; })
114
115#define min(a,b) \
116 ({ __typeof__ (a) _a = (a); \
117 __typeof__ (b) _b = (b); \
118 _a < _b ? _a : _b; })
119
120#endif
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* SCPI_UTILS_PRIVATE_H */
127
SCPI Configuration.
enum _scpi_array_format_t scpi_array_format_t
Definition types.h:407
bool scpi_bool_t
Definition types.h:67
uint64_t SCPI_Swap64(uint64_t val)
Definition utils.c:1143
char * SCPI_dtostre(double __val, char *__s, size_t __ssize, unsigned char __prec, unsigned char __flags)
Definition utils.c:1017
char * strnpbrk(const char *str, size_t size, const char *set)
Definition utils.c:59
size_t skipWhitespace(const char *cmd, size_t len)
Definition utils.c:410
scpi_bool_t compareStrAndNum(const char *str1, size_t len1, const char *str2, size_t len2, int32_t *num)
Definition utils.c:368
#define LOCAL
scpi_bool_t matchPattern(const char *pattern, size_t pattern_len, const char *str, size_t str_len, int32_t *num)
Definition utils.c:479
size_t UInt64ToStrBaseSign(uint64_t val, char *str, size_t len, int8_t base, scpi_bool_t sign)
Definition utils.c:167
uint32_t SCPI_Swap32(uint32_t val)
Definition utils.c:1131
scpi_bool_t locateText(const char *str1, size_t len1, const char **str2, size_t *len2)
size_t strToDouble(const char *str, double *val)
Definition utils.c:334
size_t strBaseToUInt64(const char *str, uint64_t *val, int8_t base)
Definition utils.c:310
scpi_bool_t matchCommand(const char *pattern, const char *cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value, bool *query)
Definition utils.c:505
size_t strBaseToUInt32(const char *str, uint32_t *val, int8_t base)
Definition utils.c:286
scpi_bool_t composeCompoundCommand(const scpi_token_t *prev, scpi_token_t *current)
Definition utils.c:688
scpi_array_format_t SCPI_GetNativeFormat(void)
Definition utils.c:1106
size_t strBaseToInt64(const char *str, int64_t *val, int8_t base)
Definition utils.c:298
scpi_bool_t locateStr(const char *str1, size_t len1, const char **str2, size_t *len2)
scpi_bool_t compareStr(const char *str1, size_t len1, const char *str2, size_t len2)
Definition utils.c:348
size_t strBaseToInt32(const char *str, int32_t *val, int8_t base)
Definition utils.c:274
size_t BSD_strnlen(const char *s, size_t maxlen)
Definition utils.c:734
int OUR_strncasecmp(const char *s1, const char *s2, size_t n)
Definition utils.c:747
char * OUR_strndup(const char *s, size_t n)
size_t strToFloat(const char *str, float *val)
Definition utils.c:322
uint16_t SCPI_Swap16(uint16_t val)
Definition utils.c:1121
size_t UInt32ToStrBaseSign(uint32_t val, char *str, size_t len, int8_t base, scpi_bool_t sign)
Definition utils.c:81