|
@@ -140,6 +140,8 @@ static char *parse_text(char *line, char *cmd) {
|
140
|
140
|
|
141
|
141
|
bool parse_command(struct videohub_data *data, char *cmd) {
|
142
|
142
|
unsigned int i;
|
|
143
|
+ if (!strlen(cmd))
|
|
144
|
+ return false;
|
143
|
145
|
struct videohub_commands *v = NULL;
|
144
|
146
|
for (i = 0; i < ARRAY_SIZE(videohub_commands); i++) {
|
145
|
147
|
if (!videohub_commands[i].txt)
|
|
@@ -301,3 +303,27 @@ bool parse_command(struct videohub_data *data, char *cmd) {
|
301
|
303
|
|
302
|
304
|
return true;
|
303
|
305
|
}
|
|
306
|
+
|
|
307
|
+int parse_text_buffer(struct videohub_data *data, char *cmd_buffer) {
|
|
308
|
+ // The buffer contains only one command, no splitting is needed
|
|
309
|
+ if (!strstr(cmd_buffer, "\n\n"))
|
|
310
|
+ return parse_command(data, cmd_buffer);
|
|
311
|
+ // Split commands and parse them one by one
|
|
312
|
+ int ok_commands = 0;
|
|
313
|
+ char *bcopy = xstrdup(cmd_buffer);
|
|
314
|
+ char *newcmd, *cmd = bcopy;
|
|
315
|
+ while(1) {
|
|
316
|
+ newcmd = strstr(cmd, "\n\n"); // Find next command
|
|
317
|
+ if (!newcmd) {
|
|
318
|
+ if (parse_command(data, cmd)) // Parse current command
|
|
319
|
+ ok_commands++;
|
|
320
|
+ break;
|
|
321
|
+ }
|
|
322
|
+ newcmd[0] = '\0'; // Terminate previous command
|
|
323
|
+ if (parse_command(data, cmd)) // Parse previous command
|
|
324
|
+ ok_commands++;
|
|
325
|
+ cmd = newcmd + 2; // Advance cmd to the next command
|
|
326
|
+ }
|
|
327
|
+ free(bcopy);
|
|
328
|
+ return ok_commands;
|
|
329
|
+}
|