[Toxine-cvs] CVS: toxine/src commands.c,1.68,1.69 parse.c,1.8,1.9 utils.c,1.28,1.29 utils.h,1.14,1.1
Brought to you by:
f1rmb
From: Daniel Caujolle-B. <f1...@us...> - 2004-05-19 21:23:49
|
Update of /cvsroot/toxine/toxine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6332 Modified Files: commands.c parse.c utils.c utils.h Log Message: add repeat command Index: commands.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/commands.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -r1.68 -r1.69 --- commands.c 19 May 2004 20:19:03 -0000 1.68 +++ commands.c 19 May 2004 21:23:38 -0000 1.69 @@ -162,6 +162,8 @@ static void do_dumpconfig(commands_t *, toxine_t *, void *); static void do_dumpstream(commands_t *, toxine_t *, void *); static void do_gettime(commands_t *, toxine_t *, void *); +static void do_repeat(commands_t *, toxine_t *, void *); + static commands_t commands[] = { { "!", NO_ARGS, do_shell, @@ -345,6 +347,11 @@ "Quit toxine.", "quit" }, + { "repeat", REQUIRE_ARGS, do_repeat, + "repeat x time a set of commands", + "repeat <x> <command>\n" + "repeat <x> { <<command><;command>...> }" + }, { "right", NO_ARGS, do_events, "send XINE_EVENT_INPUT_RIGHT event to xine engine", "right" @@ -2357,7 +2364,62 @@ gettimeofday(&tv, NULL); if((ptm = localtime(&tv.tv_sec))) - pinfo("%02d:%02d:%02d.%d\n", ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tv.tv_usec / 1000)); + pinfo("%02d:%02d:%02d.%03d\n", ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tv.tv_usec / 1000)); pinfo(".\n"); } + +static void do_repeat(commands_t *command, toxine_t *tox, void *data) { + int nargs; + + nargs = toxine_is_args(tox); + if(nargs >= 2) { + char *c_repeat; + int repeat = 0; + char *f_command = NULL; + + c_repeat = (char *) toxine_get_arg(tox, 1); + if((repeat = strtol(c_repeat, &c_repeat, 10))) { + + if(toxine_is_arg_match(tox, 2, "{") && toxine_is_last_arg_match(tox, "}")) { + int i = 3; + + for(;i < tox->command.num_args; i++) { + char *arg = (char *) toxine_get_arg(tox, i); + int len = strlen(arg); + int f_len = (f_command ? strlen(f_command) : 0); + + if(!f_command) + f_command = strdup(arg); + else { + f_command = (char *) realloc(f_command, f_len + len + 2); + strcat(f_command, " "); + strcat(f_command, arg); + } + } + + } + else + f_command = strdup((char *)toxine_get_arg(tox, 2)); + + if(f_command && strlen(f_command)) { + char *r_command = NULL; + int i; + + r_command = (char *) xine_xmalloc(((strlen(f_command) + 1) * repeat) + 1); + for(i = 0; i < repeat; i++) { + strcat(r_command, f_command); + strcat(r_command, ";"); + } + + toxine_set_command_line(tox, r_command); + toxine_handle_command(tox, NULL); + toxine_free(r_command); + } + + toxine_free(f_command); + + } + } +} + Index: parse.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/parse.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- parse.c 17 May 2004 20:31:43 -0000 1.8 +++ parse.c 19 May 2004 21:23:38 -0000 1.9 @@ -46,7 +46,9 @@ if((tox->command.remain) && (tox->command.line)) return; - if((tox->command.remain == NULL) && (tox->command.line && (strchr(tox->command.line, ';')))) { + if((tox->command.remain == NULL) && + (tox->command.line && + ((p = strchr(tox->command.line, ';')) && (*(p - 1) != '\\')))) { tox->command.remain = strdup(tox->command.line); toxine_free(tox->command.line); } @@ -58,7 +60,7 @@ memset(&commandline, 0, sizeof(commandline)); memset(&remaining, 0, sizeof(remaining)); - if((p = strchr(tox->command.remain, ';')) != NULL) { + if((p = strchr(tox->command.remain, ';')) && (*(p - 1) != '\\')) { pp = tox->command.remain; pbuf = commandline; @@ -140,13 +142,24 @@ * parse command, extract arguments. */ void toxine_parse_command(toxine_t *tox) { - char *cmd, *cmdl; + char *p, *cmd, *cmdl; int i = 0; toxine_parse_destock_remain(tox); + + if((p = strchr(tox->command.line, ';'))) { - if(strchr(tox->command.line, ';')) - toxine_parse_handle_multicommands(tox); + if((*(p - 1) != '\\')) + toxine_parse_handle_multicommands(tox); + else { + char *pp = tox->command.line; + + while((p = strchr(pp, ';')) && (*(p - 1) == '\\')) { + *(p - 1) = ' '; + pp = p + 1; + } + } + } cmdl = tox->command.line; @@ -262,7 +275,9 @@ case ' ': if((*(pcmd - 1) != '\\') && ((get_quote == 0) && (get_dbl_quote == 0))) { - + while(*(pcmd + 1) == ' ') + pcmd++; + __end_args: sprintf(tox->command.args[nargs], "%s", buf); nargs++; Index: utils.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/utils.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- utils.c 17 May 2004 20:31:43 -0000 1.28 +++ utils.c 19 May 2004 21:23:38 -0000 1.29 @@ -261,6 +261,37 @@ return 0; } +int toxine_is_arg_match(toxine_t *tox, int pos, const char *arg) { + + if(tox && pos && ((arg != NULL) && (strlen(arg))) && (tox->command.num_args >= pos)) { + if(!strcmp(tox->command.args[pos - 1], arg)) + return 1; + } + + return 0; +} + +/* + * return 1 if last arg match *arg + */ +int toxine_is_last_arg_contain(toxine_t *tox, const char *arg) { + + if(tox && ((arg != NULL) && (strlen(arg))) && tox->command.num_args) { + if(!strncmp(tox->command.args[tox->command.num_args - 1], arg, strlen(tox->command.args[tox->command.num_args - 1]))) + return 1; + } + + return 0; +} +int toxine_is_last_arg_match(toxine_t *tox, const char *arg) { + + if(tox && ((arg != NULL) && (strlen(arg))) && tox->command.num_args) { + if(!strcmp(tox->command.args[tox->command.num_args - 1], arg)) + return 1; + } + + return 0; +} /* * Set current command line from line. Index: utils.h =================================================================== RCS file: /cvsroot/toxine/toxine/src/utils.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- utils.h 17 May 2004 19:53:25 -0000 1.14 +++ utils.h 19 May 2004 21:23:38 -0000 1.15 @@ -35,6 +35,10 @@ int toxine_is_args(toxine_t *tox); const char *toxine_get_arg(toxine_t *tox, int num); int toxine_is_arg_contain(toxine_t *tox, int pos, const char *arg); +int toxine_is_arg_match(toxine_t *tox, int pos, const char *arg); +int toxine_is_last_arg_contain(toxine_t *tox, const char *arg); +int toxine_is_last_arg_match(toxine_t *tox, const char *arg); + int toxine_mkdir_safe(char *path); void toxine_draw_bar(toxine_t *tox, char *title, int min, int max, int val); |