Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / brave.cpp
blob6a9c09bb8a8b5262214e73154d77aa87cec9e41e
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 #if 0
8 #include "head.h"
9 #include "dbg.h"
11 char * try_name (char * ptr)
13 int len;
14 char * end;
16 if (! abc_test (ptr))
17 return NULL;
19 while (*ptr == '*' || *ptr == '&')
20 ptr++;
22 len = strlen (ptr);
23 end = &ptr[len-1];
25 while (end > ptr && (*end == '&' || *end == '*'))
26 end--;
28 end++;
29 *end = 0;
30 return ptr;
33 struct hash_t * parse_variable (char *OP)
35 hash_t * Ret = NULL;
36 DArray * words;
37 char * op;
38 char * S;
39 int size;
40 char * var = NULL;
41 char * type = NULL;
43 if (! OP)
44 return NULL;
46 op = strdup (OP);
47 ww_last_word (op);
49 words = Dsplit (op, " ");
50 if (! words)
51 goto tpv_out;
53 size = words->get_size();
54 if (size < 2)
55 goto tpv_out;
57 while (size > 0) {
58 S = words->get (size-1);
60 S = try_name (S);
61 if (! S) {
62 --size;
63 continue;
66 if (var == NULL) {
67 var = S;
68 } else {
69 type = S;
70 break;
73 --size;
76 if (var && type)
77 Ret = hash (var, type);
79 tpv_out:
80 if (words)
81 words->foreach (free);
82 DROP (words);
83 DROP (op);
84 return Ret;
87 int fdecl_parse (char * d_out, DArray * d_vars)
89 DArray * words;
90 char * ptr;
91 int i;
92 int size;
93 struct hash_t * one;
95 /*
96 * 1. Arguments check.
97 * 2. Function declaration parse.
98 * 3. Function arguments parse.
102 if (d_out == NULL || d_vars == NULL)
103 return -1;
105 ptr = Dstrmid (d_out, "(", ")");
106 if (ptr == 0)
107 return -1;
109 sstrkill (ptr);
111 words = Dsplit (ptr, ",");
112 if (! words)
113 return -1;
115 size = words->get_size ();
116 if (! size)
117 return 0;
119 for (i = 0; i < size; i++) {
120 one = parse_variable (words->get (i));
121 if (one)
122 d_vars->add (LPCHAR(one));
125 DROP (ptr);
126 return 0;
128 #endif