cvs: pear /XMMS xmms.c

From: Date: Sun, 12 Aug 2001 04:59:51 +0000
Subject: cvs: pear /XMMS xmms.c
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-474@lists.php.net to get a copy of this message
rasmus Sun Aug 12 00:59:51 2001 EDT Modified files: /pear/XMMS xmms.c Log: Clean up code - check for 0 args in void funcs - use parse_parameters function for simplicity

Index: pear/XMMS/xmms.c diff -u pear/XMMS/xmms.c:1.4 pear/XMMS/xmms.c:1.5 --- pear/XMMS/xmms.c:1.4 Sat Aug 11 02:57:32 2001 +++ pear/XMMS/xmms.c Sun Aug 12 00:59:51 2001 @@ -95,7 +95,7 @@ */ PHP_MINIT_FUNCTION(xmms) { - ZEND_INIT_MODULE_GLOBALS(xmms, zend_xmms_init_globals, NULL); + ZEND_INIT_MODULE_GLOBALS(xmms, php_xmms_init_globals, NULL); REGISTER_INI_ENTRIES(); return SUCCESS; @@ -158,6 +158,9 @@ pid_t pid; char *av[] = { "xmms",NULL }; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + if(!xmms_remote_is_running(XG(session))) { /* Ok, this is pretty weird, but hey, why not? */ pid = fork(); @@ -185,6 +188,9 @@ Get current playlist position */ PHP_FUNCTION(xmms_playlist_pos) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + RETURN_LONG(xmms_remote_get_playlist_pos(XG(session))); } /* }}} */ @@ -193,23 +199,13 @@ Get full playlist */ PHP_FUNCTION(xmms_playlist) { - zval **pos_arg; - int pos, len, i; int argc = ZEND_NUM_ARGS(); + long pos; pval *tmp; + int len, i; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &pos_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } - - switch (argc) { - case 1: - convert_to_long_ex(pos_arg); - pos = Z_LVAL_PP(pos_arg); - /* Fall-through. */ - case 0: - break; - } + if (zend_parse_parameters(argc, "|l", &pos) == FAILURE) + return; array_init(return_value); @@ -236,31 +232,24 @@ */ PHP_FUNCTION(xmms_play) { - zval **pos_arg; - int pos; int argc = ZEND_NUM_ARGS(); + long pos; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &pos_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(argc, "|l", &pos) == FAILURE) + return; - switch (argc) { - case 1: - convert_to_long_ex(pos_arg); - pos = Z_LVAL_PP(pos_arg); - xmms_remote_set_playlist_pos(XG(session), pos); - /* Fall-through. */ - case 0: - xmms_remote_play(XG(session)); - break; - } + if(argc) xmms_remote_set_playlist_pos(XG(session), pos); + xmms_remote_play(XG(session)); } /* }}} */ -/* {{{ proto void xmms_stop() +/* {{{ proto void xmms_stop(void) Stop playing current song */ PHP_FUNCTION(xmms_stop) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + xmms_remote_stop(XG(session)); } /* }}} */ @@ -269,6 +258,9 @@ Pause current song (toggle) */ PHP_FUNCTION(xmms_pause) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + xmms_remote_pause(XG(session)); } /* }}} */ @@ -277,6 +269,9 @@ Force XMMS to terminate */ PHP_FUNCTION(xmms_quit) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + xmms_remote_quit(XG(session)); } /* }}} */ @@ -287,6 +282,9 @@ { int version; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + version = xmms_remote_get_version(XG(session)); RETURN_LONG(version); } @@ -296,6 +294,9 @@ Go to next song in playlist */ PHP_FUNCTION(xmms_next) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + xmms_remote_playlist_next(XG(session)); } /* }}} */ @@ -304,6 +305,9 @@ Go to previous song in playlist */ PHP_FUNCTION(xmms_prev) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + xmms_remote_playlist_prev(XG(session)); } /* }}} */ @@ -314,6 +318,9 @@ { int playing, paused; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + playing = xmms_remote_is_playing(XG(session)); paused = xmms_remote_is_paused(XG(session)); @@ -333,38 +340,28 @@ Get repeat setting */ PHP_FUNCTION(xmms_is_repeat) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + RETURN_BOOL(xmms_remote_is_repeat(XG(session))); } /* }}} */ -/* {{{ proto int xmms_repeat([int setting]) +/* {{{ proto int xmms_repeat([bool setting]) Toggle/Set repeat setting */ PHP_FUNCTION(xmms_repeat) { - zval **setting_arg; - int setting; - gboolean current; int argc = ZEND_NUM_ARGS(); + zend_bool setting; + gboolean current; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &setting_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } - - switch (argc) { - case 1: - convert_to_long_ex(setting_arg); - setting = Z_LVAL_PP(setting_arg); - if(setting) setting=TRUE; - else setting=FALSE; - /* Fall-through. */ - case 0: - break; - } + if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) + return; if(argc) { current = xmms_remote_is_repeat(XG(session)); - if(current) current=TRUE; - else current=FALSE; + if(current) current=1; + else current=0; if(current != setting) { xmms_remote_toggle_repeat(XG(session)); } @@ -381,38 +378,28 @@ Get shuffle setting */ PHP_FUNCTION(xmms_is_shuffle) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + RETURN_BOOL(xmms_remote_is_shuffle(XG(session))); } /* }}} */ -/* {{{ proto int xmms_shuffle([int setting]) +/* {{{ proto int xmms_shuffle([bool setting]) Toggle/Set shuffle setting*/ PHP_FUNCTION(xmms_shuffle) { - zval **setting_arg; - int setting; - gboolean current; int argc = ZEND_NUM_ARGS(); + zend_bool setting; + gboolean current; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &setting_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } - - switch (argc) { - case 1: - convert_to_long_ex(setting_arg); - setting = Z_LVAL_PP(setting_arg); - if(setting) setting=TRUE; - else setting=FALSE; - /* Fall-through. */ - case 0: - break; - } + if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) + return; if(argc) { current = xmms_remote_is_shuffle(XG(session)); - if(current) current=TRUE; - else current=FALSE; + if(current) current=1; + else current=0; if(current != setting) { xmms_remote_toggle_shuffle(XG(session)); } @@ -428,12 +415,10 @@ Add entries to playlist */ PHP_FUNCTION(xmms_add) { - zval **songs_arg; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &songs_arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + zval *songs = NULL; - /* Write your own code here to handle argument songs. */ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &songs) == FAILURE) + return; php_error(E_WARNING, "xmms_add: not yet implemented"); } @@ -443,24 +428,23 @@ Delete entry from playlist */ PHP_FUNCTION(xmms_delete) { - zval **pos_arg; - int pos; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pos_arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + int argc = ZEND_NUM_ARGS(); + long pos; - convert_to_long_ex(pos_arg); - pos = Z_LVAL_PP(pos_arg); + if (zend_parse_parameters(argc, "l", &pos) == FAILURE) + return; php_error(E_WARNING, "xmms_delete: not yet implemented"); } /* }}} */ -/* {{{ proto xmms_clear() +/* {{{ proto xmms_clear(void) Clear playlist */ PHP_FUNCTION(xmms_clear) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + php_error(E_WARNING, "xmms_clear: not yet implemented"); } /* }}} */ @@ -475,6 +459,9 @@ int playing, paused, repeat, shuffle; char status[10]; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + playing = xmms_remote_is_playing(XG(session)); paused = xmms_remote_is_paused(XG(session)); timepos = xmms_remote_get_output_time(XG(session)); @@ -510,27 +497,12 @@ */ PHP_FUNCTION(xmms_volume) { - zval **level_arg, **right_level_arg; - int level; - int right_level; int argc = ZEND_NUM_ARGS(); + long level; + long right_level; - if (argc > 2 || (argc && zend_get_parameters_ex(argc, &level_arg, &right_level_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } - - switch (argc) { - case 2: - convert_to_long_ex(right_level_arg); - right_level = Z_LVAL_PP(right_level_arg); - /* Fall-through. */ - case 1: - convert_to_long_ex(level_arg); - level = Z_LVAL_PP(level_arg); - /* Fall-through. */ - case 0: - break; - } + if (zend_parse_parameters(argc, "|ll", &level, &right_level) == FAILURE) + return; php_error(E_WARNING, "xmms_volume: not yet implemented"); } @@ -540,15 +512,14 @@ Play from url */ PHP_FUNCTION(xmms_url) { - zval **url; + char *url = NULL; + int url_len; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &url) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &url, &url_len) == FAILURE) + return; - convert_to_string_ex(url); /* this add_url call doesn't seem to work - not sure why yet */ - xmms_remote_playlist_add_url_string(XG(session),Z_STRVAL_PP(url)); + xmms_remote_playlist_add_url_string(XG(session),url); } /* }}} */ @@ -556,22 +527,12 @@ */ PHP_FUNCTION(xmms_skin) { - zval **skin_file_arg; - char *skin_file = NULL; - int argc = ZEND_NUM_ARGS(); + char *skin_file = NULL; + int argc = ZEND_NUM_ARGS(); + int skin_file_len; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &skin_file_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } - - switch (argc) { - case 1: - convert_to_string_ex(skin_file_arg); - skin_file = Z_STRVAL_PP(skin_file_arg); - /* Fall-through. */ - case 0: - break; - } + if (zend_parse_parameters(argc, "|s", &skin_file, &skin_file_len) == FAILURE) + return; php_error(E_WARNING, "xmms_skin: not yet implemented"); } @@ -581,18 +542,14 @@ Get/Set output time position */ PHP_FUNCTION(xmms_time) { - zval **time_pos_arg; - double time_pos; int argc = ZEND_NUM_ARGS(); + double time_pos; - if (argc > 1 || (argc && zend_get_parameters_ex(argc, &time_pos_arg) == FAILURE)) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(argc, "|d", &time_pos) == FAILURE) + return; switch (argc) { case 1: - convert_to_double_ex(time_pos_arg); - time_pos = Z_DVAL_PP(time_pos_arg); xmms_remote_jump_to_time(XG(session), (int)(time_pos*1000)); RETVAL_DOUBLE(time_pos); break; @@ -607,17 +564,13 @@ Hide/Unhide main xmms window */ PHP_FUNCTION(xmms_main_win) { - zval **setting_arg; - int setting; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &setting_arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + int argc = ZEND_NUM_ARGS(); + zend_bool setting; - convert_to_long_ex(setting_arg); - setting = Z_LVAL_PP(setting_arg); + if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) + return; - xmms_remote_main_win_toggle(XG(session),setting?TRUE:FALSE); + xmms_remote_main_win_toggle(XG(session),setting); } /* }}} */ @@ -625,17 +578,13 @@ Hide/Unhide playlist xmms window */ PHP_FUNCTION(xmms_pl_win) { - zval **setting_arg; - int setting; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &setting_arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + int argc = ZEND_NUM_ARGS(); + zend_bool setting; - convert_to_long_ex(setting_arg); - setting = Z_LVAL_PP(setting_arg); + if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) + return; - xmms_remote_pl_win_toggle(XG(session),setting?TRUE:FALSE); + xmms_remote_pl_win_toggle(XG(session),setting); } /* }}} */ @@ -643,17 +592,13 @@ Hide/Unhide equalizer xmms window */ PHP_FUNCTION(xmms_eq_win) { - zval **setting_arg; - int setting; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &setting_arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + int argc = ZEND_NUM_ARGS(); + zend_bool setting; - convert_to_long_ex(setting_arg); - setting = Z_LVAL_PP(setting_arg); + if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) + return; - xmms_remote_eq_win_toggle(XG(session),setting?TRUE:FALSE); + xmms_remote_eq_win_toggle(XG(session),setting); } /* }}} */
« previous php.pear.cvs (#474) next »