[Toxine-cvs] CVS: toxine/src Makefile.am,1.10,1.11 commands.c,1.71,1.72 common.h,1.30,1.31 loader.c,
Brought to you by:
f1rmb
From: Daniel Caujolle-B. <f1...@us...> - 2004-05-27 00:27:57
|
Update of /cvsroot/toxine/toxine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30316 Modified Files: Makefile.am commands.c common.h loader.c main.c playlist.c script.c utils.c utils.h xine_commands.c Log Message: preliminary implementation of return code. (now in script or stdin mode, any error is fatal). Index: Makefile.am =================================================================== RCS file: /cvsroot/toxine/toxine/src/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Makefile.am 17 May 2004 20:15:52 -0000 1.10 +++ Makefile.am 27 May 2004 00:27:39 -0000 1.11 @@ -15,7 +15,7 @@ GETOPT_H = getopt.h endif -COMMON_sources = utils.c parse.c xine_commands.c loader.c script.c playlist.c +COMMON_sources = utils.c parse.c xine_commands.c loader.c script.c playlist.c errors.c toxine_SOURCES = $(GETOPT_C) main.c commands.c $(COMMON_sources) toxine_DEPENDENTIES = @@ -27,7 +27,7 @@ sortcmds_SOURCES = $(GETOPT_C) sortcmds.c $(COMMON_sources) sortcmds_LDADD = @XINE_LIBS@ $(DYNAMIC_LD_LIBS) $(READLINE_LIBS) $(NCURSES_LIB) -lm -noinst_HEADERS = common.h utils.h commands.h parse.h xine_commands.h loader.h script.h playlist.h +noinst_HEADERS = common.h utils.h commands.h parse.h xine_commands.h loader.h script.h playlist.h errors.h debug: @$(MAKE) CFLAGS="$(DEBUG_CFLAGS) @XINE_CFLAGS@ `if test -f .local; then echo -DLOCAL_BUILD; fi`" Index: commands.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/commands.c,v retrieving revision 1.71 retrieving revision 1.72 diff -u -r1.71 -r1.72 --- commands.c 19 May 2004 23:16:42 -0000 1.71 +++ commands.c 27 May 2004 00:27:39 -0000 1.72 @@ -442,10 +442,13 @@ __playmrloop: toxine_set_current_mrl_from_cur(tox); + error_code_clear(tox); if(xine_open(tox->stream, tox->current_mrl)) { tox->xine_state |= XINE_OPEN; _xine_play(NULL, tox, (void *)NO_ARGS); } + else + error_code_set(tox, TOX_ERR_XINE_OPEN); } else { if(tox->playlist.loop && tox->playlist.num) { @@ -479,10 +482,14 @@ if((tox->xine_state & (XINE_NEW | XINE_OPEN))) { int secs; - - secs = xine_get_pos_length(tox->stream, NULL, &secs, NULL); - secs /= 1000; - + int err; + + error_code_clear(tox); + if((err = xine_get_pos_length(tox->stream, NULL, &secs, NULL))) + secs /= 1000; + else + error_code_set(tox, TOX_ERR_XINE_GET_POS_LENGTH); + if(cur == tox->playlist.cur) { if(secs >= tox->playlist.mmk[cur]->end) { @@ -553,13 +560,17 @@ pthread_attr_t pth_attrs; struct sched_param pth_params; + error_code_clear(tox); + if(!tox->video.name) { perr("you should specify a video driver name first.\n"); + error_code_set(tox, TOX_ERR_MISSING_STEP); return 0; } if(!tox->video.plugins_num) { perr("no video plugin found.\n"); + error_code_set(tox, TOX_ERR_NO_VOP); return 0; } @@ -584,6 +595,7 @@ if(!tox->video.cur_plugin) { perr("No video driver name match with '%s'\n", tox->video.name); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return 0; } @@ -626,6 +638,8 @@ */ int toxine_audio_out_init(toxine_t *tox) { + error_code_clear(tox); + if(!tox->audio.name) { perr("no audio driver sets, no audio output.\n"); return 1; @@ -639,6 +653,7 @@ tox->audio.port = xine_open_audio_driver(tox->xine, (const char*)tox->audio.name, NULL); if(tox->audio.port == NULL) { perr("xine_load_audio_output_plugin() failed to load '%s' driver.\n", tox->audio.name); + error_code_set(tox, TOX_ERR_XINE_OPEN_AUDIO_DRIVER); return 0; } tox->audio.mixer.enable = 1; @@ -697,22 +712,34 @@ if((commands[i].argtype == REQUIRE_ARGS) && (tox->command.num_args <= 0)) { perr("Command '%s' require argument(s).\n", commands[i].command); + if(tox->script.in_use || tox->stdin) + exit(TOX_ERR_WRONG_SYNTAX); found++; } else if((commands[i].argtype == NO_ARGS) && (tox->command.num_args > 0)) { perr("Command '%s' doesn't require argument.\n", commands[i].command); + if(tox->script.in_use || tox->stdin) + exit(TOX_ERR_WRONG_SYNTAX); found++; } else { commands[i].function(&commands[i], tox, NULL); + if(tox->script.in_use || tox->stdin) { + if(tox->last_error != TOX_ERR_SUCCESS) + exit(tox->last_error); + } found++; } } i++; } - if(!found) + if(!found) { perr("unhandled command '%s'.\n", tox->command.command); + if(tox->script.in_use || tox->stdin) + exit(TOX_ERR_UNKNOWN_CMD); + + } } @@ -759,6 +786,7 @@ */ void toxine_stop(toxine_t *tox) { + error_code_clear(tox); if(tox->xine) { toxine_set_command_line(tox, "xine_stop"); toxine_handle_command(tox, NULL); @@ -914,8 +942,9 @@ __re_readline: if((grabbed_line = readline(tox->prompt)) == NULL) { - fprintf(stderr, "%s(%d): readline() failed: %s\n", - __tox_func__, __LINE__, strerror(errno)); +#ifdef DEBUG + perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, strerror(errno)); +#endif goto __re_readline; } @@ -974,6 +1003,8 @@ static void do_get(commands_t *command, toxine_t *tox, void *data) { int nargs; + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs) { if(toxine_is_arg_contain(tox, 1, "audio")) { @@ -1030,7 +1061,6 @@ } - } else if(nargs >= 3) { @@ -1066,6 +1096,8 @@ static void do_set(commands_t *command, toxine_t *tox, void *data) { int nargs; + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs) { if(nargs >= 2) { @@ -1087,8 +1119,10 @@ tox->loop_mode = mode; pinfo("Loop mode is set to: '%s' [%d]\n", loop_modes[i].name, loop_modes[i].mode); } - else + else { perr("Loop mode '%s' isn't valid\n", lmode); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } else if(toxine_is_arg_contain(tox, 1, "interactive")) { @@ -1229,6 +1263,7 @@ return_if_no_init(tox); return_if_no_stream(tox); + error_code_clear(tox); if(tox->command.num_args) toxine_set_current_mrl(tox, (toxine_get_arg(tox, 1))); @@ -1244,6 +1279,8 @@ tox->xine_state |= XINE_OPEN; _xine_play(command, tox, (void *)NO_ARGS); } + else + error_code_set(tox, TOX_ERR_XINE_OPEN); } @@ -1253,6 +1290,7 @@ static void do_stop(commands_t *command, toxine_t *tox, void *data) { return_if_no_init(tox); + error_code_clear(tox); _xine_stop(command, tox, NULL); } @@ -1263,6 +1301,7 @@ static void do_pause(commands_t *command, toxine_t *tox, void *data) { return_if_no_init(tox); + error_code_clear(tox); if((xine_get_param(tox->stream, XINE_PARAM_SPEED)) != XINE_SPEED_PAUSE) xine_set_param(tox->stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE); @@ -1278,19 +1317,25 @@ int pos; return_if_no_init(tox); + error_code_clear(tox); - if((xine_get_stream_info(tox->stream, XINE_STREAM_INFO_SEEKABLE)) == 0) + if((xine_get_stream_info(tox->stream, XINE_STREAM_INFO_SEEKABLE)) == 0) { + pinfo("Stream is not seekable\n"); return; + } if(!tox->current_mrl) { perr("You should set/specify an MRL.\n"); + error_code_set(tox, TOX_ERR_MISSING_STEP); return; } pos = atoi((toxine_get_arg(tox, 1))); - if(!xine_play(tox->stream, pos, 0)) - fprintf(stderr, "xine_play() failed.\n"); + if(!xine_play(tox->stream, pos, 0)) { + perr("xine_play() failed.\n"); + error_code_set(tox, TOX_ERR_XINE_PLAY); + } } @@ -1301,12 +1346,16 @@ int msec; return_if_no_init(tox); + error_code_clear(tox); - if((xine_get_stream_info(tox->stream, XINE_STREAM_INFO_SEEKABLE)) == 0) + if((xine_get_stream_info(tox->stream, XINE_STREAM_INFO_SEEKABLE)) == 0) { + pinfo("Stream is not seekable\n"); return; + } if(!tox->current_mrl) { perr("You should set/specify an MRL.\n"); + error_code_set(tox, TOX_ERR_MISSING_STEP); return; } @@ -1315,8 +1364,10 @@ if(msec < 0) msec = 0; - if(!xine_play(tox->stream, 0, msec)) - fprintf(stderr, "xine_play() failed.\n"); + if(!xine_play(tox->stream, 0, msec)) { + perr("xine_play() failed.\n"); + error_code_set(tox, TOX_ERR_XINE_PLAY); + } } /* @@ -1326,18 +1377,20 @@ char buffer[2048] = ""; int retval; - if(tox->command.num_args) { - int i; + if(!tox->script.in_use) { + if(tox->command.num_args) { + int i; + + for(i = 0; i < tox->command.num_args; i++) + sprintf(buffer, "%s %s", buffer, (toxine_get_arg(tox, (i+1)))); + } + else + sprintf(buffer, "%s", "/bin/sh --login"); - for(i = 0; i < tox->command.num_args; i++) - sprintf(buffer, "%s %s", buffer, (toxine_get_arg(tox, (i+1)))); + retval = toxine_system(0, buffer); + pinfo("shell returned %d.\n", retval); + pinfo(".\n"); } - else - sprintf(buffer, "%s", "/bin/sh --login"); - - retval = toxine_system(0, buffer); - pinfo("shell returned %d.\n", retval); - pinfo(".\n"); } /* @@ -1346,6 +1399,8 @@ static void do_version(commands_t *command, toxine_t *tox, void *data) { int major, minor, sub; + error_code_clear(tox); + pinfo("Toxine version %s\n", VERSION); pinfo("Copyright 2002-2004, Daniel Caujolle-Bert <f1...@us...>.\n"); pinfo("Built with xine library %d.%d.%d (%s).\n", @@ -1363,6 +1418,8 @@ static void do_syntax(commands_t *command, toxine_t *tox, void *data) { int i; + error_code_clear(tox); + for(i = 0; commands[i].command != NULL; i++) { if(!strcasecmp((toxine_get_arg(tox, 1)), commands[i].command)) { toxine_command_syntax(&commands[i], tox); @@ -1371,6 +1428,7 @@ } perr("Unknown command '%s'\n", (toxine_get_arg(tox, 1))); + error_code_set(tox, TOX_ERR_UNKNOWN_CMD); } /* @@ -1378,6 +1436,8 @@ */ static void do_help(commands_t *command, toxine_t *tox, void *data) { + error_code_clear(tox); + if(!tox->command.num_args) { int i = 0, j; int maxlen = 0; @@ -1432,6 +1492,7 @@ } perr("Unknown command '%s'\n", (toxine_get_arg(tox, 1))); + error_code_set(tox, TOX_ERR_UNKNOWN_CMD); } } @@ -1483,6 +1544,7 @@ int speed, speed_status; return_if_no_init(tox); + error_code_clear(tox); if(toxine_get_event_value((toxine_get_arg(tox, 1)), &event_value)) { @@ -1545,15 +1607,19 @@ } } - else + else { perr("Invalid status name '%s'\n", (toxine_get_arg(tox, 2))); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } - else + else { perr("Wait for event '%s' is invalid.\n", (toxine_get_arg(tox, 1))); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } static void do_events(commands_t *command, toxine_t *tox, void *data) { - int i; + int i, found = 0; static struct event_aliases_s { char *alias; int event; @@ -1576,18 +1642,28 @@ { "select", XINE_EVENT_INPUT_SELECT }, { NULL, 0 } }; - + + error_code_clear(tox); + for(i = 0; event_aliases[i].alias != NULL; i++) { if(!strncmp(command->command, event_aliases[i].alias, strlen(command->command))) { _xine_event_send(command, tox, (void *) event_aliases[i].event); + found = 1; break; } } + + if(!found) { + perr("Event %s unknown\n", command->command); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } static void do_playlist(commands_t *command, toxine_t *tox, void *data) { int nargs; + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs == 1) { @@ -1798,6 +1874,7 @@ int nargs; nargs = toxine_is_args(tox); + error_code_clear(tox); if(nargs == 1) { if(toxine_is_arg_contain(tox, 1, "settings")) { @@ -1841,22 +1918,27 @@ else if(nargs >= 2) { if(toxine_is_arg_contain(tox, 1, "current")) { if(toxine_is_arg_contain(tox, 2, "position")) { - int pos; - + int ret, pos; +#warning Set last result return_if_no_init(tox); - - xine_get_pos_length(tox->stream, &pos, NULL, NULL); - toxine_draw_bar(tox, "Current position", 0, 65535, pos); + + if(!(ret = xine_get_pos_length(tox->stream, &pos, NULL, NULL))) + error_code_set(tox, TOX_ERR_XINE_GET_POS_LENGTH); + else + toxine_draw_bar(tox, "Current position", 0, 65535, pos); } else if(toxine_is_arg_contain(tox, 2, "time")) { - int seconds; + int err, seconds; return_if_no_init(tox); - xine_get_pos_length(tox->stream, NULL, &seconds, NULL); - seconds /= 1000; - pinfo("Current time: %02d:%02d:%02d\n", - seconds / (60 * 60), (seconds / 60) % 60, seconds % 60); + if(!(err = xine_get_pos_length(tox->stream, NULL, &seconds, NULL))) + error_code_set(tox, TOX_ERR_XINE_GET_POS_LENGTH); + else { + seconds /= 1000; + pinfo("Current time: %02d:%02d:%02d\n", + seconds / (60 * 60), (seconds / 60) % 60, seconds % 60); + } } } @@ -1875,6 +1957,8 @@ static void do_mediamk(commands_t *command, toxine_t *tox, void *data) { int nargs; + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs >= 1 && (toxine_is_arg_contain(tox, 1, "add"))) { @@ -1896,8 +1980,9 @@ __re_readline_1: if((line = readline(questions[question_counter])) == NULL) { - perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, - strerror(errno)); +#ifdef DEBUG + perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, strerror(errno)); +#endif goto __re_readline_1; } @@ -1913,6 +1998,7 @@ else { perr("Mrl should be specified, at least.\n"); perr("Action canceled.\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } break; @@ -2008,6 +2094,7 @@ if((mmk.end != -1) && ((mmk.start >= mmk.end) || (mmk.end <= mmk.start))) { perr("start and end time are wrong:start @ %d, end @ %d\n", mmk.start, mmk.end); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); pinfo("Set start/end times to default\n"); mmk.start = 0; mmk.end = -1; @@ -2033,8 +2120,10 @@ pout("Canceled.\n"); } } - else + else { perr("MRL wasn't specified\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } else { @@ -2048,6 +2137,7 @@ i++; } pout("\b'\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); } } @@ -2187,8 +2277,9 @@ __re_readline_2: if((line = readline(questions[question_counter])) == NULL) { - perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, - strerror(errno)); +#ifdef DEBUG + perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, strerror(errno)); +#endif goto __re_readline_2; } @@ -2255,8 +2346,10 @@ pinfo("Nothing has been changed for this mediamark.\n"); } - else + else { perr("Entry %d is out of bounds\n", entry); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } else if(toxine_is_arg_contain(tox, 1, "select")) { @@ -2299,6 +2392,8 @@ int len = 0; const char *var, *arg; + error_code_clear(tox); + i = 1; while(i <= nargs) { arg = toxine_get_arg(tox, i++); @@ -2342,6 +2437,7 @@ _cfg_entry_t cfg_entry; return_if_no_new(tox); + error_code_clear(tox); pinfo("Dumping all config object:\n"); if((xine_config_get_first_entry(tox->xine, &cfg_entry))) { @@ -2349,6 +2445,8 @@ toxine_dump_config_entry(tox, &cfg_entry); } while((xine_config_get_next_entry(tox->xine, &cfg_entry))); } + else + error_code_set(tox, TOX_ERR_XINE_CONFIG_GET_FIRST_ENTRY); pinfo(".\n"); pinfo("\n"); @@ -2362,6 +2460,8 @@ struct tm *ptm; struct timeval tv; + error_code_clear(tox); + gettimeofday(&tv, NULL); if((ptm = localtime(&tv.tv_sec))) pinfo("%02d:%02d:%02d.%03d\n", ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tv.tv_usec / 1000)); @@ -2371,7 +2471,9 @@ static void do_repeat(commands_t *command, toxine_t *tox, void *data) { int nargs; - + + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs >= 2) { char *c_repeat; @@ -2422,4 +2524,3 @@ } } } - Index: common.h =================================================================== RCS file: /cvsroot/toxine/toxine/src/common.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- common.h 19 May 2004 22:46:21 -0000 1.30 +++ common.h 27 May 2004 00:27:39 -0000 1.31 @@ -34,6 +34,7 @@ #include "utils.h" #include "vo_plugin.h" +#include "errors.h" #ifndef __GNUC__ #define __tox_func__ __func__ @@ -130,33 +131,62 @@ if(((x)->xine == NULL) || !((x)->xine_state & XINE_INIT)) { \ perr("%s(): xine engine uninitialized. Do it first.\n", \ __tox_func__); \ - return; \ + if(((x)->script.in_use || (x)->stdin)) { \ + perr("%s\n", toxine_get_error_description((x), (TOX_ERR_MISSING_STEP))); \ + exit((TOX_ERR_MISSING_STEP)); \ + } \ + return; \ } \ - } while(0) + } while(0) #define return_if_no_new(x) do { \ if(((x)->xine == NULL) || !((x)->xine_state & XINE_NEW)) { \ perr("%s(): xine instance not created. Do it first.\n", \ __tox_func__); \ + if(((x)->script.in_use || (x)->stdin)) { \ + perr("%s\n", toxine_get_error_description((x), (TOX_ERR_MISSING_STEP))); \ + exit((TOX_ERR_MISSING_STEP)); \ + } \ return; \ } \ - } while(0) + } while(0) #define return_if_no_open(x) do { \ - if(((x)->xine == NULL) || !((x)->xine_state & XINE_OPEN)) { \ - perr("%s(): mrl not opened. Do it first.\n", \ - __tox_func__); \ - return; \ - } \ - } while(0) + if(((x)->xine == NULL) || !((x)->xine_state & XINE_OPEN)) { \ + perr("%s(): mrl not opened. Do it first.\n", \ + __tox_func__); \ + if(((x)->script.in_use || (x)->stdin)) { \ + perr("%s\n", toxine_get_error_description((x), (TOX_ERR_MISSING_STEP))); \ + exit((TOX_ERR_MISSING_STEP)); \ + } \ + return; \ + } \ + } while(0) #define return_if_no_stream(x) do { \ - if(((x)->xine == NULL) || !((x)->xine_state & XINE_STREAM)) { \ - perr("%s(): no stream created. Do it first.\n", \ - __tox_func__); \ - return; \ - } \ - } while(0) + if(((x)->xine == NULL) || !((x)->xine_state & XINE_STREAM)) { \ + perr("%s(): no stream created. Do it first.\n", \ + __tox_func__); \ + if(((x)->script.in_use || (x)->stdin)) { \ + perr("%s\n", toxine_get_error_description((x), (TOX_ERR_MISSING_STEP))); \ + exit((TOX_ERR_MISSING_STEP)); \ + } \ + return; \ + } \ + } while(0) + +#define error_code_clear(x) do { \ + (x)->last_error = TOX_ERR_SUCCESS; \ + } while(0) + +#define error_code_set(x, E) do { \ + (x)->last_error = (E); \ + if(((x)->script.in_use || (x)->stdin) && ((E) != TOX_ERR_SUCCESS)) { \ + perr("%s\n", toxine_get_error_description((x), (E))); \ + exit((E)); \ + } \ + } while(0) + #ifndef NAME_MAX #define _NAME_MAX 256 @@ -273,6 +303,8 @@ } script; int stdin; + + toxine_error_code_t last_error; }; typedef struct commands_s commands_t; Index: loader.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/loader.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- loader.c 17 May 2004 20:31:43 -0000 1.19 +++ loader.c 27 May 2004 00:27:39 -0000 1.20 @@ -45,9 +45,8 @@ DIR *dir; if(tox == NULL) { - fprintf(stderr, "%s(%s@%d): toxine_t * parameter should be non null, exiting\n", - __FILE__, __tox_func__, __LINE__); - exit(1); + perr("%s(%s@%d): toxine_t * parameter should be non null, exiting\n", __FILE__, __tox_func__, __LINE__); + exit(TOX_ERR_INTERNAL); } tox->video.plugins_num = 0; @@ -68,8 +67,8 @@ sprintf(str, "%s/%s", TOXINE_PLUGINDIR, pf->d_name); if(!(plugin = dlopen(str, RTLD_LAZY))) { - fprintf(stderr, "%s(%s@%d): cannot open demux plugin %s:\n%s\n", - __FILE__, __tox_func__, __LINE__, str, dlerror()); + perr("%s(%s@%d): cannot open video output plugin %s:\n%s\n", __FILE__, __tox_func__, __LINE__, str, dlerror()); + error_code_set(tox, TOX_ERR_INTERNAL); } else { void *(*initplug) (toxine_t *); @@ -106,9 +105,8 @@ } if(tox->video.plugins_num > TOXINE_VO_PLUGINS_MAX) { - fprintf(stderr, "%s(%s@%d): too many video out plugins installed, exiting.\n", - __FILE__, __tox_func__, __LINE__); - exit(1); + perr("%s(%s@%d): too many video out plugins installed, exiting.\n", __FILE__, __tox_func__, __LINE__); + exit(TOX_ERR_INTERNAL); } } } @@ -116,8 +114,8 @@ closedir(dir); } else { - fprintf(stderr, "Can't open plugin directory: '%s'\nGiving up.\n", TOXINE_PLUGINDIR); - exit(1); + perr("Can't open plugin directory: '%s'\nGiving up.\n", TOXINE_PLUGINDIR); + exit(TOX_ERR_NO_VOP); } tox->video.cur_plugin = NULL; Index: main.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/main.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- main.c 17 May 2004 21:23:35 -0000 1.33 +++ main.c 27 May 2004 00:27:39 -0000 1.34 @@ -54,20 +54,22 @@ static toxine_t *tox; +#define ERROR_CODES 1000 /* options args */ static const char *short_options = "?hs:e:o::vV:A:iIS"; static struct option long_options[] = { - { "help" , no_argument , 0, 'h' }, - { "script" , required_argument, 0, 's' }, - { "execute" , required_argument, 0, 'e' }, - { "output" , optional_argument, 0, 'o' }, - { "video" , required_argument, 0, 'V' }, - { "audio" , required_argument, 0, 'A' }, - { "interactive" , required_argument, 0, 'i' }, - { "autoinit" , no_argument , 0, 'I' }, - { "stdin" , no_argument , 0, 'S' }, - { "version" , no_argument , 0, 'v' }, - { 0 , no_argument , 0, 0 } + { "help" , no_argument , 0, 'h' }, + { "script" , required_argument, 0, 's' }, + { "execute" , required_argument, 0, 'e' }, + { "output" , optional_argument, 0, 'o' }, + { "video" , required_argument, 0, 'V' }, + { "audio" , required_argument, 0, 'A' }, + { "interactive" , required_argument, 0, 'i' }, + { "autoinit" , no_argument , 0, 'I' }, + { "stdin" , no_argument , 0, 'S' }, + { "version" , no_argument , 0, 'v' }, + { "error-codes" , optional_argument, 0, ERROR_CODES }, + { 0 , no_argument , 0, 0 } }; /* @@ -77,7 +79,7 @@ pid_t pid = getppid(); if(pid == tox->pid) { - + switch(sig) { /* Kill the line on C-c */ case SIGINT: @@ -89,7 +91,12 @@ } else { tox->video.running = tox->running = 0; - exit(1); + if(sig == SIGINT) + exit(TOX_ERR_SIGINT); + else if(sig == SIGTERM) + exit(TOX_ERR_SIGTERM); + else if(sig == SIGQUIT) + exit(TOX_ERR_SIGQUIT); } break; @@ -134,6 +141,8 @@ printf(" *(video/audio driver names should be sets).\n"); printf(" -v, --version Display version.\n"); printf(" -h, --help Display this help text.\n"); + printf(" --error-codes[=num] Display error codes descriptions.\n"); + printf(" if 'num' is specified, the error description will be printed.\n"); printf("\n"); } @@ -202,10 +211,11 @@ * ... */ int main(int argc, char **argv) { - int c = '?'; - int option_index = 0; - int interactive = 1; - int i; + int c = '?'; + int option_index = 0; + int interactive = 1; + int i; + toxine_error_code_t last_error; /* Check xine library version */ if(!xine_check_version(1, 0, 0)) { @@ -213,7 +223,7 @@ xine_get_version(&major, &minor, &sub); fprintf(stderr, "Require xine library version 1.0.0, found %d.%d.%d.\n", major, minor, sub); - exit(1); + exit(TOX_ERR_WRONG_VERSION); } tox = (toxine_t *) xine_xmalloc(sizeof(toxine_t)); @@ -245,12 +255,12 @@ tox->script.in_use = 1; } else - fprintf(stderr, "script filename already set: '%s'\n", tox->script.filename); + perr("Script filename already set: '%s'\n", tox->script.filename); } else { - fprintf(stderr, "script filename is required to -S/--script option\n"); - exit(1); + perr("Script filename is required to -S/--script option\n"); + exit(TOX_ERR_BAD_CMDLINE); } break; @@ -266,8 +276,8 @@ char *ofile = (optarg) ? optarg : "toxine.out"; if((tox->msg_fd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, 0644)) < 0) { - fprintf(stderr, "Cannot open %s: %s\n", ofile, strerror(errno)); - exit(1); + perr("Cannot open %s: %s\n", ofile, strerror(errno)); + exit(TOX_ERR_INTERNAL); } } @@ -297,33 +307,43 @@ case 'v': /* Display version and exit*/ toxine_show_version(tox); - exit(1); + exit(TOX_ERR_SUCCESS); break; + case ERROR_CODES: + if(optarg) { + toxine_error_code_t err = (toxine_error_code_t) atoi(optarg); + pout("%s\n", toxine_get_error_description(tox, err)); + } + else + toxine_print_error_codes(tox); + exit(TOX_ERR_SUCCESS); + break; + case 'h': /* Display usage */ case '?': toxine_print_usage(); - exit(1); + exit(TOX_ERR_SUCCESS); break; default: toxine_print_usage(); - fprintf(stderr, "invalid argument %d => exit\n",c); - exit(1); + perr("Invalid argument %d => exit\n",c); + exit(TOX_ERR_BAD_CMDLINE); } } if(tox->msg_fd >= 0) { if((!tox->script.in_use) && (!tox->command.execute)) { - fprintf(stderr, "You can't use message redirection in prompt mode.\n"); + perr("You can't use message redirection in prompt mode.\n"); toxine_release(tox); - exit(1); + exit(TOX_ERR_BAD_CMDLINE); } if(dup2(tox->msg_fd, STDOUT_FILENO) < 0) - fprintf(stderr, "Cannot dup2 stdout: %s\n", strerror(errno)); + perr("Cannot dup2 stdout: %s\n", strerror(errno)); if(dup2(tox->msg_fd, STDERR_FILENO) < 0) - fprintf(stderr, "Cannot dup2 stderr: %s\n", strerror(errno)); + perr("Cannot dup2 stderr: %s\n", strerror(errno)); } toxine_show_version(tox); @@ -358,7 +378,8 @@ tox->interactive = 0; toxine_run(tox, argc - optind, &argv[optind]); + last_error = tox->last_error; toxine_release(tox); - return 1; + return last_error; } Index: playlist.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/playlist.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- playlist.c 17 May 2004 20:31:43 -0000 1.13 +++ playlist.c 27 May 2004 00:27:39 -0000 1.14 @@ -692,7 +692,7 @@ if(fn) { *fn = '\0'; fn++; - status = toxine_mkdir_safe(pn); + status = toxine_mkdir_safe(tox, pn); } else fn = pn; Index: script.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/script.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- script.c 19 May 2004 22:46:21 -0000 1.5 +++ script.c 27 May 2004 00:27:39 -0000 1.6 @@ -113,7 +113,7 @@ if((br = read(fd, buf, st.st_size)) != st.st_size) { close(fd); toxine_free(buf); - fprintf(stderr, "read() returned wrong size (expected %lld, readed %lld)\n", st.st_size, br); + perr("read() returned wrong size (expected %lld, readed %lld)\n", st.st_size, br); return; } @@ -139,15 +139,21 @@ } } - else - fprintf(stderr, "failed to open '%s': %s\n", tox->script.filename, strerror(errno)); + else { + perr("Failed to open '%s': %s\n", tox->script.filename, strerror(errno)); + error_code_set(tox, TOX_ERR_INTERNAL); + } } - else - fprintf(stderr, "file is empty; '%s'\n", tox->script.filename); - + else { + perr("File is empty; '%s'\n", tox->script.filename); + error_code_set(tox, TOX_ERR_INTERNAL); + } + + } + else { + perr("Unable to stat() '%s': %s\n", tox->script.filename, strerror(errno)); + error_code_set(tox, TOX_ERR_INTERNAL); } - else - fprintf(stderr, "unable to stat() '%s': %s\n", tox->script.filename, strerror(errno)); } Index: utils.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/utils.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- utils.c 19 May 2004 21:23:38 -0000 1.29 +++ utils.c 27 May 2004 00:27:39 -0000 1.30 @@ -126,10 +126,13 @@ char prompt[strlen(HELP_PREFIX) + strlen(message) + 1]; sprintf(prompt, "%s%s", HELP_PREFIX, message); + + __re_readline: if((line = readline(prompt)) == NULL) { - perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, - strerror(errno)); - exit(1); +#ifdef DEBUG + perr("%s(%d): readline() failed: %s\n", __tox_func__, __LINE__, strerror(errno)); +#endif + goto __re_readline; } if (*line) { @@ -410,7 +413,7 @@ /* * */ -static int _mkdir_safe(char *path) { +static int _mkdir_safe(toxine_t *tox, char *path) { struct stat pstat; if(path == NULL) @@ -419,14 +422,16 @@ if((lstat(path, &pstat)) < 0) { /* file or directory no exist, create it */ if(mkdir(path, 0755) < 0) { - fprintf(stderr, "mkdir(%s) failed: %s\n", path, strerror(errno)); + perr("mkdir(%s) failed: %s\n", path, strerror(errno)); + error_code_set(tox, TOX_ERR_INTERNAL); return 0; } } else { /* Check of found file is a directory file */ if(!S_ISDIR(pstat.st_mode)) { - fprintf(stderr, "%s is not a directory.\n", path); + perr("%s is not a directory.\n", path); + error_code_set(tox, TOX_ERR_INTERNAL); return 0; } } @@ -437,14 +442,16 @@ /* * */ -int toxine_mkdir_safe(char *path) { +int toxine_mkdir_safe(toxine_t *tox, char *path) { char *p, *pp; char buf[_PATH_MAX + _NAME_MAX + 1]; char buf2[_PATH_MAX + _NAME_MAX + 1]; if(path == NULL) return 0; - + + error_code_clear(tox); + memset(&buf, 0, sizeof(buf)); memset(&buf2, 0, sizeof(buf2)); @@ -453,7 +460,7 @@ while((p = xine_strsep(&pp, "/")) != NULL) { if(p && strlen(p)) { sprintf(buf2, "%s/%s", buf2, p); - if(!_mkdir_safe(buf2)) + if(!_mkdir_safe(tox, buf2)) return 0; } } @@ -571,7 +578,8 @@ break; default: - fprintf(stderr, "Unknown config type %d\n", type); + perr("Unknown config type %d\n", type); + error_code_set(tox, TOX_ERR_INTERNAL); return; break; } @@ -582,64 +590,80 @@ void toxine_config_update_range(toxine_t *tox, char *key, int min, int max) { _cfg_entry_t entry; + error_code_clear(tox); memset(&entry, 0, sizeof(_cfg_entry_t)); if(xine_config_lookup_entry(tox->xine, key, &entry)) _config_update(tox, &entry, XINE_CONFIG_TYPE_RANGE, min, max, 0, NULL); - else - fprintf(stderr, "WOW, range key %s isn't registered\n", key); + else { + perr("WOW, range key %s isn't registered\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } } void toxine_config_update_string(toxine_t *tox, char *key, char *string) { _cfg_entry_t entry; + error_code_clear(tox); memset(&entry, 0, sizeof(_cfg_entry_t)); - if((xine_config_lookup_entry(tox->xine, key, &entry)) && string) _config_update(tox, &entry, XINE_CONFIG_TYPE_STRING, 0, 0, 0, string); else { if(string == NULL) - fprintf(stderr, "string is NULL\n"); + perr("String is NULL\n"); else - fprintf(stderr, "WOW, string key %s isn't registered\n", key); + perr("WOW, string key %s isn't registered\n", key); + + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); } } void toxine_config_update_enum(toxine_t *tox, char *key, int value) { _cfg_entry_t entry; + error_code_clear(tox); memset(&entry, 0, sizeof(_cfg_entry_t)); if(xine_config_lookup_entry(tox->xine, key, &entry)) _config_update(tox, &entry, XINE_CONFIG_TYPE_ENUM, 0, 0, value, NULL); - else - fprintf(stderr, "WOW, enum key %s isn't registered\n", key); + else { + perr("WOW, enum key %s isn't registered\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } } void toxine_config_update_bool(toxine_t *tox, char *key, int value) { _cfg_entry_t entry; + error_code_clear(tox); memset(&entry, 0, sizeof(_cfg_entry_t)); if(xine_config_lookup_entry(tox->xine, key, &entry)) _config_update(tox, &entry, XINE_CONFIG_TYPE_BOOL, 0, 0, ((value > 0) ? 1 : 0), NULL); - else - fprintf(stderr, "WOW, bool key %s isn't registered\n", key); + else { + perr("WOW, bool key %s isn't registered\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } } void toxine_config_update_num(toxine_t *tox, char *key, int value) { _cfg_entry_t entry; + error_code_clear(tox); memset(&entry, 0, sizeof(_cfg_entry_t)); if(xine_config_lookup_entry(tox->xine, key, &entry)) _config_update(tox, &entry, XINE_CONFIG_TYPE_NUM, 0, 0, value, NULL); - else - fprintf(stderr, "WOW, num key %s isn't registered\n", key); + else { + perr("WOW, num key %s isn't registered\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } } void toxine_config_load(toxine_t *tox) { + error_code_clear(tox); if(tox) xine_config_load(tox->xine, tox->configfile); } void toxine_config_save(toxine_t *tox) { + error_code_clear(tox); if(tox) { return_if_no_new(tox); xine_config_save(tox->xine, tox->configfile); @@ -647,6 +671,8 @@ } void toxine_show_stream_info(toxine_t *tox, int info_type, uint32_t iinfo) { + error_code_clear(tox); + switch(info_type) { case XINE_STREAM_INFO_BITRATE: case XINE_STREAM_INFO_SEEKABLE: @@ -685,11 +711,13 @@ default: perr("Unknown stream info type %d\n", iinfo); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); break; } } char *toxine_get_var(toxine_t *tox, const char *var) { + error_code_clear(tox); if(tox && var) { char *variable; @@ -827,5 +855,6 @@ } } + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return NULL; } Index: utils.h =================================================================== RCS file: /cvsroot/toxine/toxine/src/utils.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- utils.h 19 May 2004 21:23:38 -0000 1.15 +++ utils.h 27 May 2004 00:27:39 -0000 1.16 @@ -39,7 +39,7 @@ 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); +int toxine_mkdir_safe(toxine_t *tox, char *path); void toxine_draw_bar(toxine_t *tox, char *title, int min, int max, int val); void toxine_set_last_char_result(toxine_t *tox, const char *result); Index: xine_commands.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/xine_commands.c,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- xine_commands.c 17 May 2004 19:53:25 -0000 1.45 +++ xine_commands.c 27 May 2004 00:27:39 -0000 1.46 @@ -308,7 +308,7 @@ return_if_no_stream(tox); err = xine_get_error(tox->stream); - + switch(err) { case XINE_ERROR_NONE: /* noop */ @@ -436,6 +436,8 @@ void _xine_new(commands_t *command, toxine_t *tox, void *data) { toxine_unset_last_result(tox); + error_code_clear(tox); + if(tox->xine) { pinfo("Exiting old xine instance\n"); _xine_exit(NULL, tox, NULL); @@ -453,27 +455,32 @@ void _xine_stream_new(commands_t *command, toxine_t *tox, void *data) { return_if_no_init(tox); + error_code_clear(tox); if(tox->video.port == NULL) { perr("Choose and initialise a video driver first\n"); + error_code_set(tox, TOX_ERR_MISSING_STEP); return; } if(tox->xine_state & XINE_STREAM) { perr("Stream is already created, use xine_dispose() in order to create a new one\n"); + error_code_set(tox, TOX_ERR_SURNUM_STEP); return; } pinfo("xine_stream_new():\n"); tox->stream = xine_stream_new(tox->xine, tox->audio.port, tox->video.port); pinfo(".\n"); - + if(tox->stream) { tox->xine_state |= XINE_STREAM; toxine_set_last_int_result(tox, (int)tox->stream); } - else + else { perr("Wow, xine_stream_new() failed.\n"); + error_code_set(tox, TOX_ERR_XINE_STREAM_NEW); + } tox->event_queue = xine_event_new_queue(tox->stream); xine_event_create_listener_thread(tox->event_queue, toxine_event_listener, (void *) tox); @@ -485,9 +492,11 @@ void _xine_init(commands_t *command, toxine_t *tox, void *data) { toxine_unset_last_result(tox); - + error_code_clear(tox); + if(tox->xine_state & XINE_INIT) { perr("xine engine already initialized.\n"); + error_code_set(tox, TOX_ERR_SURNUM_STEP); return; } @@ -503,12 +512,14 @@ if(!toxine_video_out_init(tox)) { perr("unable to initialize video out plugin.\n"); _xine_exit(NULL, tox, NULL); + error_code_set(tox, TOX_ERR_VOP_FAILURE); return; } if(!toxine_audio_out_init(tox)) { perr("unable to initialize audio driver, audio output disabled.\n"); _xine_exit(NULL, tox, NULL); + error_code_set(tox, TOX_ERR_AOP_FAILURE); return; } @@ -522,7 +533,8 @@ const char *mrl; return_if_no_stream(tox); - + error_code_clear(tox); + mrl = toxine_get_arg(tox, 1); if(mrl) { int result; @@ -531,7 +543,9 @@ toxine_set_current_mrl(tox, mrl); pinfo("xine_open(%s):\n", tox->current_mrl); - result = xine_open(tox->stream, tox->current_mrl); + if(!(result = xine_open(tox->stream, tox->current_mrl))) + error_code_set(tox, TOX_ERR_XINE_OPEN); + toxine_set_last_int_result(tox, result); pinfo("-- returned %d\n", result); tox->xine_state |= XINE_OPEN; @@ -549,10 +563,13 @@ int ignore_args = 0; int nargs; int need_open = 1; - int result; + int open_result, result; toxine_unset_last_result(tox); + return_if_no_stream(tox); + + error_code_clear(tox); /* Don't take care about arguments */ if(data) @@ -566,6 +583,7 @@ if((!nargs) || (ignore_args == NO_ARGS)) { if(!tox->current_mrl) { perr("You should set/specify an MRL.\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } else { @@ -625,6 +643,7 @@ time = atoi((toxine_get_arg(tox, 2))); else { perr("Unhandled argument '%s'\n", (toxine_get_arg(tox, 1))); + error_code_set(tox, TOX_ERR_UNKNOWN_CMD); return; } @@ -633,6 +652,7 @@ mrl = (const char *)tox->current_mrl; else { perr("You should set/specify an MRL.\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } } @@ -666,18 +686,21 @@ time = atoi((toxine_get_arg(tox, 4))); else { perr("Unhandled argument '%s'\n", toxine_get_arg(tox, 3)); + error_code_set(tox, TOX_ERR_UNKNOWN_CMD); return; } } else { perr("Unhandled argument '%s'\n", toxine_get_arg(tox, 1)); + error_code_set(tox, TOX_ERR_UNKNOWN_CMD); return; } } else { - perr("wrong command syntax, try 'syntax xine_play'\n"); + perr("Wrong command syntax, try 'syntax xine_play'\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } @@ -692,16 +715,25 @@ if(need_open) { pinfo("xine_open(%s) && xine_play(%d, %d):\n", mrl, start, time); - if((!(result = xine_open(tox->stream, mrl))) || (!(result = xine_play(tox->stream, start, time)))) + if((!(open_result = xine_open(tox->stream, mrl))) || (!(result = xine_play(tox->stream, start, time)))) { + if(!open_result) { + error_code_set(tox, TOX_ERR_XINE_OPEN); + result = open_result; + } + else + error_code_set(tox, TOX_ERR_XINE_PLAY); toxine_handle_xine_errors(tox); + } else tox->xine_state |= XINE_OPEN; } else { pinfo("xine_play(%d, %d):\n", start, time); - if(!(result = xine_play(tox->stream, start, time))) + if(!(result = xine_play(tox->stream, start, time))) { + error_code_set(tox, TOX_ERR_XINE_PLAY); toxine_handle_xine_errors(tox); + } } pinfo(".\n"); @@ -719,12 +751,12 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if((nargs = toxine_is_args(tox)) == 2) { int i, trick_mode = -1; const char *trick = toxine_get_arg(tox, 1); - for(i = 0; xine_tricks[i].name != NULL; i++) { if(!strncasecmp(trick, xine_tricks[i].name, strlen(trick))) { trick_mode = xine_tricks[i].mode; @@ -737,11 +769,15 @@ value = atoi(((char *)toxine_get_arg(tox, 2))); pinfo("xine_trick_mode(%s, %d):\n", xine_tricks[i].name, value); result = xine_trick_mode(tox->stream, trick_mode, value); + if(!result) + error_code_set(tox, TOX_ERR_XINE_TRICK_MODE); toxine_set_last_int_result(tox, result); pinfo("--returned %d\n", result); } - else + else { perr("invalid trick mode: %s.\n", trick); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } pinfo(".\n"); } @@ -755,7 +791,8 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); - + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs) { char *info_name = (char *)toxine_get_arg(tox, 1); @@ -784,7 +821,8 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); - + error_code_clear(tox); + nargs = toxine_is_args(tox); if(nargs) { char *info_name = (char *)toxine_get_arg(tox, 1); @@ -819,6 +857,8 @@ } pinfo(".\n"); } + else + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); } } /* @@ -827,6 +867,7 @@ void _xine_stop(commands_t *command, toxine_t *tox, void *data) { toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); tox->ignore_finished = 1; pinfo("xine_stop():\n"); xine_stop(tox->stream); @@ -856,6 +897,7 @@ toxine_unset_last_result(tox); return_if_no_new(tox); + error_code_clear(tox); toxine_config_save(tox); @@ -904,6 +946,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); pinfo("xine_get_error():\n"); xine_errno = xine_get_error(tox->stream); @@ -940,7 +983,8 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); - + error_code_clear(tox); + pinfo("xine_get_status():\n"); status = xine_get_status(tox->stream); toxine_set_last_int_result(tox, status); @@ -963,6 +1007,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if((toxine_is_args(tox)) >= 2) { const char *param; @@ -1039,19 +1084,25 @@ } - if(value_found == -1) + if(value_found == -1) { sprintf(buffer, "%s, UNKNOWN[%d])\n", buffer, value); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } pinfo(buffer); xine_set_param(tox->stream, xine_params[found].param, value); pinfo(".\n"); } - else + else { perr("Unknown xine parameter: '%s'\n", param); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } - else + else { perr("Argument(s) missing.\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } /* @@ -1063,6 +1114,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); param = toxine_get_arg(tox, 1); for(i = 0; xine_params[i].name != NULL; i++) { @@ -1182,8 +1234,10 @@ } } - else + else { perr("Unknown xine parameter: '%s'\n", param); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } pinfo(".\n"); } @@ -1198,7 +1252,8 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); - + error_code_clear(tox); + if(toxine_is_args(tox)) channel = atoi(((char *)toxine_get_arg(tox, 1))); else @@ -1206,6 +1261,8 @@ pinfo("xine_get_audio_lang(%d):\n", channel); ret = xine_get_audio_lang(tox->stream, channel, &lang[0]); + if(!ret) + error_code_set(tox, TOX_ERR_XINE_GET_AUDIO_LANG); toxine_set_last_int_result(tox, ret); poutalign(); pout("'%s'\n", lang); @@ -1222,6 +1279,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if(toxine_is_args(tox)) channel = atoi(((char *)toxine_get_arg(tox, 1))); @@ -1231,6 +1289,8 @@ pinfo("xine_get_spu_lang(%d):\n", channel); ret = xine_get_spu_lang(tox->stream, channel, &lang[0]); + if(!ret) + error_code_set(tox, TOX_ERR_XINE_GET_SPU_LANG); toxine_set_last_int_result(tox, ret); poutalign(); pout("'%s'\n", lang); @@ -1246,9 +1306,12 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); pinfo("xine_get_pos_length():\n"); result = xine_get_pos_length (tox->stream, &stream, &time, &length); + if(!result) + error_code_set(tox, TOX_ERR_XINE_GET_POS_LENGTH); toxine_set_last_int_result(tox, result); stime = time / 1000; slength = length / 1000; @@ -1273,10 +1336,13 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); bufname = toxine_get_arg(tox, 1); - + log_names = xine_get_log_names(tox->xine); + if(!log_names) + error_code_set(tox, TOX_ERR_XINE_GET_LOG_NAMES); toxine_set_last_achar_result(tox, log_names); if(log_names) { @@ -1294,6 +1360,7 @@ buftype = atoi(((char *)bufname)); if(buftype >= xine_get_log_section_count(tox->xine)) { perr("buffer number %d is out of bounds\n", buftype); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } pinfo("xine_get_log(%d):\n", buftype); @@ -1328,11 +1395,14 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); memset(&buffer, 0, sizeof(buffer)); pinfo("xine_get_log_names():\n"); log_names = xine_get_log_names(tox->xine); + if(!log_names) + error_code_set(tox, TOX_ERR_XINE_GET_LOG_NAMES); toxine_set_last_achar_result(tox, log_names); if(log_names) { for(log = *log_names++; log; log = *log_names++) { @@ -1355,6 +1425,8 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); + pinfo("xine_get_log_section_count():\n"); count = xine_get_log_section_count(tox->xine); toxine_set_last_int_result(tox, count); @@ -1373,10 +1445,13 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); bufname = toxine_get_arg(tox, 1); log_names = xine_get_log_names(tox->xine); - if(log_names) { + if(!log_names) + error_code_set(tox, TOX_ERR_XINE_GET_LOG_NAMES); + else { int i; for(i = 0, log = *log_names++; log; log = *log_names++, i++) { @@ -1393,6 +1468,7 @@ buftype = atoi(((char *)bufname)); if(buftype >= xine_get_log_section_count(tox->xine)) { perr("buffer number %d is out of bounds\n", buftype); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); return; } pinfo("xine_log(%d, '%s')\n", buftype, msg); @@ -1412,6 +1488,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_get_browsable_input_plugin_ids():\n"); inpp = xine_get_browsable_input_plugin_ids(tox->xine); @@ -1446,6 +1523,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); if((nargs = toxine_is_args(tox))) { xine_mrl_t **bmrls; @@ -1539,6 +1617,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_get_autoplay_input_plugin_ids():\n"); inpp = xine_get_autoplay_input_plugin_ids(tox->xine); @@ -1575,6 +1654,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); if(toxine_is_args(tox)) { const char *pname; @@ -1604,6 +1684,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); if(toxine_is_args(tox)) { const char *ipd; @@ -1633,6 +1714,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_list_audio_output_plugins():\n"); aop = xine_list_audio_output_plugins(tox->xine); @@ -1670,6 +1752,8 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); + pinfo("xine_list_video_output_plugins():\n"); vop = xine_list_video_output_plugins(tox->xine); toxine_set_last_achar_result(tox, vop); @@ -1705,6 +1789,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if((toxine_is_args(tox)) || (alias_event > 0)) { const char *event_name = NULL; @@ -1741,6 +1826,8 @@ else pinfo("there is no event type # %d.\n", alias_event); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } } @@ -1753,12 +1840,15 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_config_get_first_entry():\n"); if((xine_config_get_first_entry(tox->xine, &cfg_entry))) toxine_dump_config_entry(tox, &cfg_entry); - else + else { perr("xine_config_get_first_entry() returned NULL\n"); + error_code_set(tox, TOX_ERR_XINE_CONFIG_GET_FIRST_ENTRY); + } pinfo(".\n"); } @@ -1767,12 +1857,15 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_config_get_next_entry():\n"); if((xine_config_get_next_entry(tox->xine, &cfg_entry))) toxine_dump_config_entry(tox, &cfg_entry); - else + else { perr("xine_config_get_next_entry() returned NULL\n"); + error_code_set(tox, TOX_ERR_XINE_CONFIG_GET_NEXT_ENTRY); + } pinfo(".\n"); } @@ -1782,13 +1875,16 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); key = toxine_get_arg(tox, 1); pinfo("xine_config_lookup_entry(%s):\n", key); if((xine_config_lookup_entry(tox->xine, key, &cfg_entry))) toxine_dump_config_entry(tox, &cfg_entry); - else + else { perr("Entry '%s' doesn't exist.\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } pinfo(".\n"); } @@ -1799,6 +1895,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); if(toxine_is_args(tox) >= 2) { const char *svalue; @@ -1841,20 +1938,25 @@ pinfo(".\n"); } } - else + else { perr("Entry '%s' doesn't exist.\n", key); + error_code_set(tox, TOX_ERR_XINE_CONFIG_LOOKUP_ENTRY); + } pinfo(".\n"); } - else + else { perr("Argument(s) missing.\n"); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } } void _xine_config_load(commands_t *command, toxine_t *tox, void *data) { const char *filename = NULL; return_if_no_new(tox); + error_code_clear(tox); if(toxine_is_args(tox)) { filename = toxine_get_arg(tox, 1); @@ -1873,6 +1975,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); if(toxine_is_args(tox)) filename = toxine_get_arg(tox, 1); @@ -1886,6 +1989,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_config_reset():\n"); xine_config_reset(tox->xine); @@ -1903,6 +2007,8 @@ char buffer[32]; toxine_unset_last_result(tox); + error_code_clear(tox); + pinfo("xine_get_version():\n"); xine_get_version(&major, &minor, &sub); sprintf(buffer, "%d.%d.%d", major, minor, sub); @@ -1920,8 +2026,12 @@ const char *result; toxine_unset_last_result(tox); + error_code_clear(tox); + pinfo("xine_get_version_string():\n"); result = xine_get_version_string(); + if(!result) + error_code_set(tox, TOX_ERR_XINE_GET_VERSION_STRING); toxine_set_last_char_result(tox, result); poutalign(); pout("'%s'\n", result); @@ -1935,11 +2045,14 @@ int major, minor, sub, retval; toxine_unset_last_result(tox); + error_code_clear(tox); if(toxine_is_args(tox) >= 1) { if((sscanf((toxine_get_arg(tox, 1)), "%d.%d.%d", &major, &minor, &sub)) == 3) { pinfo("xine_check_version(%d,%d,%d):\n", major, minor, sub); retval = xine_check_version(major, minor, sub); + if(!retval) + error_code_set(tox, TOX_ERR_XINE_CHECK_VERSION); toxine_set_last_int_result(tox, retval); pinfo("returned %d.\n", retval); pinfo(".\n"); @@ -1950,6 +2063,7 @@ void _xine_close(commands_t *command, toxine_t *tox, void *data) { toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); pinfo("xine_close():\n"); xine_close(tox->stream); @@ -1960,6 +2074,7 @@ void _xine_dispose(commands_t *command, toxine_t *tox, void *data) { toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if(tox->event_queue) { pinfo("xine_event_dispose_queue():\n"); @@ -1980,6 +2095,8 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); + pinfo("xine_get_file_extensions():\n"); exts = xine_get_file_extensions(tox->xine); toxine_set_last_char_result(tox, exts); @@ -1993,6 +2110,7 @@ toxine_unset_last_result(tox); return_if_no_init(tox); + error_code_clear(tox); pinfo("xine_get_mime_types():\n"); mimes = xine_get_mime_types(tox->xine); @@ -2015,6 +2133,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); + error_code_clear(tox); if(toxine_is_args(tox)) filename = (char *) toxine_get_arg(tox, 1); @@ -2026,8 +2145,10 @@ width = xine_get_stream_info(tox->stream,XINE_STREAM_INFO_VIDEO_WIDTH); height = xine_get_stream_info(tox->stream,XINE_STREAM_INFO_VIDEO_HEIGHT); - if((!width) || (!height)) + if((!width) || (!height)) { perr("Wrong frame size: %dx%d\n", width, height); + error_code_set(tox, TOX_ERR_WRONG_SYNTAX); + } else { int size = (width * height) * 2; @@ -2044,12 +2165,16 @@ fclose(fd); pinfo("File '%s' saved\n", filename); } - else + else { perr("Unable to open file '%s' in write mode\n", filename); + error_code_set(tox, TOX_ERR_INTERNAL); + } } - else + else { perr("unable to get current frame\n"); + error_code_set(tox, TOX_ERR_XINE_GET_CURRENT_FRAME); + } pinfo(".\n"); toxine_free(frame); @@ -2064,6 +2189,8 @@ unsigned usecs; toxine_unset_last_result(tox); + error_code_clear(tox); + usecs = (unsigned) atoi((toxine_get_arg(tox, 1))); pinfo("xine_usec_sleep(%u):\n", usecs); xine_usec_sleep(usecs); @@ -2078,6 +2205,7 @@ toxine_unset_last_result(tox); return_if_no_stream(tox); return_if_no_open(tox); + error_code_clear(tox); pinfo("Meta info:\n"); for(i = 0; meta_infos[i].name != NULL; i++) { |