Very old versions for history.
[opsoft_archive.git] / silentbob / silentbob-1.1 / src / t_op.cpp
blobcbe24dc9bc8a4aef15d818c97dbfadf0deb81e8f
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 char t_op (char ** d_in, char ** d_prev, bool b_no_operators)
9 bool b_instring = false;
10 int brace_depth = 0; // for '(' !
11 char *d_ptr = *d_in;
12 int slash_count;
13 char ch_last = 0;
14 char ch = 0;
16 if (*d_prev)
17 *d_prev = *d_in;
19 while (*d_ptr) {
20 if (*d_ptr == '\'' || *d_ptr == '\"') {
21 if (b_instring && *d_ptr != ch_last) {
22 d_ptr++;
23 continue; // Mmm...
26 if (b_instring) {
27 if (d_ptr[-1] == '\\') {
28 slash_count = 1;
29 while (d_ptr [-(slash_count)] == '\\') // Yes, I'm don't like this.
30 slash_count++;
32 if (slash_count & 1)
33 b_instring = false;
34 } else {
35 d_ptr++;
36 b_instring = false;
37 continue;
39 } else {
40 ch_last = *d_ptr;
41 b_instring = true;
45 if (b_instring) {
46 d_ptr++;
47 continue;
50 if (d_ptr[0] == '(')
51 brace_depth++;
53 if (d_ptr[0] == ')')
54 brace_depth--;
56 if (brace_depth < 0)
57 brace_depth = 0;
59 if (b_no_operators && (*d_ptr == '{' || *d_ptr == '}' || *d_ptr == '\n')) {
60 ch = *d_ptr;
61 *d_ptr = 0;
62 if (ch != '\n')
63 d_ptr++;
64 break;
67 if (d_ptr[0] == '{' ||
68 ((*d_ptr == ';') &&
69 (! brace_depth)) ||
70 d_ptr[0] == '}' ||
71 d_ptr[0] == '\n') {
72 ch = *d_ptr;
73 *d_ptr = 0;
74 if (ch != '\n')
75 d_ptr++; // Skip space
76 break;
78 d_ptr++;
81 d_ptr++;
82 *d_in = d_ptr;
83 return ch;