1 /*****************************************************************************
2 * vlm.c: VLM interface plugin
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Simon Latapie <garf@videolan.org>
8 * Laurent Aimar <fenrir@videolan.org>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
33 #include <vlc_common.h>
36 #include <ctype.h> /* tolower() */
43 #include <time.h> /* ctime() */
45 #include <vlc_input.h>
46 #include "input_internal.h"
47 #include <vlc_stream.h>
48 #include "vlm_internal.h"
49 #include <vlc_charset.h>
51 #include "../stream_output/stream_output.h"
52 #include "../libvlc.h"
54 /*****************************************************************************
56 *****************************************************************************/
59 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
61 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
63 static char *Save( vlm_t * );
64 static int Load( vlm_t *, char * );
66 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
67 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
68 const char *psz_value );
71 static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
73 static const char quotes[] = "\"'";
75 * FindCommandEnd: look for the end of a possibly quoted string
76 * @return NULL on mal-formatted string,
77 * pointer past the last character otherwise.
79 static const char *FindCommandEnd( const char *psz_sent )
83 while( (c = *psz_sent) != '\0' )
87 if( strchr(quotes,c) ) // opening quote
89 else if( isspace(c) ) // non-escaped space
93 psz_sent++; // skip escaped character
94 if( *psz_sent == '\0' )
100 if( c == quote ) // non-escaped matching quote
102 else if( (quote == '"') && (c == '\\') )
104 psz_sent++; // skip escaped character
105 if (*psz_sent == '\0')
106 return NULL; // error, closing quote missing
112 // error (NULL) if we could not find a matching quote
113 return quote ? NULL : psz_sent;
118 * Unescape a nul-terminated string.
119 * Note that in and out can be identical.
121 * @param out output buffer (at least <strlen (in) + 1> characters long)
122 * @param in nul-terminated string to be unescaped
124 * @return 0 on success, -1 on error.
126 static int Unescape( char *out, const char *in )
131 while( (c = *in++) != '\0' )
133 // Don't escape the end of the string if we find a '#'
134 // that's the begining of a vlc command
135 // TODO: find a better solution
136 if( c == '#' || param )
145 if (strchr(quotes,c)) // opening quote
169 /* None of the special cases - copy the backslash */
175 if( c == quote ) // non-escaped matching quote
180 if( (quote == '"') && (c == '\\') )
189 case '\0': // should never happen
193 /* None of the special cases - copy the backslash */
205 /*****************************************************************************
206 * ExecuteCommand: The main state machine
207 *****************************************************************************
208 * Execute a command which ends with '\0' (string)
209 *****************************************************************************/
210 static int ExecuteSyntaxError( const char *psz_cmd, vlm_message_t **pp_status )
212 *pp_status = vlm_MessageNew( psz_cmd, "Wrong command syntax" );
216 static bool ExecuteIsMedia( vlm_t *p_vlm, const char *psz_name )
220 if( !psz_name || vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
224 static bool ExecuteIsSchedule( vlm_t *p_vlm, const char *psz_name )
226 if( !psz_name || !vlm_ScheduleSearch( p_vlm, psz_name ) )
231 static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
233 vlm_media_sys_t *p_media;
234 vlm_schedule_sys_t *p_schedule;
236 p_media = vlm_MediaSearch( p_vlm, psz_name );
237 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
239 if( p_schedule != NULL )
241 vlm_ScheduleDelete( p_vlm, p_schedule );
243 else if( p_media != NULL )
245 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_media->cfg.id );
247 else if( !strcmp(psz_name, "media") )
249 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
251 else if( !strcmp(psz_name, "schedule") )
253 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
255 else if( !strcmp(psz_name, "all") )
257 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
258 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
262 *pp_status = vlm_MessageNew( "del", "%s: media unknown", psz_name );
266 *pp_status = vlm_MessageSimpleNew( "del" );
270 static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
272 vlm_media_sys_t *p_media;
273 vlm_schedule_sys_t *p_schedule;
277 *pp_status = vlm_Show( p_vlm, NULL, NULL, NULL );
281 p_media = vlm_MediaSearch( p_vlm, psz_name );
282 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
284 if( p_schedule != NULL )
285 *pp_status = vlm_Show( p_vlm, NULL, p_schedule, NULL );
286 else if( p_media != NULL )
287 *pp_status = vlm_Show( p_vlm, p_media, NULL, NULL );
289 *pp_status = vlm_Show( p_vlm, NULL, NULL, psz_name );
294 static int ExecuteHelp( vlm_message_t **pp_status )
296 vlm_message_t *message_child;
298 #define MessageAdd( a ) \
299 vlm_MessageAdd( *pp_status, vlm_MessageSimpleNew( a ) );
300 #define MessageAddChild( a ) \
301 vlm_MessageAdd( message_child, vlm_MessageSimpleNew( a ) );
303 *pp_status = vlm_MessageSimpleNew( "help" );
305 message_child = MessageAdd( "Commands Syntax:" );
306 MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
307 MessageAddChild( "setup (name) (properties)" );
308 MessageAddChild( "show [(name)|media|schedule]" );
309 MessageAddChild( "del (name)|all|media|schedule" );
310 MessageAddChild( "control (name) [instance_name] (command)" );
311 MessageAddChild( "save (config_file)" );
312 MessageAddChild( "export" );
313 MessageAddChild( "load (config_file)" );
315 message_child = MessageAdd( "Media Proprieties Syntax:" );
316 MessageAddChild( "input (input_name)" );
317 MessageAddChild( "inputdel (input_name)|all" );
318 MessageAddChild( "inputdeln input_number" );
319 MessageAddChild( "output (output_name)" );
320 MessageAddChild( "option (option_name)[=value]" );
321 MessageAddChild( "enabled|disabled" );
322 MessageAddChild( "loop|unloop (broadcast only)" );
323 MessageAddChild( "mux (mux_name)" );
325 message_child = MessageAdd( "Schedule Proprieties Syntax:" );
326 MessageAddChild( "enabled|disabled" );
327 MessageAddChild( "append (command_until_rest_of_the_line)" );
328 MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):"
330 MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
331 "(days)-(hours):(minutes):(seconds)" );
332 MessageAddChild( "repeat (number_of_repetitions)" );
334 message_child = MessageAdd( "Control Commands Syntax:" );
335 MessageAddChild( "play [input_number]" );
336 MessageAddChild( "pause" );
337 MessageAddChild( "stop" );
338 MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](milliseconds)ms" );
343 static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, char ** ppsz_arg, vlm_message_t **pp_status )
345 vlm_media_sys_t *p_media;
346 const char *psz_control = NULL;
347 const char *psz_instance = NULL;
348 const char *psz_argument = NULL;
352 if( !ExecuteIsMedia( p_vlm, psz_name ) )
354 *pp_status = vlm_MessageNew( "control", "%s: media unknown", psz_name );
360 #define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
362 if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
365 psz_instance = ppsz_arg[0];
367 if( i_index >= i_arg || ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
368 return ExecuteSyntaxError( "control", pp_status );
371 psz_control = ppsz_arg[i_index];
373 if( i_index+1 < i_arg )
374 psz_argument = ppsz_arg[i_index+1];
376 p_media = vlm_MediaSearch( p_vlm, psz_name );
379 if( !strcmp( psz_control, "play" ) )
381 int i_input_index = 0;
384 if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input )
388 else if( psz_argument )
391 vlm_media_t *p_cfg = &p_media->cfg;
392 for ( j=0; j < p_cfg->i_input; j++)
394 if( !strcmp( p_cfg->ppsz_input[j], psz_argument ) )
402 if( p_media->cfg.b_vod )
403 i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_VOD_INSTANCE, p_media->cfg.id, psz_instance, i_input_index, NULL ); // we should get here now
405 i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, psz_instance, i_input_index );
407 else if( !strcmp( psz_control, "seek" ) )
412 if( psz_argument[0] == '+' || psz_argument[0] == '-' )
417 if( strstr( psz_argument, "ms" ) || strstr( psz_argument, "s" ) )
422 if( strstr( psz_argument, "ms" ) )
423 i_new_time = 1000 * (int64_t)atoi( psz_argument );
425 i_new_time = 1000000 * (int64_t)atoi( psz_argument );
430 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, &i_time );
431 i_new_time += i_time;
435 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, i_new_time );
440 double d_new_position = us_atof( psz_argument ) / 100.0;
444 double d_position = 0.0;
446 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
447 d_new_position += d_position;
449 if( d_new_position < 0.0 )
450 d_new_position = 0.0;
451 else if( d_new_position > 1.0 )
452 d_new_position = 1.0;
453 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_new_position );
458 i_result = VLC_EGENERIC;
461 else if( !strcmp( psz_control, "rewind" ) )
465 const double d_scale = us_atof( psz_argument );
468 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
469 d_position -= (d_scale / 1000.0);
470 if( d_position < 0.0 )
472 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
476 i_result = VLC_EGENERIC;
479 else if( !strcmp( psz_control, "forward" ) )
483 const double d_scale = us_atof( psz_argument );
486 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
487 d_position += (d_scale / 1000.0);
488 if( d_position > 1.0 )
490 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
495 i_result = VLC_EGENERIC;
498 else if( !strcmp( psz_control, "stop" ) )
500 i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
502 else if( !strcmp( psz_control, "pause" ) )
504 i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
508 i_result = VLC_EGENERIC;
513 *pp_status = vlm_MessageNew( "control", "unknown error" );
516 *pp_status = vlm_MessageSimpleNew( "control" );
520 static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
522 char *psz_export = Save( p_vlm );
524 *pp_status = vlm_MessageNew( "export", "%s", psz_export );
529 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
531 FILE *f = utf8_fopen( psz_file, "wt" );
532 char *psz_save = NULL;
537 psz_save = Save( p_vlm );
538 if( psz_save == NULL )
540 if( fputs( psz_save, f ) == EOF )
550 *pp_status = vlm_MessageSimpleNew( "save" );
557 *pp_status = vlm_MessageNew( "save", "Unable to save to file");
561 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
563 stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
569 *pp_status = vlm_MessageNew( "load", "Unable to load from file" );
574 if( stream_Seek( p_stream, 0 ) != 0 )
576 stream_Delete( p_stream );
578 *pp_status = vlm_MessageNew( "load", "Read file error" );
582 i_size = stream_Size( p_stream );
584 psz_buffer = malloc( i_size + 1 );
587 stream_Delete( p_stream );
589 *pp_status = vlm_MessageNew( "load", "Read file error" );
593 stream_Read( p_stream, psz_buffer, i_size );
594 psz_buffer[i_size] = '\0';
596 stream_Delete( p_stream );
598 if( Load( p_vlm, psz_buffer ) )
602 *pp_status = vlm_MessageNew( "load", "Error while loading file" );
608 *pp_status = vlm_MessageSimpleNew( "load" );
612 static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,
613 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
615 const char *psz_cmd = b_new ? "new" : "setup";
618 for( i = 0; i < i_property; i++ )
620 if( !strcmp( ppsz_property[i], "enabled" ) ||
621 !strcmp( ppsz_property[i], "disabled" ) )
623 if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )
626 else if( !strcmp( ppsz_property[i], "append" ) )
630 /* Beware: everything behind append is considered as
633 if( ++i >= i_property )
636 psz_line = strdup( ppsz_property[i] );
637 for( j = i+1; j < i_property; j++ )
639 psz_line = xrealloc( psz_line,
640 strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
641 strcat( psz_line, " " );
642 strcat( psz_line, ppsz_property[j] );
645 if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
651 if( i + 1 >= i_property )
654 vlm_ScheduleDelete( p_vlm, p_schedule );
655 return ExecuteSyntaxError( psz_cmd, pp_status );
658 if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )
663 *pp_status = vlm_MessageSimpleNew( psz_cmd );
667 *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",
672 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
673 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
675 const char *psz_cmd = b_new ? "new" : "setup";
676 vlm_media_t *p_cfg = NULL;
682 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
683 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )
684 ERROR( "unknown media" );
686 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
687 for( i = 0; i < i_property; i++ )
689 const char *psz_option = ppsz_property[i];
690 const char *psz_value = i+1 < i_property ? ppsz_property[i+1] : NULL;
692 if( !strcmp( psz_option, "enabled" ) )
694 p_cfg->b_enabled = true;
696 else if( !strcmp( psz_option, "disabled" ) )
698 p_cfg->b_enabled = false;
700 else if( !strcmp( psz_option, "input" ) )
703 TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
706 else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
708 while( p_cfg->i_input > 0 )
709 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
712 else if( !strcmp( psz_option, "inputdel" ) )
716 MISSING( "inputdel" );
718 for( j = 0; j < p_cfg->i_input; j++ )
720 if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
722 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
728 else if( !strcmp( psz_option, "inputdeln" ) )
732 MISSING( "inputdeln" );
734 i_index = atoi( psz_value );
735 if( i_index > 0 && i_index <= p_cfg->i_input )
736 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
739 else if( !strcmp( psz_option, "output" ) )
743 free( p_cfg->psz_output );
744 p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
747 else if( !strcmp( psz_option, "option" ) )
751 TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
754 else if( !strcmp( psz_option, "loop" ) )
757 ERROR( "invalid loop option for vod" );
758 p_cfg->broadcast.b_loop = true;
760 else if( !strcmp( psz_option, "unloop" ) )
763 ERROR( "invalid unloop option for vod" );
764 p_cfg->broadcast.b_loop = false;
766 else if( !strcmp( psz_option, "mux" ) )
770 ERROR( "invalid mux option for broadcast" );
772 free( p_cfg->vod.psz_mux );
773 p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
778 fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
779 ERROR( "Wrong command syntax" );
786 i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
787 vlm_media_Delete( p_cfg );
789 *pp_status = vlm_MessageSimpleNew( psz_cmd );
796 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
797 vlm_media_Delete( p_cfg );
802 static int ExecuteNew( vlm_t *p_vlm, const char *psz_name, const char *psz_type, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
805 if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
807 *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
810 if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
812 *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
816 if( !strcmp( psz_type, "schedule" ) )
818 vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
821 *pp_status = vlm_MessageNew( "new", "could not create schedule" );
824 return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );
826 else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
831 vlm_media_Init( &cfg );
832 cfg.psz_name = strdup( psz_name );
833 cfg.b_vod = !strcmp( psz_type, "vod" );
835 if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
837 vlm_media_Clean( &cfg );
838 *pp_status = vlm_MessageNew( "new", "could not create media" );
841 vlm_media_Clean( &cfg );
842 return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );
846 *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
851 static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
853 if( ExecuteIsSchedule( p_vlm, psz_name ) )
855 vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
856 return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );
858 else if( ExecuteIsMedia( p_vlm, psz_name ) )
861 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
863 return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );
867 *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
871 int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
872 vlm_message_t **pp_message )
874 size_t i_command = 0;
875 char buf[strlen (psz_command) + 1], *psz_buf = buf;
876 char *ppsz_command[3+sizeof (buf) / 2];
877 vlm_message_t *p_message = NULL;
879 /* First, parse the line and cut it */
880 while( *psz_command != '\0' )
882 const char *psz_temp;
884 if(isspace (*psz_command))
890 /* support for comments */
891 if( i_command == 0 && *psz_command == '#')
893 p_message = vlm_MessageSimpleNew( "" );
897 psz_temp = FindCommandEnd( psz_command );
899 if( psz_temp == NULL )
901 p_message = vlm_MessageNew( "Incomplete command", "%s", psz_command );
905 assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
907 ppsz_command[i_command] = psz_buf;
908 memcpy (psz_buf, psz_command, psz_temp - psz_command);
909 psz_buf[psz_temp - psz_command] = '\0';
911 Unescape (psz_buf, psz_buf);
914 psz_buf += psz_temp - psz_command + 1;
915 psz_command = psz_temp;
917 assert (buf + sizeof (buf) >= psz_buf);
921 * And then Interpret it
924 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; }
927 p_message = vlm_MessageSimpleNew( "" );
930 else IF_EXECUTE( "del", (i_command != 2), ExecuteDel(p_vlm, ppsz_command[1], &p_message) )
931 else IF_EXECUTE( "show", (i_command > 2), ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) )
932 else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp( &p_message ) )
933 else IF_EXECUTE( "control", (i_command < 3), ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) )
934 else IF_EXECUTE( "save", (i_command != 2), ExecuteSave(p_vlm, ppsz_command[1], &p_message) )
935 else IF_EXECUTE( "export", (i_command != 1), ExecuteExport(p_vlm, &p_message) )
936 else IF_EXECUTE( "load", (i_command != 2), ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )
937 else IF_EXECUTE( "new", (i_command < 3), ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )
938 else IF_EXECUTE( "setup", (i_command < 2), ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
941 p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
947 *pp_message = p_message;
951 return ExecuteSyntaxError( ppsz_command[0], pp_message );
954 *pp_message = p_message;
958 /*****************************************************************************
960 *****************************************************************************/
961 vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
965 for( i = 0; i < vlm->i_media; i++ )
967 if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
968 return vlm->media[i];
974 /*****************************************************************************
976 *****************************************************************************/
977 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
982 vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
986 p_sched->psz_name = strdup( psz_name );
987 p_sched->b_enabled = false;
988 p_sched->i_command = 0;
989 p_sched->command = NULL;
991 p_sched->i_period = 0;
992 p_sched->i_repeat = -1;
994 TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
999 /* for now, simple delete. After, del with options (last arg) */
1000 void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
1002 if( sched == NULL ) return;
1004 TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
1006 if( vlm->i_schedule == 0 ) free( vlm->schedule );
1007 free( sched->psz_name );
1008 while( sched->i_command )
1010 char *psz_cmd = sched->command[0];
1011 TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
1017 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
1021 for( i = 0; i < vlm->i_schedule; i++ )
1023 if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
1025 return vlm->schedule[i];
1032 /* Ok, setup schedule command will be able to support only one (argument value) at a time */
1033 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
1034 const char *psz_value )
1036 if( !strcmp( psz_cmd, "enabled" ) )
1038 schedule->b_enabled = true;
1040 else if( !strcmp( psz_cmd, "disabled" ) )
1042 schedule->b_enabled = false;
1044 else if( !strcmp( psz_cmd, "date" ) )
1050 time.tm_sec = 0; /* seconds */
1051 time.tm_min = 0; /* minutes */
1052 time.tm_hour = 0; /* hours */
1053 time.tm_mday = 0; /* day of the month */
1054 time.tm_mon = 0; /* month */
1055 time.tm_year = 0; /* year */
1056 time.tm_wday = 0; /* day of the week */
1057 time.tm_yday = 0; /* day in the year */
1058 time.tm_isdst = -1; /* daylight saving time */
1060 /* date should be year/month/day-hour:minutes:seconds */
1061 p = strchr( psz_value, '-' );
1063 if( !strcmp( psz_value, "now" ) )
1065 schedule->i_date = 0;
1075 switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
1093 switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
1099 time.tm_mon = i - 1;
1103 time.tm_year = i - 1900;
1104 time.tm_mon = j - 1;
1111 date = mktime( &time );
1112 schedule->i_date = ((mtime_t) date) * 1000000;
1115 else if( !strcmp( psz_cmd, "period" ) )
1119 const char *psz_time = NULL, *psz_date = NULL;
1123 /* First, if date or period are modified, repeat should be equal to -1 */
1124 schedule->i_repeat = -1;
1126 time.tm_sec = 0; /* seconds */
1127 time.tm_min = 0; /* minutes */
1128 time.tm_hour = 0; /* hours */
1129 time.tm_mday = 0; /* day of the month */
1130 time.tm_mon = 0; /* month */
1131 time.tm_year = 0; /* year */
1132 time.tm_wday = 0; /* day of the week */
1133 time.tm_yday = 0; /* day in the year */
1134 time.tm_isdst = -1; /* daylight saving time */
1136 /* date should be year/month/day-hour:minutes:seconds */
1137 p = strchr( psz_value, '-' );
1140 psz_date = psz_value;
1145 psz_time = psz_value;
1148 switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
1167 switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
1186 /* ok, that's stupid... who is going to schedule streams every 42 years ? */
1187 date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;
1188 schedule->i_period = ((mtime_t) date) * 1000000;
1190 else if( !strcmp( psz_cmd, "repeat" ) )
1194 if( sscanf( psz_value, "%d", &i ) == 1 )
1196 schedule->i_repeat = i;
1203 else if( !strcmp( psz_cmd, "append" ) )
1205 char *command = strdup( psz_value );
1207 TAB_APPEND( schedule->i_command, schedule->command, command );
1216 /*****************************************************************************
1217 * Message handling functions
1218 *****************************************************************************/
1219 vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
1221 if( !psz_name ) return NULL;
1223 vlm_message_t *p_message = malloc( sizeof(*p_message) );
1227 p_message->psz_name = strdup( psz_name );
1228 if( !p_message->psz_name )
1233 p_message->psz_value = NULL;
1234 p_message->i_child = 0;
1235 p_message->child = NULL;
1240 vlm_message_t *vlm_MessageNew( const char *psz_name,
1241 const char *psz_format, ... )
1243 vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
1249 assert( psz_format );
1250 va_start( args, psz_format );
1251 if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
1252 p_message->psz_value = NULL;
1255 if( !p_message->psz_value )
1257 vlm_MessageDelete( p_message );
1263 void vlm_MessageDelete( vlm_message_t *p_message )
1265 free( p_message->psz_name );
1266 free( p_message->psz_value );
1267 while( p_message->i_child-- )
1268 vlm_MessageDelete( p_message->child[p_message->i_child] );
1269 free( p_message->child );
1274 vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
1275 vlm_message_t *p_child )
1277 if( p_message == NULL ) return NULL;
1281 TAB_APPEND( p_message->i_child, p_message->child, p_child );
1287 /*****************************************************************************
1288 * Misc utility functions
1289 *****************************************************************************/
1290 static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
1292 vlm_media_t *p_cfg = &p_media->cfg;
1293 vlm_message_t *p_msg;
1294 vlm_message_t *p_msg_sub;
1297 p_msg = vlm_MessageSimpleNew( p_cfg->psz_name );
1298 vlm_MessageAdd( p_msg,
1299 vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
1300 vlm_MessageAdd( p_msg,
1301 vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );
1304 vlm_MessageAdd( p_msg,
1305 vlm_MessageNew( "mux", "%s", p_cfg->vod.psz_mux ) );
1307 vlm_MessageAdd( p_msg,
1308 vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
1310 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "inputs" ) );
1311 for( i = 0; i < p_cfg->i_input; i++ )
1314 if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )
1316 vlm_MessageAdd( p_msg_sub,
1317 vlm_MessageNew( psz_tmp, "%s", p_cfg->ppsz_input[i] ) );
1322 vlm_MessageAdd( p_msg,
1323 vlm_MessageNew( "output", "%s", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
1325 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "options" ) );
1326 for( i = 0; i < p_cfg->i_option; i++ )
1327 vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( p_cfg->ppsz_option[i] ) );
1329 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "instances" ) );
1330 for( i = 0; i < p_media->i_instance; i++ )
1332 vlm_media_instance_sys_t *p_instance = p_media->instance[i];
1334 vlm_message_t *p_msg_instance;
1338 if( p_instance->p_input )
1339 var_Get( p_instance->p_input, "state", &val );
1341 p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( "instance" ) );
1343 vlm_MessageAdd( p_msg_instance,
1344 vlm_MessageNew( "name" , "%s", p_instance->psz_name ? p_instance->psz_name : "default" ) );
1345 vlm_MessageAdd( p_msg_instance,
1346 vlm_MessageNew( "state",
1347 val.i_int == PLAYING_S ? "playing" :
1348 val.i_int == PAUSE_S ? "paused" :
1351 /* FIXME should not do that this way */
1352 if( p_instance->p_input )
1354 #define APPEND_INPUT_INFO( a, format, type ) \
1355 if( asprintf( &psz_tmp, format, \
1356 var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
1358 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
1359 "%s", psz_tmp ) ); \
1362 APPEND_INPUT_INFO( "position", "%f", Float );
1363 APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
1364 APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
1365 APPEND_INPUT_INFO( "rate", "%f", Float );
1366 APPEND_INPUT_INFO( "title", "%d", Integer );
1367 APPEND_INPUT_INFO( "chapter", "%d", Integer );
1368 APPEND_INPUT_INFO( "can-seek", "%d", Bool );
1370 #undef APPEND_INPUT_INFO
1371 if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
1373 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
1381 static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
1382 vlm_schedule_sys_t *schedule,
1383 const char *psz_filter )
1387 vlm_message_t *p_msg = vlm_MessageSimpleNew( "show" );
1389 vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) );
1393 else if( schedule != NULL )
1397 vlm_message_t *msg_schedule;
1398 vlm_message_t *msg_child;
1401 msg = vlm_MessageSimpleNew( "show" );
1403 vlm_MessageAdd( msg, vlm_MessageSimpleNew( schedule->psz_name ) );
1405 vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
1407 vlm_MessageAdd( msg_schedule,
1408 vlm_MessageNew( "enabled", schedule->b_enabled ?
1411 if( schedule->i_date != 0 )
1414 time_t i_time = (time_t)( schedule->i_date / 1000000 );
1417 localtime_r( &i_time, &date);
1418 if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
1419 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1420 date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
1422 vlm_MessageAdd( msg_schedule,
1423 vlm_MessageNew( "date", "%s", psz_date ) );
1428 vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
1430 if( schedule->i_period != 0 )
1432 time_t i_time = (time_t) ( schedule->i_period / 1000000 );
1435 date.tm_sec = (int)( i_time % 60 );
1436 i_time = i_time / 60;
1437 date.tm_min = (int)( i_time % 60 );
1438 i_time = i_time / 60;
1439 date.tm_hour = (int)( i_time % 24 );
1440 i_time = i_time / 24;
1441 date.tm_mday = (int)( i_time % 30 );
1442 i_time = i_time / 30;
1443 /* okay, okay, months are not always 30 days long */
1444 date.tm_mon = (int)( i_time % 12 );
1445 i_time = i_time / 12;
1446 date.tm_year = (int)i_time;
1448 sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
1449 date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
1451 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "%s", buffer) );
1454 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
1456 sprintf( buffer, "%d", schedule->i_repeat );
1457 vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", "%s", buffer ) );
1460 vlm_MessageAdd( msg_schedule, vlm_MessageSimpleNew("commands" ) );
1462 for( i = 0; i < schedule->i_command; i++ )
1464 vlm_MessageAdd( msg_child,
1465 vlm_MessageSimpleNew( schedule->command[i] ) );
1472 else if( psz_filter && !strcmp( psz_filter, "media" ) )
1474 vlm_message_t *p_msg;
1475 vlm_message_t *p_msg_child;
1476 int i_vod = 0, i_broadcast = 0;
1480 for( i = 0; i < vlm->i_media; i++ )
1482 if( vlm->media[i]->cfg.b_vod )
1488 if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
1491 p_msg = vlm_MessageSimpleNew( "show" );
1492 p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", "%s",
1496 for( i = 0; i < vlm->i_media; i++ )
1497 vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
1502 else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
1506 vlm_message_t *msg_child;
1508 msg = vlm_MessageSimpleNew( "show" );
1509 msg_child = vlm_MessageAdd( msg, vlm_MessageSimpleNew( "schedule" ) );
1511 for( i = 0; i < vlm->i_schedule; i++ )
1513 vlm_schedule_sys_t *s = vlm->schedule[i];
1514 vlm_message_t *msg_schedule;
1515 mtime_t i_time, i_next_date;
1517 msg_schedule = vlm_MessageAdd( msg_child,
1518 vlm_MessageSimpleNew( s->psz_name ) );
1519 vlm_MessageAdd( msg_schedule,
1520 vlm_MessageNew( "enabled", s->b_enabled ?
1523 /* calculate next date */
1524 i_time = vlm_Date();
1525 i_next_date = s->i_date;
1527 if( s->i_period != 0 )
1530 while( s->i_date + j * s->i_period <= i_time &&
1536 i_next_date = s->i_date + j * s->i_period;
1539 if( i_next_date > i_time )
1541 time_t i_date = (time_t) (i_next_date / 1000000) ;
1543 #if !defined( UNDER_CE )
1546 ctime_r( &i_date, psz_date );
1548 char *psz_date = ctime( &i_date );
1551 vlm_MessageAdd( msg_schedule,
1552 vlm_MessageNew( "next launch", "%s", psz_date ) );
1560 else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
1562 vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
1563 vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
1565 vlm_MessageAdd( show1, show2->child[0] );
1567 /* We must destroy the parent node "show" of show2
1568 * and not the children */
1569 free( show2->psz_name );
1577 return vlm_MessageSimpleNew( "show" );
1581 /*****************************************************************************
1582 * Config handling functions
1583 *****************************************************************************/
1584 static int Load( vlm_t *vlm, char *file )
1589 while( *pf != '\0' )
1591 vlm_message_t *message = NULL;
1594 while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
1599 if( pf[i_end] == '\r' || pf[i_end] == '\n' )
1603 if( pf[i_end] == '\n' ) i_end++;
1606 if( *pf && ExecuteCommand( vlm, pf, &message ) )
1610 if( message->psz_value )
1611 msg_Err( vlm, "Load error on line %d: %s: %s",
1612 i_line, message->psz_name, message->psz_value );
1613 vlm_MessageDelete( message );
1617 if( message ) vlm_MessageDelete( message );
1626 static char *Save( vlm_t *vlm )
1629 char psz_header[] = "\n"
1630 "# VLC media player VLM command batch\n"
1631 "# http://www.videolan.org/vlc/\n\n" ;
1634 int i_length = strlen( psz_header );
1636 for( i = 0; i < vlm->i_media; i++ )
1638 vlm_media_sys_t *media = vlm->media[i];
1639 vlm_media_t *p_cfg = &media->cfg;
1642 i_length += strlen( "new * vod " ) + strlen(p_cfg->psz_name);
1644 i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
1646 if( p_cfg->b_enabled == true )
1647 i_length += strlen( "enabled" );
1649 i_length += strlen( "disabled" );
1651 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == true )
1652 i_length += strlen( " loop\n" );
1654 i_length += strlen( "\n" );
1656 for( j = 0; j < p_cfg->i_input; j++ )
1657 i_length += strlen( "setup * input \"\"\n" ) + strlen( p_cfg->psz_name ) + strlen( p_cfg->ppsz_input[j] );
1659 if( p_cfg->psz_output != NULL )
1660 i_length += strlen( "setup * output \n" ) + strlen(p_cfg->psz_name) + strlen(p_cfg->psz_output);
1662 for( j = 0; j < p_cfg->i_option; j++ )
1663 i_length += strlen("setup * option \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->ppsz_option[j]);
1665 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1666 i_length += strlen("setup * mux \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->vod.psz_mux);
1669 for( i = 0; i < vlm->i_schedule; i++ )
1671 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1673 i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
1675 if( schedule->b_enabled == true )
1677 i_length += strlen( "date //-:: enabled\n" ) + 14;
1681 i_length += strlen( "date //-:: disabled\n" ) + 14;
1685 if( schedule->i_period != 0 )
1687 i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
1688 strlen( "period //-::\n" ) + 14;
1691 if( schedule->i_repeat >= 0 )
1695 sprintf( buffer, "%d", schedule->i_repeat );
1696 i_length += strlen( "setup repeat \n" ) +
1697 strlen( schedule->psz_name ) + strlen( buffer );
1704 for( j = 0; j < schedule->i_command; j++ )
1706 i_length += strlen( "setup append \n" ) +
1707 strlen( schedule->psz_name ) + strlen( schedule->command[j] );
1712 /* Don't forget the '\0' */
1714 /* now we have the length of save */
1716 p = save = malloc( i_length );
1717 if( !save ) return NULL;
1720 p += sprintf( p, "%s", psz_header );
1722 /* finally we can write in it */
1723 for( i = 0; i < vlm->i_media; i++ )
1725 vlm_media_sys_t *media = vlm->media[i];
1726 vlm_media_t *p_cfg = &media->cfg;
1729 p += sprintf( p, "new %s vod ", p_cfg->psz_name );
1731 p += sprintf( p, "new %s broadcast ", p_cfg->psz_name );
1733 if( p_cfg->b_enabled )
1734 p += sprintf( p, "enabled" );
1736 p += sprintf( p, "disabled" );
1738 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
1739 p += sprintf( p, " loop\n" );
1741 p += sprintf( p, "\n" );
1743 for( j = 0; j < p_cfg->i_input; j++ )
1744 p += sprintf( p, "setup %s input \"%s\"\n", p_cfg->psz_name, p_cfg->ppsz_input[j] );
1746 if( p_cfg->psz_output )
1747 p += sprintf( p, "setup %s output %s\n", p_cfg->psz_name, p_cfg->psz_output );
1749 for( j = 0; j < p_cfg->i_option; j++ )
1750 p += sprintf( p, "setup %s option %s\n", p_cfg->psz_name, p_cfg->ppsz_option[j] );
1752 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1753 p += sprintf( p, "setup %s mux %s\n", p_cfg->psz_name, p_cfg->vod.psz_mux );
1756 /* and now, the schedule scripts */
1757 for( i = 0; i < vlm->i_schedule; i++ )
1759 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1761 time_t i_time = (time_t) ( schedule->i_date / 1000000 );
1763 localtime_r( &i_time, &date);
1764 p += sprintf( p, "new %s schedule ", schedule->psz_name);
1766 if( schedule->b_enabled == true )
1768 p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
1769 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1770 date.tm_hour, date.tm_min, date.tm_sec );
1774 p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
1775 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1776 date.tm_hour, date.tm_min, date.tm_sec);
1779 if( schedule->i_period != 0 )
1781 p += sprintf( p, "setup %s ", schedule->psz_name );
1783 i_time = (time_t) ( schedule->i_period / 1000000 );
1785 date.tm_sec = (int)( i_time % 60 );
1786 i_time = i_time / 60;
1787 date.tm_min = (int)( i_time % 60 );
1788 i_time = i_time / 60;
1789 date.tm_hour = (int)( i_time % 24 );
1790 i_time = i_time / 24;
1791 date.tm_mday = (int)( i_time % 30 );
1792 i_time = i_time / 30;
1793 /* okay, okay, months are not always 30 days long */
1794 date.tm_mon = (int)( i_time % 12 );
1795 i_time = i_time / 12;
1796 date.tm_year = (int)i_time;
1798 p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
1799 date.tm_year, date.tm_mon, date.tm_mday,
1800 date.tm_hour, date.tm_min, date.tm_sec);
1803 if( schedule->i_repeat >= 0 )
1805 p += sprintf( p, "setup %s repeat %d\n",
1806 schedule->psz_name, schedule->i_repeat );
1810 p += sprintf( p, "\n" );
1813 for( j = 0; j < schedule->i_command; j++ )
1815 p += sprintf( p, "setup %s append %s\n",
1816 schedule->psz_name, schedule->command[j] );
1824 #endif /* ENABLE_VLM */