2000-05-07 22:23:41 +02:00
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-05-07 22:23:41 +02:00
|
|
|
* Character List
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-05-07 22:23:41 +02:00
|
|
|
* Copyright (c) 2000 by Jean-Claude Batista
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-05-07 22:23:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
2000-11-30 02:31:28 +01:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
#include "charlist.h"
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-01-14 20:44:07 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
2000-05-07 22:23:41 +02:00
|
|
|
|
|
|
|
extern HANDLE RICHED32_hHeap;
|
|
|
|
|
|
|
|
void CHARLIST_Enqueue( CHARLIST* pCharList, char myChar )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-05-07 22:23:41 +02:00
|
|
|
CHARLISTENTRY* pNewEntry = HeapAlloc(RICHED32_hHeap, 0,sizeof(CHARLISTENTRY));
|
|
|
|
pNewEntry->pNext = NULL;
|
|
|
|
pNewEntry->myChar = myChar;
|
2002-01-14 20:44:07 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
if(pCharList->pTail == NULL)
|
|
|
|
{
|
|
|
|
pCharList->pHead = pCharList->pTail = pNewEntry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
CHARLISTENTRY* pCurrent = pCharList->pTail;
|
2000-05-07 22:23:41 +02:00
|
|
|
pCharList->pTail = pCurrent->pNext = pNewEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
pCharList->nCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHARLIST_Push( CHARLIST* pCharList, char myChar)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-05-07 22:23:41 +02:00
|
|
|
CHARLISTENTRY* pNewEntry = malloc(sizeof(CHARLISTENTRY));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-14 20:44:07 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
pNewEntry->myChar = myChar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
if(pCharList->pHead == NULL)
|
|
|
|
{
|
|
|
|
pCharList->pHead = pCharList->pTail = pNewEntry;
|
|
|
|
pNewEntry->pNext = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pNewEntry->pNext = pCharList->pHead;
|
|
|
|
pCharList->pHead = pNewEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
pCharList->nCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char CHARLIST_Dequeue(CHARLIST* pCharList)
|
|
|
|
{
|
|
|
|
CHARLISTENTRY* pCurrent;
|
|
|
|
char myChar;
|
|
|
|
|
2002-01-14 20:44:07 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if(pCharList->nCount == 0)
|
2000-05-07 22:23:41 +02:00
|
|
|
return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
pCharList->nCount--;
|
|
|
|
myChar = pCharList->pHead->myChar;
|
|
|
|
pCurrent = pCharList->pHead->pNext;
|
|
|
|
HeapFree(RICHED32_hHeap, 0,pCharList->pHead);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
if(pCharList->nCount == 0)
|
|
|
|
{
|
|
|
|
pCharList->pHead = pCharList->pTail = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCharList->pHead = pCurrent;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return myChar;
|
2000-05-07 22:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CHARLIST_GetNbItems(CHARLIST* pCharList)
|
|
|
|
{
|
2002-01-14 20:44:07 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
return pCharList->nCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHARLIST_FreeList(CHARLIST* pCharList){
|
2002-01-14 20:44:07 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
while(pCharList->nCount)
|
2002-06-01 01:06:46 +02:00
|
|
|
CHARLIST_Dequeue(pCharList);
|
2000-05-07 22:23:41 +02:00
|
|
|
}
|
|
|
|
|
2002-02-27 02:34:08 +01:00
|
|
|
/* this function counts the number of occurrences of a caracter */
|
2000-05-07 22:23:41 +02:00
|
|
|
int CHARLIST_CountChar(CHARLIST* pCharList, char myChar)
|
|
|
|
{
|
|
|
|
CHARLISTENTRY *pCurrent;
|
|
|
|
int nCount = 0;
|
2002-01-14 20:44:07 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
for(pCurrent =pCharList->pHead ;pCurrent;pCurrent=pCurrent->pNext)
|
|
|
|
if(pCurrent->myChar == myChar)
|
|
|
|
nCount++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
return nCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHARLIST_toBuffer(CHARLIST* pCharList, char* pBuffer, int nBufferSize)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-14 20:44:07 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
/* we add one to store a NULL caracter */
|
2002-06-01 01:06:46 +02:00
|
|
|
if(nBufferSize < pCharList->nCount + 1)
|
2000-05-07 22:23:41 +02:00
|
|
|
return pCharList->nCount;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
for(;pCharList->nCount;pBuffer++)
|
|
|
|
*pBuffer = CHARLIST_Dequeue(pCharList);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-07 22:23:41 +02:00
|
|
|
*pBuffer = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|