Пример #1
0
int
int_dict_del(
    int_dict_t         *dict,
    intkey_t            key)
{
    int_dict_node_t target;
    int_dict_node_t *node;

    assert(dict);
    assert(dict->tree);

    target.key = key;

    WRITE_LOCK(&dict->mutex);
    node = (int_dict_node_t *)rbdelete(&target, dict->tree);
    RW_MUTEX_UNLOCK(&dict->mutex);

    if (node == NULL) {
        return 1;
    }
    dict->count--;

    free(node);
    return 0;
}
Пример #2
0
Файл: cmd.c Проект: Slipyx/r1q2
/*
============
Cmd_RemoveCommand
============
*/
void	EXPORT Cmd_RemoveCommand (const char *cmd_name)
{
	cmd_function_t	*cmd, **back;

	back = &cmd_functions;
	for (;;)
	{
		cmd = *back;
		if (!cmd)
		{
			Com_Printf ("Cmd_RemoveCommand: %s not added\n", LOG_GENERAL, cmd_name);
			return;
		}

		if (!strcmp (cmd_name, cmd->name))
		{
			rbdelete (cmd->name, cmdtree);

			*back = cmd->next;
			Z_Free (cmd);
			return;
		}
		back = &cmd->next;
	}
}
Пример #3
0
Файл: c.c Проект: noodles-v6/ACM
int process(int val) {
  int ix=rbindex[val];
  int r=rbfindrankbyindex(ix);
  rbdelete(ix);
  rbinsertrank(val,0);
  return r;
}
Пример #4
0
static void RB_Purge (const struct rbtree *r)
{
	RBLIST *rblist;
	const void *val;
	void *data;
	void *ptr;

	if ((rblist=rbopenlist(rb)) != NULL)
	{
		while((val=rbreadlist(rblist)) != NULL)
		{
			data = rbfind (val, rb);
			ptr = *(void **)data;
			rbdelete (val, rb);

			if (ptr)
				Z_Free (ptr);
		}
	}

	rbcloselist(rblist);
	rbdestroy (rb);

	FS_InitCache();
}
Пример #5
0
const lsn_t * stasis_aggregate_min_remove(stasis_aggregate_min_t * min, lsn_t * a) {
  if(min->tree) {
    const lsn_t * ret = rbdelete(a, min->tree);
    assert(ret == a);
    return ret;
  } else {
    if(min->memo && *min->memo == *a) { min->memo = NULL; }
    lsn_t * p = pthread_getspecific(min->key);
    if(p /*key defined*/) {
      if(*p != -1 /*key points to slot in array*/) {
        if(min->vals[*p]/*slot in array points to something*/ ) {
          if(*min->vals[*p] == *a) {
            min->vals[*p] = 0;  // clear array entry
            return a;
          }
        }
      }
    }
    for(int i = 0; i < min->num_entries; i++) {
      if(min->vals[i] && (*min->vals[i] == *a)) {
	assert(min->vals[i] == a);
        lsn_t * ret = min->vals[i];
        min->vals[i] = 0;
        return ret;
      }
    }
    abort();
  }
}
Пример #6
0
int c_hash_delete(lv_t *hash, lv_t *key) {
    hash_node_t node_key;
    hash_node_t *result;

    assert(hash->type == l_hash);
    assert(key->type == l_str || key->type == l_sym);

    node_key.key = s_hash_item(key);
    result = (hash_node_t *)rbdelete(&node_key, L_HASH(hash));
    return(result != NULL);
}
Пример #7
0
/*
 * Find the named alias, remove it from the tree and return it.
 */
