prefix.c (76116) | prefix.c (94290) |
---|---|
1/******************************************************************* 2** p r e f i x . c 3** Forth Inspired Command Language 4** Parser extensions for Ficl 5** Authors: Larry Hastings & John Sadler (john_sadler@alum.mit.edu) 6** Created: April 2001 | 1/******************************************************************* 2** p r e f i x . c 3** Forth Inspired Command Language 4** Parser extensions for Ficl 5** Authors: Larry Hastings & John Sadler (john_sadler@alum.mit.edu) 6** Created: April 2001 |
7** $Id: prefix.c,v 1.1 2001-04-26 21:41:33-07 jsadler Exp jsadler $ | 7** $Id: prefix.c,v 1.6 2001/12/05 07:21:34 jsadler Exp $ |
8*******************************************************************/ 9/* 10** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 11** All rights reserved. 12** 13** Get the latest Ficl release at http://ficl.sourceforge.net 14** | 8*******************************************************************/ 9/* 10** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 11** All rights reserved. 12** 13** Get the latest Ficl release at http://ficl.sourceforge.net 14** |
15** I am interested in hearing from anyone who uses ficl. If you have 16** a problem, a success story, a defect, an enhancement request, or 17** if you would like to contribute to the ficl release, please 18** contact me by email at the address above. 19** |
|
15** L I C E N S E and D I S C L A I M E R 16** 17** Redistribution and use in source and binary forms, with or without 18** modification, are permitted provided that the following conditions 19** are met: 20** 1. Redistributions of source code must retain the above copyright 21** notice, this list of conditions and the following disclaimer. 22** 2. Redistributions in binary form must reproduce the above copyright --- 6 unchanged lines hidden (view full) --- 29** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 30** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36** SUCH DAMAGE. | 20** L I C E N S E and D I S C L A I M E R 21** 22** Redistribution and use in source and binary forms, with or without 23** modification, are permitted provided that the following conditions 24** are met: 25** 1. Redistributions of source code must retain the above copyright 26** notice, this list of conditions and the following disclaimer. 27** 2. Redistributions in binary form must reproduce the above copyright --- 6 unchanged lines hidden (view full) --- 34** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 35** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41** SUCH DAMAGE. |
37** 38** I am interested in hearing from anyone who uses ficl. If you have 39** a problem, a success story, a defect, an enhancement request, or 40** if you would like to contribute to the ficl release, please send 41** contact me by email at the address above. 42** 43** $Id: prefix.c,v 1.1 2001-04-26 21:41:33-07 jsadler Exp jsadler $ | |
44*/ 45 | 42*/ 43 |
46/* $FreeBSD: head/sys/boot/ficl/prefix.c 76116 2001-04-29 02:36:36Z dcs $ */ | 44/* $FreeBSD: head/sys/boot/ficl/prefix.c 94290 2002-04-09 17:45:28Z dcs $ */ |
47 48#include <string.h> 49#include <ctype.h> 50#include "ficl.h" 51#include "math64.h" 52 53/* 54** (jws) revisions: --- 16 unchanged lines hidden (view full) --- 71** This is the parse step for prefixes - it checks an incoming word 72** to see if it starts with a prefix, and if so runs the corrseponding 73** code against the remainder of the word and returns true. 74**************************************************************************/ 75int ficlParsePrefix(FICL_VM *pVM, STRINGINFO si) 76{ 77 int i; 78 FICL_HASH *pHash; | 45 46#include <string.h> 47#include <ctype.h> 48#include "ficl.h" 49#include "math64.h" 50 51/* 52** (jws) revisions: --- 16 unchanged lines hidden (view full) --- 69** This is the parse step for prefixes - it checks an incoming word 70** to see if it starts with a prefix, and if so runs the corrseponding 71** code against the remainder of the word and returns true. 72**************************************************************************/ 73int ficlParsePrefix(FICL_VM *pVM, STRINGINFO si) 74{ 75 int i; 76 FICL_HASH *pHash; |
79 FICL_WORD *pFW = ficlLookup(list_name); | 77 FICL_WORD *pFW = ficlLookup(pVM->pSys, list_name); |
80 | 78 |
81 assert(pFW); | 79 /* 80 ** Make sure we found the prefix dictionary - otherwise silently fail 81 ** If forth-wordlist is not in the search order, we won't find the prefixes. 82 */ 83 if (!pFW) 84 return FICL_FALSE; 85 |
82 pHash = (FICL_HASH *)(pFW->param[0].p); 83 /* 84 ** Walk the list looking for a match with the beginning of the incoming token 85 */ 86 for (i = 0; i < (int)pHash->size; i++) 87 { 88 pFW = pHash->table[i]; 89 while (pFW != NULL) 90 { 91 int n; 92 n = pFW->nName; 93 /* 94 ** If we find a match, adjust the TIB to give back the non-prefix characters 95 ** and execute the prefix word. 96 */ 97 if (!strincmp(SI_PTR(si), pFW->name, (FICL_UNS)n)) 98 { | 86 pHash = (FICL_HASH *)(pFW->param[0].p); 87 /* 88 ** Walk the list looking for a match with the beginning of the incoming token 89 */ 90 for (i = 0; i < (int)pHash->size; i++) 91 { 92 pFW = pHash->table[i]; 93 while (pFW != NULL) 94 { 95 int n; 96 n = pFW->nName; 97 /* 98 ** If we find a match, adjust the TIB to give back the non-prefix characters 99 ** and execute the prefix word. 100 */ 101 if (!strincmp(SI_PTR(si), pFW->name, (FICL_UNS)n)) 102 { |
99 vmSetTibIndex(pVM, vmGetTibIndex(pVM) - 1 - SI_COUNT(si) + n); | 103 /* (sadler) fixed off-by-one error when the token has no trailing space in the TIB */ 104 vmSetTibIndex(pVM, si.cp + n - pVM->tib.cp ); |
100 vmExecute(pVM, pFW); 101 102 return FICL_TRUE; 103 } 104 pFW = pFW->link; 105 } 106 } 107 --- 5 unchanged lines hidden (view full) --- 113{ 114 int oldbase = pVM->base; 115 STRINGINFO si = vmGetWord0(pVM); 116 117 pVM->base = base; 118 if (!ficlParseNumber(pVM, si)) 119 { 120 int i = SI_COUNT(si); | 105 vmExecute(pVM, pFW); 106 107 return FICL_TRUE; 108 } 109 pFW = pFW->link; 110 } 111 } 112 --- 5 unchanged lines hidden (view full) --- 118{ 119 int oldbase = pVM->base; 120 STRINGINFO si = vmGetWord0(pVM); 121 122 pVM->base = base; 123 if (!ficlParseNumber(pVM, si)) 124 { 125 int i = SI_COUNT(si); |
121 vmThrowErr(pVM, "0x%.*s is not a valid hex value", i, SI_PTR(si)); | 126 vmThrowErr(pVM, "%.*s not recognized", i, SI_PTR(si)); |
122 } 123 124 pVM->base = oldbase; 125 return; 126} 127 128static void fTempBase(FICL_VM *pVM) 129{ --- 33 unchanged lines hidden (view full) --- 163 ** Create a named wordlist for prefixes to reside in... 164 ** Since we're doing a special kind of search, make it 165 ** a single bucket hashtable - hashing does not help here. 166 */ 167 pHash = dictCreateWordlist(dp, 1); 168 pHash->name = list_name; 169 dictAppendWord(dp, list_name, constantParen, FW_DEFAULT); 170 dictAppendCell(dp, LVALUEtoCELL(pHash)); | 127 } 128 129 pVM->base = oldbase; 130 return; 131} 132 133static void fTempBase(FICL_VM *pVM) 134{ --- 33 unchanged lines hidden (view full) --- 168 ** Create a named wordlist for prefixes to reside in... 169 ** Since we're doing a special kind of search, make it 170 ** a single bucket hashtable - hashing does not help here. 171 */ 172 pHash = dictCreateWordlist(dp, 1); 173 pHash->name = list_name; 174 dictAppendWord(dp, list_name, constantParen, FW_DEFAULT); 175 dictAppendCell(dp, LVALUEtoCELL(pHash)); |
176 177 /* 178 ** Put __tempbase in the forth-wordlist 179 */ |
|
171 dictAppendWord(dp, "__tempbase", fTempBase, FW_DEFAULT); 172 173 /* 174 ** Temporarily make the prefix list the compile wordlist so that 175 ** we can create some precompiled prefixes. 176 */ 177 dp->pCompile = pHash; 178 dictAppendWord(dp, "0x", prefixHex, FW_DEFAULT); 179 dictAppendWord(dp, "0d", prefixTen, FW_DEFAULT); 180#if (FICL_EXTENDED_PREFIX) | 180 dictAppendWord(dp, "__tempbase", fTempBase, FW_DEFAULT); 181 182 /* 183 ** Temporarily make the prefix list the compile wordlist so that 184 ** we can create some precompiled prefixes. 185 */ 186 dp->pCompile = pHash; 187 dictAppendWord(dp, "0x", prefixHex, FW_DEFAULT); 188 dictAppendWord(dp, "0d", prefixTen, FW_DEFAULT); 189#if (FICL_EXTENDED_PREFIX) |
181 pFW = ficlLookup("\\"); | 190 pFW = ficlLookup(pSys, "\\"); |
182 if (pFW) 183 { 184 dictAppendWord(dp, "//", pFW->code, FW_DEFAULT); 185 } 186#endif 187 dp->pCompile = pPrevCompile; 188 | 191 if (pFW) 192 { 193 dictAppendWord(dp, "//", pFW->code, FW_DEFAULT); 194 } 195#endif 196 dp->pCompile = pPrevCompile; 197 |
189 ficlAddPrecompiledParseStep(pSys, "prefix?", ficlParsePrefix); | |
190 return; 191} | 198 return; 199} |