int help_cmdfunc(int argc, char *argv[])
{
	const command_list_t *cmdlist = get_current_commands();
	const command_t *cmd;
	const char *name = 0;
	int found, i, spaces;
	char abbrev;

	if (argc > 2)
		return -H_EUSAGE;
	if (argc == 2)
		name = *++argv;

	for (found=0, i=0; (cmd = cmdlist->commands[i]); ++i) {
		if (name && strcmp(name, cmd->name))
			continue;
		found = 1;
		spaces = 30;
		if ((abbrev = find_abbrev(cmdlist, cmd)))
			spaces -= hprintf("%c ", abbrev);
		else
			spaces -= hprint("  ");
		spaces -= hprint(cmd->name);
		if (cmd->arghelp)
			spaces -= hprintf(" %s", cmd->arghelp);
		for (/* nothing */; spaces > 0; --spaces)
			hputchar(' ');
		hprintf(": %s\n", cmd->cmdhelp);
	}
	if (name && !found)
		return -H_ENOCMD;
	return 0;
}
Example #2
0
static void dump_info_headers( const char *input, uint length )
/*************************************************************/
{
    const uint_8 *p;
    uint_32     abbrev_code;
    uint_32     abbrev_offset;
    uint_8 *    abbrev;
    uint_32     tag;
    uint_32     unit_length;
    uint_32     tag_offset;
    const uint_8 *unit_base;
    info_state  state;
    bool        found;

    p = input;
    state.addr_size = 0;
    found = false;
    while( p - input < length ) {
        state.cu_header = p - input;
        unit_length = get_u32( (uint_32 *)p );
        unit_base = p + sizeof( uint_32 );
        Wdputs( "Length: " );
        Puthex( unit_length, 8 );
        Wdputslc( "\nVersion: " );
        Puthex( get_u16( (uint_16 *)(p + 4) ), 4 );
        Wdputslc( "\nAbbrev: " );
        abbrev_offset =  get_u32( (uint_32 *)(p + 6) );
        Puthex( abbrev_offset, 8 );
        state.addr_size = *(p + 10);
        Wdputslc( "\nAddress Size " );
        Puthex( *(p + 10), 2 );
        Wdputslc( "\n" );
        p += 11;
        while( p - unit_base < unit_length ) {
            tag_offset = p - input;
            p = DecodeULEB128( p, &abbrev_code );
            if( abbrev_code == 0 ) continue;
            abbrev = find_abbrev( abbrev_offset, abbrev_code );
            if( abbrev == NULL ) {
                Wdputs( "can't find abbreviation " );
                Puthex( abbrev_code, 8 );
                Wdputslc( "\n" );
                break;
            }
            if( p >= input + length ) break;
            abbrev = DecodeULEB128( abbrev, &tag );
            abbrev++;
            state.abbrev = abbrev;
            state.p = p;
            if( tag_offset == 0x59a125 ) {
                found = true;
            }
            if( found ) {
                Wdputs( "Offset: " );
                Puthex(  tag_offset, 8 );
                Wdputs( "  Code: " );
                Puthex( abbrev_code, 8 );
                Wdputslc( "\n" );
                Wdputs( "        " );
                getTAG( tag );
                Wdputslc( "\n" );
               if( !dump_tag( &state ) )break;
            } else {
                skip_tag( &state );
            }
            p = state.p;
        }
        if( found )break;
    }
}