コード例 #1
0
ファイル: list.c プロジェクト: BzzzBoy/gethooks
/* print_list_store()
Print a list store and all its descendants.

if 'store' is NULL this function returns without having printed anything.
*/
void print_list_store( 
	const struct list *const store   // in
)
{
	const char *const objname = "Generic List Store";
	struct list_item *item = NULL;
	
	
	if( !store )
		return;
	
	PRINT_DBLSEP_BEGIN( objname );
	print_init_time( "store->init_time", store->init_time );
	
	printf( "store->type: " );
	switch( store->type )
	{
		case LIST_INVALID_TYPE:
			printf( "LIST_INVALID_TYPE (the user-specified list type hasn't been set.)" );
			break;
		case LIST_INCLUDE_TEST:
			printf( "LIST_INCLUDE_TEST (user-specified list of tests to include.)" );
			break;
		case LIST_INCLUDE_DESK:
			printf( "LIST_INCLUDE_DESK (user-specified list of desktops to include.)" );
			break;
		case LIST_INCLUDE_HOOK:
			printf( "LIST_INCLUDE_HOOK (user-specified list of hooks to include.)" );
			break;
		case LIST_INCLUDE_PROG:
			printf( "LIST_INCLUDE_PROG (user-specified list of programs to include.)" );
			break;
		case LIST_EXCLUDE_HOOK:
			printf( "LIST_EXCLUDE_HOOK (user-specified list of hooks to exclude.)" );
			break;
		case LIST_EXCLUDE_PROG:
			printf( "LIST_EXCLUDE_PROG (user-specified list of programs to exclude.)" );
			break;
		default:
			printf( "%d (unknown type)", store->type );
	}
	printf( "\n" );
	
	//printf( "\nNow printing the desktop items in the list from head to tail.\n " );
	PRINT_HEX( store->head );
	
	for( item = store->head; item; item = item->next )
	{
		//PRINT_HEX( item );
		print_list_item( item );
	}
	
	PRINT_HEX( store->tail );
	
	PRINT_DBLSEP_END( objname );
	
	return;
}
コード例 #2
0
ファイル: songs.c プロジェクト: viibridges/mpc_d
void
songlist_redraw_screen(void)
{
  int line = 0, i, height = wchain[SONGLIST].win->_maxy + 1;

  WINDOW *win = specific_win(SONGLIST);  

  int id;
  char *title, *artist;
  for(i = songlist->begin - 1; i < songlist->begin
		+ height - 1 && i < songlist->length; i++)
	{
	  id = songlist->meta[i].id;
	  title = songlist->meta[i].pretty_title;
	  artist = songlist->meta[i].artist;

	  // cursor in
	  if(i + 1 == songlist->cursor)
		{
		  print_list_item(win, line++, 2, id, title, artist);
		  continue;
		}

	  // selected
	  if(songlist->selected[i] && !songlist->search_mode)
		{
		  print_list_item(win, line++, 9, id, title, artist);
		  continue;
		}
		
	  if(songlist->meta[i].id == songlist->current)
		{
		  print_list_item(win, line++, 1, id, title, artist);
		}
	  else
		{
		  print_list_item(win, line++, 0, id, title, artist);
		}
	}
}
コード例 #3
0
ファイル: option_l.c プロジェクト: FantzFoXx/ft_ls
void			print_ls_l(t_dir_item *items, char *params, int only_dirs)
{
    int		*spaces;
    int		total;
    t_list	*container;

    container = NULL;
    total = 0;
    while (items)
    {
        ft_lstpush(&container, ft_lstnew(print_list_item(items, &total, params),
                                         sizeof(t_litem)));
        items = items->next;
    }
    if (container && only_dirs)
    {
        ft_putstr("total ");
        ft_putnbr((total));
        ft_putchar('\n');
    }
    spaces = max_size_elem(container);
    print_padded_item(container, spaces);
    free(spaces);
}
コード例 #4
0
ファイル: search.c プロジェクト: mdevaev/lightlang
static int find_word_unified(const char *word, const regimen_t regimen, const char *dict_name, FILE *dict_fp)
{
	wchar_t word_wc[MAX_WORD_SIZE];
	wchar_t str_wc[MAX_WORD_SIZE];

	char *str = NULL;
	size_t str_len = 0;

	long index_pos = -1;
	int translate_count = 0;

	bool break_end_flag = false;


	if ( strlen(word) < 1 )
		return 0;

	if ( strncpy_lower_wc(word_wc, word, MAX_WORD_SIZE - 1) == NULL ) {
		fprintf(stderr, "Cannot convert \"%s\" to (wchar_t *): %s\n", word, strerror(errno));
		return -1;
	}

	if ( regimen == usually_regimen || regimen == first_concurrence_regimen || list_regimen ) {
		index_pos = linear_index_pos(word_wc[0], dict_fp);
		if ( index_pos == 0 ) {
			return 0;
		}
		else if ( index_pos > 0 ) {
			if ( fseek(dict_fp, index_pos, SEEK_SET) != 0 )
				fprintf(stderr, "Seek fail on index \"%lc %ld\": %s: ignored\n", word_wc[0], index_pos, strerror(errno));
		}
		else {
			rewind(dict_fp);
		}
	}

	while ( getline(&str, &str_len, dict_fp) != -1 ) {
		if ( str[0] == '#' || str[0] == '\n' )
			continue;

		if ( (str_wc[0] = first_lower_wc(str)) == L'\0' )
			continue;

		if ( regimen == usually_regimen || regimen == first_concurrence_regimen || list_regimen ) {
			if ( word_wc[0] != str_wc[0] && break_end_flag )
				break;
			if ( word_wc[0] != str_wc[0] )
				continue;
			else
				break_end_flag = true;
		}

		if ( strncpy_lower_filter_wc(str_wc, str, MAX_WORD_SIZE - 1) == NULL ) {
			break_end_flag = false; // ill_defined_regimen not required this
			continue;
		}

		if ( regimen == usually_regimen ) {
			if ( !strcmp_full_wc(str_wc, word_wc) ) {
				++translate_count;

				if ( translate_count == 1 )
					print_header(dict_name, word_wc);
				print_translate(str, translate_count);

				if ( translate_count >= settings.max_translate_count )
					break;
			}
		}
		else if ( regimen == first_concurrence_regimen ) {
			if ( !strcmp_noend_wc(str_wc, word_wc) ) {
				++translate_count;

				if ( translate_count == 1 )
					print_header(dict_name, word_wc);
				print_translate(str, translate_count);

				break;
			}
		}
		else if ( regimen == list_regimen ) {
			if ( !strcmp_noend_wc(str_wc, word_wc) ) {
				++translate_count;

				if ( translate_count == 1 )
					print_header(dict_name, word_wc);
				print_list_item(str_wc, translate_count);

				if ( translate_count >= settings.max_translate_count )
					break;
			}
		}
		else if ( regimen == ill_defined_regimen ) {
			if ( !strcmp_jump_wc(str_wc, word_wc, settings.ill_defined_search_percent) ) {
				++translate_count;

				if ( translate_count == 1 )
					print_header(dict_name, word_wc);
				print_list_item(str_wc, translate_count);

				if ( translate_count >= settings.max_translate_count )
					break;
			}
		}
	}

	free(str);

	return translate_count;
}
コード例 #5
0
ファイル: list.c プロジェクト: BzzzBoy/gethooks
/* add_list_item()
Append an item to a list store's linked list.

this function appends an item to a list if the id and/or name (depending on list type) is not 
already in the list. any comparison of 'name' is case insensitive.

'store' is the generic list store to append the item to.
whether 'id' and/or 'name' is used depends on the type of list. refer to list_item struct in list.h

hook:
'name' is optional. 'id' is required.
if 'name' then its corresponding id will be used for id instead of the passed in 'id'.
if not 'name' then the corresponding name (if any) of the passed in 'id' will be used for name.

prog:
'name' and 'id' are mutually exclusive. if 'name' use name and ignore 'id', else use 'id'.

desktop:
'name' required. 'id' is ignored.

test:
'name' required. 'id' required.

the item's name will point to a duplicate of the passed in 'name'.

returns on success a pointer to the list item that was added to the list. if there is already an 
existing item with the same id and/or name (depending on list type) a pointer to it is returned.
*/
struct list_item *add_list_item( 
	struct list *const store,   // in
	__int64 id,   // in, optional
	const WCHAR *name   // in, optional
)
{
	struct list_item *item = NULL;
	
	/* special case, if there's no 'name' for a hook point to a copy of the corresponding name 
	associated with the 'id'. this must be freed if a new item will not be created.
	*/
	WCHAR *hookname = NULL;
	
	FAIL_IF( !store );
	FAIL_IF( !store->type );
	
	
	/* if an item already in the list matches then return */
	if( ( store->type == LIST_INCLUDE_HOOK ) || ( store->type == LIST_EXCLUDE_HOOK ) )
	{
		if( name )
		{
			int hookid = 0;
			
			/* it is considered fatal if there's no id associated with a name. 
			it's possible this program's list of hooks is outdated, but in that case the user 
			would have to specify by id instead of name
			*/
			if( !get_HOOK_id_from_name( &hookid, name ) )
			{
				MSG_ERROR( "get_HOOK_id_from_name() failed." );
				printf( "Unknown id for hook name: %ls\n", name );
				printf( "\n" );
				item = NULL;
				goto existing_item;
			}
			
			id = hookid;
		}
		else
		{
			/* it is not considered fatal if there's no name associated with an id.
			maybe the user specified some undocumented hook ids in use without a name?
			hookname points to allocated memory and must be freed if a new item will not be created.
			*/
			if( !get_HOOK_name_from_id( &hookname, (int)id ) )
			{
				MSG_WARNING( "get_HOOK_name_from_id() failed." );
				printf( "Unknown name for hook id: %I64d\n", id );
				printf( "\n" );
			}
		}
		
		/* check if the hook id is already in the list.
		a hook id always has the same name (if any).
		if the hook id is already in the list a new item will not be created.
		*/
		for( item = store->head; item; item = item->next )
		{
			if( id == item->id ) /* hook id in list */
			{
				MSG_WARNING( "Hook id already in list." );
				print_list_item( item );
				printf( "\n" );
				goto existing_item;
			}
		}
		
		goto new_item;
	}
	else if( ( store->type == LIST_INCLUDE_PROG ) || ( store->type == LIST_EXCLUDE_PROG ) )
	{
		/* for the program list, name and id are mutually exclusive.
		if name then a program name has been passed in, 
		otherwise an id has been passed in. 
		if name or id is already in the list then there is no reason to append
		*/
		if( name )
		{
			/* check if the program name is already in the list */
			for( item = store->head; item; item = item->next )
			{
				if( item->name && !_wcsicmp( item->name, name ) ) /* name in list */
				{
					MSG_WARNING( "Program name already in list." );
					print_list_item( item );
					printf( "\n" );
					goto existing_item;
				}
			}
		}
		else
		{
			/* check if the PID/TID is already in the list */
			for( item = store->head; item; item = item->next )
			{
				/* a program list item's id is only valid if doesn't have a name */
				if( !item->name && id == item->id ) /* PID/TID in list */
				{
					MSG_WARNING( "PID/TID already in list." );
					print_list_item( item );
					printf( "\n" );
					goto existing_item;
				}
			}
		}
		
		goto new_item;
	}
	else if( store->type == LIST_INCLUDE_DESK )
	{
		FAIL_IF( !name );
		FAIL_IF( id ); // not expecting an id parameter for a desktop list
		
		/* for a desktop list only the name is used. check if it's already in the list */
		for( item = store->head; item; item = item->next )
		{
			if( item->name && !_wcsicmp( item->name, name ) ) /* name in list */
			{
				MSG_WARNING( "Desktop name already in list." );
				print_list_item( item );
				printf( "\n" );
				goto existing_item;
			}
		}
		
		goto new_item;
	}
	else if( store->type == LIST_INCLUDE_TEST )
	{
		FAIL_IF( !name );
		// id can be 0
		
		/* for a test list both name and id are used. check if it's already in the list */
		for( item = store->head; item; item = item->next )
		{
			if( ( item->id && id )
				&& ( item->name && !_wcsicmp( item->name, name ) )
			) // name/id combo already in list
			{
				MSG_WARNING( "Test name/id combo already in list." );
				print_list_item( item );
				printf( "\n" );
				goto existing_item;
			}
		}
		
		goto new_item;
	}
	else // handle generic here?
	{
		MSG_FATAL( "Unknown list type." );
		printf( "store->type: %d\n", store->type );
		exit( 1 );
	}
	
	
new_item:
	/* create a new item and add it to the list */
	
	item = must_calloc( 1, sizeof( *item ) );
	
	if( hookname ) /* special case. this function already has made a copy of the name to store */
		item->name = hookname;
	else if( name ) /* store a copy of the passed in name */
		item->name = must_wcsdup( name );
	else
		item->name = NULL;
	
	item->id = id;
	item->next = NULL;
	
	if( !store->head )
	{
		store->head = item;
		store->tail = item;
	}
	else
	{
		store->tail->next = item;
		store->tail = item;
	}
	
	return item;
	
	
existing_item:
	/* do not create a new item. free resources and return existing item, if any */
	
	free( hookname );
	return item;
}