⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 free_mgr.c

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 C
📖 第 1 页 / 共 2 页
字号:
int DebugReturnListToFreeList(                              char *list,                              FreeList *freeList,                              const char *file,                              int line){    char *fileName;    /*     * Find the file name minus the preceding path name     */    fileName = strrchr(file, '/');    if(fileName == NULL)        fileName = (char *) file;    else        fileName++;    sprintf(debugMsg, "%14s, %04d", fileName, line);    return(ReturnListToFreeList(list, freeList));}int ReturnListToFreeList(char *list, FreeList *freeList){    unsigned long base;    char **next;        if(freeList == NoFreeList)        return(-1);        if( CorruptedFreeList(freeList) )    {        sprintf(errorString, "Corrupted free list at 0x%x", freeList);        FATAL_MESSAGE(errorString);        return(-1);    }    if(list == (char *) 0)        return(-1);        /*      * base will point the the base of an 'itemSize' chunk of the      *      returned list     * next will point to the place where the structure element called     *      'next' would be if we were dealing with an actual user     *      structure rather than a hunk of memory      */    base = (unsigned long)list;    next = (char **)(base + freeList->offsetToNext);    /*     * Find the end of the user's list     */    while(*next != (char *) 0)    {        if(checkFree && CheckIfAlreadyFree((char *) base, freeList))            continue;        freeList->inUseItems--;        freeList->freeItems++;                if(Debug(freelist))        {            seq++;            sprintf(msgBuf,                     "FreeList %06d FREE    %20s 0x%08x %06d %06d %s",                    seq, freeList->name, base, freeList->inUseItems,                    freeList->freeItems, debugMsg);            DEBUG_MESSAGE(msgBuf);        }                base = (unsigned long) *next;        next = (char **)(base + freeList->offsetToNext);    }    if(!(checkFree && CheckIfAlreadyFree((char *) base, freeList)))    {        freeList->inUseItems--;        freeList->freeItems++;        if(Debug(freelist))        {            seq++;            sprintf(msgBuf, "FreeList %06d FREE    %20s 0x%08x %06d %06d %s",                    seq, freeList->name, base, freeList->inUseItems,                    freeList->freeItems, debugMsg);            DEBUG_MESSAGE(msgBuf);        }                *next = freeList->list;        freeList->list = list;    }    return(0);}int CheckIfAlreadyFree(char *element, FreeList *freeList){    unsigned long base;    char **next;        if(freeList == NoFreeList)        return(-1);        if( CorruptedFreeList(freeList) )    {        sprintf(errorString, "Corrupted free list at 0x%x", freeList);        FATAL_MESSAGE(errorString);        return(-1);    }    if(element == (char *) 0)        return(-1);        base = (unsigned long)(freeList->list);    next = (char **)(base + freeList->offsetToNext);    /*     * Find the end of the user's list     */    while(base)    {        if((char *) base == element)            return(1);                base = (unsigned long) *next;        next = (char **)(base + freeList->offsetToNext);    }    return(0);}/*+------------------------------------------------------------------------ *      ReturnToFreeList() * *              Puts an item back onto the free list. * *      RETURNS: *              0 if all went ok *              -1 if the given type was not found or the list was NULL *________________________________________________________________________*/int DebugReturnToFreeList(                          char *listElement,                          FreeList *freeList,                          const char *file,                          int line){    char *fileName;    /*     * Find the file name minus the preceding path name     */    fileName = strrchr(file, '/');    if(fileName == NULL)        fileName = (char *) file;    else        fileName++;    sprintf(debugMsg, "%14s, %04d", fileName, line);    return(ReturnToFreeList(listElement, freeList));}int ReturnToFreeList(                     char *listElement,                     FreeList *freeList){    char **next;        if(freeList == NoFreeList)        return(-1);        if( CorruptedFreeList(freeList) )    {        sprintf(errorString, "Corrupted free list at 0x%x", freeList);        FATAL_MESSAGE(errorString);        return(-1);    }    if(listElement == (char *) 0)        return(-1);        /*      * next will point to the place where the structure element called     *      'next' would be if we were dealing with an actual user     *      structure rather than a hunk of memory      */    if(!(checkFree && CheckIfAlreadyFree(listElement, freeList)))    {        freeList->inUseItems--;        freeList->freeItems++;        if(Debug(freelist))        {            seq++;            sprintf(msgBuf,                    "FreeList %06d FREE    %20s 0x%08x %06d %06d %s",                    seq, freeList->name, listElement, freeList->inUseItems,                    freeList->freeItems, debugMsg);            DEBUG_MESSAGE(msgBuf);        }            next = (char **)(listElement + freeList->offsetToNext);        *next = freeList->list;        freeList->list = listElement;    }    return(0);}/*+--------------------------------------------------------------------- *    ReallocateFreeList() *  *    RETURNS: *            0 if successful *            -1 if unsuccessful *---------------------------------------------------------------------*/static int ReallocateFreeList(FreeList *freeList){    int i;    unsigned long base;    char **next;        if(freeList == NoFreeList)        return(-1);    if( CorruptedFreeList(freeList) )    {        sprintf(errorString, "Corrupted free list at 0x%x", freeList);        FATAL_MESSAGE(errorString);        return(-1);    }    if (freeList->list == (char *) 0)    {        freeList->list =              malloc((int)(freeList->reallocSize) *                    (int)(freeList->itemSize));        if (freeList->list == (char *) 0)        {            sprintf(errorString,                    "ReallocateFreeList: Failed to allocate for list 0x%x",                    freeList);            FATAL_MESSAGE(errorString);            return(-1);        }        /*          * base will point the the base of an 'itemSize' chunk of the newly         *      allocated memory area,         * next will point to the place where the structure element called         *      'next' would be if we were dealing with an actual user         *      structure rather than a hunk of memory          */        base = (unsigned long)freeList->list;        for (i = 0 ; i < freeList->reallocSize; i++)        {            freeList->freeItems++;                        if(Debug(freelist))            {                seq++;                sprintf(msgBuf,                        "FreeList %06d REALLOC %20s 0x%08x %06d %06d %s",                        seq, freeList->name, base, freeList->inUseItems,                        freeList->freeItems, debugMsg);                DEBUG_MESSAGE(msgBuf);            }                    next = (char **)(base + freeList->offsetToNext);            base = (base + freeList->itemSize);            *next = (char *) base;        }        *next = (char *) 0;        return(0);    }    return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -