30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 */
49
50 #include "ficl.h"
51
52 #if FICL_ROBUST >= 2
53 #define FICL_VM_CHECK(vm) \
54 FICL_VM_ASSERT(vm, (*(vm->ip - 1)) == vm->runningWord)
55 #else
56 #define FICL_VM_CHECK(vm)
57 #endif
58
59 /*
60 * v m B r a n c h R e l a t i v e
61 */
62 void
63 ficlVmBranchRelative(ficlVm *vm, int offset)
64 {
65 vm->ip += offset;
66 }
67
68 /*
69 * v m C r e a t e
2148 trace++;
2149
2150 ficlVmUpdateTib(vm, trace);
2151
2152 return (s);
2153 }
2154
2155 /*
2156 * v m G e t W o r d T o P a d
2157 * Does vmGetWord and copies the result to the pad as a NULL terminated
2158 * string. Returns the length of the string. If the string is too long
2159 * to fit in the pad, it is truncated.
2160 */
2161 int
2162 ficlVmGetWordToPad(ficlVm *vm)
2163 {
2164 ficlString s;
2165 char *pad = (char *)vm->pad;
2166 s = ficlVmGetWord(vm);
2167
2168 if (FICL_STRING_GET_LENGTH(s) > FICL_PAD_SIZE)
2169 FICL_STRING_SET_LENGTH(s, FICL_PAD_SIZE);
2170
2171 (void) strncpy(pad, FICL_STRING_GET_POINTER(s),
2172 FICL_STRING_GET_LENGTH(s));
2173 pad[FICL_STRING_GET_LENGTH(s)] = '\0';
2174 return ((int)(FICL_STRING_GET_LENGTH(s)));
2175 }
2176
2177 /*
2178 * v m P a r s e S t r i n g
2179 * Parses a string out of the input buffer using the delimiter
2180 * specified. Skips leading delimiters, marks the start of the string,
2181 * and counts characters to the next delimiter it encounters. It then
2182 * updates the vm input buffer to consume all these chars, including the
2183 * trailing delimiter.
2184 * Returns the address and length of the parsed string, not including the
2185 * trailing delimiter.
2186 */
2187 ficlString
2188 ficlVmParseString(ficlVm *vm, char delimiter)
2189 {
|
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 */
49
50 /*
51 * Copyright 2019 Joyent, Inc.
52 */
53
54 #include "ficl.h"
55
56 #if FICL_ROBUST >= 2
57 #define FICL_VM_CHECK(vm) \
58 FICL_VM_ASSERT(vm, (*(vm->ip - 1)) == vm->runningWord)
59 #else
60 #define FICL_VM_CHECK(vm)
61 #endif
62
63 /*
64 * v m B r a n c h R e l a t i v e
65 */
66 void
67 ficlVmBranchRelative(ficlVm *vm, int offset)
68 {
69 vm->ip += offset;
70 }
71
72 /*
73 * v m C r e a t e
2152 trace++;
2153
2154 ficlVmUpdateTib(vm, trace);
2155
2156 return (s);
2157 }
2158
2159 /*
2160 * v m G e t W o r d T o P a d
2161 * Does vmGetWord and copies the result to the pad as a NULL terminated
2162 * string. Returns the length of the string. If the string is too long
2163 * to fit in the pad, it is truncated.
2164 */
2165 int
2166 ficlVmGetWordToPad(ficlVm *vm)
2167 {
2168 ficlString s;
2169 char *pad = (char *)vm->pad;
2170 s = ficlVmGetWord(vm);
2171
2172 if (FICL_STRING_GET_LENGTH(s) >= FICL_PAD_SIZE)
2173 FICL_STRING_SET_LENGTH(s, FICL_PAD_SIZE - 1);
2174
2175 (void) strncpy(pad, FICL_STRING_GET_POINTER(s),
2176 FICL_STRING_GET_LENGTH(s));
2177 pad[FICL_STRING_GET_LENGTH(s)] = '\0';
2178 return ((int)(FICL_STRING_GET_LENGTH(s)));
2179 }
2180
2181 /*
2182 * v m P a r s e S t r i n g
2183 * Parses a string out of the input buffer using the delimiter
2184 * specified. Skips leading delimiters, marks the start of the string,
2185 * and counts characters to the next delimiter it encounters. It then
2186 * updates the vm input buffer to consume all these chars, including the
2187 * trailing delimiter.
2188 * Returns the address and length of the parsed string, not including the
2189 * trailing delimiter.
2190 */
2191 ficlString
2192 ficlVmParseString(ficlVm *vm, char delimiter)
2193 {
|