Esempio n. 1
0
/*************************************************************
 *                      ReadRingName                         *
 * Read startstop's configfile as far as the first ring name *
 *************************************************************/
void ReadRingName( char *ringname, char *configFile )
{
	int        nfiles;
	char      *com, *str;
	char       configfile[20];

	strcpy( configfile, "" );

	nfiles = k_open( configFile );
	if ( nfiles == 0 )
	{
		printf( "status: Error opening file <%s>. Exiting.\n",
				configFile );
		exit( -1 );
	}

	/* Process Ring commands from startstop's command file
	 ***************************************************/
	while(nfiles > 0)          /* While there are command files open */
	{
		while(k_rd())         /* Read next line from active file  */
		{
			com = k_str();    /* Get the first token from line */

			/* Ignore blank lines & comments
			 *****************************/
			if( !com )           continue;
			if( com[0] == '#' )  continue;

			/* Process only 1st Ring command
			 *****************************/
			if( k_its( "Ring" ) )
			{
				str = k_str();
				strcpy( ringname, str );
				break;
			}

			/* See if there were any errors processing this command
			 ****************************************************/
			if( k_err() )
			{
				printf( "status: Bad <%s> command in <%s>. Exiting.\n",
						com, configfile );
				return;
			}
		}
		nfiles = k_close();
	}

	return;
}
Esempio n. 2
0
/*
 **** k_val() Return next token as a double real
 */
double k_val( void )
{
        double val;
        char *s;

        s = k_str();
        if(!s) {
                com.ierr = -1;
                return(0.0);
        }
        val = atof(s);
        return(val);
}
Esempio n. 3
0
/*
 * k_long : Return next token as a long integer.
 */
long k_long( void )
{
        long lval;
        char *s;

        s = k_str();
        if(!s) {
                com.ierr = -1;
                return(0L);
        }
        lval = atol(s);
        if(lval == 0 && *s != '0') {
                com.ierr = -2;
               return(0L);
        }
        return(lval);
}
Esempio n. 4
0
/*
 * k_int : Parce next token as integer.
 */
int k_int( void )
{
        int ival;
        char *s;

        s = k_str();
        if(!s) {
                com.ierr = -1;
                return(0);
        }
        ival = atoi(s);
        if(ival == 0 && *s != '0') {
                com.ierr = -2;
                return(0);
        }
        return(ival);
}
/******************************************************************************
 *  orb2eworm_config() processes command file(s) using kom.c functions;        *
 *                    exits if any errors are encountered.                    *
 ******************************************************************************/
void 
orb2eworm_config( char *configfile )
{
	int	ncommand; /* # of required commands you expect to process */
	char	init[10]; /* init flags, one byte for each required command */
	int	nmiss;	/* number of required commands that were missed */
	char	*com;
	char	*str;
	int	nfiles;
	int	success;
	int	i;

	/*
	 * Set to zero one init flag for each required command 
	 */
	ncommand = 7;
	for ( i = 0; i < ncommand; i++ )
		init[i] = 0;
	nLogo = 0;

	/*
	 * Open the main configuration file 
	 */
	nfiles = k_open( configfile );
	if ( nfiles == 0 ) 
	{
		fprintf( stderr,
		   "orb2eworm: Error opening command file <%s>; exiting!\n",
			configfile );
		exit( -1 );
	}
	/*
	 * Process all command files 
	 */
	while ( nfiles > 0 ) 
	{	/* While there are command files open */
		while ( k_rd() ) 
		{/* Read next line from active file  */
			com = k_str();	/* Get the first token from line */

			/*
			 * Ignore blank lines & comments 
			 */
			if ( !com )
				continue;
			if ( com[0] == '#' )
				continue;

			/*
			 * Open a nested configuration file 
			 */
			if ( com[0] == '@' ) 
			{
				success = nfiles + 1;
				nfiles = k_open( &com[1] );
				if ( nfiles != success ) 
				{
					fprintf( stderr,
					"orb2eworm: Error opening command " );
					fprintf( stderr,
					"file <%s>; exiting!\n", &com[1] );
					exit( -1 );
				}
				continue;
			}
			/*
			 * Process anything else as a command 
			 */
			 /* 0 */ if ( k_its( "LogFile" ) ) 
			 {
				LogSwitch = k_int();
				init[0] = 1;
			}
			 /* 1 */ 
			else if ( k_its( "MyModuleId" ) ) 
			{
				str = k_str();
				if ( str )
					strcpy( MyModName, str );
				init[1] = 1;
			}
			 /* 2 */ 
			else if ( k_its( "RingName" ) ) 
			{
				str = k_str();
				if ( str )
					strcpy( RingName, str );
				init[2] = 1;
			}
			 /* 3 */ 
			else if ( k_its( "HeartBeatInterval" ) ) 
			{
				HeartBeatInterval = k_long();
				init[3] = 1;
			}
			 /* 4 */ 
			else if ( k_its( "OrbName" ) ) 
			{
				str = k_str();
				if ( str )
					strcpy( OrbName, str );
				init[4] = 1;
			}
			 /* 5 */ 
			else if ( k_its( "ChannelSelect" ) ) 
			{
				str = k_str();
				if ( str )
					strcpy( ChannelSelect, str );
				init[5] = 1;
			}
			 /* 6 */ 
			else if ( k_its( "ChannelReject" ) ) 
			{
				str = k_str();
				if ( str )
					strcpy( ChannelReject, str );
				init[6] = 1;
			}
			/*
			 * Unknown command 
			 */
			else 
			{
				fprintf( stderr,
				   "orb2eworm: <%s> Unknown command in <%s>.\n",
				   com, configfile );
				continue;
			}

			/*
			 * See if there were any errors processing the
			 * command 
			 */
			if ( k_err() ) 
			{
				fprintf( stderr,
				"orb2eworm: Bad <%s> command in <%s>; exiting!\n",
					com, configfile );
				exit( -1 );
			}
		}
		nfiles = k_close();
	}

	/*
	 * After all files are closed, check init flags for missed commands 
	 */
	nmiss = 0;
	for ( i = 0; i < ncommand; i++ )
		if ( !init[i] )
			nmiss++;
	if ( nmiss ) 
	{
		fprintf( stderr, "orb2eworm: ERROR, no " );
		if ( !init[0] ) fprintf( stderr, "<LogFile> " );
		if ( !init[1] ) fprintf( stderr, "<MyModuleId> " );
		if ( !init[2] ) fprintf( stderr, "<RingName> " );
		if ( !init[3] ) fprintf( stderr, "<HeartBeatInterval> " );
		if ( !init[4] ) fprintf( stderr, "<OrbName> " );
		if ( !init[5] ) fprintf( stderr, "<ChannelSelect> " );
		if ( !init[6] ) fprintf( stderr, "<ChannelReject> " );
		fprintf( stderr, "command(s) in <%s>; exiting!\n", configfile );
		exit( -1 );
	}
	return;
}