Beispiel #1
0
int insert_command( char * path , cmd_node_t * head , cmd_t * comm )
{
   if( !comm  || ! path || ! head ) 
      error_ret("null arg",-1);


   char * nextstr;
   if( !(nextstr = strchr( path + 1 , '/' )) ) { /* add here */
      head->opts = add_comm_to_list( head->opts , comm );
   }
   else  /* it's a sub-command */
   {
      *nextstr = 0;
      cmd_node_t * nextnode ;

      /* we should have the requested child */
      if(!(nextnode = find_command( head->opts , path + 1 )))
         error_ret("request sub-command, but none available",-1);

      *nextstr = '/';
      if( insert_command( nextstr ,  nextnode , comm ) < 0 ) 
         error_ret("recursive badness",-1);
   }

   return(0);
}
Beispiel #2
0
static void cmd_done() {
	CMD_DATA* n;

	CREATE(n, CMD_DATA, 1);
	memcpy(n, &build, sizeof(CMD_DATA));

	insert_command(n, n->language);
}
Beispiel #3
0
/**
 * \brief Insert a command in the system stack.
 * \param delay Delay before the execution of the command.
 * \param cmd Command to execute.
 */
LIBLOCAL TuxDrvError
tux_cmd_parser_insert_sys_command(float delay, delay_cmd_t *cmd)
{
    TuxDrvError ret;

#ifdef USE_MUTEX
    mutex_lock(__stack_mutex);
#endif

    ret = insert_command(delay, cmd, &sys_cmd_stack);

#ifdef USE_MUTEX
    mutex_unlock(__stack_mutex);
#endif
    return ret;
}
Beispiel #4
0
/**
 * \brief Insert a command in the user stack.
 * \param delay Delay before the execution of the command.
 * \param cmd Command to execute.
 */
LIBLOCAL TuxDrvError
tux_cmd_parser_insert_user_command(float delay, const char *cmd_str)
{
    TuxDrvError ret;
    delay_cmd_t cmd;

#ifdef USE_MUTEX
    mutex_lock(__stack_mutex);
#endif
    ret = parse_command(cmd_str, &cmd);
    if (ret == E_TUXDRV_NOERROR)
    {
        ret = insert_command(delay, &cmd, &user_cmd_stack);
    }

#ifdef USE_MUTEX
    mutex_unlock(__stack_mutex);
#endif
    return ret;
}
Beispiel #5
0
int register_command( char * path , cmd_t * comm ){

   if(!path || !is_good_path(path) )
      error_ret("bad arg",-1);

   cmd_node_t * head = command_head.opts;
   if( ! head ) {
      /* path should be "/" */
      head = calloc( 1 , sizeof(*head) );
      head->cmd = comm;
      command_head.opts = head;
   } else {
      char * npath = strdup(path);
      if( insert_command( npath , &command_head , comm ) < 0 ) {
         free(npath);
         error_ret("can't insert",-1);
      }
      free(npath);
   }
   return(0);
}
Beispiel #6
0
//return false if there was a ( or ) in the command
bool Subshell::parse_pointers()
{
	bool check_arg = false;
	string temp;
	string c = command_line;
	string for_connectors = c;
	for (unsigned i = 0; i < c.size(); i++)
	{
		if (c.at(i) == '(')
		{
			stack<char> left;
			stack<char> right;
			temp = "";
			i++;
			left.push('(');
			while (i < c.size())
			{
				if (c.at(i) == '(') left.push('(');
				else if (c.at(i) == ')') right.push(')');
				if (left.size() >= right.size() && !left.empty() && !right.empty())
				{
					bool more_p = pop_stack(left, right);
					if (more_p) break;
					else check_arg = true;
				}
				temp = temp + c.at(i);
				i++;
			}
			if (!empty_stack(left, right))
			{
				cout << "Error: No matching '(' for ')'" << endl;
				return false;
			}
			if (empty_command(temp))
			{
				cout << "Error: Unexpected '(' or ')'" << endl;
				return false;
			}
			bool continue_on = true;
			if (check_arg && arg_error(temp))
			{
				temp = "QuynhNguyenIsAwesome";
				continue_on = false;
			}
			insert_command(temp);
			if (continue_on)
			{
				int start = for_connectors.find(temp);
				--start;
				int end = temp.size() + 2;
				for_connectors.replace(start, end, "C");
				temp = "";
			}
		}
		else if (c.at(i) == ';')
		{
			if (empty_command(temp))
			{
				temp = "";
			}
			else
			{
				insert_command(temp);
				if (check_paren_in_commands(temp) == false) return false;
				temp = "";
			}
		}
		else if (c.at(i) == '|')
		{
			if (empty_command(temp))
			{
				temp = "";
			}
			else
			{
				insert_command(temp);
				if (check_paren_in_commands(temp) == false) return false;
				temp = "";
			}
			i++;
		}
		else if (c.at(i) == '&')
		{
			if (empty_command(temp))
			{
				temp = "";
			}
			else
			{
				insert_command(temp);
				if (check_paren_in_commands(temp) == false) return false;
				temp = "";
			}
			i++;
		}
		else temp = temp + c.at(i);
	}
	if (!empty_command(temp))
	{
		insert_command(temp);
		if (check_paren_in_commands(temp) == false) return false;
	}
	command_line = for_connectors;
	return true;

}