2 * (c) Oleg Puchinin 2006,2007,2008
3 * graycardinalster@gmail.com
5 * Oleg, "THE FLY", and BUGS.
7 * "THE FLY" - "THE TT" analog for Perl code.
8 * 1 May 2006 - started.
17 #include <gclib/gclib.h>
22 #include "the_fly.hpp"
35 pair_t
* d_attachment
= NULL
;
39 inline void t_attach ()
42 d_attachment
[t_op_no
].pair_op
= t_op_no
;
43 d_attachment
[t_op_no
].pair_line
= nlines
;
44 d_attachment
[t_op_no
].offset
= i
;
47 inline void TN (char ch
)
51 if ((i
&& t_map
[i
-1] != '\\') && (ch
== '{' || ch
== '}' || ch
== ';'))
55 inline char * fly_fw (char * word
)
67 Ret
= CNEW (char, S
- word
+ 1);
68 memcpy (Ret
, word
, S
- word
);
80 if (*word
== '\'' || *word
== '\"')
87 ptrn
= CNEW (char, strlen (word
)+3);
88 sprintf (ptrn
, "\n%s\n", word
);
89 S
= (char *) Dmemmem (&t_map
[i
+2], t_size
-i
-2, ptrn
, strlen (ptrn
));
90 assert (! S
, "fly_skip fail !");
96 nlines
+= Dsyms (&t_map
[i
+2], S
, '\n');
98 i
+= S
- &t_map
[i
] + strlen (ptrn
) + 1;
108 char * ptrn
= (char *) "\n=cut\n";
110 S
= (char *) Dmemmem (&t_map
[i
], t_size
-i
, ptrn
, 6);
116 nlines
+= Dsyms (&t_map
[i
], S
, '\n');
118 i
+= S
- &t_map
[i
] + 4;
149 for (; i
< t_size
; ++i
) {
153 if (t_map
[i
] == ss
&& !(ww_nsyms_r (ptr
, &t_map
[i
-1], '\\') % 2))
160 assert (i
>= t_size
, "Sibadi 2006.2");
181 if (isalnum (pch
) || pch
== '_' || pch
== ')')
184 if (! (ch
== '/' || ch
== 's' || ch
== 'm' || !strncmp (&t_map
[i
], "tr", 2)))
195 if (! (ss
== '/' || ss
== '?' || ss
== '#'
196 || ss
== '!' || ss
== '&' || ss
== '|' || ss
== '{'))
204 inline void tt_skip ()
206 while (T
!= '\n' && i
< t_size
)
211 int fly_for_buffers (char * d_input
, int size
, char * d_output
)
227 if (T
== '#' || T
== '=') {
232 for (; i
< size
; i
++) {
237 if (regexp_test ()) {
242 if (if_digit (&t_map
[i
]) || if_abc (&t_map
[i
])) {
247 if ((ch
== '\'' || ch
== '\"') && t_map
[i
-1] != '$' && t_map
[i
-1] != '\\') {
248 if (ch
== '\'' && (isalnum (t_map
[i
-1]) || t_map
[i
-1] == '&'))
251 S
= sstrend (&t_map
[i
]);
252 assert (S
== NULL
, "\n\nSibadi 2006\n\n");
253 nlines
+= Dsyms (&t_map
[i
], S
, '\n');
261 if (ch
== '\n' || ch
== ' ' || ch
== '\t') {
270 if (ch
== '<' && t_map
[i
+1] == '<') {
283 if (ch
== ';' || ch
== '}' || ch
== ')' ||
284 ch
== '{' || ch
== '(') {
294 if (ch
== '=' && t_map
[i
-1] == '\n') {
300 if (ch
== '#' && t_map
[i
-1] != '$') {
315 char * fly_for_file (struct tt_state_t
* tt
)
322 if (access (tt
->fileName
, R_OK
) != F_OK
) {
323 fprintf (stderr
, "No such file %s\n", tt
->fileName
);
329 m_size
= fsize (tt
->fileName
);
330 tt
->result
= CNEW (char, m_size
<< 2);
332 d_attachment
= (pair_t
*) CNEW (char, m_size
<< 2);
333 tt
->attachment
= d_attachment
;
334 tt
->resultSize
= fly_for_buffers (tt
->fileData
, tt
->fileDataSize
, tt
->result
);
339 } // namespace THE_FLY