예제 #1
0
void command_delete(int argc, char *argv, nodotrie *root){
    if ( root == NULL ) {
        printf("El programa ha cerrado de forma inesperada.\n");
        exit(1);
    }
    
    if (argc == 1){
        printf("Error al usar insertar, faltan argumentos.\n");
        return;
    }
    
    
    if (isValid(argv) == 0){
        printf("No se ha agregado la palabra. Esta contiene caracteres no validos.\n");
        return;
    }
    
    if (command_search(argc, argv, root,  0) != 1) {
        printf("La palabra que desea eliminar no existe\n");
        return;
    }
    
    trie_del(root, argv);

}
예제 #2
0
파일: normal.c 프로젝트: fanglingsu/vimb
static VbResult normal_search(Client *c, const NormalCmdInfo *info)
{
    int count = (info->count > 0) ? info->count : 1;

    command_search(c, &((Arg){info->key == 'n' ? count : -count, NULL}), FALSE);

    return RESULT_COMPLETE;
}
예제 #3
0
파일: cmd.c 프로젝트: 453483289/rop-tool
static void help_cmd_info(const char *cmd) {
  int cmd_id;

  if((cmd_id = command_search(cmd)) == -1) {
    R_UTILS_ERR("%s isn't a valid command, see the help.", cmd);
  } else if(cmd_id == -2) {
    R_UTILS_ERR("Too much commands match %s, be more precise.", cmd);
  }

  command_help(cmd_id);
  exit(EXIT_FAILURE);
}
예제 #4
0
파일: cmd.c 프로젝트: 453483289/rop-tool
void command_execute(const char *cmd, int argc, char **argv) {
  int cmd_id;

  assert(cmd != NULL && argv != NULL);
  assert(argc > 0);

  if((cmd_id = command_search(cmd)) == -1) {
    R_UTILS_ERR("%s isn't a valid command, see the help.", cmd);
  } else if(cmd_id == -2) {
    printf("Too much commands match \"%s\"\n", cmd);
    printf("Did you mean : ");
    command_print_matchs(cmd);
    printf(" ?!\n");
    exit(EXIT_FAILURE);
  }

  command_list[cmd_id].cmd(argc, argv);
}
예제 #5
0
파일: normal.c 프로젝트: fanglingsu/vimb
static VbResult normal_search_selection(Client *c, const NormalCmdInfo *info)
{
    int count;
    char *query;

    /* there is no function to get the selected text so we copy current
     * selection to clipboard */
    webkit_web_view_execute_editing_command(c->webview, WEBKIT_EDITING_COMMAND_COPY);
    query = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
    if (!query) {
        return RESULT_ERROR;
    }
    count = (info->count > 0) ? info->count : 1;

    command_search(c, &((Arg){info->key == '*' ? count : -count, query}), TRUE);
    g_free(query);

    return RESULT_COMPLETE;
}
예제 #6
0
/*
 * register a command into command_list
 * return true is successed, otherwise is not.
 */
bool_t command_register(struct command_t * cmd)
{
	struct command_list * list;

	list = malloc(sizeof(struct command_list));
	if(!list || !cmd)
	{
		free(list);
		return FALSE;
	}

	if(!cmd->name || !cmd->func || command_search(cmd->name))
	{
		free(list);
		return FALSE;
	}

	list->cmd = cmd;
	list_add(&list->entry, &command_list->entry);

	return TRUE;
}
예제 #7
0
파일: normal.c 프로젝트: fanglingsu/vimb
static VbResult normal_clear_input(Client *c, const NormalCmdInfo *info)
{
    /* If an element requested the fullscreen - the <esc> shoudl cause to
     * leave this fullscreen mode. */
    if (c->state.is_fullscreen) {
        /* Unset the processed_key to indicate that the <esc> was not handled
         * by us and letting the event bubble up. So that webkit handles the
         * key for us to leave the fullscreen mode. */
        c->state.processed_key = FALSE;
        return RESULT_COMPLETE;
    }

    gtk_widget_grab_focus(GTK_WIDGET(c->webview));

    /* Clear the inputbox and change the style to normal to reset also the
     * possible colored error background. */
    vb_echo(c, MSG_NORMAL, FALSE, "");

    /* Unset search highlightning. */
    command_search(c, &((Arg){0, NULL}), FALSE);

    return RESULT_COMPLETE;
}
예제 #8
0
/* run_client:
 * This is the function which each spawned p_thread will
 * run. Parses commands from clients and responds to 
 * client accordingly.
 */
