2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
11 #include <gclib/gclib.h>
12 #include <gclib/gclib_c.h>
17 extern "C" DArray
* plugin_init (struct env_t
*env
);
23 struct grep_env_t ENV_grep
;
25 void grep_one (char * buf
, int size
, char * search
, int s_len
)
41 end
= &buf
[size
- s_len
- 1];
42 end2
= &buf
[size
- 1];
51 if (! memcmp (ptr
, search
, s_len
)) {
52 s_line
= Dmid_getstr (line_ptr
, end2
);
56 if (SB_FLGET (SB_FLTAGSTYLE
))
57 printf ("%s\t%s\t%i\n", search
, ENV_grep
.f_name
, nlines
);
59 printf ("%s:%i: %s\n", ENV_grep
.f_name
, nlines
, s_line
);
68 void grep_loop (DArray
* files
, char * search
)
76 if (! files
|| ! search
)
79 s_len
= strlen (search
);
80 nfiles
= files
->get_size ();
81 for (i
= 0; i
< nfiles
; ++i
) {
83 ptr
= DFILE (files
->get (i
), &size
);
88 ENV_grep
.f_name
= files
->get (i
);
89 grep_one (ptr
, size
, search
, s_len
);
94 char grep_opt (DArray
* d_opts
, int * pos
)
99 if (! d_opts
|| ! pos
)
102 count
= d_opts
->get_size ();
103 S
= d_opts
->get (*pos
);
104 if (EQ (S
, "--grep")) {
112 char grep_opt2 (DArray
* d_opts
, int * pos
)
116 if (! d_opts
|| ! pos
)
119 S
= d_opts
->get (*pos
);
120 if (EQ (S
, "--grep")) {
122 S
= d_opts
->get (*pos
);
124 printf ("SilentBob grep require parameter.\n");
127 grep_loop (ENV
->d_files
, S
);
136 printf ("Search of text.\n");
137 printf ("Version: 1.0\n");
138 printf ("options: --grep\n");
141 DArray
* plugin_init (struct env_t
*env
)
144 struct mod_feature
* pm
;
147 Ret
= new DArray (1);
148 pm
= CNEW (mod_feature
, 1);
149 memset (pm
, 0, sizeof (mod_feature
));
150 pm
->mod
.Type
= TYPE_FEATURE
;
151 pm
->mod
.Version
= strdup ("1.0");
152 pm
->mod
.info
= grep_info
;
154 pm
->opt2
= grep_opt2
;
156 Ret
->add (LPCHAR (pm
));