Select one of the symbols to view example projects that use it.
 
Outline
#include "argtable3.h"
#include "argtable3_private.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
s_panic
dbg_printf(const char *, ...)
panic(const char *, ...)
arg_set_panic(arg_panicfn *)
argtable3_xmalloc(size_t)
argtable3_xcalloc(size_t, size_t)
argtable3_xrealloc(void *, size_t)
argtable3_xfree(void *)
merge(void *, int, int, int, int, arg_comparefn *)
arg_mgsort(void *, int, int, int, int, arg_comparefn *)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
argtable3
linenoise
private_include
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/console/argtable3/arg_utils.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2013-2019 Tom G. Huang * * SPDX-License-Identifier: BSD-3-Clause *//* ... */ /******************************************************************************* * arg_utils: Implements memory, panic, and other utility functions * * This file is part of the argtable3 library. * * Copyright (C) 2013-2019 Tom G. Huang * <tomghuang@gmail.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of STEWART HEITMANN nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************//* ... */ #include "argtable3.h" #ifndef ARG_AMALGAMATION #include "argtable3_private.h" #endif #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static void panic(const char* fmt, ...); static arg_panicfn* s_panic = panic; void dbg_printf(const char* fmt, ...) { va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); }{ ... } static void panic(const char* fmt, ...) { va_list args; char* s; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4996)/* ... */ #endif s = getenv("EF_DUMPCORE"); #if defined(_MSC_VER) #pragma warning(pop) #endif if (s != NULL && *s != '\0') { abort(); }{...} else { exit(EXIT_FAILURE); }{...} }{ ... } void arg_set_panic(arg_panicfn* proc) { s_panic = proc; }{ ... } void* xmalloc(size_t size) { void* ret = malloc(size); if (!ret) { s_panic("Out of memory!\n"); }{...} return ret; }{ ... } void* xcalloc(size_t count, size_t size) { size_t allocated_count = count && size ? count : 1; size_t allocated_size = count && size ? size : 1; void* ret = calloc(allocated_count, allocated_size); if (!ret) { s_panic("Out of memory!\n"); }{...} return ret; }{ ... } void* xrealloc(void* ptr, size_t size) { size_t allocated_size = size ? size : 1; void* ret = realloc(ptr, allocated_size); if (!ret) { s_panic("Out of memory!\n"); }{...} return ret; }{ ... } void xfree(void* ptr) { free(ptr); }{ ... } static void merge(void* data, int esize, int i, int j, int k, arg_comparefn* comparefn) { char* a = (char*)data; char* m; int ipos, jpos, mpos; /* Initialize the counters used in merging. */ ipos = i; jpos = j + 1; mpos = 0; /* Allocate storage for the merged elements. */ m = (char*)xmalloc((size_t)(esize * ((k - i) + 1))); /* Continue while either division has elements to merge. */ while (ipos <= j || jpos <= k) { if (ipos > j) { /* The left division has no more elements to merge. */ while (jpos <= k) { memcpy(&m[mpos * esize], &a[jpos * esize], (size_t)esize); jpos++; mpos++; }{...} continue; }{...} else if (jpos > k) { /* The right division has no more elements to merge. */ while (ipos <= j) { memcpy(&m[mpos * esize], &a[ipos * esize], (size_t)esize); ipos++; mpos++; }{...} continue; }{...} /* Append the next ordered element to the merged elements. */ if (comparefn(&a[ipos * esize], &a[jpos * esize]) < 0) { memcpy(&m[mpos * esize], &a[ipos * esize], (size_t)esize); ipos++; mpos++; }{...} else { memcpy(&m[mpos * esize], &a[jpos * esize], (size_t)esize); jpos++; mpos++; }{...} }{...} /* Prepare to pass back the merged data. */ memcpy(&a[i * esize], m, (size_t)(esize * ((k - i) + 1))); xfree(m); }{ ... } void arg_mgsort(void* data, int size, int esize, int i, int k, arg_comparefn* comparefn) { int j; /* Stop the recursion when no more divisions can be made. */ if (i < k) { /* Determine where to divide the elements. */ j = (int)(((i + k - 1)) / 2); /* Recursively sort the two divisions. */ arg_mgsort(data, size, esize, i, j, comparefn); arg_mgsort(data, size, esize, j + 1, k, comparefn); merge(data, esize, i, j, k, comparefn); }{...} }{ ... }
Details