Parses the format string ("-option %s %d %f") to extract the flag ("-option") and create a code string ("sdf"). After the code string is created, the param list of void* pointers is allocated to hold the argument variable pointers.
| 121 | // code string is created, the param list of void* pointers is |
| 122 | // allocated to hold the argument variable pointers. |
| 123 | int |
| 124 | ArgOption::initialize() |
| 125 | { |
| 126 | size_t n; |
| 127 | const char *s; |
| 128 | |
| 129 | if (m_format.empty() || m_format == "%*") { |
| 130 | m_type = Sublist; |
| 131 | m_count = 1; // sublist callback function pointer |
| 132 | m_code = "*"; |
| 133 | m_flag = ""; |
| 134 | } else if (m_format == "<SEPARATOR>") { |
| 135 | } else { |
| 136 | // extract the flag name |
| 137 | s = &m_format[0]; |
| 138 | assert(*s == '-'); |
| 139 | assert(isalpha(s[1]) || (s[1] == '-' && isalpha(s[2]))); |
| 140 | |
| 141 | s++; |
| 142 | if (*s == '-') |
| 143 | s++; |
| 144 | |
| 145 | while (isalnum(*s) || *s == '_' || *s == '-') s++; |
| 146 | |
| 147 | if (! *s) { |
| 148 | m_flag = m_format; |
| 149 | m_type = Flag; |
| 150 | m_count = 1; |
| 151 | m_code = "b"; |
| 152 | } else { |
| 153 | n = s - (&m_format[0]); |
| 154 | m_flag.assign (m_format.begin(), m_format.begin()+n); |
| 155 | |
| 156 | // Parse the scanf-like parameters |
| 157 | |
| 158 | m_type = Regular; |
| 159 | |
| 160 | n = (m_format.length() - n) / 2; // conservative estimate |
| 161 | m_code.clear (); |
| 162 | |
| 163 | while (*s != '\0') { |
| 164 | if (*s == '%') { |
| 165 | s++; |
| 166 | assert(*s != '\0'); |
| 167 | |
| 168 | m_count++; // adding another parameter |
| 169 | |
| 170 | switch (*s) { |
| 171 | case 'd': // 32bit int |
| 172 | case 'g': // float |
| 173 | case 'f': // float |
| 174 | case 'F': // double |
| 175 | case 's': // string |
| 176 | case 'L': // vector<string> |
| 177 | assert (m_type == Regular); |
| 178 | m_code += *s; |
| 179 | break; |
| 180 | case '!': |