struct alias *
alias_remove(char *name, int type)
{
    struct rbnode *node;
    struct alias key;
    debug_decl(alias_remove, SUDOERS_DEBUG_ALIAS)

    key.name = name;
    key.type = type;
    if ((node = rbfind(aliases, &key)) == NULL) {
	errno = ENOENT;
	return NULL;
    }
    debug_return_ptr(rbdelete(aliases, node));
}
Пример #8
0
int EXPORT FS_FOpenFile (const char *filename, FILE **file, handlestyle_t openHandle, qboolean *closeHandle)
{
	fscache_t		*cache;
	searchpath_t	*search;
	pack_t			*pak;
	filelink_t		*link;
	char			netpath[MAX_OSPATH];
	char			lowered[MAX_QPATH];

	// check for links firstal
	if (!fs_noextern->intvalue)
	{
		for (link = fs_links ; link ; link=link->next)
		{
			if (!strncmp (filename, link->from, link->fromlength))
			{
				Com_sprintf (netpath, sizeof(netpath), "%s%s",link->to, filename+link->fromlength);
				if (openHandle != HANDLE_NONE)
				{
					*file = fopen (netpath, "rb");
					if (*file)
					{	
						Com_DPrintf ("link file: %s\n",netpath);
						*closeHandle = true;
						return FS_filelength (*file);
					}
					return -1;
				}
				else
				{
					return Sys_FileLength (netpath);
				}
			}
		}
	}

#ifdef BTREE_SEARCH
	cache = rbfind (filename, rb);
	if (cache)
	{
		cache = *(fscache_t **)cache;
		if (cache->filepath[0] == 0)
		{
			*file = NULL;
			return -1;
		}
#ifdef _DEBUG
		Com_DPrintf ("File '%s' found in cache: %s\n", filename, cache->filepath);
#endif
		if (openHandle != HANDLE_NONE)
		{
			if (cache->pak)
			{
				if (openHandle == HANDLE_DUPE)
				{
					*file = fopen (cache->pak->filename, "rb");
					if (!*file)
					{
						Com_Printf ("WARNING: Cached pak '%s' failed to open! Did you delete it?\n", LOG_WARNING|LOG_GENERAL, cache->pak->filename);
						rbdelete (filename, rb);
						return -1;
					}
					*closeHandle = true;
				}
				else
				{
					*file = cache->pak->h.handle;
					*closeHandle = false;
				}
			}
			else
			{
				*file = fopen (cache->filepath, "rb");
				if (!*file)
				{
					Com_Printf ("WARNING: Cached file '%s' failed to open! Did you delete it?\n", LOG_WARNING|LOG_GENERAL, cache->filepath);
					rbdelete (filename, rb);
					return -1;
				}
					//Com_Error (ERR_FATAL, "Couldn't open %s (cached)", cache->filepath);	

				*closeHandle = true;
			}
			if (cache->fileseek && fseek (*file, cache->fileseek, SEEK_SET))
				Com_Error (ERR_FATAL, "Couldn't seek to offset %u in %s (cached)", cache->fileseek, cache->filepath);
		}
		return cache->filelen;
	}

#elif HASH_CACHE
	hash = hashify (filename);

	cache = &fscache;

	while (cache->next)
	{ 
		cache = cache->next;
		if (cache->hash == hash && !Q_stricmp (cache->filename, filename))
		{
			Com_Printf (" (cached) ", LOG_GENERAL);
			if (cache->filepath[0] == 0)
			{
				*file = NULL;
				return -1;
			}
			*file = fopen (cache->filepath, "rb");
			if (!*file)
				Com_Error (ERR_FATAL, "Couldn't open %s", cache->filepath);	
			fseek (*file, cache->fileseek, SEEK_SET);
			return cache->filelen;
		}
	}
#elif MAGIC_BTREE
	{
		magic_t *magic;

		hash = hashify (filename);

		magic = rbfind ((void *)hash, rb);
		if (magic)
		{
			magic = *(magic_t **)magic;

			do
			{
				cache = magic->entry;
				if (!Q_stricmp (cache->filename, filename))
				{
					if (cache->filepath[0] == 0)
					{
						*file = NULL;
						return -1;
					}
					*file = fopen (cache->filepath, "rb");
					if (!*file)
						Com_Error (ERR_FATAL, "Couldn't open %s", cache->filepath);	
					fseek (*file, cache->fileseek, SEEK_SET);
					return cache->filelen;
				}

				magic = magic->next;
			} while (magic);
		}
	}
#endif

#ifdef _DEBUG
	Com_DPrintf ("File '%s' not found in cache, searching fs_searchpaths\n", filename);
#endif

	Q_strncpy (lowered, filename, sizeof(lowered)-1);
	fast_strlwr (lowered);

	for (search = fs_searchpaths ; search ; search = search->next)
	{
		// is the element a pak file?
		if (search->pack)
		{
//			char		*lower;
			packfile_t	*entry;

			//r1: optimized btree search
			pak = search->pack;

			if (pak->type == PAK_QUAKE)
			{
				entry = rbfind (lowered, pak->rb);

				if (entry)
				{
					entry = *(packfile_t **)entry;

	#ifdef _DEBUG
					Com_DPrintf ("File '%s' found in %s, (%s)\n", filename, pak->filename, entry->name);
	#endif
					if (openHandle != HANDLE_NONE)
					{
						//*file = fopen (pak->filename, "rb");
						if (openHandle == HANDLE_DUPE)
						{
							*file = fopen (pak->filename, "rb");
							*closeHandle = true;	
						}
						else
						{
							*file = pak->h.handle;
							*closeHandle = false;
						}
						//if (!*file)
						//	Com_Error (ERR_FATAL, "Couldn't reopen pak file %s", pak->filename);	

						if (fseek (*file, entry->filepos, SEEK_SET))
							Com_Error (ERR_FATAL, "Couldn't seek to offset %u for %s in %s", entry->filepos, entry->name, pak->filename);
					}

					if (fs_cache->intvalue & 1)
					{
	#if BTREE_SEARCH
						FS_AddToCache (pak->filename, entry->filelen, entry->filepos, filename, pak);
	#elif HASH_CACHE
						FS_AddToCache (hash, pak->filename, entry->filelen, entry->filepos, cache, filename);
	#elif MAGIC_BTREE
						FS_AddToCache (pak->filename, entry->filelen, entry->filepos, filename, hash);
	#endif
					}

					return entry->filelen;
				}
			}
		}
		else if (!fs_noextern->intvalue)
		{
			struct stat	statInfo;
			int filelen;
			// check a file in the directory tree
			
			Com_sprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename);

			if (openHandle == HANDLE_NONE)
			{
				filelen = Sys_FileLength (netpath);
				if (filelen == -1)
					continue;
				
				if (fs_cache->intvalue & 4)
					FS_AddToCache (netpath, filelen, 0, filename, NULL);

				return filelen;
			}

			//fix for moronic implementations that allow fopen (FILE OPEN) to open a directory
			//(this means you linux and krew)
			if (stat (netpath, &statInfo))
				continue;

			if (statInfo.st_mode & S_IFDIR)
			{
				Com_Printf ("WARNING: Tried to open a directory as a file: %s\n", LOG_WARNING, netpath);
				continue;
			}

			*file = fopen (netpath, "rb");

			if (!*file)
				continue;

			*closeHandle = true;
			
			Com_DPrintf ("FindFile: %s\n",netpath);

			filelen = FS_filelength (*file);
			if (fs_cache->intvalue & 4)
			{
#if BTREE_SEARCH
				FS_AddToCache (netpath, filelen, 0, filename, NULL);
#elif HASH_CACHE
				FS_AddToCache (hash, netpath, filelen, 0, cache, filename);
#elif MAGIC_BTREE
				FS_AddToCache (netpath, filelen, 0, filename, hash);
#endif
			}
			return filelen;
		}
		
	}
	
	Com_DPrintf ("FindFile: can't find %s\n", filename);

	if (fs_cache->intvalue & 2)
	{
#if BTREE_SEARCH
		FS_AddToCache (NULL, 0, 0, filename, NULL);
#elif HASH_CACHE
		FS_AddToCache (hash, NULL, 0, 0, cache, filename);
#elif MAGIC_BTREE
		FS_AddToCache (NULL, 0, 0, filename, hash);
#endif
	}
	
	*file = NULL;
	return -1;
}
Пример #9
0
/**
 * scan an iTunes xml music database file, augmenting
 * the metainfo with that found in the xml file
 *
 * @param filename xml file to parse
 * @returns TRUE if playlist parsed successfully, FALSE otherwise
 */
