============ Cbuf_Execute ============ */
| 172 | ============ |
| 173 | */ |
| 174 | void Cbuf_Execute (void) |
| 175 | { |
| 176 | int i; |
| 177 | char *text; |
| 178 | char line[MAX_CMD_LINE]; |
| 179 | int quotes; |
| 180 | |
| 181 | // This will keep // style comments all on one line by not breaking on |
| 182 | // a semicolon. It will keep /* ... */ style comments all on one line by not |
| 183 | // breaking it for semicolon or newline. |
| 184 | qboolean in_star_comment = qfalse; |
| 185 | qboolean in_slash_comment = qfalse; |
| 186 | |
| 187 | while (cmd_text.cursize) |
| 188 | { |
| 189 | if ( cmd_wait > 0 ) { |
| 190 | // skip out while text still remains in buffer, leaving it |
| 191 | // for next frame |
| 192 | cmd_wait--; |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | // find a \n or ; line break or comment: // or /* */ |
| 197 | text = (char *)cmd_text.data; |
| 198 | |
| 199 | quotes = 0; |
| 200 | for (i=0 ; i< cmd_text.cursize ; i++) |
| 201 | { |
| 202 | if (text[i] == '"') |
| 203 | quotes++; |
| 204 | |
| 205 | if ( !(quotes&1)) { |
| 206 | if (i < cmd_text.cursize - 1) { |
| 207 | if (! in_star_comment && text[i] == '/' && text[i+1] == '/') |
| 208 | in_slash_comment = qtrue; |
| 209 | else if (! in_slash_comment && text[i] == '/' && text[i+1] == '*') |
| 210 | in_star_comment = qtrue; |
| 211 | else if (in_star_comment && text[i] == '*' && text[i+1] == '/') { |
| 212 | in_star_comment = qfalse; |
| 213 | // If we are in a star comment, then the part after it is valid |
| 214 | // Note: This will cause it to NUL out the terminating '/' |
| 215 | // but ExecuteString doesn't require it anyway. |
| 216 | i++; |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | if (! in_slash_comment && ! in_star_comment && text[i] == ';') |
| 221 | break; |
| 222 | } |
| 223 | if (! in_star_comment && (text[i] == '\n' || text[i] == '\r')) { |
| 224 | in_slash_comment = qfalse; |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if( i >= (MAX_CMD_LINE - 1)) { |
| 230 | i = MAX_CMD_LINE - 1; |
| 231 | } |
no test coverage detected