* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
+#include "defs.h"
+
#include <errno.h> /* errno */
#include <stdio.h> /* FILE */
#include <stdlib.h> /* strtod(), strtol() */
#include <string.h> /* strerror() */
-#include "threads.h"
#include "config.h"
#include "common.h"
+#include "threads.h"
#include "mtime.h"
#include "plugins.h"
/*
* Local prototypes
*/
-static int ParseCommandArguments ( char *psz_argv[INTF_MAX_ARGS], char *psz_cmd );
-static int CheckCommandArguments ( intf_arg_t argv[INTF_MAX_ARGS], int i_argc,
- char *psz_argv[INTF_MAX_ARGS], char *psz_format );
-static void ParseFormatString ( intf_arg_t format[INTF_MAX_ARGS], char *psz_format );
-static int ConvertArgument ( intf_arg_t *p_arg, int i_flags, char *psz_str );
+static int ParseCommandArguments ( char *psz_argv[INTF_MAX_ARGS],
+ char *psz_cmd );
+static int CheckCommandArguments ( intf_arg_t argv[INTF_MAX_ARGS],
+ int i_argc,
+ char *psz_argv[INTF_MAX_ARGS],
+ char *psz_format );
+static void ParseFormatString ( intf_arg_t format[INTF_MAX_ARGS],
+ char *psz_format );
+static int ConvertArgument ( intf_arg_t *p_arg, int i_flags,
+ char *psz_str );
/*****************************************************************************
* intf_ExecCommand: parse and execute a command
}
/* Check arguments validity */
- if( CheckCommandArguments( argv, i_argc, psz_argv, control_command[i_index].psz_format ) )
+ if( CheckCommandArguments( argv, i_argc, psz_argv,
+ control_command[i_index].psz_format ) )
{
- /* The given arguments does not match the format string. An error message has
- * already been displayed, so only the usage string is printed */
+ /* The given arguments does not match the format string. An error
+ * message has already been displayed, so only the usage string
+ * is printed */
intf_IntfMsg( "usage: %s", control_command[i_index].psz_usage );
return( INTF_USAGE_ERROR );
}
case INTF_CRITICAL_ERROR: /* critical error */
/* Print message, flush messages queue and exit. Note that this
- * error should be very rare since it does not even try to cancel other
- * threads... */
- intf_ErrMsg("critical error in command `%s'. Please report this error !\n", psz_argv[0] );
+ * error should be very rare since it does not even try to cancel
+ * other threads... */
+ intf_ErrMsg( "critical error in command `%s', "
+ "please report this error !\n", psz_argv[0] );
intf_FlushMsg();
exit( INTF_CRITICAL_ERROR );
break;
FILE * p_file; /* file */
char psz_line[INTF_MAX_CMD_SIZE]; /* line */
char * psz_index; /* index in string */
+ char * psz_vlcrc; /* full path to vlcrc */
int i_err; /* error indicator */
/* Open file */
i_err = 0;
- p_file = fopen( psz_filename, "r" );
+
+ if( !( psz_index = getenv("HOME") ) )
+ {
+ psz_index = "/";
+ }
+ psz_vlcrc = malloc( strlen( psz_index ) + 1 + strlen( psz_filename ) + 1 );
+ sprintf( psz_vlcrc, "%s/%s", psz_index, psz_filename );
+
+ p_file = fopen( psz_vlcrc, "r" );
if( p_file == NULL )
{
- intf_ErrMsg("warning: %s: %s\n", psz_filename, strerror(errno));
+ intf_DbgMsg("intf warning: %s: %s\n", psz_vlcrc, strerror(errno));
return( -1 );
}
if( psz_line[0] != '#' )
{
/* The final '\n' needs to be removed before execution */
- for( psz_index = psz_line; *psz_index && (*psz_index != '\n'); psz_index++ )
+ for( psz_index = psz_line;
+ *psz_index && (*psz_index != '\n');
+ psz_index++ )
{
;
}
}
if( !feof( p_file ) )
{
- intf_ErrMsg("error: %s: %s\n", psz_filename, strerror(errno));
+ intf_ErrMsg("error: %s: %s\n", psz_vlcrc, strerror(errno));
return( -1 );
}
/* Go through command until end has been reached or maximal number of
* arguments has been reached */
- for( psz_index = psz_cmd; *psz_index && (i_argc < INTF_MAX_ARGS); psz_index++ )
+ for( psz_index = psz_cmd;
+ *psz_index && (i_argc < INTF_MAX_ARGS);
+ psz_index++ )
{
/* Inside a block, end of blocks are marked by spaces */
if( b_block )
* can be modified.
*****************************************************************************/
static int CheckCommandArguments( intf_arg_t argv[INTF_MAX_ARGS], int i_argc,
- char *psz_argv[INTF_MAX_ARGS], char *psz_format )
+ char *psz_argv[INTF_MAX_ARGS],
+ char *psz_format )
{
intf_arg_t format[INTF_MAX_ARGS]; /* parsed format indicators */
int i_arg; /* argument index */
/* Test if argument can be taken as a named argument: try to find a
* '=' in the string */
- for( psz_index = psz_argv[i_arg]; *psz_index && ( *psz_index != '=' ); psz_index++ )
+ for( psz_index = psz_argv[i_arg];
+ *psz_index && ( *psz_index != '=' );
+ psz_index++ )
{
;
}
/* Current format string is named... compare start of two
* names. A local inline ntation of a strcmp is used since
* string isn't ended by '\0' but by '=' */
- for( psz_index = psz_argv[i_arg], psz_cmp_index = format[i_index].ps_name;
- (*psz_index == *psz_cmp_index) && (*psz_index != '=') && (*psz_cmp_index != '=');
+ for( psz_index = psz_argv[i_arg],
+ psz_cmp_index = format[i_index].ps_name;
+ (*psz_index == *psz_cmp_index) && (*psz_index != '=')
+ && (*psz_cmp_index != '=');
psz_index++, psz_cmp_index++ )
{
;
if( *psz_index == *psz_cmp_index ) /* the names match */
{
/* The argument is a named argument which name match the
- * named argument i_index. To be valid, the argument should
- * not have been already encountered and the type must
- * match. Before going further, the '=' is replaced by
- * a '\0'. */
+ * named argument i_index. To be valid, the argument
+ * should not have been already encountered and the type
+ * must match. Before going further, the '=' is replaced
+ * by a '\0'. */
*psz_index = '\0';
- /* Check unicity. If the argument has already been encountered,
- * print an error message and return. */
- if( format[i_index].i_flags & INTF_PRESENT_ARG )/* present */
+ /* Check unicity. If the argument has already been
+ * encountered, print an error message and return. */
+ if( format[i_index].i_flags & INTF_PRESENT_ARG )
{
- intf_IntfMsg("error: `%s' has already been encountered", psz_argv[i_arg] );
+ intf_IntfMsg( "error: `%s' has already been "
+ "encountered", psz_argv[i_arg] );
return( 1 );
}
/* Check type and store value */
psz_index++;
- if( ConvertArgument( &argv[i_arg], format[i_index].i_flags, psz_index ) )
+ if( ConvertArgument( &argv[i_arg],
+ format[i_index].i_flags, psz_index ) )
{
/* An error occured during conversion */
- intf_IntfMsg( "error: invalid type for `%s'", psz_index );
+ intf_IntfMsg( "error: invalid type for `%s'",
+ psz_index );
}
}
}
* be browsed starting from last position until the argument is
* found, an error occurs or the last format argument is
* reached */
- while( !b_found && (i_format < INTF_MAX_ARGS) && format[i_format].i_flags )
+ while( !b_found && (i_format < INTF_MAX_ARGS)
+ && format[i_format].i_flags )
{
/* Try to convert argument */
- if( !ConvertArgument( &argv[i_arg], format[i_format].i_flags, psz_argv[i_arg] ) )
+ if( !ConvertArgument( &argv[i_arg], format[i_format].i_flags,
+ psz_argv[i_arg] ) )
{
/* Matching format has been found */
b_found = 1;
format[i_format].i_flags |= INTF_PRESENT_ARG;
argv[i_arg].i_index = i_format;
- /* If argument is repeatable, dot not increase format counter */
+ /* If argument is repeatable, dot not increase format
+ * counter */
if( !(format[i_format].i_flags & INTF_REP_ARG) )
{
i_format++;
}
else
{
- /* Argument does not match format. This can be an error, or
- * just a missing optionnal parameter, or the end of a
+ /* Argument does not match format. This can be an error,
+ * or just a missing optionnal parameter, or the end of a
* repeated argument */
if( (format[i_format].i_flags & INTF_OPT_ARG)
|| (format[i_format].i_flags & INTF_PRESENT_ARG) )
{
/* The present format argument is mandatory and does
* not match the argument */
- intf_IntfMsg("error: missing argument before `%s'", psz_argv[i_arg] );
+ intf_IntfMsg( "error: missing argument before `%s'",
+ psz_argv[i_arg] );
return( 1 );
}
}
* return */
if( !b_found )
{
- intf_IntfMsg("error: `%s' does not match any argument", psz_argv[i_arg] );
+ intf_IntfMsg( "error: `%s' does not match any argument",
+ psz_argv[i_arg] );
return( 1 );
}
- intf_DbgMsg("argument flags=0x%x (index=%d) name=%s str=%s int=%d float=%f\n",
- argv[i_arg].i_flags,
- argv[i_arg].i_index,
- (argv[i_arg].i_flags & INTF_NAMED_ARG) ? argv[i_arg].ps_name : "NA",
- (argv[i_arg].i_flags & INTF_STR_ARG) ? argv[i_arg].psz_str : "NA",
- (argv[i_arg].i_flags & INTF_INT_ARG) ? argv[i_arg].i_num : 0,
- (argv[i_arg].i_flags & INTF_FLOAT_ARG) ? argv[i_arg].f_num : 0);
+ intf_DbgMsg(
+ "argument flags=0x%x (index=%d) name=%s str=%s int=%d float=%f\n",
+ argv[i_arg].i_flags, argv[i_arg].i_index,
+ (argv[i_arg].i_flags & INTF_NAMED_ARG) ? argv[i_arg].ps_name : "NA",
+ (argv[i_arg].i_flags & INTF_STR_ARG) ? argv[i_arg].psz_str : "NA",
+ (argv[i_arg].i_flags & INTF_INT_ARG) ? argv[i_arg].i_num : 0,
+ (argv[i_arg].i_flags & INTF_FLOAT_ARG) ? argv[i_arg].f_num : 0 );
}
/* Parse all remaining format specifier to verify they are all optionnal */
}
/*****************************************************************************
- * ParseFormatString: parse a format string (ok ?)
+ * ParseFormatString: parse a format string (ok ?)
*****************************************************************************
* This function read a format string, as specified in the control_command
* array, and fill a format array, to allow easier argument identification.
* Note that no memory is allocated by this function, but that, in a named
* argument, the name field does not end with a '\0' but with an '='.
* See command.h for format string specifications.
- * Note that this function is designed to be efficient, not to check everything
- * in a format string, which should be entered by a developper and therefore
- * should be correct (TRUST !).
+ * Note that this function is designed to be efficient, not to check
+ * everything in a format string, which should be entered by a developper
+ * and therefore should be correct (TRUST !).
*****************************************************************************/
static void ParseFormatString( intf_arg_t format[INTF_MAX_ARGS], char *psz_format )
{