current version
[opsoft_test.git] / silentbob / plugins / plugin_test.cxx
blob79c44d32998f5d71fc5c311ffb7263729fc8685d
1 /*
2 * (c) Oleg Puchinin 2007
3 * graycardinalster@gmail.com
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <gclib/gclib.h>
12 #include <gclib/gclib_c.h>
13 #include <mod.h>
14 #include <head.h>
15 #include <dbg.h>
16 #include <TT.h>
17 #include <wit.h>
19 extern "C" DArray * plugin_init (struct env_t *env);
20 struct env_t *ENV;
22 char test_plugin_opt (DArray * d_opts, int * pos)
24 int count;
25 char * S;
27 if (! d_opts || ! pos)
28 return 0;
30 count = d_opts->get_size ();
31 S = d_opts->get (*pos);
32 if (EQ (S, "--test")) {
33 return 1;
36 return 0;
39 int test_plugin_file (char * fileName)
41 TT * tt;
42 char * op;
43 int m_type;
45 tt = new TT;
46 tt->loadFile (fileName);
47 tt->init ();
49 while (true) {
50 op = tt->nextOperator ();
51 if (tt->ch == 0)
52 break;
54 // if (tt->bracketDepth)
55 // continue;
57 m_type = tt->wit ();
58 if (m_type & OT::Class)
59 globalsPrint (tt->tt, tt->op (), m_type);
62 delete tt;
63 return 0;
66 char test_plugin_opt2 (DArray * d_opts, int * pos)
68 char * S;
69 int i;
71 if (! d_opts || ! pos)
72 return 0;
74 S = d_opts->get (*pos);
75 if (EQ (S, "--test")) {
76 for (i = 0; i < ENV->d_files->get_size (); ++i)
77 test_plugin_file (ENV->d_files->get (i));
78 exit (0);
81 return 0;
84 void test_plugin_info ()
86 printf ("Test plugin.\n");
87 printf ("Version: 1.0\n");
88 printf ("options: --test\n");
91 DArray * plugin_init (struct env_t *env)
93 DArray * Ret;
94 struct mod_feature * pm;
96 ENV = env;
97 Ret = new DArray (1);
98 pm = CNEW (mod_feature, 1);
99 memset (pm, 0, sizeof (mod_feature));
100 pm->mod.Type = TYPE_FEATURE;
101 pm->mod.Version = strdup ("1.0");
102 pm->mod.short_info = test_plugin_info;
103 pm->opt = test_plugin_opt;
104 pm->opt2 = test_plugin_opt2;
106 Ret->add (LPCHAR (pm));
107 return Ret;