1 /* # skkinput (Simple Kana-Kanji Input)
2  *
3  * This file is part of skkinput.
4  * Copyright (C) 2002
5  * Takashi SAKAMOTO (PXG01715@nifty.ne.jp)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with skkinput; see the file COPYING.  If not, write to
19  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 #include "local.h"
22 #include <stdio.h>
23 #include <assert.h>
24 #include "lmachinep.h"
25 
26 /*========================================================================*
27  *	private functions
28  */
29 
30 /*	symbol-to-symbol �� wrapper��
31  *--
32  *	last-command-char, last-command-event �Τ褦��Ʊ������ư���褦�ʤ�Τ�
33  *	�б����뤿��� wrapper �Ǥ��롣�����lisp machine ���̤�����Ǥ��롣
34  */
35 static inline TLispEntity*
lispMachine_getRealSymbol(register TLispMachine * pLM,register TLispEntity * pEntSymbol)36 lispMachine_getRealSymbol (
37 	register TLispMachine*	pLM,
38 	register TLispEntity*	pEntSymbol)
39 {
40 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
41 	register TLispBind**	pSym2SymTbl	= pLM->m_apSymbol2SymbolTable ;
42 	register Boolean		f ;
43 	TLispBind*				pBind ;
44 	TLispEntity*			pEntNewSymbol ;
45 
46 	f	= lispBindTable_SearchEntry (pLispMgr, pSym2SymTbl, SIZE_LISP_BIND_TABLE, pEntSymbol, &pBind) ;
47 	if (TSUCCEEDED (f) && pBind != NULL) {
48 		if (TSUCCEEDED (lispBind_GetValue (pBind, &pEntNewSymbol)) &&
49 			pEntNewSymbol != NULL)
50 			return	pEntNewSymbol ;
51 	}
52 	return	pEntSymbol ;
53 }
54 
55 /*
56  *[��ǽ]
57  *	buffer-local-variable ���ͤ����ꤹ�롣
58  *[����]
59  *	Lisp ��̿��� buffer-local-variable ������ؤ��ơ��ͤ��åȤ���
60  *	��Τ����뤫�ɤ�����ʬ����ʤ���Ĵ����­���⤷��ʤ�����
61  */
62 static inline Boolean
lispMachine_setCurrentBufferLocalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)63 lispMachine_setCurrentBufferLocalSymbolValue (
64 	register TLispMachine*	pLM,
65 	register TLispEntity*	pEntSymbol,
66 	register TLispEntity*	pEntValue)
67 {
68 	register TLispManager*	pLispMgr ;
69 	register TLispEntity*	pEntBuffer ;
70 
71 	assert (pLM        != NULL) ;
72 	assert (pEntSymbol != NULL) ;
73 	assert (pEntValue  != NULL) ;
74 
75 	pLispMgr	= pLM->m_pLispMgr ;
76 	assert (pLispMgr   != NULL) ;
77 	pEntBuffer	= pLM->m_pCurBuffer ;
78 
79 	/*	���ιԤϰ��Ū�ʤ�Τ�������*/
80 	if (pEntBuffer == NULL)
81 		return	False ;
82 
83 	return	lispBuffer_SetSymbolValue (pLispMgr, pEntBuffer, pEntSymbol, pEntValue) ;
84 }
85 
86 /*
87  *[��ǽ]
88  *	Lisp Machine �� Local �ʥ���ܥ���ͤ��åȤ��롣
89  */
90 static inline Boolean
lispMachine_setGlobalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)91 lispMachine_setGlobalSymbolValue (
92 	register TLispMachine*	pLM,
93 	register TLispEntity*	pEntSymbol,
94 	register TLispEntity*	pEntValue)
95 {
96 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
97 	register TLispBind**	pVarTbl ;
98 	TLispBind*	pBind ;
99 
100 	assert (pLM             != NULL) ;
101 	assert (pLM->m_pLispMgr != NULL) ;
102 	assert (pEntSymbol      != NULL) ;
103 
104 	pVarTbl		= pLM->m_apVariableTable ;
105 	if (TFAILED (lispBindTable_SearchEntry (pLispMgr, pVarTbl, SIZE_LISP_BIND_TABLE, pEntSymbol, &pBind)) ||
106 		pBind == NULL) {
107 		if (TFAILED (lispBindTable_MakeEntry (pLispMgr, pVarTbl, SIZE_LISP_BIND_TABLE, pEntSymbol, &pBind)))
108 			return	False ;
109 	}
110 	lispBind_SetValue (pLispMgr, pBind, pEntValue) ;
111 	return	True ;
112 }
113 
114 static inline Boolean
lispMachine_getBufferLocalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntBuffer,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)115 lispMachine_getBufferLocalSymbolValue (
116 	register TLispMachine*			pLM,
117 	register TLispEntity*			pEntBuffer,
118 	register TLispEntity*			pEntTarget,
119 	register TLispEntity** const	ppEntReturn)
120 {
121 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
122 	register Boolean			fRetval ;
123 	TLispEntity*	pEntRetval ;
124 
125 	assert (pLM         != NULL) ;
126 	assert (pEntTarget  != NULL) ;
127 	assert (pEntBuffer  != NULL) ;
128 	assert (ppEntReturn != NULL) ;
129 
130 	fRetval	= lispBuffer_GetSymbolValue (pLispMgr, pEntBuffer, pEntTarget, &pEntRetval) ;
131 	if (TFAILED (fRetval) ||
132 		pEntRetval == NULL ||
133 		TSUCCEEDED (lispEntity_Emptyp (pLispMgr, pEntRetval)))
134 		return	False ;
135 	*ppEntReturn	= pEntRetval ;
136 	return	True ;
137 }
138 
139 /*
140  *[��ǽ]
141  *	Lisp Machine �� local �ʥ���ܥ�(�ѿ�)��������롣����ܥ��̾����
142  *	Lisp �� Entity ��Ϳ���롣
143  */
144 Boolean
lispMachine_MakeSymbolValue(register TLispMachine * pLM,register TLispEntity * pSymbol,register TLispBind ** ppBindReturn)145 lispMachine_MakeSymbolValue (
146 	register TLispMachine*	pLM,
147 	register TLispEntity*	pSymbol,
148 	register TLispBind**	ppBindReturn)
149 {
150 	assert (pLM      != NULL) ;
151 	assert (pSymbol  != NULL) ;
152 
153 	return	lispBindTable_MakeEntry (pLM->m_pLispMgr, pLM->m_apVariableTable, NELEMENTS (pLM->m_apVariableTable), pSymbol, ppBindReturn) ;
154 }
155 
156 /*
157  *[��ǽ]
158  *	Lisp Machine �� Local �ʥ���ܥ�(�ѿ�)��������롣����ܥ��̾����
159  *	Char ʸ�����Ϳ���롣
160  */
161 Boolean
lispMachine_MakeSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispBind ** ppBindReturn)162 lispMachine_MakeSymbolValueWithName (
163 	register TLispMachine*	pLM,
164 	register const Char*	pName,
165 	register const int		nName,
166 	register TLispBind**	ppBindReturn)
167 {
168 	register TLispManager*	pLispMgr ;
169 	TLispEntity*	pEntSymbol ;
170 	assert (pLM      != NULL) ;
171 
172 	pLispMgr	= pLM->m_pLispMgr ;
173 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
174 		return	False ;
175 	return	lispBindTable_MakeEntry (pLispMgr, pLM->m_apVariableTable, NELEMENTS (pLM->m_apVariableTable), pEntSymbol, ppBindReturn) ;
176 }
177 
178 /*
179  *[��ǽ]
180  *	Local �ʤ�Τ�����֤˥���ܥ�(�ѿ�)��¸�ߤ��뤫��ǧ���ơ����դ��ä�
181  *	����ܥ���Ф����ͤ��åȤ��롣
182  *	Global �ʥ���ܥ�ޤ�����¸�ߤ��ʤ��ä����ˤϡ�Global ����ܥ���
183  *	�������ͤ��åȤ��롣
184  */
185 Boolean
lispMachine_SetCurrentSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)186 lispMachine_SetCurrentSymbolValue (
187 	register TLispMachine*	pLM,
188 	register TLispEntity*	pEntSymbol,
189 	register TLispEntity*	pEntValue)
190 {
191 	assert (pLM        != NULL) ;
192 	assert (pEntSymbol != NULL) ;
193 	assert (pEntValue  != NULL) ;
194 
195 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
196 	return	(lispMachine_setCurrentBufferLocalSymbolValue (pLM, pEntSymbol, pEntValue) ||
197 			 lispMachine_setGlobalSymbolValue      (pLM, pEntSymbol, pEntValue)) ;
198 }
199 
200 /*
201  *[��ǽ]
202  *	buffer-local-variable ���ͤ����ꤹ�롣
203  *[����]
204  *	Lisp ��̿��� buffer-local-variable ������ؤ��ơ��ͤ��åȤ���
205  *	��Τ����뤫�ɤ�����ʬ����ʤ���Ĵ����­���⤷��ʤ�����
206  */
207 Boolean
lispMachine_SetCurrentBufferLocalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)208 lispMachine_SetCurrentBufferLocalSymbolValue (
209 	register TLispMachine*	pLM,
210 	register TLispEntity*	pEntSymbol,
211 	register TLispEntity*	pEntValue)
212 {
213 	register TLispManager*	pLispMgr ;
214 	register TLispEntity*	pEntBuffer ;
215 
216 	assert (pLM        != NULL) ;
217 	assert (pEntSymbol != NULL) ;
218 	assert (pEntValue  != NULL) ;
219 
220 	pLispMgr	= pLM->m_pLispMgr ;
221 	assert (pLispMgr   != NULL) ;
222 	pEntBuffer	= pLM->m_pCurBuffer ;
223 
224 	/*	���ιԤϰ��Ū�ʤ�Τ�������*/
225 	if (pEntBuffer == NULL)
226 		return	False ;
227 
228 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
229 	return	lispBuffer_SetSymbolValue (pLispMgr, pEntBuffer, pEntSymbol, pEntValue) ;
230 }
231 
232 /*
233  *[��ǽ]
234  *	Lisp Machine �� Local �ʥ���ܥ���ͤ��åȤ��롣
235  */
236 Boolean
lispMachine_SetGlobalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)237 lispMachine_SetGlobalSymbolValue (
238 	register TLispMachine*	pLM,
239 	register TLispEntity*	pEntSymbol,
240 	register TLispEntity*	pEntValue)
241 {
242 	assert (pLM             != NULL) ;
243 	assert (pEntSymbol      != NULL) ;
244 
245 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
246 	return	lispMachine_setGlobalSymbolValue (pLM, pEntSymbol, pEntValue) ;
247 }
248 
249 /*
250  *[��ǽ]
251  *	buffer-local-variable ���ͤ��åȤ��롣����ܥ�� Char ʸ�����Ϳ���롣
252  */
253 Boolean
lispMachine_SetCurrentBufferLocalSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity * pEntValue)254 lispMachine_SetCurrentBufferLocalSymbolValueWithName (
255 	register TLispMachine*	pLM,
256 	register const Char*	pName,
257 	register const int		nName,
258 	register TLispEntity*	pEntValue)
259 {
260 	assert (pLM       != NULL) ;
261 	assert (pName     != NULL && nName > 0) ;
262 	assert (pEntValue != NULL) ;
263 
264 	/*	���ιԤϰ��Ū�ʤ�Τ�������*/
265 	if (pLM->m_pCurBuffer == NULL)
266 		return	False ;
267 
268 	return	lispBuffer_SetSymbolValueWithName (pLM->m_pLispMgr, pLM->m_pCurBuffer, pName, nName, pEntValue) ;
269 }
270 
271 /*
272  *[��ǽ]
273  *	Lisp Machine �� local �ʥ���ܥ���ͤ��åȤ��롣����ܥ�� Char ʸ����
274  *	�ǻ��ꤹ�롣
275  */
276 Boolean
lispMachine_SetGlobalSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity * pEntValue)277 lispMachine_SetGlobalSymbolValueWithName (
278 	register TLispMachine*	pLM,
279 	register const Char*	pName,
280 	register const int		nName,
281 	register TLispEntity*	pEntValue)
282 {
283 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
284 	TLispEntity*	pEntSymbol ;
285 
286 	assert (pLM             != NULL) ;
287 	assert (pLM->m_pLispMgr != NULL) ;
288 	assert (pName           != NULL && nName > 0) ;
289 	assert (pEntValue       != NULL) ;
290 
291 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
292 		return	False ;
293 
294 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
295 	return	lispMachine_setGlobalSymbolValue (pLM, pEntSymbol, pEntValue) ;
296 }
297 
298 /*
299  *[��ǽ]
300  *	Symbol ̾�Ǥ�äơ�Symbol ���ͤ������Ƥ롣Local �ʤ�Τ��� Global ��
301  *	��ΤؤȽ��֤� Symbol ���ͤ�������Ƥ��Ƥ��뤫���Ƥ�����
302  *	�ǽ�Ū��ï�⤽�� Symbol ���ͤ�������ƤƤ��ʤ���С�Global �� Symbol
303  *	Value �Ȥ����ͤ�������Ƥ��뤳�Ȥˤʤ롣
304  *	Buffer Local �� Machine Local �� Symbol ���ͤ������Ƥ������ˤϡ���
305  *	�����Ѱդ��Ƥ���ɬ�פ����롣
306  */
307 Boolean
lispMachine_SetCurrentSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity * pEntValue)308 lispMachine_SetCurrentSymbolValueWithName (
309 	register TLispMachine*	pLM,
310 	register const Char*	pName,
311 	register const int		nName,
312 	register TLispEntity*	pEntValue)
313 {
314 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
315 	TLispEntity*	pEntSymbol ;
316 
317 	assert (pLM       != NULL) ;
318 	assert (pName     != NULL && nName > 0) ;
319 	assert (pEntValue != NULL) ;
320 
321 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
322 		return	False ;
323 
324 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
325 	return	(lispMachine_setCurrentBufferLocalSymbolValue (pLM, pEntSymbol, pEntValue) ||
326 			 lispMachine_setGlobalSymbolValue      (pLM, pEntSymbol, pEntValue)) ;
327 }
328 
329 Boolean
lispMachine_SetCurrentSymbolValueWithNameA(register TLispMachine * pLM,register const char * pName,register const int nName,register TLispEntity * pEntValue)330 lispMachine_SetCurrentSymbolValueWithNameA (
331 	register TLispMachine*	pLM,
332 	register const char*	pName,
333 	register const int		nName,
334 	register TLispEntity*	pEntValue)
335 {
336 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
337 	TLispEntity*	pEntSymbol ;
338 
339 	assert (pLM       != NULL) ;
340 	assert (pName     != NULL && nName > 0) ;
341 	assert (pEntValue != NULL) ;
342 
343 	if (TFAILED (lispMgr_InternSymbolA (pLispMgr, pName, nName, &pEntSymbol)))
344 		return	False ;
345 
346 	pEntSymbol	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
347 	return	(lispMachine_setCurrentBufferLocalSymbolValue (pLM, pEntSymbol, pEntValue) ||
348 			 lispMachine_setGlobalSymbolValue      (pLM, pEntSymbol, pEntValue)) ;
349 }
350 
351 /*
352  *[��ǽ]
353  *	����ܥ�˳�����Ƥ��Ƥ����ͤ����롣local �ʤ�Τ�����֤˸�������
354  *	���դ��ä��Ȥ���ǡ����Υ���ܥ���ͤ����롣����ܥ�� entity �ǻ���
355  *	���롣
356  *[����]
357  *	������entity �Υ����פ�����ܥ�Ǥʤ���Х��顼�ˤʤ롣
358  */
359 Boolean
lispMachine_GetCurrentSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)360 lispMachine_GetCurrentSymbolValue (
361 	register TLispMachine*			pLM,
362 	register TLispEntity*			pEntTarget,
363 	register TLispEntity** const	ppEntReturn)
364 {
365 	assert (pLM         != NULL) ;
366 	assert (pEntTarget  != NULL) ;
367 	assert (ppEntReturn != NULL) ;
368 
369 	return	(lispMachine_GetCurrentBufferLocalSymbolValue (pLM, pEntTarget, ppEntReturn) ||
370 			 lispMachine_GetGlobalSymbolValue (pLM, pEntTarget, ppEntReturn)) ;
371 }
372 
373 Boolean
lispMachine_GetCurrentBufferLocalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)374 lispMachine_GetCurrentBufferLocalSymbolValue (
375 	register TLispMachine*			pLM,
376 	register TLispEntity*			pEntTarget,
377 	register TLispEntity** const	ppEntReturn)
378 {
379 	pEntTarget	= lispMachine_getRealSymbol (pLM, pEntTarget) ;
380 	return	lispMachine_getBufferLocalSymbolValue (pLM, pLM->m_pCurBuffer, pEntTarget, ppEntReturn) ;
381 }
382 
383 Boolean
lispMachine_GetGlobalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity ** const ppEntReturn)384 lispMachine_GetGlobalSymbolValue (
385 	register TLispMachine*			pLM,
386 	register TLispEntity*			pEntSymbol,
387 	register TLispEntity** const	ppEntReturn)
388 {
389 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
390 	register TLispEntity*	pEntTarget ;
391 
392 	assert (pLM             != NULL) ;
393 	assert (pLispMgr        != NULL) ;
394 	assert (pEntSymbol      != NULL) ;
395 	assert (ppEntReturn     != NULL) ;
396 
397 	while (pLM != NULL) {
398 		pEntTarget	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
399 		if (TSUCCEEDED (lispBindTable_GetEntryValue (pLispMgr, pLM->m_apVariableTable, NELEMENTS (pLM->m_apVariableTable), pEntTarget, ppEntReturn)))
400 			return	True ;
401 		pLM	= pLM->m_pMacParent ;
402 	}
403 	return	False ;
404 }
405 
406 Boolean
lispMachine_GetSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntBuffer,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)407 lispMachine_GetSymbolValue (
408 	register TLispMachine*			pLM,
409 	register TLispEntity*			pEntBuffer,
410 	register TLispEntity*			pEntTarget,
411 	register TLispEntity** const	ppEntReturn)
412 {
413 	return	(lispMachine_GetBufferLocalSymbolValue (pLM, pEntBuffer, pEntTarget, ppEntReturn) ||
414 			 lispMachine_GetGlobalSymbolValue (pLM, pEntTarget, ppEntReturn)) ;
415 }
416 
417 Boolean
lispMachine_GetBufferLocalSymbolValue(register TLispMachine * pLM,register TLispEntity * pEntBuffer,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)418 lispMachine_GetBufferLocalSymbolValue (
419 	register TLispMachine*			pLM,
420 	register TLispEntity*			pEntBuffer,
421 	register TLispEntity*			pEntTarget,
422 	register TLispEntity** const	ppEntReturn)
423 {
424 	assert (pLM         != NULL) ;
425 	assert (pEntTarget  != NULL) ;
426 	assert (pEntBuffer  != NULL) ;
427 	assert (ppEntReturn != NULL) ;
428 
429 	pEntTarget	= lispMachine_getRealSymbol (pLM, pEntTarget) ;
430 	return	lispMachine_getBufferLocalSymbolValue (pLM, pEntBuffer, pEntTarget, ppEntReturn) ;
431 }
432 
433 Boolean
lispMachine_GetCurrentSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity ** const ppReturn)434 lispMachine_GetCurrentSymbolValueWithName (
435 	register TLispMachine*			pLM,
436 	register const Char*			pName,
437 	register const int				nName,
438 	register TLispEntity** const	ppReturn)
439 {
440 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
441 	TLispEntity*	pEntSymbol ;
442 
443 	assert (pLM      != NULL) ;
444 	assert (ppReturn != NULL) ;
445 
446 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
447 		return	False ;
448 
449 	return	(lispMachine_GetCurrentBufferLocalSymbolValue (pLM, pEntSymbol, ppReturn) ||
450 			 lispMachine_GetGlobalSymbolValue (pLM, pEntSymbol, ppReturn)) ;
451 }
452 
453 Boolean
lispMachine_GetCurrentBufferLocalSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity ** const ppEntReturn)454 lispMachine_GetCurrentBufferLocalSymbolValueWithName (
455 	register TLispMachine*			pLM,
456 	register const Char*			pName,
457 	register const int				nName,
458 	register TLispEntity** const	ppEntReturn)
459 {
460 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
461 	register TLispEntity*	pEntBuffer	= pLM->m_pCurBuffer ;
462 	TLispEntity*			pEntSymbol ;
463 	register TLispEntity*	pEntTarget ;
464 
465 	assert (pLM      != NULL) ;
466 	assert (pName    != NULL && nName > 0) ;
467 	assert (ppEntReturn != NULL) ;
468 
469 	if (pEntBuffer == NULL)
470 		return	False ;
471 
472 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
473 		return	False ;
474 	pEntTarget	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
475 	return	lispMachine_getBufferLocalSymbolValue (pLM, pEntBuffer, pEntTarget, ppEntReturn) ;
476 }
477 
478 Boolean
lispMachine_GetGlobalSymbolValueWithName(register TLispMachine * pLM,register const Char * pName,register const int nName,register TLispEntity ** const ppEntReturn)479 lispMachine_GetGlobalSymbolValueWithName (
480 	register TLispMachine*			pLM,
481 	register const Char*			pName,
482 	register const int				nName,
483 	register TLispEntity** const	ppEntReturn)
484 {
485 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
486 	TLispEntity*			pEntSymbol ;
487 	register TLispEntity*	pEntTarget ;
488 
489 	assert (pLM             != NULL) ;
490 	assert (pLM->m_pLispMgr != NULL) ;
491 
492 	if (TFAILED (lispMgr_InternSymbol (pLispMgr, pName, nName, &pEntSymbol)))
493 		return	False ;
494 
495 	while (pLM != NULL) {
496 		pEntTarget	= lispMachine_getRealSymbol (pLM, pEntSymbol) ;
497 		if (TSUCCEEDED (lispBindTable_GetEntryValue (pLispMgr, pLM->m_apVariableTable, NELEMENTS (pLM->m_apVariableTable), pEntTarget, ppEntReturn)))
498 			return	True ;
499 		pLM	= pLM->m_pMacParent ;
500 	}
501 	return	False ;
502 }
503 
504 /*	function, property �ˤ� symbol -> symbol �� map �ϱƶ����ʤ����Ȥ��롣
505  */
506 Boolean
lispMachine_SetSymbolFunctionValue(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)507 lispMachine_SetSymbolFunctionValue (
508 	register TLispMachine*			pLM,
509 	register TLispEntity*			pEntSymbol,
510 	register TLispEntity*			pEntValue)
511 {
512 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
513 	register TLispBind**	ppBindTbl ;
514 	TLispBind*	pBind ;
515 
516 	assert (pLM         != NULL) ;
517 	assert (pEntSymbol  != NULL) ;
518 	assert (pEntValue   != NULL) ;
519 
520 	ppBindTbl	= pLM->m_apFunctionTable ;
521 	if (TFAILED (lispBindTable_SearchEntry (pLispMgr, ppBindTbl, NELEMENTS (pLM->m_apFunctionTable), pEntSymbol, &pBind)) ||
522 		pBind == NULL) {
523 		if (TFAILED (lispBindTable_MakeEntry (pLispMgr, ppBindTbl, NELEMENTS (pLM->m_apFunctionTable), pEntSymbol, &pBind)))
524 			return	False ;
525 	}
526 	lispBind_SetValue (pLispMgr, pBind, pEntValue) ;
527 	return	True ;
528 }
529 
530 Boolean
lispMachine_GetSymbolFunctionValue(register TLispMachine * pLM,register TLispEntity * pEntTarget,register TLispEntity ** const ppEntReturn)531 lispMachine_GetSymbolFunctionValue (
532 	register TLispMachine*			pLM,
533 	register TLispEntity*			pEntTarget,
534 	register TLispEntity** const	ppEntReturn)
535 {
536 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
537 	const LMCMDINFO*	pProcInfo ;
538 
539 	assert (pLM         != NULL) ;
540 	assert (pEntTarget  != NULL) ;
541 	assert (ppEntReturn != NULL) ;
542 
543 	while (pLM != NULL) {
544 		if (TSUCCEEDED (lispBindTable_GetEntryValue (pLispMgr, pLM->m_apFunctionTable, NELEMENTS (pLM->m_apFunctionTable), pEntTarget, ppEntReturn)))
545 			return	True ;
546 		pLM	= pLM->m_pMacParent ;
547 	}
548 	/*	builtin function �ˤʤ���Ĵ�٤롣*/
549 	if (TFAILED (lispMachine_SearchBuiltinFunction (pLispMgr, pEntTarget, &pProcInfo)) ||
550 		pProcInfo == NULL)
551 		return	False ;
552 
553 	return	lispMgr_CreateSubr (pLispMgr, pProcInfo, ppEntReturn) ;
554 }
555 
556 Boolean
lispMachine_GetFinalSymbolFunctionValue(register TLispMachine * pLM,register TLispEntity * pEntTarget,register TLispEntity ** ppEntReturn)557 lispMachine_GetFinalSymbolFunctionValue (
558 	register TLispMachine*	pLM,
559 	register TLispEntity*	pEntTarget,
560 	register TLispEntity**	ppEntReturn)
561 {
562 	register TLispManager*	pLispMgr ;
563 	TLispEntity*	pEntValue ;
564 	register int	nCount		= MAX_NEST_COUNT ;
565 
566 	assert (pLM != NULL) ;
567 	assert (pEntTarget  != NULL) ;
568 	assert (ppEntReturn != NULL) ;
569 
570 	pLispMgr	= pLM->m_pLispMgr ;
571 	while (TSUCCEEDED (lispEntity_Symbolp (pLispMgr, pEntTarget)) &&
572 		   nCount -- > 0) {
573 		if (TFAILED (lispMachine_GetSymbolFunctionValue (pLM, pEntTarget, &pEntValue))) {
574 #if 1
575 			fprintf (stderr, "void function: ") ;
576 			lispEntity_Print (pLispMgr, pEntTarget) ;
577 #endif
578 		}
579 		pEntTarget	= pEntValue ;
580 	}
581 	if (nCount == 0)
582 		return	False ;
583 	*ppEntReturn	= pEntValue ;
584 	return	True ;
585 }
586 
587 /*
588  */
589 Boolean
lispMachine_SetSymbolProperty(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity * pEntValue)590 lispMachine_SetSymbolProperty (
591 	register TLispMachine*			pLM,
592 	register TLispEntity*			pEntSymbol,
593 	register TLispEntity* 			pEntValue)
594 {
595 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
596 	register TLispBind**	pBindTbl ;
597 	TLispBind*	pBind ;
598 
599 	assert (pLM         != NULL) ;
600 	assert (pEntSymbol  != NULL) ;
601 	assert (pEntValue   != NULL) ;
602 
603 	pBindTbl	= pLM->m_apPropertyTable ;
604 	if (TFAILED (lispBindTable_SearchEntry (pLispMgr, pBindTbl, NELEMENTS (pLM->m_apPropertyTable), pEntSymbol, &pBind)) ||
605 		pBind == NULL) {
606 		if (TFAILED (lispBindTable_MakeEntry (pLispMgr, pBindTbl, NELEMENTS (pLM->m_apPropertyTable), pEntSymbol, &pBind)))
607 			return	False ;
608 	}
609 	lispBind_SetValue (pLispMgr, pBind, pEntValue) ;
610 	return	True ;
611 }
612 
613 Boolean
lispMachine_GetSymbolProperty(register TLispMachine * pLM,register TLispEntity * pEntSymbol,register TLispEntity ** ppEntReturn)614 lispMachine_GetSymbolProperty (
615 	register TLispMachine*			pLM,
616 	register TLispEntity*			pEntSymbol,
617 	register TLispEntity**			ppEntReturn)
618 {
619 	register TLispManager*	pLispMgr	= pLM->m_pLispMgr ;
620 
621 	assert (pLM         != NULL) ;
622 	assert (pEntSymbol  != NULL) ;
623 	assert (ppEntReturn != NULL) ;
624 
625 	while (pLM != NULL) {
626 		if (TSUCCEEDED (lispBindTable_GetEntryValue (pLispMgr, pLM->m_apPropertyTable, NELEMENTS (pLM->m_apPropertyTable), pEntSymbol, ppEntReturn)))
627 			return	True ;
628 		pLM	= pLM->m_pMacParent ;
629 	}
630 	return	False ;
631 }
632 
633