2 static char *RCSid
= "$Id$";
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1993-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 struct extlib_funcbox
{
27 struct extlib_funcbox
*next
, *prev
;
33 #define EXTFUNCS_COUNT (sizeof(((tsd_t *)0)->extfuncs) / \
34 sizeof(((tsd_t *)0)->extfuncs[0]))
36 static struct extlib_funcbox
*findfunc( const tsd_t
*TSD
, const streng
*name
, int *hash
,
39 struct extlib_funcbox
*fptr
=NULL
;
42 *hash
= lhash
= hashvalue( name
->value
, name
->len
) ;
43 *hashbox
= lhashbox
= lhash
% EXTFUNCS_COUNT
;
44 for (fptr
=TSD
->extfuncs
[lhashbox
]; fptr
; fptr
=fptr
->prev
)
45 if (fptr
->hash1
== lhash
)
46 if (!Str_cmp(name
, fptr
->name
))
52 int delfunc( tsd_t
*TSD
, const streng
*name
)
54 struct extlib_funcbox
*old
=NULL
;
57 old
= findfunc( TSD
, name
, &hash
, &hashbox
) ;
61 Free_stringTSD( old
->name
) ;
62 if (old
==TSD
->extfuncs
[hashbox
])
63 TSD
->extfuncs
[hashbox
] = old
->prev
;
65 old
->next
->prev
= old
->prev
;
68 old
->prev
->next
= old
->next
;
74 /* addfunc returns 1 on success, 0 if already defined, -1 if memory is short.
75 * The argument name is used for further operation on success only.
77 int addfunc( tsd_t
*TSD
, streng
*name
, int type
)
79 struct extlib_funcbox
*new=NULL
;
82 if (findfunc( TSD
, name
, &hash
, &hashbox
))
85 new = MallocTSD( sizeof(struct extlib_funcbox
)) ;
93 new->prev
= TSD
->extfuncs
[hashbox
] ;
94 if (TSD
->extfuncs
[hashbox
])
95 TSD
->extfuncs
[hashbox
]->next
= new ;
96 TSD
->extfuncs
[hashbox
] = new ;
101 int external_func( const tsd_t
*TSD
, const streng
*name
)
103 struct extlib_funcbox
*ptr
=NULL
;
106 ptr
= findfunc( TSD
, name
, &hash
, &hashbox
) ;