+ Fixes
[opsoft.git] / silentbob / plugins / plugin_perlpackages.cxx
blobb873fe8cbe48a6af957cb60f71e01d2ffc821171
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include <gclib/gclib.h>
12 #include <mod.h>
13 #include <head.h>
14 #include <dbg.h>
15 #include <the_tt.h>
16 #include <the_fly.hpp>
18 extern "C" DArray * plugin_init (struct env_t *env);
19 char t_op2 (char ** d_in, char ** d_prev);
21 void __perl_files (char * f_name)
23 unlink (f_name);
24 sblib_find ("./", "*.pm", f_name);
25 sblib_find ("./", "*.pl", f_name);
26 sblib_find ("./", "*.ph", f_name);
29 void plpkg_one (struct tt_state_t * tt)
31 char * d_out, *d_ptr; // for t_op2
32 int block_depth = 0;
33 char ch;
34 char * S;
36 d_out = tt->result;
37 d_ptr = d_out;
39 while (true) {
40 ch = t_op2 (&d_ptr, &d_out);
41 if (ch == '\0')
42 break;
44 S = d_out;
45 if (*S == ' ')
46 ++S;
48 if (! block_depth && !strncmp (S, "package ", 8))
49 printf ("%s\n", S);
51 if (ch == '{')
52 ++block_depth;
54 if (ch == '}')
55 --block_depth;
57 if (block_depth < 0)
58 block_depth = 0;
63 void try_packages ()
65 int i;
66 struct tt_state_t * tt;
67 DArray * d_files;
69 d_files = ENV->d_files;
70 if (d_files->get_size () == 0) {
71 __perl_files (ENV->tmp_files);
72 d_files->from_file (ENV->tmp_files);
73 d_files->foreach ((Dfunc_t)chomp);
74 unlink (ENV->tmp_files);
77 for (i = 0; i < d_files->get_size (); i++) {
78 tt = CNEW (tt_state_t, 1);
80 memset (tt, 0, sizeof (struct tt_state_t));
81 if (! d_files->get (i))
82 continue;
84 tt->fileName = strdup (d_files->get (i));
85 THE_FLY::fly_for_file (tt);
86 plpkg_one (tt);
87 free_tt_state (tt);
91 char pl_opt (DArray * d_opts, int * i)
93 if (! d_opts || ! i)
94 return 0;
96 if (EQ (d_opts->get (*i), "--packages")) {
97 if (EQ (ENV->language, "Perl")) {
98 try_packages ();
99 exit (1);
103 return 0;
106 void plug_short_info ()
108 printf ("Perl packages.");
111 void plug_long_info ()
113 printf ("Perl packages.\n");
114 printf ("Version: 1.0\n");
115 printf ("options: --perl --packages\n");
118 DArray * plugin_init (struct env_t * env)
120 DArray * Ret;
121 mod_t * plug;
123 ENV = env;
124 Ret = new DArray (32);
125 plug = CNEW (mod_t, 1);
126 memset (plug, 0, sizeof (mod_t));
127 plug->Version = strdup ("1.0");
128 plug->short_info = plug_short_info;
129 plug->long_info = plug_long_info;
130 plug->opt2 = pl_opt;
132 ENV->listOptions->add ("--packages");
133 ENV->listOptions->add ("--perl");
135 Ret->add (LPCHAR (plug));
136 return Ret;