Example #1
0
int		env_builtin(t_parser *parser)
{
	int			i;
	t_node_cmd	*node;

	i = 1;
	node = (t_node_cmd *)parser->data;
	if (node->cmd[i] && ft_strcmp(node->cmd[i], "--help") == 0)
	{
		print_env_usage(node);
		return (SUCCESS);
	}
	while (node->cmd[i] && is_env_opt(node->cmd[i]))
		if (handle_env_opt(node, &i) < 0)
		{
			print_env_usage(node);
			return (FAILURE);
		}
	if (node->cmd[i] && ft_strequ(node->cmd[i], "--"))
		i++;
	if (node->cmd[i])
	{
		node->cmd = update_cmd(node->cmd, i);
		return (exec_fork(parser));
	}
	print_env(node, node->env);
	return (SUCCESS);
}
Example #2
0
/*
** Do an update to version vid.
**
** Start an undo session but do not terminate it.  Do not autosync.
*/
int update_to(int vid) {
    int savedArgc;
    char **savedArgv;
    char *newArgv[3];
    newArgv[0] = g.argv[0];
    newArgv[1] = "update";
    newArgv[2] = 0;
    savedArgv = g.argv;
    savedArgc = g.argc;
    g.argc = 2;
    g.argv = newArgv;
    internalUpdate = vid;
    internalConflictCnt = 0;
    update_cmd();
    g.argc = savedArgc;
    g.argv = savedArgv;
    return internalConflictCnt;
}
Example #3
0
/* Update the command history, then create a new gtp command
 * for all slaves. The slave lock is held upon entry and
 * upon return, so the command will actually be sent when the
 * lock is released. cmd is a single word; args has all
 * arguments and is empty or has a trailing \n */
void
new_cmd(struct board *b, char *cmd, char *args)
{
	// Clear the history when a new game starts:
	if (!gtp_cmd || is_gamestart(cmd)) {
		gtp_cmd = gtp_cmds;
		memset(history, 0, sizeof(history));
	} else {
		/* Preserve command history for new slaves.
		 * To indicate that the slave should only reply to
		 * the last command we force the id of previous
		 * commands to be just the move number. */
		int id = prevent_reply(atoi(gtp_cmd));
		int len = strspn(gtp_cmd, "0123456789");
		char buf[32];
		snprintf(buf, sizeof(buf), "%0*d", len, id);
		memcpy(gtp_cmd, buf, len);

		gtp_cmd += strlen(gtp_cmd);
	}

	// Let the slave threads send the new gtp command:
	update_cmd(b, cmd, args, true);
}
Example #4
0
void input_command(){
  int ch;
  unsigned int i, current = hist_last+1;

  for(i = 0; i<CMD_SIZE; i++) command[i] = '\0';

  command[0] = ':';
  command[1] = '\0';
  cursor = 1;
  update_cmd();

  while((ch = w_getch()) != 10){
    if(ch == 127){ /* backspace */
      i = cursor-1;
      while(command[i]){
        command[i] = command[i+1];
        i++;
      }
      cursor--;
    } else if(ch == KEY_DC){ /* delete */
      i = cursor;
      while(command[i]){
        command[i] = command[i+1];
        i++;
      }
    } else if(ch == KEY_UP){  
      if(current!=hist_first){
        current = (current-1)%CMD_HIST;
        strcpy(command, command_history[current]);
        cursor = strlen(command);
      }
    } else if(ch == KEY_DOWN){
      if(current<hist_last){
        current = (current+1)%CMD_HIST;
        strcpy(command, command_history[current]);
        cursor = strlen(command);
      } else{
        command[1] = '\0';
        cursor = 1;
        if(current == hist_last) current = (current+1)%CMD_HIST;
      }
    }else if(ch == KEY_LEFT){
      cursor--;
    } else if(ch == KEY_RIGHT){
      if(command[cursor]) cursor++;
    } else{
      i = strlen(command)+1; 
      while(i>cursor){
        command[i] = command[i-1];
        i--;
      }
      command[cursor++] = ch;
    }
 
    update_ui();
    d_print("%d, %d\n", hist_first, current);
    update_cmd(); 
    if(cursor==0) break;
  }

  if(strlen(command)>1){ 
    hist_last = (hist_last+1)%CMD_HIST;
    /*if((hist_last+1)%CMD_HIST == hist_first) hist_first = (hist_first+1)%CMD_HIST;*/
    strcpy(command_history[hist_last], command);
    run_command();
  }
}