2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
7 #include <gclib/gclib_c.h>
8 #include <gclib/gclib.h>
11 EArray::EArray (int asize
)
15 int EArray::add (long one
)
17 return DArray::add (LPCHAR (one
));
20 int EArray::sfind (char * d_find
)
23 int d_size
= get_size ();
24 char ** d_array
= get_skeleton ();
26 for (i
= 0; i
< d_size
; i
++) {
27 if (EQ (d_find
, d_array
[i
]))
34 int EArray::snfind (char * d_find
)
37 int d_size
= get_size ();
38 char ** d_array
= get_skeleton ();
40 for (i
= 0; i
< d_size
; i
++) {
41 if (!strncmp (d_find
, d_array
[i
], strlen (d_array
[i
])))
48 void EArray::push (char ** d_push
)
55 add ((long) d_push
[i
]);
60 int EArray::snfind_fast (char *str
, int n
)
74 if (strcmp (get (0), str
) > 0)
78 move
= (last
- first
) >> 1;
80 if (EQ (get (first
), str
))
82 if (EQ (get (last
), str
))
89 fact
= strncmp (get (check
), str
, n
);
91 fact
= strcmp (get (check
), str
);
93 if (fact
< 0) { // [check] < str
95 } else if (! fact
) { // [check] == str
97 } else if (fact
> 0) { // [chec] > str
102 if (EQ (get (first
), str
))
108 int EArray::from_pipe (int fd
)
113 m_file
= fdopen (fd
, "r");
117 buf
= CNEW (char, 256);
119 if (fgets (buf
, 256, m_file
) == NULL
)
130 char * EArray::join (char * mid
, int *len_out
)
143 mid_len
= strlen (mid
);
146 for (i
= 0; i
< count
; i
++)
147 len
+= strlen (get (i
));
150 len
+= count
* mid_len
;
153 Ret
= CNEW (char, len
);
155 for (i
= 0; i
< count
; i
++) {
156 strcpy (ptr
, (char *) get (i
));
157 ptr
+= strlen (get (i
));
168 int EArray::strings_to_file (char * f_name
)
174 d_file
= fopen (f_name
, "w");
179 for (i
= 0; i
< d_len
; ++i
)
180 fprintf (d_file
, "%s\n", get (i
));
186 EArray
& EArray::operator << (char *S
)
192 int EArray::expand (EArray
* e
)
200 count
= e
->get_size ();
204 for (i
= 0; i
< count
; ++i
)
210 int EArray::expand (char *buf
, char * split
)
217 if (!buf
|| !split
|| !(*buf
))
220 last
= &buf
[strlen (buf
)-1];
221 split_len
= strlen (split
);
222 while((S
= Dmid_memmem (ptr
, last
, split
, split_len
)) && S
) {
223 add (Dstrndup (ptr
, S
- ptr
));
229 add (Dstrndup (ptr
, last
-ptr
+1));
234 int EArray::dump (char * d_join
)
240 for (i
= 0; i
< count
; ++i
)
241 printf ("%s%s", get (i
), d_join
);