Пример #1
0
void *hashmap_put(hashmap *map, void *key, void *value) {
    S(key); S(value);
    generic_type *k = (generic_type *)key;
    if (k->hashcode == NULL || k->equals == NULL) {
        L(key); L(value);
        return (void *)0x01;
    }
    ssize_t hashcode = (k->hashcode)(k) % 100;
    
    list *insert_in_array = (map->nodes)[hashcode];
    while(insert_in_array) {
        key_value_pair *each = (key_value_pair *)insert_in_array->first;
        generic_type *e_key = (generic_type *)each->key;
        if (k->equals(k, e_key)) {
            void *ret = each->value;
            each->value = value;
            L(key);
            return ret;
        }
        insert_in_array = insert_in_array->rest;
    }
    insert_in_array = (map->nodes)[hashcode];
    
    key_value_pair *kvp = _key_value_pair(key, value);
    (map->nodes)[hashcode] = S(_list(kvp, insert_in_array));
    L(insert_in_array);
    L(key); L(value);
    return NULL;
}
Пример #2
0
int
main (int argc, char **argv)
{
  ipmi_oem_prog_data_t prog_data;
  struct ipmi_oem_arguments cmd_args;
  int hosts_count;
  int rv;

  ipmi_disable_coredump ();

  memset (&prog_data, '\0', sizeof (ipmi_oem_prog_data_t));
  prog_data.progname = argv[0];
  ipmi_oem_argp_parse (argc, argv, &cmd_args);
  prog_data.args = &cmd_args;

  /* Special case, just output list, don't do anything else */
  /* offer "help" as well as list, for those used to ipmitool */
  if (!cmd_args.oem_id
      || !strcasecmp (cmd_args.oem_id, "list")
      || !strcasecmp (cmd_args.oem_id, "help")
      || cmd_args.list)
    {
      if (_list () < 0)
	return (EXIT_FAILURE);
      return (EXIT_SUCCESS);
    }

  if ((hosts_count = pstdout_setup (&(prog_data.args->common_args.hostname),
				    &(prog_data.args->common_args))) < 0)
    return (EXIT_FAILURE);

  if (!hosts_count)
    return (EXIT_SUCCESS);

  /* We don't want caching info to output when are doing ranged output */
  if (hosts_count > 1)
    prog_data.args->common_args.quiet_cache = 1;

  if ((rv = pstdout_launch (prog_data.args->common_args.hostname,
                            _ipmi_oem,
                            &prog_data)) < 0)
    {
      fprintf (stderr,
               "pstdout_launch: %s\n",
               pstdout_strerror (pstdout_errnum));
      return (EXIT_FAILURE);
    }

  return (rv);
}
Пример #3
0
void _list(Bnode *t)
{
    int i;
    static int x = 0;
    if (t != NULL)
    {
        x += 2;
        for (i = 2; i < x; i++) printf("   ");
        for (i = 0; i < t->n; i++) printf("%c", t->key[i]);
        printf("\n");
        for (i = 0; i < t->n+1; i++) _list(t->ptr[i]);
        x -= 2;
    }
}
Пример #4
0
 void list() {
     
     bool failed = false;
     auto startTokenIndex = index();
     
     if (isSpeculating() && alreadyParsedRule(list_memo))
         return;
     
     try { _list(); }
     catch (RecognitionException re) {
         failed = true;
         if (isSpeculating())
             memoize(list_memo, startTokenIndex, failed);
         throw RecognitionException();
     }
     
     if (isSpeculating())
         memoize(list_memo, startTokenIndex, failed);
 }
