From 706e27f8ac8a202f9d9e87793bb4285908cc4bbd Mon Sep 17 00:00:00 2001 From: Oleg Puchinin Date: Thu, 28 Aug 2008 15:17:51 +0700 Subject: [PATCH] New plugin system --- silentbob/src/modding.cxx | 67 ++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/silentbob/src/modding.cxx b/silentbob/src/modding.cxx index 6d78041..ded6b58 100644 --- a/silentbob/src/modding.cxx +++ b/silentbob/src/modding.cxx @@ -33,52 +33,37 @@ char modding_optparse (int * i, int step) { int pos; mod_t * plug; - mod_feature * f; - mod_language * for (pos = 0; pos < ENV->modding->get_size (); pos++) { plug = (mod_t *) ENV->modding->get (pos); - f = (mod_feature *) plug; - - if (plug->Type == TYPE_FEATURE) { - f = (mod_feature *) plug; - - if (step == 1) { - if (f->opt && f->opt (ENV->d_opts, i)) - return 1; - } - - if (step == 2) { - if (f->opt2 && f->opt2 (ENV->d_opts, i)) - return 1; - } + + if (step == 1) { + if (plug->opt && plug->opt (ENV->d_opts, i)) + return 1; + } + + if (step == 2) { + if (plug->opt2 && plug->opt2 (ENV->d_opts, i)) + return 1; } } - return 0; } -struct mod_language * find_language (char *S) +mod_t * find_language (char *S) { - struct mod_language *pm = NULL; + mod_t * plug; int i; - //printf ("Plugins count : %i\n", ENV->modding->get_size ()); for (i = 0; i < ENV->modding->get_size (); i++) { - pm = (struct mod_language *) ENV->modding->get (i); - if (! pm) - continue; - - if (pm->mod.Type != TYPE_LANGUAGE) - continue; - - if (EQ (pm->language, S)) + plug = (mod_t *) ENV->modding->get (i); + if (EQ (plug->language, S)) break; } if (i < ENV->modding->get_size ()) - return pm; + return plug; return NULL; } @@ -145,17 +130,15 @@ FILE * mkctags_prepare () int modding_start (int i_cmd) { - struct mod_language *pm = NULL; + mod_t * plug; struct tt_state_t * tt; int i; int size; FILE * ofile = NULL; - pm = find_language (ENV->language); - if (pm == NULL || pm->the == NULL) { - assert (true, "Language plugin not found !\n"); + plug = find_language (ENV->language); + if (plug == NULL) return 1; - } if (i_cmd == cmd_makectags) ofile = mkctags_prepare (); @@ -164,9 +147,9 @@ int modding_start (int i_cmd) if (! size) { switch (i_cmd) { case cmd_makectags: - if (! pm->make_ctags) + if (! plug->make_ctags) return 2; - pm->make_ctags (NULL, ofile); + plug->make_ctags (NULL, ofile); } goto mod_out; } @@ -181,10 +164,10 @@ int modding_start (int i_cmd) memset (tt, 0, sizeof (struct tt_state_t)); tt->fileName = ENV->d_files->get (i); - if (! pm->the) + if (! plug->the) return 2; - pm->the (tt); + plug->the (tt); if (! SB_FLGET (SB_FLSIMULATE)) { write (fileno (stdout), tt->result, tt->resultSize); @@ -195,17 +178,17 @@ int modding_start (int i_cmd) break; case cmd_makectags: - if (! pm->make_ctags || !pm->the) + if (! plug->make_ctags) return 2; - pm->make_ctags (ENV->d_files->get (i), ofile); + plug->make_ctags (ENV->d_files->get (i), ofile); break; case cmd_call_tags: - if (! pm->call_tags) + if (! plug->call_tags) return 2; - pm->call_tags (ENV->d_files->get (i)); + plug->call_tags (ENV->d_files->get (i)); break; default: -- 2.11.4.GIT