Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / plugins / plugin_perlpackages.cpp
blob89465bc2510381100d062608ff62bc33a306b4b2
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->d_output;
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->d_file_name = 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_info ()
108 printf ("Perl packages.\n");
109 printf ("Version: 1.0\n");
110 printf ("options: --perl --packages\n");
113 DArray * plugin_init (struct env_t * env)
115 DArray * Ret;
116 struct mod_feature * pm;
118 ENV = env;
119 Ret = new DArray (32);
120 pm = CNEW (mod_feature, 1);
121 memset (pm, 0, sizeof (mod_feature));
122 pm->mod.Type = TYPE_FEATURE;
123 pm->mod.Version = strdup ("1.0");
124 pm->mod.info = plug_info;
125 pm->opt2 = pl_opt;
127 Ret->add (LPCHAR (pm));
128 return Ret;