summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoye <joye>2014-03-14 19:18:49 (GMT)
committerjoye <joye>2014-03-14 19:18:49 (GMT)
commit60825c55bc5562d64299a132f99958734cf90f98 (patch)
tree521a44bcde343aac0fa6d44debd60952ab66222f
parent9bb57c2e36c9f322b9737965f52f940b9a03b7e9 (diff)
downloadblt-60825c55bc5562d64299a132f99958734cf90f98.zip
blt-60825c55bc5562d64299a132f99958734cf90f98.tar.gz
blt-60825c55bc5562d64299a132f99958734cf90f98.tar.bz2
*** empty log message ***
-rwxr-xr-xconfigure2
-rwxr-xr-xconfigure.in2
-rw-r--r--src/bltChain.C514
-rw-r--r--src/bltGrBind.C8
4 files changed, 154 insertions, 372 deletions
diff --git a/configure b/configure
index d7e87a1..0cc7141 100755
--- a/configure
+++ b/configure
@@ -5526,7 +5526,7 @@ done
#-----------------------------------------------------------------------
vars="
- bltBind.c
+ bltBind.C
bltBitmap.c
bltChain.c
bltConfig.c
diff --git a/configure.in b/configure.in
index a6c3a1e..619f066 100755
--- a/configure.in
+++ b/configure.in
@@ -71,7 +71,7 @@ TEA_SETUP_COMPILER
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------
TEA_ADD_SOURCES([
- bltBind.c
+ bltBind.C
bltBitmap.c
bltChain.c
bltConfig.c
diff --git a/src/bltChain.C b/src/bltChain.C
index b95e520..50d3421 100644
--- a/src/bltChain.C
+++ b/src/bltChain.C
@@ -27,406 +27,202 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+extern "C" {
#include "bltInt.h"
#include "bltChain.h"
+};
#ifndef ALIGN
-#define ALIGN(a) \
- (((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1)))
+#define ALIGN(a) \
+ (((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1)))
#endif /* ALIGN */
typedef struct _Blt_ChainLink ChainLink;
typedef struct _Blt_Chain Chain;
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Create --
- *
- * Creates a new linked list (chain) structure and initializes its
- * pointers;
- *
- * Results:
- * Returns a pointer to the newly created chain structure.
- *
- *---------------------------------------------------------------------------
- */
-Blt_Chain
-Blt_Chain_Create(void)
+Blt_Chain Blt_Chain_Create(void)
{
- Chain *chainPtr;
-
- chainPtr = malloc(sizeof(Chain));
- if (chainPtr != NULL) {
- Blt_Chain_Init(chainPtr);
- }
- return chainPtr;
+ Chain* chainPtr =(Chain*)malloc(sizeof(Chain));
+ if (chainPtr) {
+ Blt_Chain_Init(chainPtr);
+ }
+ return chainPtr;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_AllocLink --
- *
- * Creates a new chain link. Unlink Blt_Chain_NewLink, this routine also
- * allocates extra memory in the node for data.
- *
- * Results:
- * The return value is the pointer to the newly created entry.
- *
- *---------------------------------------------------------------------------
- */
-Blt_ChainLink
-Blt_Chain_AllocLink(size_t extraSize)
+Blt_ChainLink Blt_Chain_AllocLink(size_t extraSize)
{
- ChainLink *linkPtr;
- size_t linkSize;
-
- linkSize = ALIGN(sizeof(ChainLink));
- linkPtr = calloc(1, linkSize + extraSize);
- if (extraSize > 0) {
- /* Point clientData at the memory beyond the normal structure. */
- linkPtr->clientData = (ClientData)((char *)linkPtr + linkSize);
- }
- return linkPtr;
+ size_t linkSize = ALIGN(sizeof(ChainLink));
+ ChainLink* linkPtr = (ChainLink*)calloc(1, linkSize + extraSize);
+ if (extraSize > 0) {
+ // Point clientData at the memory beyond the normal structure
+ linkPtr->clientData = (ClientData)((char *)linkPtr + linkSize);
+ }
+ return linkPtr;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_InitLink --
- *
- * Initializes the new link. This routine is for applications that use
- * their own memory allocation procedures to allocate links.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_InitLink(ChainLink *linkPtr)
+void Blt_Chain_InitLink(ChainLink* linkPtr)
{
- linkPtr->clientData = NULL;
- linkPtr->next = linkPtr->prev = NULL;
+ linkPtr->clientData = NULL;
+ linkPtr->next = linkPtr->prev = NULL;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_NewLink --
- *
- * Creates a new link.
- *
- * Results:
- * The return value is the pointer to the newly created link.
- *
- *---------------------------------------------------------------------------
- */
-Blt_ChainLink
-Blt_Chain_NewLink(void)
+Blt_ChainLink Blt_Chain_NewLink(void)
{
- ChainLink *linkPtr;
-
- linkPtr = malloc(sizeof(ChainLink));
- linkPtr->clientData = NULL;
- linkPtr->next = linkPtr->prev = NULL;
- return linkPtr;
+ ChainLink* linkPtr = (ChainLink*)malloc(sizeof(ChainLink));
+ linkPtr->clientData = NULL;
+ linkPtr->next = linkPtr->prev = NULL;
+ return linkPtr;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Reset --
- *
- * Removes all the links in the chain, freeing the memory used for each
- * link. Memory pointed to by the link (clientData) is not freed. It's
- * the caller's responsibility to deallocate it.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_Reset(Chain *chainPtr) /* Chain to clear */
+void Blt_Chain_Reset(Chain* chainPtr)
{
- if (chainPtr != NULL) {
- ChainLink *oldPtr;
- ChainLink *linkPtr = chainPtr->head;
+ if (chainPtr) {
+ ChainLink* oldPtr;
+ ChainLink* linkPtr = chainPtr->head;
- while (linkPtr != NULL) {
- oldPtr = linkPtr;
- linkPtr = linkPtr->next;
- free(oldPtr);
- }
- Blt_Chain_Init(chainPtr);
+ while (linkPtr) {
+ oldPtr = linkPtr;
+ linkPtr = linkPtr->next;
+ free(oldPtr);
}
+ Blt_Chain_Init(chainPtr);
+ }
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Destroy
- *
- * Frees all the nodes in the chain and deallocates the memory used for
- * the chain structure itself. It's assumed that the chain was previously
- * allocated by Blt_Chain_Create.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_Destroy(Chain *chainPtr)
+void Blt_Chain_Destroy(Chain* chainPtr)
{
- if (chainPtr != NULL) {
- Blt_Chain_Reset(chainPtr);
- free(chainPtr);
- chainPtr = NULL;
- }
+ if (chainPtr) {
+ Blt_Chain_Reset(chainPtr);
+ free(chainPtr);
+ chainPtr = NULL;
+ }
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Init --
- *
- * Initializes a linked list.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_Init(Chain *chainPtr)
+void Blt_Chain_Init(Chain* chainPtr)
{
- chainPtr->nLinks = 0;
- chainPtr->head = chainPtr->tail = NULL;
+ chainPtr->nLinks = 0;
+ chainPtr->head = chainPtr->tail = NULL;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_LinkAfter --
- *
- * Inserts a link after another link. If afterPtr is NULL, then the new
- * link is prepended to the beginning of the chain.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_LinkAfter(Chain *chainPtr, ChainLink *linkPtr, ChainLink *afterPtr)
+void Blt_Chain_LinkAfter(Chain* chainPtr, ChainLink* linkPtr,
+ ChainLink* afterPtr)
{
- if (chainPtr->head == NULL) {
- chainPtr->tail = chainPtr->head = linkPtr;
- } else {
- if (afterPtr == NULL) {
- /* Append to the end of the chain. */
- linkPtr->next = NULL;
- linkPtr->prev = chainPtr->tail;
- chainPtr->tail->next = linkPtr;
- chainPtr->tail = linkPtr;
- } else {
- linkPtr->next = afterPtr->next;
- linkPtr->prev = afterPtr;
- if (afterPtr == chainPtr->tail) {
- chainPtr->tail = linkPtr;
- } else {
- afterPtr->next->prev = linkPtr;
- }
- afterPtr->next = linkPtr;
- }
- }
- chainPtr->nLinks++;
+ if (chainPtr->head == NULL)
+ chainPtr->tail = chainPtr->head = linkPtr;
+ else {
+ if (afterPtr == NULL) {
+ // Append to the end of the chain
+ linkPtr->next = NULL;
+ linkPtr->prev = chainPtr->tail;
+ chainPtr->tail->next = linkPtr;
+ chainPtr->tail = linkPtr;
+ }
+ else {
+ linkPtr->next = afterPtr->next;
+ linkPtr->prev = afterPtr;
+ if (afterPtr == chainPtr->tail)
+ chainPtr->tail = linkPtr;
+ else
+ afterPtr->next->prev = linkPtr;
+ afterPtr->next = linkPtr;
+ }
+ }
+ chainPtr->nLinks++;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_LinkBefore --
- *
- * Inserts a new link preceding a given link in a chain. If beforePtr is
- * NULL, then the new link is placed at the beginning of the list.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_LinkBefore(Chain *chainPtr, ChainLink *linkPtr, ChainLink *beforePtr)
+void Blt_Chain_LinkBefore(Chain* chainPtr, ChainLink* linkPtr,
+ ChainLink* beforePtr)
{
- if (chainPtr->head == NULL) {
- chainPtr->tail = chainPtr->head = linkPtr;
- } else {
- if (beforePtr == NULL) {
- /* Prepend to the front of the chain */
- linkPtr->next = chainPtr->head;
- linkPtr->prev = NULL;
- chainPtr->head->prev = linkPtr;
- chainPtr->head = linkPtr;
- } else {
- linkPtr->prev = beforePtr->prev;
- linkPtr->next = beforePtr;
- if (beforePtr == chainPtr->head) {
- chainPtr->head = linkPtr;
- } else {
- beforePtr->prev->next = linkPtr;
- }
- beforePtr->prev = linkPtr;
- }
- }
- chainPtr->nLinks++;
+ if (chainPtr->head == NULL)
+ chainPtr->tail = chainPtr->head = linkPtr;
+ else {
+ if (beforePtr == NULL) {
+ // Prepend to the front of the chain
+ linkPtr->next = chainPtr->head;
+ linkPtr->prev = NULL;
+ chainPtr->head->prev = linkPtr;
+ chainPtr->head = linkPtr;
+ }
+ else {
+ linkPtr->prev = beforePtr->prev;
+ linkPtr->next = beforePtr;
+ if (beforePtr == chainPtr->head)
+ chainPtr->head = linkPtr;
+ else
+ beforePtr->prev->next = linkPtr;
+ beforePtr->prev = linkPtr;
+ }
+ }
+ chainPtr->nLinks++;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_UnlinkLink --
- *
- * Unlinks a link from the chain. The link is not deallocated, but only
- * removed from the chain.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_UnlinkLink(Chain *chainPtr, ChainLink *linkPtr)
+void Blt_Chain_UnlinkLink(Chain* chainPtr, ChainLink* linkPtr)
{
- int unlinked; /* Indicates if the link is actually removed
- * from the chain. */
-
- unlinked = FALSE;
- if (chainPtr->head == linkPtr) {
- chainPtr->head = linkPtr->next;
- unlinked = TRUE;
- }
- if (chainPtr->tail == linkPtr) {
- chainPtr->tail = linkPtr->prev;
- unlinked = TRUE;
- }
- if (linkPtr->next != NULL) {
- linkPtr->next->prev = linkPtr->prev;
- unlinked = TRUE;
- }
- if (linkPtr->prev != NULL) {
- linkPtr->prev->next = linkPtr->next;
- unlinked = TRUE;
- }
- if (unlinked) {
- chainPtr->nLinks--;
- }
- linkPtr->prev = linkPtr->next = NULL;
+ // Indicates if the link is actually remove from the chain
+ int unlinked;
+
+ unlinked = FALSE;
+ if (chainPtr->head == linkPtr) {
+ chainPtr->head = linkPtr->next;
+ unlinked = TRUE;
+ }
+ if (chainPtr->tail == linkPtr) {
+ chainPtr->tail = linkPtr->prev;
+ unlinked = TRUE;
+ }
+ if (linkPtr->next) {
+ linkPtr->next->prev = linkPtr->prev;
+ unlinked = TRUE;
+ }
+ if (linkPtr->prev) {
+ linkPtr->prev->next = linkPtr->next;
+ unlinked = TRUE;
+ }
+ if (unlinked) {
+ chainPtr->nLinks--;
+ }
+ linkPtr->prev = linkPtr->next = NULL;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_DeleteLink --
- *
- * Unlinks and frees the given link from the chain. It's assumed that
- * the link belong to the chain. No error checking is performed to verify
- * this.
- *
- * Results:
- * None.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_DeleteLink(Blt_Chain chain, Blt_ChainLink link)
+void Blt_Chain_DeleteLink(Blt_Chain chain, Blt_ChainLink link)
{
- Blt_Chain_UnlinkLink(chain, link);
- free(link);
- link = NULL;
+ Blt_Chain_UnlinkLink(chain, link);
+ free(link);
+ link = NULL;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Append
- *
- * Creates and new link with the given data and appends it to the end of
- * the chain.
- *
- * Results:
- * Returns a pointer to the link created.
- *
- *---------------------------------------------------------------------------
- */
-Blt_ChainLink
-Blt_Chain_Append(Blt_Chain chain, ClientData clientData)
+Blt_ChainLink Blt_Chain_Append(Blt_Chain chain, ClientData clientData)
{
- Blt_ChainLink link;
+ Blt_ChainLink link;
- link = Blt_Chain_NewLink();
- Blt_Chain_LinkAfter(chain, link, (Blt_ChainLink)NULL);
- Blt_Chain_SetValue(link, clientData);
- return link;
+ link = Blt_Chain_NewLink();
+ Blt_Chain_LinkAfter(chain, link, (Blt_ChainLink)NULL);
+ Blt_Chain_SetValue(link, clientData);
+ return link;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Prepend
- *
- * Creates and new link with the given data and prepends it to beginning
- * of the chain.
- *
- * Results:
- * Returns a pointer to the link created.
- *
- *---------------------------------------------------------------------------
- */
-Blt_ChainLink
-Blt_Chain_Prepend(Blt_Chain chain, ClientData clientData)
+Blt_ChainLink Blt_Chain_Prepend(Blt_Chain chain, ClientData clientData)
{
- Blt_ChainLink link;
+ Blt_ChainLink link;
- link = Blt_Chain_NewLink();
- Blt_Chain_LinkBefore(chain, link, (Blt_ChainLink)NULL);
- Blt_Chain_SetValue(link, clientData);
- return link;
+ link = Blt_Chain_NewLink();
+ Blt_Chain_LinkBefore(chain, link, (Blt_ChainLink)NULL);
+ Blt_Chain_SetValue(link, clientData);
+ return link;
}
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_Sort --
- *
- * Sorts the chain according to the given comparison routine.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * The chain is reordered.
- *
- *---------------------------------------------------------------------------
- */
-void
-Blt_Chain_Sort(Chain *chainPtr, Blt_ChainCompareProc *proc)
+void Blt_Chain_Sort(Chain *chainPtr, Blt_ChainCompareProc *proc)
{
- ChainLink **linkArr;
- ChainLink *linkPtr;
- long i;
+ if (chainPtr->nLinks < 2)
+ return;
- if (chainPtr->nLinks < 2) {
+ ChainLink** linkArr =
+ (ChainLink**)malloc(sizeof(Blt_ChainLink) * (chainPtr->nLinks + 1));
+ if (!linkArr)
return;
- }
- linkArr = malloc(sizeof(Blt_ChainLink) * (chainPtr->nLinks + 1));
- if (linkArr == NULL) {
- return; /* Out of memory. */
- }
- i = 0;
+
+ long i = 0;
+ ChainLink *linkPtr;
for (linkPtr = chainPtr->head; linkPtr != NULL;
linkPtr = linkPtr->next) {
linkArr[i++] = linkPtr;
@@ -448,28 +244,12 @@ Blt_Chain_Sort(Chain *chainPtr, Blt_ChainCompareProc *proc)
free(linkArr);
}
-
-/*
- *---------------------------------------------------------------------------
- *
- * Blt_Chain_IsBefore --
- *
- *
- * Results:
- * Return boolean value if the first link comes before the second.
- *
- *---------------------------------------------------------------------------
- */
-int
-Blt_Chain_IsBefore(ChainLink *firstPtr, ChainLink *lastPtr)
+int Blt_Chain_IsBefore(ChainLink* firstPtr, ChainLink* lastPtr)
{
- ChainLink *linkPtr;
-
- for (linkPtr = firstPtr; linkPtr != NULL; linkPtr = linkPtr->next) {
- if (linkPtr == lastPtr) {
- return TRUE;
- }
- }
- return FALSE;
+ for (ChainLink* linkPtr = firstPtr; linkPtr; linkPtr = linkPtr->next) {
+ if (linkPtr == lastPtr)
+ return TRUE;
+ }
+ return FALSE;
}
diff --git a/src/bltGrBind.C b/src/bltGrBind.C
index a78dd1c..54d9fbc 100644
--- a/src/bltGrBind.C
+++ b/src/bltGrBind.C
@@ -27,8 +27,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+extern "C" {
#include "bltInt.h"
#include "bltBind.h"
+};
static Tk_EventProc BindProc;
@@ -130,7 +132,7 @@ DoEvent(
tagArray = staticTags;
nTags = Blt_List_GetLength(tagList);
if (nTags >= MAX_STATIC_TAGS) {
- tagArray = malloc(sizeof(ClientData) * nTags);
+ tagArray = (ClientData*)malloc(sizeof(ClientData) * nTags);
}
nTags = 0;
@@ -357,7 +359,7 @@ PickCurrentItem(
static void BindProc(ClientData clientData, XEvent *eventPtr)
{
- BindTable *bindPtr = clientData;
+ BindTable *bindPtr = (BindTable*)clientData;
int mask;
Tcl_Preserve(bindPtr->clientData);
@@ -559,7 +561,7 @@ Blt_BindTable Blt_CreateBindingTable(
unsigned int mask;
BindTable *bindPtr;
- bindPtr = calloc(1, sizeof(BindTable));
+ bindPtr = (BindTable*)calloc(1, sizeof(BindTable));
bindPtr->bindingTable = Tk_CreateBindingTable(interp);
bindPtr->clientData = clientData;
bindPtr->tkwin = tkwin;