Пример #5
0
int _can_handler(int argc, char **argv)
{
    if (argc < 2) {
        _can_usage();
        return 1;
    }
    else if (strncmp(argv[1], "list", 5) == 0) {
        return _list(argc - 1, argv + 1);
    }
    else if (strncmp(argv[1], "send", 5) == 0) {
        return _send(argc - 1, argv + 1);
    }
    else if (strncmp(argv[1], "dump", 5) == 0) {
        return _dump(argc - 1, argv + 1);
    }
    else {
        printf("unknown command: %s\n", argv[1]);
        return 1;
    }
    return 0;
}
Пример #6
0
static int _choose(menu_ptr menu)
{
    int     choice = -1;
    bool describe = FALSE;
    bool allow_browse = FALSE;
    char choose_prompt[255];
    char browse_prompt[255];
    char keys[100];
    
    if (menu->browse_prompt)
    {
        allow_browse = TRUE;
        sprintf(choose_prompt, "%s (Type '?' to browse)", menu->choose_prompt);
        sprintf(browse_prompt, "%s (Type '?' to choose)", menu->browse_prompt);
    }
    else
    {
        sprintf(choose_prompt, "%s", menu->choose_prompt);
        sprintf(browse_prompt, "%s", "");
    }
    
    _list(menu, keys);

    for (;;)
    {
        char ch = '\0';
        int i;

        choice = -1;
        if (!get_com(describe ? browse_prompt : choose_prompt, &ch, FALSE)) break;

        if (ch == '?' && allow_browse)
        {
            describe = !describe;
            continue;
        }

        for (i = 0; i < menu->count; i++)
        {
            if (menu->count <= 26)
            {
                if (toupper(keys[i]) == toupper(ch))
                {
                    choice = i;
                    break;
                }
            }
            else if (keys[i] == ch)
            {
                choice = i;
                break;
            }
        }

        if (choice < 0 || choice >= menu->count)
        {
            bell();
            continue;
        }

        if (describe)
        {
            _describe(menu, choice);
            continue;
        }

        break;
    }
    return choice;
}
Пример #7
0
void Btree_list(Bnode *base)
{
    _list(base->ptr[0]);
}
Пример #8
0
static bool _choose(_choice_array_t *choices)
{
    int  key = 0, i;
    bool redraw = TRUE;
    bool done = FALSE;

    assert(choices->size);

    choices->current = 0;
    if (choices->mode == _CHOOSE_MODE_LEARN)
    {
        /* In this mode, the first choice is the form to learn followed by a single group of existing slots */
        assert(choices->size > 1);
        choices->current = 1;
    }

    while (!done)
    {
        if (redraw)
        {
            _list(choices);
            redraw = FALSE;
        }
        {
            int r_idx = choices->choices[choices->current].r_idx;
            if (r_idx > 0)
            {
                monster_race_track(r_idx);
                window_stuff();
            }
        }

        /* No macros. The problem is that arrow keys are implemented with macros! */
        key = inkey_special(TRUE);
        
        switch (key)
        {
        case ESCAPE:
            done = TRUE;
            break;
        case '?':
        {
            int r_idx = choices->choices[choices->current].r_idx;
            if (r_idx > 0)
            {
                int x = Term->scr->cx; /* No way to query this? */
                int y = Term->scr->cy;

                mon_display(&r_info[r_idx]);

                Term_gotoxy(x, y);
                redraw = TRUE; /* screen_save buggily misses row 0 */
            }
            break;
        }
        case '=':
            _next_display_mode();
            redraw = TRUE;
            break;

        case '8':
        case SKEY_UP:
        {
            int old_current = choices->current;
            choices->current--;
            if (choices->current < 0)
                choices->current = 0;
            if (old_current != choices->current)
                redraw = TRUE;
            break;
        }

        case '2':
        case SKEY_DOWN:
        {
            int old_current = choices->current;
            choices->current++;
            if (choices->current > choices->size - 1)
                choices->current = choices->size - 1;
            if (old_current != choices->current)
                redraw = TRUE;
            break;
        }

        case '\t':
        {
            int old_current = choices->current;
            int old_type = choices->choices[old_current].type;
            /* Tab to next group in the list. Wrap to first group as needed. */
            for (;;)
            {
                choices->current++;
                if (choices->current == choices->size) /* Wrap */
                    choices->current = 0;
                if (choices->choices[choices->current].type != old_type)
                    break;
                if (choices->current == old_current)
                    break;
            }
            if (old_current != choices->current)
                redraw = TRUE;
            break;
        }
        case ' ': case '\r': case '\n':
            if (_confirm(choices, choices->current))
                return TRUE;
            redraw = TRUE;
            break;
        default:
            for (i = 0; i < choices->size; i++)
            {
                if (choices->choices[i].key == key)
                {
                    choices->current = i;
                    if (_confirm(choices, choices->current))
                        return TRUE;
                    redraw = TRUE;
                    break;
                }
            }
        }
    }

    return FALSE;
}
Пример #9
0
// edit or display a file with vertical & horizontal scrolling & text searching
int _near List_Cmd( LPTSTR pszCmdLine )
{
	int nFVal, nReturn = 0, argc;
	TCHAR szSource[MAXFILENAME+1], szFileName[MAXFILENAME+1], *pszArg;
	FILESEARCH dir;

	memset( &dir, '\0', sizeof(FILESEARCH) );
	
	// check for and remove switches
	if ( GetRange( pszCmdLine, &(dir.aRanges), 0 ) != 0 )
		return ERROR_EXIT;
	
	// check for /T"search string"
	GetMultiCharSwitch( pszCmdLine, _TEXT("T"), szSource, 255 );
	if ( szSource[0] == _TEXT('"') )
		sscanf( szSource+1, _TEXT("%79[^\"]"), szListFindWhat );
	else if ( szSource[0] )
		sprintf( szListFindWhat, FMT_PREC_STR, 79, szSource );
	
	if ( GetSwitches( pszCmdLine, _TEXT("*HIRSWX"), &lListFlags, 0 ) != 0 )
		return ( Usage( LIST_USAGE ));
	
	if ( szSource[0] )
		lListFlags |= LIST_SEARCH;
	
	// check for pipe to LIST w/o explicit /S switch
	if ( first_arg( pszCmdLine ) == NULL ) {

		if ( _isatty( STDIN ) == 0 )

				lListFlags |= LIST_STDIN;
			else if (( lListFlags & LIST_STDIN ) == 0 )
				return ( Usage( LIST_USAGE ));
	}
	
	// initialize buffers & globals
	
	if ( ListInit() )
		return ERROR_EXIT;
	nCurrent = nStart = 0;
	
	// ^C handling
	if ( setjmp( cv.env ) == -1 ) {
list_abort:
		FindClose( dir.hdir );
		Cls_Cmd( NULL );
		nReturn = CTRLC;
		goto list_bye;
	}
	
RestartFileSearch:
	for ( argc = 0; ; argc++ ) {
		
		// break if at end of arg list, & not listing STDIN
		if (( pszArg = ntharg( pszCmdLine, argc )) == NULL ) {
			if (( lListFlags & LIST_STDIN ) == 0 )
				break;
		} else
			strcpy( szSource, pszArg );
		
		for ( nFVal = FIND_FIRST; ; ) {
			
			szClip[0] = _TEXT('\0');
			
			// if not reading from STDIN, get the next matching file
			if (( lListFlags & LIST_STDIN ) == 0 ) {
				
				// qualify filename
				if ( nFVal == FIND_FIRST ) {
					mkfname( szSource, 0 );
					if ( is_dir( szSource ))
						mkdirname( szSource, WILD_FILE );
				}

				if ( stricmp( szSource, CLIP ) == 0 ) {
					
					RedirToClip( szClip, 99 );
					if ( CopyFromClipboard( szClip ) != 0 )
						break;
					strcpy( szFileName, szClip );
					
				} else if ( QueryIsPipeName( szSource )) {
					
					// only look for pipe once
					if ( nFVal == FIND_NEXT )
						break;
					copy_filename( szFileName, szSource );
					
				} else if ( find_file( nFVal, szSource, ( FIND_BYATTS | FIND_RANGE | FIND_EXCLUDE | 0x07), &dir, szFileName ) == NULL ) {
					nReturn = (( nFVal == FIND_FIRST ) ? ERROR_EXIT : 0 );
					break;
					
				} else if ( nStart < nCurrent ) {
					nStart++;
					nFVal = FIND_NEXT;
					continue;
					
				} else if ( dir.ulSize > 0L )
					LFile.lSize = dir.ulSize;
			}
			
			// clear the screen (scrolling the buffer first to save the current screen)

			Cls_Cmd( NULL );
			
			if (( nReturn = _list( szFileName )) == CTRLC )
				goto list_abort;
			
			if ( szClip[0] )
				remove( szClip );
			
			if ( nReturn != 0 )
				break;
			
			SetCurPos( nScreenRows, 0 );
			
			if (( szClip[0] ) || ( lListFlags & LIST_STDIN ))
				break;

			if ( LFile.hHandle > 0 )
				_close( LFile.hHandle );
			LFile.hHandle = -1;
			
			// increment index to current file
			if ( nCurrent < nStart ) {
				FindClose( dir.hdir );
				nStart = 0;
				goto RestartFileSearch;
			} else {
				nFVal = FIND_NEXT;
				nCurrent++;
				nStart++;
			}
		}
		
		// we can only read STDIN once!
		lListFlags &= ~LIST_STDIN;
	}
	
	crlf();
list_bye:
	FreeMem( LFile.lpBufferStart );
	if ( LFile.hHandle > 0 )
		_close( LFile.hHandle );
	LFile.hHandle = -1;
	
	return nReturn;
}