void *run_client(void *args){
    struct workerArgs *wa;
    wa = (struct workerArgs*) args;

    pthread_detach(pthread_self());

    pthread_mutex_lock(&lock);
    num_pthreads++;
    pthread_mutex_unlock(&lock);

    // setting total amount of chars buf can parse
    // at a time. (Command max len is handled in break_commands)
    int bufLen = 6000;
    // setting total amount of commands which can be parsed at
    // at time.
    int commandBufLen = 250;
    int nbytes;
    int n;
    char inputBuf[bufLen];
    char buildBuf[bufLen];
    char **commandList;
    int buildLen = 0;
    memset(inputBuf, 0, bufLen);
    memset(buildBuf, 0, bufLen);
    commandList = (char **) malloc(COMMANDNUM*sizeof(char **));
    command_init(commandList);
    userInfo * info;
    info = (userInfo *) malloc(sizeof(userInfo));
    memset(info, 0, sizeof(userInfo));
    int clientSocket = wa->socket;
    char * clientHost = wa->clientHost;

    int hostLen = strlen(clientHost);
    if (hostLen > MAXHOST)
      hostLen = MAXHOST;
    memcpy(info->host, clientHost, hostLen);
    info->host[hostLen] = '\0';
    info->socket = clientSocket;

    list_t * userList = wa->userList;
    list_t * chanList = wa->chanList;
    struct serverInfo * servData = wa->servData;

    // collect input from client until disconnect
    // build input buffer until buffer terminates with "\r\n"
    while( (nbytes = recv(clientSocket, inputBuf, bufLen, 0)) )
    {
      if (nbytes + buildLen > bufLen)
        nbytes = bufLen - buildLen;
      memcpy(buildBuf+buildLen, inputBuf, nbytes);
      buildLen = buildLen + nbytes;
      // handles case if string is too long for buffer
      if ((buildBuf[bufLen-1]) && (buildBuf[bufLen-1]!='\n'))
      {
        buildBuf[bufLen-2]='\r';
        buildBuf[bufLen-1]='\n';
      }
      // if input buffer ends with \r\n, parse buffer and run commands
      if (buildBuf[buildLen-1]=='\n' && buildBuf[buildLen-2]=='\r')
      {
        int maxArgs = 15;
        char ** argList;

        argList = (char **) malloc(maxArgs*sizeof(char *));
	      memset(argList, 0, sizeof(argList));
        char ** cmndList;
        cmndList = (char **) malloc(commandBufLen*sizeof(char *));
	      memset(cmndList, 0, sizeof(cmndList));

        // determine how many commands are stored in buffer
        int numCmnds = break_commands(buildBuf, buildLen, cmndList);
        int command;

        for (n=0; n<numCmnds; n++)
        {
          int argNum = parser(cmndList[n], strlen(cmndList[n]), argList);
          command = command_search(argList[0], commandList);
          if (command == -1)
          { 
            replyPackage reply;
            memset(&reply, 0, sizeof(replyPackage));
            memcpy(reply.serverName, servData->serverHost, strlen(servData->serverHost));
            if (info->nickname[0])
              memcpy(reply.nickname, info->nickname, strlen(info->nickname));
            else
              memcpy(reply.nickname, "*", 1);
            memcpy(reply.responseCode, ERR_UNKNOWNCOMMAND, REPLYCODELEN);
            reply.numArgs = 1;
            int argLen = strlen(argList[0]) + reply.numArgs;
            snprintf(reply.args, argLen, "%s", argList[0]);
            reply.args[argLen] = '\0';
            send_response(clientSocket, &reply);
  
          }
          else
            run_command(command, argList, argNum, info, userList, chanList, servData);
        }
        free(argList);
        free(cmndList);
        buildLen = 0;
        memset(inputBuf, 0, bufLen);
        memset(buildBuf, 0, bufLen);
      }
    }
    free(wa);

    pthread_mutex_lock(&lock);
    num_pthreads--;
    pthread_mutex_unlock(&lock);
    pthread_exit(NULL);
}
예제 #9
0
파일: exec.c 프로젝트: rharter/xboot-clone
/*
 * exec the command line
 */
void exec_cmdline(const char * cmdline)
{
    struct command * cmd;
    int n;
    char **args;
    char *p, *buf, *pos;
    int ret;

    if(!cmdline)
    	return;

    p = buf = malloc(strlen(cmdline) + 2);
    if(!p)
    	return;

    strcpy(p, cmdline);
    strcat(p, " ");

    while(*p)
    {
    	if(parser(p, &n, &args, &pos))
    	{
    		if(n > 0)
    		{
    			cmd = command_search(args[0]);
    			if(cmd)
    			{
    				ret = cmd->func(n, args);
    				if(ret != 0)
    				{
    					/*
    					 * if having other command which waitting be exec, abort.
    					 */
    			    	if(pos)
    			    	{
    			    		printk(" when exec \'%s\' command return an error code (%ld).\r\n", args[0], ret);
    			    		free(args[0]);
    			    		free(args);
    			    		break;
    			    	}
    				}
    			}
    			else
    			{
    				printk(" could not found \'%s\' command \r\n", args[0]);
    				printk(" if you want to kown available commands, type 'help'.\r\n");

					/*
					 * if having other command which waitting be exec, abort.
					 */
			    	if(pos)
			    	{
			    		free(args[0]);
			    		free(args);
			    		break;
			    	}
    			}
    		}

    		free(args[0]);
    		free(args);
    	}

    	if(!pos)
    		*p = 0;
    	else
    		p = pos;
    }

    free(buf);
}
예제 #10
0
파일: normal.c 프로젝트: fanglingsu/vimb
/**
 * Called when the normal mode is left.
 */
void normal_leave(Client *c)
{
    command_search(c, &((Arg){0, NULL}), FALSE);
}