1 /* Copyright (c) 2008 Sadrul Habib Chowdhury (sadrul@users.sf.net)
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program (see the file COPYING); if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
18 ****************************************************************
26 struct scripts
*s_next
;
27 struct ScriptFuncs
*fns
;
30 struct scripts
*scripts
;
33 AddScript(struct ScriptFuncs
*sf
)
35 struct scripts
*ns
= (struct scripts
*)calloc(1, sizeof(*ns
));
43 #define ALL_SCRIPTS(fn, params, stop) do { \
44 struct scripts *iter; \
45 for (iter = scripts; iter; iter = iter->s_next) \
47 if (iter->fns->fn && (ret = (iter->fns->fn params)) && stop) \
55 ALL_SCRIPTS(sf_Init
, (), 0);
58 void ScriptFinit(void)
61 ALL_SCRIPTS(sf_Finit
, (), 0);
64 void ScriptForeWindowChanged(void)
67 ALL_SCRIPTS(sf_ForeWindowChanged
, (), 0);
70 void ScriptSource(int argc
, const char **argv
)
74 const char *binding
= 0, *path
;
76 while (*argv
&& **argv
== '-') {
77 // check for (-a | -async)
78 if ((*argv
[1] == 'a' && !*argv
[2])
79 || strcmp(*argv
, "-async") == 0)
81 // check for (-b | -binding)
82 else if ((*argv
[1] == 'b' && !*argv
[2])
83 || strcmp(*argv
, "-binding") == 0) {
92 /* If one script loader accepts the file, we don't send it to any other loader */
93 ALL_SCRIPTS(sf_Source
, (path
), 1);
95 //TODO: select the specified engine.
99 int ScriptProcessCaption(const char *str
, struct win
*win
, int len
)
102 ALL_SCRIPTS(sf_ProcessCaption
, (str
, win
, len
), 1);
106 int ScriptCommandExecuted(const char *command
, const char **args
, int argc
)
109 ALL_SCRIPTS(sf_CommandExecuted
, (command
, args
, argc
), 0);
113 #define HAVE_LUA 1 /* XXX: Remove */
115 extern struct ScriptFuncs LuaFuncs
;
118 void LoadScripts(void)
120 /* XXX: We could load the script loaders dynamically */
122 AddScript(&LuaFuncs
);