Ejemplo n.º 1
0
int cmd_execute( char * line ) {
  register int i;
  cmd_t *command;
  char *word;

  /* Isolate the command word. */
  i = 0;
  while (line[i] && whitespace (line[i]))
    i++;
  word = line + i;

  while (line[i] && !whitespace (line[i]))
    i++;

  if (line[i])
    line[i++] = '\0';

  command = cmd_find( word );
  
  if ( ! command ) {
    fprintf (stderr, "*** error: unknown command '%s' \n", word );
    return -1;
  }

  /* Get argument to command, if any. */
  while (whitespace (line[i]))
    i++;

  word = line + i;

  /* Call the function. */
  return ((*(command->func)) (word));
}
Ejemplo n.º 2
0
static int cmd_proc(void)
{
    sys_sh_proc_t cmd_func;

    cmd_func = cmd_find(cmd_arg[0]);
    
    return cmd_func(cmd_arg_num, cmd_arg);
}
Ejemplo n.º 3
0
void cmd_alias(const char *name, const char *cmd_name, const char *subcmd_name)
{
	struct command *cmd, *alias;
	assert(strchr(name, ' ') == NULL); // not supported
	assert(cmd = cmd_find(cmd_name, command_list));
	assert(!subcmd_name || (cmd->subcommands && (cmd = cmd_find(subcmd_name, cmd->subcommands))));

	alias = malloc(sizeof(struct command));
	memcpy(alias, cmd, sizeof(struct command));
	alias->name = name;
	alias->alias = 1;
	dict_insert(command_list, (char *)alias->name, alias);

	if(!cmd->aliases)
		cmd->aliases = stringlist_create();
	stringlist_add(cmd->aliases, strdup(alias->name));
}
Ejemplo n.º 4
0
void cmd_register(struct command *cmd, const char *parent_name)
{
	struct command *parent = parent_name ? cmd_find(parent_name, command_list) : NULL;
	assert(!parent_name || parent);
	if(parent && !parent->subcommands)
		parent->subcommands = dict_create();
	dict_insert(parent ? parent->subcommands : command_list, (char *)cmd->name, cmd);
}
Ejemplo n.º 5
0
static int cmd_exec(int argc, char *argv[])
{
	const struct shell_cmd *cmd;

	cmd = cmd_find(argv[0]);
	if (!cmd) {
		printf("no such command: %s\n", argv[0]);
		return -1;
	}

	return cmd->handler(argc, argv);
}
Ejemplo n.º 6
0
Archivo: cmd.c Proyecto: hettoo/chatsow
void *cvar_get(int c, char *name) {
    cmd_stack_push();
    parse_cmd(name, -1);
    cmd_t *cmd = cmd_find(NULL, c, CT_CVAR, qfalse);
    if (cmd == NULL || cmd->cvar_get == NULL) {
        cmd_stack_pop();
        return NULL;
    }
    void *result = cmd->cvar_get();
    cmd_stack_pop();
    return result;
}
Ejemplo n.º 7
0
// ----------------------------------------------------------------
void cmd_run(
	cmd_info_t * pcmd_infos[],
	int          cargc,
	char      ** cargv,
	void       * parg)
{
	cmd_info_t * pcmd;

	pcmd = cmd_find(pcmd_infos, cargv[0]);
	if (pcmd)
		pcmd->phdlr_func(cargc, cargv, pcmd->long_help, parg);
	else
		printf("Couldn't find command \"%s\".\n", cargv[0]);
}
Ejemplo n.º 8
0
void exec_command(char cmd, char *param)
{
  switch(cmd){
  case'Q':cmd_quit();  break;
  case'C':cmd_check(); break;
  case'P':cmd_print(atoi(param)); break;
  case'R':cmd_read(param);  break;
  case'W':cmd_write(param); break;
  case'F':cmd_find(param);  break;
  case'S':cmd_sort(atoi(param));  break;
  case'E':cmd_edit(); break;
  case'H':cmd_help(); break;
  default:fprintf(stderr,"error\n\n");
  }
  printf(":");
}
Ejemplo n.º 9
0
void cmd_handle(const char *line, int argc, char **argv, struct command *parent)
{
	struct command *cmd;
	static char cmdbuf[32];

	if(argc < 1)
	{
		error("No %scommand given", parent ? "sub" : "");
		return;
	}

	cmd = cmd_find(argv[0], parent ? parent->subcommands : command_list);

	if(!cmd)
	{
		if(parent)
			error("%s %s: command not found", parent->name, argv[0]);
		else
			error("%s: command not found", argv[0]);
		return;
	}

	if(cmd->subcommands)
		cmd_handle(line, argc - 1, argv + 1, cmd);
	else if(!cmd->func)
	{
		if(parent)
		{
			snprintf(cmdbuf, sizeof(cmdbuf), "%s %s", parent->name, cmd->name);
			argv[0] = cmdbuf;
		}

		error("%s: command not implemented", argv[0]);
	}
	else
	{
		if(parent)
		{
			snprintf(cmdbuf, sizeof(cmdbuf), "%s %s", parent->name, cmd->name);
			argv[0] = cmdbuf;
		}

		cmd->func(line, argc, argv);
	}
}
Ejemplo n.º 10
0
Archivo: net_pro.c Proyecto: kota395/np
void exec_command(char cmd, char *param)
{
  switch (cmd) {
  case 'Q': cmd_quit();              break;
  case 'C': cmd_check();             break;
  case 'P': cmd_print(atoi(param));  break;
  case 'R': cmd_read(param);         break;
  case 'W': cmd_write(param);        break;
  case 'F': cmd_find(param);         break;
  case 'S': cmd_sort(atoi(param));   break;
  case 'D': cmd_delete(param);       break;
  case 'r': cmd_random();            break;
  case 'T': test(atoi(param));       break;
  default:
    fprintf(stderr, "Invalid command %c: ignored.\n", cmd);
    break;
  }
}
Ejemplo n.º 11
0
int main(int argc, char ** argv)
{
	int    cargc;
	char * cargv[MAX_CARGC];
	char   line[256];
	cmd_info_t * pcmd;

	//if (!init_hdlr(argc, argv)) {
		//main_usage(argv[0]);
		//exit(1);
	//}

	printf(PROMPT);
	fflush(stdout);
	while (fgets(line, sizeof(line), stdin)) {
		int len = strlen(line);
		if (line[len-1] == '\n')
			line[len-1] = 0;

		cargc = tokenize(line, cargv, MAX_CARGC);

		if (cargc == 0) {
			printf(PROMPT);
			fflush(stdout);
			continue;
		}

		pcmd = cmd_find(pcmd_infos, cargv[0]);
		if (pcmd) {
			pcmd->phdlr_func(cargc, cargv, pcmd->long_help, 0);
		}
		else {
			printf("Couldn't find command \"%s\".\n",
				cargv[0]);
		}

		printf(PROMPT);
		fflush(stdout);
	}
	return 0;
}
Ejemplo n.º 12
0
static int do_help(int argc, char *argv[])
{
	if (argc == 1) {
		return cmd_list();
	} else {
		const struct shell_cmd *cmd;
		int i;

		for (i = 1; i < argc; ++i) {
			cmd = cmd_find(argv[i]);
			if (!cmd) {
				printf("no such command: %s\n", argv[i]);
			} else {
				printf("%s: %s\n", cmd->exe,
				       cmd->usage ? : cmd->exe);
			}
		}
	}

	return 0;
}
Ejemplo n.º 13
0
int main(int argc,char *argv[])
{
   vmfs_fs_t *fs;
   struct cmd *cmd = NULL;
   int arg, ret;
   vmfs_flags_t flags;

   if (argc < 3) {
      show_usage(argv[0]);
      return(0);
   }

   /* Scan arguments for a command */
   for (arg = 1; arg < argc; arg++) {
      if ((cmd = cmd_find(argv[arg])))
         break;
   }

   if (!cmd) {
      show_usage(argv[0]);
      return(0);
   }

   flags.packed = 0;

   flags.read_write = 1;

   argv[arg] = NULL;
   if (!(fs = vmfs_fs_open(&argv[1], flags))) {
      fprintf(stderr,"Unable to open filesystem\n");
      exit(EXIT_FAILURE);
   }

   ret = cmd->fn(fs,argc-arg-1,&argv[arg+1]);
   vmfs_fs_close(fs);
   return(ret);
}
Ejemplo n.º 14
0
// ----------------------------------------------------------------
static void help_hdlr(int cargc, char ** cargv, char * long_help,
	void * not_used)
{
	int cargi;
	cmd_info_t * pcmd;

	if (cargc == 1) {
		cmd_show_names(pcmd_infos);
	}
	else {
		for (cargi = 1; cargi < cargc; cargi++) {
			pcmd = cmd_find(pcmd_infos, cargv[cargi]);
			if (pcmd) {
				printf("%s\n", pcmd->short_help);
				printf("%s\n", pcmd->long_help);
			}
			else {
				printf("Couldn't find command \"%s\".\n",
					cargv[cargi]);
			}
			printf("\n");
		}
	}
}
Ejemplo n.º 15
0
int main(void) {

  uint8_t c;
    
  DATA_OUT            // Шина данных (DDRD)
  DDRC  = 0b00000000; // Шина адреса
  DDRB  = 0b00101101; // Шина адреса, карта и светодиод
  PORTB = 0b00010001; // Подтягивающий резистор на MISO и светодиод  

  // Пауза, пока не стабилизируется питание
  _delay_ms(100);

//  while(1) {
//     error();
//  }

  // Запуск файловой системы
  if(fs_init()) error();
  strcpy_P((char*)buf, PSTR("boot/boot.rk"));
  if(fs_open()) error();
  if(fs_getfilesize()) error();
  if(fs_tmp < 7) error();
  if(fs_tmp > 128) error();
  if(fs_read0(rom, (WORD)fs_tmp)) error();  
                    
  // Гасим светодиод
  PORTB |= _BV(PB0);
  
  while(1) {

    // Эмуляция ПЗУ
    RomEmu();

    // Зажигаем светодиод
    PORTB |= _BV(PB0);

    // Проверяем наличие карты
    sendStart(ERR_START);
    send(ERR_WAIT);
    if(fs_check()) {
      send(ERR_DISK_ERR);
    } else {
      send(ERR_OK_DISK);
      recvStart();
      c = wrecv();
      
      // Сбрасываем ошибку
      lastError = 0;
    
      // Принимаем аргументы 
      switch(c) {
        case 0:  cmd_boot();         break; 
        case 1:  cmd_ver();          break;
        case 2:  cmd_exec();         break; 
        case 3:  cmd_find();         break;
        case 4:  cmd_open();         break;     
        case 5:  cmd_lseek();        break;     
        case 6:  cmd_read();         break;     
        case 7:  cmd_write();        break; 
        case 8:  cmd_move();         break;
        default: lastError = ERR_INVALID_COMMAND;      
      }
    
      // Вывод ошибки
      if(lastError) sendStart(lastError);
    }

    // Порт рабоатет на выход
    wait();
    DATA_OUT
    
    // Гасим светодиод
    PORTB &=~_BV(PB0);
    
    _delay_ms(500);
  } 
}
Ejemplo n.º 16
0
int main( int argc, char ** argv )
{
    char path[_MAX_PATH];

    char buffer[ MAX_COMMAND_LINE + 2 ] = { (char)MAX_COMMAND_LINE };  /* Used with _cgets() - maximum number of characters in must be set in 1st byte */

    int    _argc;
    char * _argv[ MAX_ARGS ],
         * result,
         * fullpath;

    int archive_handle = -1;         /* last attached archive */

    int i, cmd;

    if( !ResInit( NULL )) 
        return( 1 );            /* ResInit failed */

    
    /* these would be called after parsing an .ini file or similar */

    IF_DEBUG( ResDbgLogOpen( "resource.log" ));

    print_heading();

    _getcwd( path, _MAX_PATH );
    printf( "PATH: %s\n", path );

    do {
        do {
#if( !RES_USE_FLAT_MODEL )
            printf( "\n%s> ", GLOBAL_CURRENT_PATH );
#else
            printf( "\nRoot > " );
#endif
    _getcwd( path, _MAX_PATH );
    printf( "[SD: %s]>", path );

            result = GETS( buffer );  /* Input a line of text */
            
        } while( !buffer[1] );


        if( !stricmp( result, "exit" ))
            break;

        _argc = parse_args( result, _argv );

        cmd = COMMAND_ERROR;

        for( i=0; i<COMMAND_COUNT; i++ ) {
            if( !stricmp( result, command[i] )) {
                cmd = i;
                break;
            }
        }

        if( cmd == COMMAND_EXIT && !_argc )
            break;

        if( _argc > 1 ) {
            if( !stricmp( _argv[1], "?" ) || !stricmp( _argv[1], "help" )) {
                show_help( cmd );
                continue;
            }
            else
                if( strchr( _argv[1], ASCII_BACKSLASH )) {
                    res_fullpath( path, _argv[1], _MAX_PATH );
                    fullpath = path;
                }
                else
                    fullpath = _argv[1];
        }

        switch( cmd ) 
        {
            case COMMAND_DIR:
#if( RES_USE_FLAT_MODEL )
                printf( "This function is only meaningful when using the hierarchical model.\n" );
                break;
#endif
                if( _argc > 1 )
                    cmd_dir( _argv[1] );
                else
                    cmd_dir( NULL );
                break;


            case COMMAND_ANALYZE:
            {
#if( !RES_USE_FLAT_MODEL )
                HASH_ENTRY * entry;

                if( _argc == 1 )
                    entry = hash_find( GLOBAL_CURRENT_PATH, GLOBAL_HASH_TABLE );
                else
                    entry = hash_find( fullpath, GLOBAL_HASH_TABLE );

                if( entry ) {
#if( RES_DEBUG_VERSION )
                    if( entry -> dir )
                        dbg_analyze_hash( (HASH_TABLE *)entry -> dir );
                    else
                        printf( "No directory table for this directory.\n" );
#endif /* RES_DEBUG_VERSION */
                }
                else
                    printf( "Directory not found.\n" );
#else
                printf( "This command only meaningful when using the hierarchical model!\n" );
#endif
                break;
            }

            case COMMAND_RUN:
                cmd_run( _argc, _argv );
                break;

            case COMMAND_CD:
                if( _argc > 1 ) {
                    if( !ResSetDirectory( fullpath ))
                        printf( "Error changing to directory %s\n", fullpath );
                }
                else
                    printf( "Current directory is: %s\n", GLOBAL_CURRENT_PATH );

                break;


            case COMMAND_ADD:
                if( _argc > 1 ) {
                    int test = FALSE,
                        flag = -1;

                    if( _argc > 2 )
                        flag = is_bool( _argv[2] );
                    
                    if( flag == -1 )
                        flag = TRUE;

                    if( !GLOBAL_SEARCH_INDEX )
                        test = ResCreatePath( fullpath, flag );
                    else
                        test = ResAddPath( fullpath, flag );

                    if( !test )
                        printf( "Error adding %s to search path\n", fullpath );
                }
                else
                    show_help(cmd);
                break;


            case COMMAND_STREAM:
            {
                FILE * fptr;
                char   c;
                int    test;

                if( _argc < 2 ) {
                    show_help(cmd);
                    break;
                }

                fptr = fopen( _argv[1], "r" );

                if( fptr ) {
                    while( (test = fscanf( fptr, "%c", &c )) != EOF )
                        printf( "%c", c );

                    printf( "\n\n\n\n ************** REWINDING ****************** \n\n\n\n\n\n\n" );

                    fseek( fptr, 0, SEEK_SET );

                    while( (test = fscanf( fptr, "%c", &c )) != EOF )
                        printf( "%c", c );

                    fclose( fptr );

                } else {
                    printf( "Error opening file %s\n", _argv[1] );
                }

                break;
            }


            case COMMAND_PATH:
            {
                int x=0;
                char b[_MAX_PATH];

                if( GLOBAL_PATH_LIST ) {

                    while( ResGetPath( x++, b ))
                        printf( "%s\n", b );
                }
                else
                    printf( "No path created.\n" );

                break;
            }

            case COMMAND_EXTRACT:
            {
                /* extracts the archive to the local directory with the same filename */

                if( _argc < 3 )
                    show_help(cmd);
                else              
                    ResExtractFile( _argv[1], _argv[2] );
                break;
            }            

            case COMMAND_READ:
                if( _argc >= 2 )
                    cmd_read( _argv[1] );
                else
                    show_help(cmd);
                break;


            case COMMAND_ATTACH:
            {
                char dst[_MAX_PATH];
                int  flag = -1;

                if( _argc < 2 ) {
                    show_help(cmd);
                    break;
                }

                if( _argc >= 3 )
                    flag = is_bool( _argv[ _argc - 1 ] );

                if( _argc >= 3 ) res_fullpath( dst, _argv[2], _MAX_PATH );

                if( _argc == 2 )
                    archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, FALSE );
                else
                    if( _argc == 3 ) {
                        if( flag != -1 )
                            archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, flag );
                        else
                            archive_handle = ResAttach( fullpath, dst, FALSE );
                    } else
                        if( _argc == 4 )
                            archive_handle = ResAttach( fullpath, dst, flag == -1 ? 0 : flag );
                
                if( archive_handle == -1 )
                    printf( "Error attaching zip file %s\n", fullpath );

                break;
            }

            case COMMAND_DUMP:
                ResDbgDump();
                MemDump();          printf("\n");
                MemFindLevels();    printf("\n");
                MemFindUsage();
                break;

            case COMMAND_DETACH:
                if( archive_handle != -1 )
                {
                    ResDetach( archive_handle );
                    archive_handle = -1;
                }
                else
                    printf( "No archives currently attached.\n" );
                break;

            case COMMAND_MAP:
                if( _argc < 2 )
                    show_help(cmd);
                else
                    cmd_map( _argv[1] );
                break;

            case COMMAND_FIND:
                if( _argc < 2 )
                    show_help(cmd);
                else
                    cmd_find( fullpath );
                break;

            case COMMAND_HELP:
                print_heading();
                show_help(cmd);
                break;

            case COMMAND_ERROR:
            default:
                printf( "Syntax error\n" );
                break;
        }

    } while( TRUE );
    
    ResExit();
    MemDump();
    _getcwd( path, _MAX_PATH );
    printf( "PATH: %s\n", path );

    return(0);
}
Ejemplo n.º 17
0
Archivo: cmd.c Proyecto: hettoo/chatsow
static void cmd_execute_real(int c, int caller, char *name, int type) {
    cmd_stack_push();
    s->caller = caller;
    parse_cmd(name, -1);

    cmd_t *cmd = NULL;
    int cmds = 0;
    while ((cmd = cmd_find(cmd, c, type, qfalse)) != NULL) {
        cmds++;

        int start = c;
        int end = c;
        qboolean switch_screen = qfalse;
        int old_type = type;
        if (cmd_type_compatible(cmd->type, type))
            type = cmd->type;
        if ((type == CT_BROADCAST || type == CT_CVAR) && c < 0) {
            start = 0;
            end = CLIENTS - 1;
        } else if (type == CT_BROADCAST_ALL) {
            start = -1;
            end = CLIENTS - 1;
        } else if (type == CT_FIND_FREE && c < 0) {
            int i;
            qboolean found = qfalse;
            for (i = 0; i < CLIENTS && !found; i++) {
                if (!client_active(i)) {
                    start = i;
                    end = i;
                    found = qtrue;
                    switch_screen = qtrue;
                    break;
                }
            }
            if (!found) {
                ui_output(c, "No free client found.\n");
                cmd_stack_pop();
                return;
            }
        }
        for (s->client = start; s->client <= end; s->client++) {
            if (type == CT_SERVER)
                client_command(s->client, "%s", cmd_args(0));
            else
                cmd->f();
            if (switch_screen)
                set_screen(s->client + 1);
        }
        type = old_type;
    }
    if (cmds == 0) {
        if (cmd_type_compatible(type, CT_PUBLIC)) {
            if (cmd_argv(0)[0])
                client_say(c, "Unknown command: \"%s\"", cmd_argv(0));
        } else if (!cmd_type_compatible(type, CT_EVENT)) {
            ui_output(c, "Unknown command: \"%s\"\n", cmd_argv(0));
        }
        cmd_stack_pop();
        return;
    }
    cmd_stack_pop();
}