2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 * Oleg, "THE FLY", and BUGS.
7 * "THE FLY" - "THE TT" analog for Perl code.
8 * 1 May 2006 - started.
24 #include "../the_tt.h"
25 #include "the_fly.hpp"
38 pair_t
* d_attachment
= NULL
;
42 inline void t_attach ()
45 d_attachment
[t_op_no
].pair_op
= t_op_no
;
46 d_attachment
[t_op_no
].pair_line
= nlines
;
47 d_attachment
[t_op_no
].offset
= i
;
50 inline void TN (char ch
) {
53 if ((i
&& t_map
[i
-1] != '\\') && (ch
== '{' || ch
== '}' || ch
== ';'))
57 inline char * fly_fw (char * word
)
69 Ret
= CNEW (char, S
- word
+ 1);
70 memcpy (Ret
, word
, S
- word
);
82 if (*word
== '\'' || *word
== '\"')
89 ptrn
= CNEW (char, strlen (word
)+3);
90 sprintf (ptrn
, "\n%s\n", word
);
91 S
= (char *) memmem (&t_map
[i
+2], t_size
-i
-2, ptrn
, strlen (ptrn
));
92 assert (! S
, "fly_skip fail !");
98 nlines
+= Dsyms (&t_map
[i
+2], S
, '\n');
100 i
+= S
- &t_map
[i
] + strlen (ptrn
) + 1;
110 char * ptrn
= "\n=cut\n";
112 S
= (char *) memmem (&t_map
[i
], t_size
-i
, ptrn
, 6);
118 nlines
+= Dsyms (&t_map
[i
], S
, '\n');
120 i
+= S
- &t_map
[i
] + 4;
151 for (; i
< t_size
; ++i
) {
155 if (t_map
[i
] == ss
&& !(ww_nsyms_r (ptr
, &t_map
[i
-1], '\\') % 2))
162 assert (i
>= t_size
, "Sibadi 2006.2");
183 if (isalnum (pch
) || pch
== '_' || pch
== ')')
186 if (! (ch
== '/' || ch
== 's' || ch
== 'm' || !strncmp (&t_map
[i
], "tr", 2)))
197 if (! (ss
== '/' || ss
== '?' || ss
== '#'
198 || ss
== '!' || ss
== '&' || ss
== '|' || ss
== '{'))
206 inline void tt_skip ()
208 while (T
!= '\n' && i
< t_size
)
213 int fly_for_buffers (char * d_input
, int size
, char * d_output
)
234 for (; i
< size
; i
++) {
239 if (regexp_test ()) {
244 if (if_digit (&t_map
[i
]) || if_abc (&t_map
[i
])) {
249 if ((ch
== '\'' || ch
== '\"') && t_map
[i
-1] != '$' && t_map
[i
-1] != '\\') {
250 if (ch
== '\'' && (isalnum (t_map
[i
-1]) || t_map
[i
-1] == '&'))
253 S
= sstrend (&t_map
[i
]);
254 assert (S
== NULL
, "\n\nSibadi 2006\n\n");
255 nlines
+= Dsyms (&t_map
[i
], S
, '\n');
263 if (ch
== '\n' || ch
== ' ' || ch
== '\t') {
272 if (ch
== '<' && t_map
[i
+1] == '<') {
285 if (ch
== ';' || ch
== '}' || ch
== ')' ||
286 ch
== '{' || ch
== '(') {
296 if (ch
== '=' && t_map
[i
-1] == '\n') {
302 if (ch
== '#' && t_map
[i
-1] != '$') {
317 char * fly_for_file (struct tt_state_t
* tt
)
322 if (access (tt
->d_file_name
, R_OK
) != F_OK
) {
323 fprintf (stderr
, "No such file %s\n", tt
->d_file_name
);
329 tt
->d_output
= CNEW (char, 1024*1024);
331 d_attachment
= (pair_t
*) CNEW (char, 1024*1024);
333 tt
->d_attachment
= d_attachment
;
334 tt
->d_output_size
= fly_for_buffers (tt
->d_file_in
, tt
->d_filein_size
, tt
->d_output
);
338 } // namespace THE_FLY