1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 2003-2013 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 
22 /*
23  * return the next codex method
24  * call with meth==0 to get the first method
25  * plugins are included in the list
26  */
27 
28 #include <codex.h>
29 #include <dlldefs.h>
30 
31 Codexmeth_t*
codexlist(Codexmeth_t * meth)32 codexlist(Codexmeth_t* meth)
33 {
34 	register Codexmeth_t*	lp;
35 	Codexmeth_t*		np;
36 	Dllscan_t*		dls;
37 	Dllent_t*		dle;
38 	void*			dll;
39 	Codexlib_f		lib;
40 
41 	if (!meth)
42 		return codexstate.first;
43 	if (!meth->next && !codexstate.scanned)
44 	{
45 		codexstate.scanned = 1;
46 		lp = meth;
47 		if (dls = dllsopen(codexstate.id, NiL, NiL))
48 		{
49 			while (dle = dllsread(dls))
50 				if (dll = dlopen(dle->path, RTLD_LAZY))
51 				{
52 					/* vcodex check works around obsolete vcodex<=>codex plugin */
53 					if ((lib = (Codexlib_f)dlllook(dll, "codex_lib")) && (np = (*lib)(dle->name)) && !streq(np->name, "vcodex"))
54 						for (lp = lp->next = np; lp->next; lp = lp->next);
55 					else
56 						dlclose(dll);
57 				}
58 				else
59 					message((-1, "%s: %s", dle->path, dlerror()));
60 			dllsclose(dls);
61 		}
62 	}
63 	return meth->next;
64 }
65