Пример #1
0
/*
 * gets the next option. returns the index on data->table if the option
 *
 * Modifies internal counters (data->pt and data->i).
 */
static int
getNextOption(struct global *data)
{	int nRet;

	assert( data );
	data->arg = NULL;

	if( data->pt )
		nRet = do_short_opt( data );
	else if( !current_arg(data) )
		nRet = RET_END;
	else if( force_end( current_arg(data) ))
	{	data->i++;	/* the user don't want the "--" stuff */
		nRet = RET_END;
	}
	else if( !is_option( current_arg(data) ))
		nRet = RET_END;
	else if( is_long_opt( current_arg(data)  ))
		nRet = do_long_option(data);
	else
	{	data->pt = current_arg(data) + 1;
		nRet = do_short_opt( data );
	}

	return nRet;
}
Пример #2
0
/*
 * handle the long options.
 * returs <0 on error.  
 * TODO: stinks
 */
static int
do_long_option ( struct global *data )
{	char *q,*arg ;
	int n;
	assert( data );

	arg =  current_arg(data)+2;
	data->i++;

	if( (q=strchr( arg , '='  )) )  /* separate  --argument=something */
	{	 q++;
		*(q-1)=0;
		if(!*q)
			q=NULL;
	}
	n = findLongOption ( data->table , arg);
	
	if( n<0 )
	{	n =  RET_UNKNOW;
		report(data->flags,_("unknow long option `%s'"),arg);
	}
	else if( has_one_arg( data->table[n] ) )
	{	if( q )		/* inline option */
			data->arg = q;
		else if( !current_arg(data) || force_end( current_arg(data) ) ||
 	( !is_number(current_arg(data)) && is_option(current_arg(data)) )  ) 
	{	n = RET_ENOUGH;
			report(data->flags,_("not enough parameters for `%s'"),
				arg);
		}
		else
		{	data->arg = current_arg(data);
			data->i++;
		}
	}
	else if( data->table[n].flags!=0)
		assert( 0 );

	return n;
}
Пример #3
0
/*
 * gets aditionals parameters of an option if any.
 * <0 error. else the position in the table of the command
 */
static int
do_short_opt( struct global *data )
{	int c;
	int n;
	assert( data );

	c = *(data->pt++);
	if( !*data->pt )	/* we finish this arg. go to the next */
	{	data->pt = NULL;
		data->i++;
	}
	n = findShortOption( data->table,c);

	if( n < 0 )
	{	n = RET_UNKNOW;
		report(data->flags,_("unknow option '%c'"),c);
	}
	else if( has_one_arg( data->table[n] ) )
	{	if( data->pt )	/* inlined argument */
		{	data->arg = data->pt;
			data->pt = NULL;
			data->i++;
		}
		else if ( !current_arg(data) || force_end(current_arg(data)) ||
	  ( !is_number(current_arg(data)) && is_option(current_arg(data)) )  )
		{	n = RET_ENOUGH;
			report(data->flags,_("not enough parameters for `%c'"),
				c);
		}
		else
		{	data->arg = current_arg(data);
			data->i++;
		}
	}

	return n;
}
Пример #4
0
	void check_end(int current_in_progress) {
		if (current_in_progress == 0) {
			force_end();
		}
	}