Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / sblib / wit.cpp
blobd43d3c61c2a0f48c6166d80a720a98f8b453e2f6
1 /*
2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 */
7 #include "../head.h"
8 #include "wit.h"
10 int what_is_this (char * d_op, char ch)
12 bool b_local_ftest;
13 int d_words_count;
14 char d_last_ch;
15 char * S;
16 int Ret = 0;
18 if (*d_op == '#' || ch == '\n') {
19 if (def_test (d_op))
20 return OP_TYPE_DEFINE;
21 return OP_TYPE_MACRO;
24 d_words_count = words_count (d_op);
26 if (words_count <= 0)
27 return OP_TYPE_OTHER;
29 if (d_words_count == 1) {
30 if (ww_call_cmp (d_op, "if", 2) ||
31 ww_call_cmp (d_op, "else", 4) ||
32 ww_call_cmp (d_op, "do", 2) ||
33 ww_call_cmp (d_op, "while", 5) ||
34 ww_call_cmp (d_op, "switch", 6) ||
35 ww_case_cmp (d_op, "case", 4))
36 return OP_TYPE_OP;
38 if (ww_after_word (d_op) == '(')
39 return OP_TYPE_CALL;
41 return OP_TYPE_OTHER; // Macro or operations (e.g. "+-=*/%^" etc...)
44 d_last_ch = last_ch (d_op);
46 if (d_last_ch == '=')
47 return OP_TYPE_VARIABLE;
49 b_local_ftest = local_ftest (d_op);
50 if ((ch == '{' && d_last_ch == ')')) {
51 if (b_local_ftest) // Paranoid.
52 return OP_TYPE_FUNCTION;
55 if (!strncmp (d_op, "extern ", 7))
56 return OP_TYPE_EXTERN;
58 if (ch == '{') {
59 Ret = 0;
60 if (!strncmp (d_op, "typedef ", 8)) {
61 Ret |= OP_TYPE_TYPEDEF;
62 d_op += 8;
65 if (!strncmp (d_op, "static ", 7))
66 d_op += 7;
68 if (!strncmp (d_op, "const ", 6)) // "static const struct"
69 d_op += 6;
71 if (!strncmp (d_op, "union ", 6))
72 return Ret | OP_TYPE_OTHER;
74 if (! strncmp (d_op, "enum ", 5))
75 return Ret | OP_TYPE_OTHER;
77 if (!strncmp (d_op, "struct ", 7)) {
78 return Ret | OP_TYPE_STRUCT;
81 if (!strncmp (d_op, "class ", 6))
82 return OP_TYPE_CLASS;
84 if (!strncmp (d_op, "namespace ", 10))
85 return OP_TYPE_NAMESPACE;
87 if ((words_count (d_op) > 1) && !b_local_ftest)
88 return OP_TYPE_VARIABLE;
90 if (Ret)
91 return Ret;
92 return OP_TYPE_OTHER;
95 if (ch == ';') {
96 if (!strncmp (d_op, "typedef ", 8))
97 return OP_TYPE_TYPEDEF;
99 if (b_local_ftest) {
100 S = strchr (d_op, '(');
101 if (! S)
102 return OP_TYPE_OTHER;
104 S++;
105 if (words_count (S) <= 1) {
106 S = strchr_r (S, ')', 0);
107 S++;
108 if (words_count (S) > 1)
109 return OP_TYPE_FUNCTION; // declaration... or not ?
111 } else {
112 if (d_words_count <= 1)
113 return OP_TYPE_OTHER;
115 if (!strncmp (d_op, "struct ", 7) && d_words_count == 2)
116 return OP_TYPE_OTHER;
118 if (!strncmp (d_op, "return ", 7))
119 return OP_TYPE_OTHER;
121 if (!strncmp (d_op, "delete ", 7))
122 return OP_TYPE_OTHER;
124 return OP_TYPE_VARIABLE;
126 // Function defenition, callback defenition... it's all ?
129 return OP_TYPE_OTHER;