int scan_xml_playlist(char *filename) {
    char *working_base;
    const void *val;
    int retval=TRUE;
    SCAN_XML_RB *lookup_ptr;
    SCAN_XML_RB lookup_val;

    RXMLHANDLE xml_handle;

    MAYBEFREE(scan_xml_itunes_version);
    MAYBEFREE(scan_xml_itunes_base_path);
    MAYBEFREE(scan_xml_itunes_decoded_base_path);
    MAYBEFREE(scan_xml_real_base_path);

    scan_xml_file = filename;

    /* initialize the redblack tree */
    if((scan_xml_db = rbinit(scan_xml_rb_compare,NULL)) == NULL) {
        DPRINTF(E_LOG,L_SCAN,"Could not initialize red/black tree\n");
        return FALSE;
    }

    /* find the base dir of the itunes playlist itself */
    working_base = strdup(filename);
    if(strrchr(working_base,'/')) {
        *(strrchr(working_base,'/') + 1) = '\x0';
        scan_xml_real_base_path = strdup(working_base);
    } else {
        scan_xml_real_base_path = strdup("/");
    }
    free(working_base);

    DPRINTF(E_SPAM,L_SCAN,"Parsing xml file: %s\n",filename);

    if(!rxml_open(&xml_handle,filename,scan_xml_handler,NULL)) {
        DPRINTF(E_LOG,L_SCAN,"Error opening xml file %s: %s\n",
                filename,rxml_errorstring(xml_handle));
    } else {
        if(!rxml_parse(xml_handle)) {
            retval=FALSE;
            DPRINTF(E_LOG,L_SCAN,"Error parsing xml file %s: %s\n",
                    filename,rxml_errorstring(xml_handle));
        }
    }

    rxml_close(xml_handle);

    /* destroy the redblack tree */
    val = rblookup(RB_LUFIRST,NULL,scan_xml_db);
    while(val) {
        lookup_val.itunes_index = ((SCAN_XML_RB*)val)->itunes_index;
        lookup_ptr = (SCAN_XML_RB *)rbdelete((void*)&lookup_val,scan_xml_db);
        if(lookup_ptr)
            free(lookup_ptr);
        val = rblookup(RB_LUFIRST,NULL,scan_xml_db);
    }

    rbdestroy(scan_xml_db);

    MAYBEFREE(scan_xml_itunes_version);
    MAYBEFREE(scan_xml_itunes_base_path);
    MAYBEFREE(scan_xml_itunes_decoded_base_path);
    MAYBEFREE(scan_xml_real_base_path);

    return retval;
}