aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoodale <goodale@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1>2004-05-17 12:28:56 +0000
committergoodale <goodale@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1>2004-05-17 12:28:56 +0000
commit78f7bc7d368abfe62495ec2b19b72c8c38333844 (patch)
treef15b679f6c3ca97b6e517f1d08c89f133d541cd3
parent1179238322c750e4ad7c2b0cd651c4e6bfa3fa62 (diff)
Untabified. Please try to adhere to the Cactus coding guidelines when
modifying or adding files. git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPDExtra/trunk@57 61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1
-rw-r--r--src/Groups.c6
-rw-r--r--src/HTTPD_FileList.c40
-rw-r--r--src/IO.c70
-rw-r--r--src/Processors.c12
-rw-r--r--src/PtrList.c851
5 files changed, 489 insertions, 490 deletions
diff --git a/src/Groups.c b/src/Groups.c
index 8ce19ab..fc8be17 100644
--- a/src/Groups.c
+++ b/src/Groups.c
@@ -164,8 +164,8 @@ static int MessagesPage (const cGH *GH, httpRequest *request, void *data)
"when the simulation finishes, but soon there will be an \n"
"option to save them to a file.</p>\n"
"<div class=\"centered\">"
- "<form action=\"/Messages/\">\n"
- "<table>\n"
+ "<form action=\"/Messages/\">\n"
+ "<table>\n"
"<tr><td>Name:</td>"
"<td><input type=\"text\" size=\"40\" maxlength=\"100\" name=\"name\" "
"value=\"\" /></td></tr>\n"
@@ -174,7 +174,7 @@ static int MessagesPage (const cGH *GH, httpRequest *request, void *data)
"</td></tr></table>\n"
"<p>\n<input type=\"submit\" value=\"Submit Message\" />\n</p>\n"
"<table width=\"80%\"><tr><td>\n"
- "<h2>Messages:</h2></td></tr>\n"
+ "<h2>Messages:</h2></td></tr>\n"
"<tr><td><table width=\"100%\" cellpadding=\"5\" cellspacing=\"5\">"
"<tr><td class=\"nomsg\">" );
diff --git a/src/HTTPD_FileList.c b/src/HTTPD_FileList.c
index fbc4a87..cf5b3ec 100644
--- a/src/HTTPD_FileList.c
+++ b/src/HTTPD_FileList.c
@@ -6,59 +6,59 @@
size_t
HTTPD_FileList_NumberOfItems( const FileList * list )
{
- return List_NumberOfItems( list );
+ return List_NumberOfItems( list );
}
FileList *
HTTPD_FileList_New()
{
- return (FileList *)List_New();
+ return (FileList *)List_New();
}
void
HTTPD_FileList_Delete( FileList * list )
{
- List_Delete( list );
+ List_Delete( list );
}
void
HTTPD_FileList_FreeItemsInListAndEmpty( FileList * list )
{
- List_FreeItemsInListAndEmpty( list );
+ List_FreeItemsInListAndEmpty( list );
}
void
HTTPD_FileList_Append( FileList * list, httpFileItem * item )
{
- List_Append( list, item );
+ List_Append( list, item );
}
httpFileItem *
HTTPD_FileList_Item( const FileList * list, size_t index )
{
- return List_Item( list, index );
+ return List_Item( list, index );
}
void
HTTPD_FileList_SortAccordingTo( FileList * list,
- HTTPD_FileListSortComparison comparison )
+ HTTPD_FileListSortComparison comparison )
{
- List_SortAccordingTo( list, (ListSortComparison)comparison );
+ List_SortAccordingTo( list, (ListSortComparison)comparison );
}
int
HTTPD_FileListCompare_Var_Thorn_Slice(
- const httpFileItem * a, const httpFileItem * b )
+ const httpFileItem * a, const httpFileItem * b )
{
- int order = Compare( a->varname, b->varname );
- if( order == 0 )
- {
- order = Compare( a->thorn, b->thorn );
- if( order == 0 )
- return Compare( a->slice, b->slice );
- else
- return order;
- }
- else
- return order;
+ int order = Compare( a->varname, b->varname );
+ if( order == 0 )
+ {
+ order = Compare( a->thorn, b->thorn );
+ if( order == 0 )
+ return Compare( a->slice, b->slice );
+ else
+ return order;
+ }
+ else
+ return order;
}
diff --git a/src/IO.c b/src/IO.c
index 483a28c..901ef76 100644
--- a/src/IO.c
+++ b/src/IO.c
@@ -134,7 +134,7 @@ static int IOFileListener(const cGH *GH, const char *filename,
entry->linkname = linknameString;
if( filelist == NULL )
- filelist = HTTPD_FileList_New();
+ filelist = HTTPD_FileList_New();
AppendFile( filelist, entry );
/* Need to mangle the filename to get a decent linkname */
@@ -184,7 +184,7 @@ buildList( const FileList *list, String * message, size_t itemNo, int depth )
{
IndentAndConcatCString( message, "<tr>", depth );
ConcatCString( message, "<td class=\"spacer\">&nbsp;</td>"
- "<td class=\"thorn\" colspan=\"4\">" );
+ "<td class=\"thorn\" colspan=\"4\">" );
Concat( message, file->thorn );
IndentAndConcatCString( message, "</td></tr>\n", depth );
i = buildList( list, message, i, 2 );
@@ -200,7 +200,7 @@ buildList( const FileList *list, String * message, size_t itemNo, int depth )
IndentAndConcatCString( message, "<tr>", depth );
ConcatCString( message, "<td class=\"spacer\">&nbsp;</td>"
"<td class=\"spacer\">&nbsp;</td>\n"
- "<td class=\"slice\">" );
+ "<td class=\"slice\">" );
Concat( message, file->slice );
ConcatCString( message, "\n" );
@@ -249,21 +249,21 @@ static int AdvertisedFilePage(const cGH *GH, httpRequest *request, void *data)
HTTP_SetHeadInfo( message);
HTTP_Send( request, "<style type=\"text/css\">"
- "\t.files td { text-align: left; font-family: sans-serif;\n"
- "\t padding-left: 1ex; padding-right: 1ex; }\n"
- "\t.files td.variable { background-color: #ff9;\n"
- "\t font-weight: bold; }\n"
- "\t.files td.thorn { background-color: #dff;\n"
- "\t color: black; }\n"
- "\t.files td.slice { background-color: #fde;\n"
- "\t font-family: monospace; }\n"
- "\t.files td.link { \n"
- " }\n"
- "\t.files td.desc { background-color: #dff;\n"
- "\t font-style: italic; }\n"
- "\t#filescaption { border-bottom: thin black solid;\n"
- "\t margin-bottom: 1em; }\n"
- "\t</style>\n");
+ "\t.files td { text-align: left; font-family: sans-serif;\n"
+ "\t padding-left: 1ex; padding-right: 1ex; }\n"
+ "\t.files td.variable { background-color: #ff9;\n"
+ "\t font-weight: bold; }\n"
+ "\t.files td.thorn { background-color: #dff;\n"
+ "\t color: black; }\n"
+ "\t.files td.slice { background-color: #fde;\n"
+ "\t font-family: monospace; }\n"
+ "\t.files td.link { \n"
+ " }\n"
+ "\t.files td.desc { background-color: #dff;\n"
+ "\t font-style: italic; }\n"
+ "\t#filescaption { border-bottom: thin black solid;\n"
+ "\t margin-bottom: 1em; }\n"
+ "\t</style>\n");
HTTP_SendString( request, message );
HTTP_Send( request, "</head>\n<body>\n");
@@ -287,9 +287,9 @@ static int AdvertisedFilePage(const cGH *GH, httpRequest *request, void *data)
"<a href=\"/Parameters/index.html\">parameter steering page</a>"
"</p>\n");
HTTP_Send( request,
- "<div class=\"centered\">\n"
+ "<div class=\"centered\">\n"
"<table class=\"files\" id=\"filescaption\" "
- "frame=\"below\" cellpadding=\"0\" cellspacing=\"0\">\n"
+ "frame=\"below\" cellpadding=\"0\" cellspacing=\"0\">\n"
"<tr><td class=\"variable\">\n"
"Variable</td><td class=\"thorn\">Thorn</td>\n"
"<td class=\"slice\"> Slice</td><td class=\"file\"> File</td>\n"
@@ -301,7 +301,7 @@ static int AdvertisedFilePage(const cGH *GH, httpRequest *request, void *data)
SortFilesAccordingTo( filelist, Variable_Thorn_Slice );
HTTP_Send( request, "<table cellpadding=\"0\" cellspacing=\"0\""
- " class=\"files\">\n");
+ " class=\"files\">\n");
buildList( filelist, message, 0, 0 );
HTTP_SendString( request, message);
@@ -448,14 +448,14 @@ static int ViewportFilePage(const cGH *GH, httpRequest *request, void *data)
HTTP_Send( request, "<h1>Viewport</h1>\n");
HTTP_Send( request,
- "<p>This page displays certain types of the output files \n"
- "from the <a href=\"/Output/index.html\">download</a> page \n"
- "as images (currently only JPEGs [mime type image/jpeg]).</p>\n"
- "<p>Many IO methods have <dfn>steerable</dfn> parameters which \n"
- "allow you to e.g. add fields and customise behaviour.\n"
- "Depending on your authorisation, you can access the \n"
- "<a href=\"/Parameters/index.html\">parameter steering page</a></p>\n"
- "<div class=\"centered\">\n");
+ "<p>This page displays certain types of the output files \n"
+ "from the <a href=\"/Output/index.html\">download</a> page \n"
+ "as images (currently only JPEGs [mime type image/jpeg]).</p>\n"
+ "<p>Many IO methods have <dfn>steerable</dfn> parameters which \n"
+ "allow you to e.g. add fields and customise behaviour.\n"
+ "Depending on your authorisation, you can access the \n"
+ "<a href=\"/Parameters/index.html\">parameter steering page</a></p>\n"
+ "<div class=\"centered\">\n");
SortFilesAccordingTo( filelist, Variable_Thorn_Slice );
@@ -467,11 +467,11 @@ static int ViewportFilePage(const cGH *GH, httpRequest *request, void *data)
if (!foundone)
{
HTTP_Send( request,
- "<table class=\"files\" cellspacing=\"5\" cellpadding=\"5\" "
- "rules=\"groups\" >\n"
- "<thead>\n<tr><th>Variable<br />Slice</th>"
- "<th>Description</th><th>Image</th></tr>\n</thead>\n");
- foundone = 1;
+ "<table class=\"files\" cellspacing=\"5\" cellpadding=\"5\" "
+ "rules=\"groups\" >\n"
+ "<thead>\n<tr><th>Variable<br />Slice</th>"
+ "<th>Description</th><th>Image</th></tr>\n</thead>\n");
+ foundone = 1;
}
HTTP_Send( request, "<tr>\n" );
HTTP_Send( request, "<td><span class=\"variable\">" );
@@ -502,7 +502,7 @@ static int ViewportFilePage(const cGH *GH, httpRequest *request, void *data)
else
{
HTTP_Send( request, "<strong>\n<p>No viewable images registered!</p>\n"
- "</strong>\n");
+ "</strong>\n");
}
HTTP_Send( request, "</div>\n");
diff --git a/src/Processors.c b/src/Processors.c
index 0817fb7..cd97361 100644
--- a/src/Processors.c
+++ b/src/Processors.c
@@ -122,12 +122,12 @@ static int ProcessorsPage(const cGH *cctkGH, httpRequest *request, void *data)
HTTP_Send(request, "<h1>Processor Information</h1>\n");
HTTP_Send(request,
- "<div class=\"centered\">\n<table rules=\"cols\">\n"
- "<tr>"
- "<th>Number</th>\n"
- "<th>Machine Name</th>\n"
- "</tr>");
-
+ "<div class=\"centered\">\n<table rules=\"cols\">\n"
+ "<tr>"
+ "<th>Number</th>\n"
+ "<th>Machine Name</th>\n"
+ "</tr>");
+
nprocs = CCTK_nProcs(cctkGH);
for (np=0;np<nprocs;np++)
{
diff --git a/src/PtrList.c b/src/PtrList.c
index d15acc9..6c431d2 100644
--- a/src/PtrList.c
+++ b/src/PtrList.c
@@ -14,8 +14,8 @@ typedef struct ListPage_tag ListPage;
typedef struct PtrList_tag
{
- ListPage *firstPage;
- size_t itemsPerPage;
+ ListPage *firstPage;
+ size_t itemsPerPage;
} PtrList_PLACEHOLDER;
/* ===========================================================================
@@ -26,26 +26,26 @@ typedef struct PtrList_tag
typedef struct ListPage_tag
{
- size_t numberOfItems;
- size_t maxItems;
- ListPage * next;
- void * *items;
+ size_t numberOfItems;
+ size_t maxItems;
+ ListPage * next;
+ void * *items;
} ListPage_PLACEHOLDER;
static ListPage *
ListPage_New( size_t maxItems )
{
- ListPage *new = (ListPage *)calloc( 1, sizeof( ListPage ) );
- if( new )
- {
- new->items = malloc( maxItems * sizeof( void * ) );
- new->maxItems = maxItems;
- }
- return new;
+ ListPage *new = (ListPage *)calloc( 1, sizeof( ListPage ) );
+ if( new )
+ {
+ new->items = malloc( maxItems * sizeof( void * ) );
+ new->maxItems = maxItems;
+ }
+ return new;
}
#define ListPage_IsFull( page ) \
- ( ((const ListPage *)page)->numberOfItems >= page->maxItems )
+ ( ((const ListPage *)page)->numberOfItems >= page->maxItems )
static ListPage *
@@ -60,82 +60,82 @@ ListPage_RemoveItem( ListPage * this, size_t index );
static void *
ListPage_InsertItem( ListPage * this, size_t index, void * item );
- /* ListPage_Dup does not copy the next pointer */
+ /* ListPage_Dup does not copy the next pointer */
ListPage *
ListPage_Dup( const ListPage * other )
{
- ListPage * this = ListPage_New( other->maxItems );
- if( other->numberOfItems > 0 )
- memcpy( this->items, other->items,
- other->numberOfItems * sizeof( void * ) );
+ ListPage * this = ListPage_New( other->maxItems );
+ if( other->numberOfItems > 0 )
+ memcpy( this->items, other->items,
+ other->numberOfItems * sizeof( void * ) );
- this->maxItems = other->maxItems;
- this->numberOfItems = other->numberOfItems;
+ this->maxItems = other->maxItems;
+ this->numberOfItems = other->numberOfItems;
- return this;
+ return this;
}
- /* Returns the input pointer if it doesn't fit on page
- * (for similarity with InsertItem) */
+ /* Returns the input pointer if it doesn't fit on page
+ * (for similarity with InsertItem) */
void *
ListPage_Append( ListPage *this, void * item )
{
- if( this->numberOfItems < this->maxItems ) /* If page not full */
- {
- *( this->items + this->numberOfItems ) = item; /* item to end*/
- this->numberOfItems++; /* Update number of items on page */
- return NULL;
- }
- return item;
+ if( this->numberOfItems < this->maxItems ) /* If page not full */
+ {
+ *( this->items + this->numberOfItems ) = item; /* item to end*/
+ this->numberOfItems++; /* Update number of items on page */
+ return NULL;
+ }
+ return item;
}
- /* Returns a pointer to the item removed, or NULL if no item found */
+ /* Returns a pointer to the item removed, or NULL if no item found */
void *
ListPage_RemoveItem( ListPage *this, size_t index )
{
- if( index < this->numberOfItems )
- {
- const size_t lastItemToShift = this->numberOfItems - 1;
- size_t i;
- void *item = *( this->items + index );
+ if( index < this->numberOfItems )
+ {
+ const size_t lastItemToShift = this->numberOfItems - 1;
+ size_t i;
+ void *item = *( this->items + index );
- this->numberOfItems--;
+ this->numberOfItems--;
- for( i = index; i < lastItemToShift; i++ )
- *( this->items + i ) = *( this->items + i + 1 );
+ for( i = index; i < lastItemToShift; i++ )
+ *( this->items + i ) = *( this->items + i + 1 );
- return item;
- }
- return NULL;
+ return item;
+ }
+ return NULL;
}
- /* Returns a pointer to any item bumped off the page due to
- * the page being full. (could be the input item) */
+ /* Returns a pointer to any item bumped off the page due to
+ * the page being full. (could be the input item) */
void *
ListPage_InsertItem( ListPage *this, size_t index, void * item )
{
- void * remainder = NULL;
+ void * remainder = NULL;
- if( index < this->numberOfItems )
- {
- const size_t firstItemToShift = this->numberOfItems - 1;
- size_t i;
+ if( index < this->numberOfItems )
+ {
+ const size_t firstItemToShift = this->numberOfItems - 1;
+ size_t i;
- if( this->numberOfItems >= this->maxItems )
- remainder = *( this->items + firstItemToShift );
+ if( this->numberOfItems >= this->maxItems )
+ remainder = *( this->items + firstItemToShift );
- this->numberOfItems = MIN( this->numberOfItems + 1,
- this->maxItems );
+ this->numberOfItems = MIN( this->numberOfItems + 1,
+ this->maxItems );
- for( i = firstItemToShift; i > index; i-- )
- *( this->items + i ) = *( this->items + i - 1 );
+ for( i = firstItemToShift; i > index; i-- )
+ *( this->items + i ) = *( this->items + i - 1 );
- *( this->items + index ) = item;
- }
- else
- remainder = ListPage_Append( this, item );
+ *( this->items + index ) = item;
+ }
+ else
+ remainder = ListPage_Append( this, item );
- return remainder;
+ return remainder;
}
/* ===========================================================================
@@ -146,511 +146,510 @@ ListPage_InsertItem( ListPage *this, size_t index, void * item )
static void
List_HandleAddressingError()
{
- /* To taste */
+ /* To taste */
}
static ListPage * List_Xerox( const PtrList *other);
static void List_FindItemAddress( const PtrList *this, size_t itemNo,
- ListPage ** thePage, size_t *thePageIndex );
+ ListPage ** thePage, size_t *thePageIndex );
- /*_____________________________________________________________________
- **Constructor & Destructor**__________________________________________
- *_____________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Constructor & Destructor**__________________________________________
+ *_____________________________________________________________________
+ */
PtrList *
List_New( void )
{
- return List_NewWithPageSize( TAKEDEFAULTSIZE );
+ return List_NewWithPageSize( TAKEDEFAULTSIZE );
}
PtrList *
List_NewWithPageSize( size_t itemsOnFullPage )
{
- PtrList *new = (PtrList *)calloc( 1, sizeof( PtrList ) );
- if( new )
- {
- if( itemsOnFullPage == TAKEDEFAULTSIZE )
- new->itemsPerPage = ITEMSONFULLPAGE;
- else
- new->itemsPerPage = itemsOnFullPage;
- }
- return new;
+ PtrList *new = (PtrList *)calloc( 1, sizeof( PtrList ) );
+ if( new )
+ {
+ if( itemsOnFullPage == TAKEDEFAULTSIZE )
+ new->itemsPerPage = ITEMSONFULLPAGE;
+ else
+ new->itemsPerPage = itemsOnFullPage;
+ }
+ return new;
}
PtrList *
List_MakeCopy( const PtrList *other )
{
- PtrList *this = (PtrList *)calloc( 1, sizeof( PtrList ) );
- this->itemsPerPage = other->itemsPerPage;
- this->firstPage = List_Xerox( other );
- return this;
+ PtrList *this = (PtrList *)calloc( 1, sizeof( PtrList ) );
+ this->itemsPerPage = other->itemsPerPage;
+ this->firstPage = List_Xerox( other );
+ return this;
}
void
List_Delete( PtrList *list )
{
- List_Empty( list );
- free( list );
+ List_Empty( list );
+ free( list );
}
- /*_____________________________________________________________________
- **Empty**____________________________________________________________
- * Runs through the list of ListPages deleting the (previous) page.
- *_____________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Empty**____________________________________________________________
+ * Runs through the list of ListPages deleting the (previous) page.
+ *_____________________________________________________________________
+ */
void
List_Empty( PtrList * this )
{
- if( this->firstPage != NULL )
- {
- ListPage *prevPage = this->firstPage,
- *startPage = this->firstPage->next;
- ListPage *page;
-
- this->firstPage = NULL; /* Prefer to do this first,
- so list is consistent */
- for( page = startPage; page != NULL; page = page->next )
- {
- free( prevPage );
- prevPage = page;
- }
- free( prevPage );
- }
+ if( this->firstPage != NULL )
+ {
+ ListPage *prevPage = this->firstPage,
+ *startPage = this->firstPage->next;
+ ListPage *page;
+
+ this->firstPage = NULL; /* Prefer to do this first,
+ so list is consistent */
+ for( page = startPage; page != NULL; page = page->next )
+ {
+ free( prevPage );
+ prevPage = page;
+ }
+ free( prevPage );
+ }
}
- /*_____________________________________________________________________
- **NumberOfItems**______________________________________________________
- * Runs through the list of ListPages totalling the items on each page.
- * -> This number could be cached.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **NumberOfItems**______________________________________________________
+ * Runs through the list of ListPages totalling the items on each page.
+ * -> This number could be cached.
+ *______________________________________________________________________
+ */
size_t
List_NumberOfItems( const PtrList *this )
{
- size_t number = 0;
- ListPage *page;
+ size_t number = 0;
+ ListPage *page;
- for( page = this->firstPage; page != NULL; page = page->next )
- number += page->numberOfItems;
+ for( page = this->firstPage; page != NULL; page = page->next )
+ number += page->numberOfItems;
- return number;
+ return number;
}
- /*_____________________________________________________________________
- **Append**_____________________________________________________________
- * This and Insert the only PtrList method that allocates ListPages.
- * If there are no pages with space on them, it allocates an new
- * page and links the page the the previous last page.
- * If there is space on the page, it adds the item to the end of
- * the page and updates the number of items on the page.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Append**_____________________________________________________________
+ * This and Insert the only PtrList method that allocates ListPages.
+ * If there are no pages with space on them, it allocates an new
+ * page and links the page the the previous last page.
+ * If there is space on the page, it adds the item to the end of
+ * the page and updates the number of items on the page.
+ *______________________________________________________________________
+ */
void
List_Append( PtrList *this, void * newItem )
{
- ListPage *page;
+ ListPage *page;
- if( this->firstPage == NULL ) /* Add first page if necessary*/
- this->firstPage = ListPage_New( this->itemsPerPage );
+ if( this->firstPage == NULL ) /* Add first page if necessary*/
+ this->firstPage = ListPage_New( this->itemsPerPage );
- page = this->firstPage;
+ page = this->firstPage;
- while( page != NULL ) /* Cycle through pages */
- { /* Try to put on page*/
- if( ListPage_Append( page, newItem ) == NULL )
- return; /* Go home with a smile */
- else if( page->next == NULL ) /* If next page doesn't exist*/
- page->next = ListPage_New( this->itemsPerPage );
- /* make new page and */
- /* link to this*/
+ while( page != NULL ) /* Cycle through pages */
+ { /* Try to put on page*/
+ if( ListPage_Append( page, newItem ) == NULL )
+ return; /* Go home with a smile */
+ else if( page->next == NULL ) /* If next page doesn't exist*/
+ page->next = ListPage_New( this->itemsPerPage );
+ /* make new page and */
+ /* link to this*/
- page = page->next; /* Try the next page*/
- }
- List_HandleAddressingError();
+ page = page->next; /* Try the next page*/
+ }
+ List_HandleAddressingError();
}
- /*_____________________________________________________________________
- * Internal routine for List_Insert.
- * Assumes check has already been done for item address and that
- * it exists on the given page.
- *
- * It is inserted on the page. The question is, what to do if the
- * page was almost empty, and an item had to be bumped off the page
- * to accomodate it.
- *
- * Could shift all elemtents in the list up by one. Might be
- * expensive
- *
- * Strategey here will be to add a new page after the present one
- * if the next page is either full or non-existant. That way, only
- * elements on the next page are affected, and if another item is
- * added to the present page (as often happens) very little more work
- * need be done.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ * Internal routine for List_Insert.
+ * Assumes check has already been done for item address and that
+ * it exists on the given page.
+ *
+ * It is inserted on the page. The question is, what to do if the
+ * page was almost empty, and an item had to be bumped off the page
+ * to accomodate it.
+ *
+ * Could shift all elemtents in the list up by one. Might be
+ * expensive
+ *
+ * Strategey here will be to add a new page after the present one
+ * if the next page is either full or non-existant. That way, only
+ * elements on the next page are affected, and if another item is
+ * added to the present page (as often happens) very little more work
+ * need be done.
+ *______________________________________________________________________
+ */
static void
List_InsertExistingItem( PtrList *list, ListPage *page, size_t pageIndex,
- void *item )
-{
- void * remnant = ListPage_InsertItem( page, pageIndex, item );
- if( remnant ) /* An item got bumped off when inserting into page */
- {
- ListPage *next = page->next;
- if( next == NULL || ListPage_IsFull( next ) )
- {
- ListPage *new = ListPage_New( list->itemsPerPage );
- ListPage_Append( new, item ); /* Item on new */
- new->next = next; /* link new page */
- page->next = new;
- }
- else
- ListPage_InsertItem( next, 0, remnant );
- }
+ void *item )
+{
+ void * remnant = ListPage_InsertItem( page, pageIndex, item );
+ if( remnant ) /* An item got bumped off when inserting into page */
+ {
+ ListPage *next = page->next;
+ if( next == NULL || ListPage_IsFull( next ) )
+ {
+ ListPage *new = ListPage_New( list->itemsPerPage );
+ ListPage_Append( new, item ); /* Item on new */
+ new->next = next; /* link new page */
+ page->next = new;
+ }
+ else
+ ListPage_InsertItem( next, 0, remnant );
+ }
}
- /*_____________________________________________________________________
+ /*_____________________________________________________________________
**List_Insert**
- * Inserts the item at the specified index, shifting indices of
- * existing list items as necessary. If index equals the number
- * of items in the list less one, the item is appended to the list.
- *______________________________________________________________________
- */
+ * Inserts the item at the specified index, shifting indices of
+ * existing list items as necessary. If index equals the number
+ * of items in the list less one, the item is appended to the list.
+ *______________________________________________________________________
+ */
void
List_Insert( PtrList * list, size_t index, void * item )
{
- if( index >= List_NumberOfItems( list ) )
- List_Append( list, item );
- else
- {
- ListPage *page = NULL;
- size_t pageIndex;
-
- List_FindItemAddress( list, index, &page, &pageIndex );
-
- if( page != NULL )
- List_InsertExistingItem( list, page, pageIndex, item );
- else
- List_HandleAddressingError();
- /* probably should handle an addressing error */
- }
+ if( index >= List_NumberOfItems( list ) )
+ List_Append( list, item );
+ else
+ {
+ ListPage *page = NULL;
+ size_t pageIndex;
+
+ List_FindItemAddress( list, index, &page, &pageIndex );
+
+ if( page != NULL )
+ List_InsertExistingItem( list, page, pageIndex, item );
+ else
+ List_HandleAddressingError();
+ /* probably should handle an addressing error */
+ }
}
- /*_____________________________________________________________________
- **Item**_______________________________________________________________
- * Returns the item of given index; returns NULL if no such index.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Item**_______________________________________________________________
+ * Returns the item of given index; returns NULL if no such index.
+ *______________________________________________________________________
+ */
void *
List_Item( const PtrList *this, size_t requestedIndex )
{
- ListPage *itsPage = NULL;
- size_t itsPageIndex;
+ ListPage *itsPage = NULL;
+ size_t itsPageIndex;
- List_FindItemAddress( this, requestedIndex, &itsPage, &itsPageIndex );
+ List_FindItemAddress( this, requestedIndex, &itsPage, &itsPageIndex );
- if( itsPage != NULL )
- return *( itsPage->items + itsPageIndex );
+ if( itsPage != NULL )
+ return *( itsPage->items + itsPageIndex );
- return NULL;
+ return NULL;
}
- /*_____________________________________________________________________
- **SetItem**____________________________________________________________
- * Sets the item of given index. Calls user-supplied addressing
- * handler if no such item exists.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **SetItem**____________________________________________________________
+ * Sets the item of given index. Calls user-supplied addressing
+ * handler if no such item exists.
+ *______________________________________________________________________
+ */
void
List_SetItem( PtrList *this, size_t requestedIndex, void *value )
{
- ListPage *itsPage = NULL;
- size_t itsPageIndex;
+ ListPage *itsPage = NULL;
+ size_t itsPageIndex;
- List_FindItemAddress( this, requestedIndex, &itsPage, &itsPageIndex );
+ List_FindItemAddress( this, requestedIndex, &itsPage, &itsPageIndex );
- if( itsPage != NULL )
- *( itsPage->items + itsPageIndex ) = value;
- else
- List_HandleAddressingError();
+ if( itsPage != NULL )
+ *( itsPage->items + itsPageIndex ) = value;
+ else
+ List_HandleAddressingError();
}
- /*_____________________________________________________________________
- **CopyList**_________________________________________________________
- * Empties this list and puts items from other list in it.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **CopyList**_________________________________________________________
+ * Empties this list and puts items from other list in it.
+ *______________________________________________________________________
+ */
void
List_CopyList( PtrList * this, const PtrList * other )
{
- List_Empty( this );
- this->itemsPerPage = other->itemsPerPage;
- this->firstPage = List_Xerox( other );
+ List_Empty( this );
+ this->itemsPerPage = other->itemsPerPage;
+ this->firstPage = List_Xerox( other );
}
- /*_____________________________________________________________________
- **RemoveItem**_________________________________________________________
- * Removes the item of given index from the list by shifting all the
- * following items back by one and reducing itsNumberOfItems by one.
- * -> It would kind of be nice if this also deleted empty pages
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **RemoveItem**_________________________________________________________
+ * Removes the item of given index from the list by shifting all the
+ * following items back by one and reducing itsNumberOfItems by one.
+ * -> It would kind of be nice if this also deleted empty pages
+ *______________________________________________________________________
+ */
void *
List_RemoveItem( PtrList *this, const size_t requestedIndex )
{
- ListPage *page = NULL;
- size_t pageIndex = 0;
+ ListPage *page = NULL;
+ size_t pageIndex = 0;
- List_FindItemAddress( this, requestedIndex, &page, &pageIndex );
+ List_FindItemAddress( this, requestedIndex, &page, &pageIndex );
- if( page != NULL )
- return ListPage_RemoveItem( page, pageIndex );
- else
- List_HandleAddressingError();
+ if( page != NULL )
+ return ListPage_RemoveItem( page, pageIndex );
+ else
+ List_HandleAddressingError();
- return NULL;
+ return NULL;
}
- /*_____________________________________________________________________
- **Remove**_____________________________________________________________
- * Removes the first item in the list with matching pointer.
- * Note: No check is done for duplicate pointers in the list.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Remove**_____________________________________________________________
+ * Removes the first item in the list with matching pointer.
+ * Note: No check is done for duplicate pointers in the list.
+ *______________________________________________________________________
+ */
void
List_Remove( PtrList *this, void * item )
{
- size_t index = 0;
+ size_t index = 0;
- if( List_GetIndexOf( this, item, &index ) )
- List_RemoveItem( this, index );
+ if( List_GetIndexOf( this, item, &index ) )
+ List_RemoveItem( this, index );
}
- /*_____________________________________________________________________
- **GetIndexOf**_________________________________________________________
- * Inverse of Item(), if pointers in list are unique.
- * Note: No check is done for duplicate pointers in the list.
- * Returns TRUE and sets the indexi argument to the first item in the
- * list with matching pointer, if such an item exists; otherwise
- * returns FALSE.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **GetIndexOf**_________________________________________________________
+ * Inverse of Item(), if pointers in list are unique.
+ * Note: No check is done for duplicate pointers in the list.
+ * Returns TRUE and sets the indexi argument to the first item in the
+ * list with matching pointer, if such an item exists; otherwise
+ * returns FALSE.
+ *______________________________________________________________________
+ */
PLBOOL
List_GetIndexOf( const PtrList *this, const void * item, size_t * index )
{
- size_t numItemsOnPreviousPages = 0;
- ListPage *page = NULL;
-
- for( page = this->firstPage; page != NULL; page = page->next )
- {
- const size_t numItemsOnPage = page->numberOfItems;
- size_t i;
-
- for( i = 0; i < numItemsOnPage; i++ )
- if( *( page->items + i ) == item )
- {
- *index = numItemsOnPreviousPages + i;
- return PLTRUE;
- }
- numItemsOnPreviousPages += numItemsOnPage;
- }
- return PLFALSE;
+ size_t numItemsOnPreviousPages = 0;
+ ListPage *page = NULL;
+
+ for( page = this->firstPage; page != NULL; page = page->next )
+ {
+ const size_t numItemsOnPage = page->numberOfItems;
+ size_t i;
+
+ for( i = 0; i < numItemsOnPage; i++ )
+ if( *( page->items + i ) == item )
+ {
+ *index = numItemsOnPreviousPages + i;
+ return PLTRUE;
+ }
+ numItemsOnPreviousPages += numItemsOnPage;
+ }
+ return PLFALSE;
}
#if 0
static void
List_BubbleSort( PtrList * list, ListSortComparison comparison )
{
- const size_t n = List_NumberOfItems( list );
- size_t i, j;
+ const size_t n = List_NumberOfItems( list );
+ size_t i, j;
- for( i = 0; i < n; i++ )
- {
- void *item_i = List_Item( list, i );
+ for( i = 0; i < n; i++ )
+ {
+ void *item_i = List_Item( list, i );
- for( j = i + 1; j < n; j++ )
- {
- void *item_j = List_Item( list, j );
+ for( j = i + 1; j < n; j++ )
+ {
+ void *item_j = List_Item( list, j );
- if( comparison( item_i, item_j ) > 0 )
- {
- List_SwapItems( list, i, j );
- item_i = item_j;
- }
- }
- }
+ if( comparison( item_i, item_j ) > 0 )
+ {
+ List_SwapItems( list, i, j );
+ item_i = item_j;
+ }
+ }
+ }
}
#endif
void
List_SwapItems( PtrList * v, size_t a, size_t b )
{
- ListPage *aPage = NULL, *bPage = NULL;
- size_t aPageInd, bPageInd;
+ ListPage *aPage = NULL, *bPage = NULL;
+ size_t aPageInd, bPageInd;
- List_FindItemAddress( v, a, &aPage, &aPageInd );
- List_FindItemAddress( v, b, &bPage, &bPageInd );
+ List_FindItemAddress( v, a, &aPage, &aPageInd );
+ List_FindItemAddress( v, b, &bPage, &bPageInd );
- if( aPage != NULL && bPage != NULL )
- {
- void *temp = *( aPage->items + aPageInd );
- *( aPage->items + aPageInd ) = *( bPage->items + bPageInd );
- *( bPage->items + bPageInd ) = temp;
- }
+ if( aPage != NULL && bPage != NULL )
+ {
+ void *temp = *( aPage->items + aPageInd );
+ *( aPage->items + aPageInd ) = *( bPage->items + bPageInd );
+ *( bPage->items + bPageInd ) = temp;
+ }
}
- /* Adapted from Kernighan & Ritchie */
+ /* Adapted from Kernighan & Ritchie */
static void
List_Qsort( PtrList * v, size_t left, size_t right,
ListSortComparison comparison )
{
- size_t i, last;
-
- if( left >= right ) /* do nothing if array contains */
- return; /* fewer than two elements */
- List_SwapItems( v, left, ( left + right ) / 2); /* move partition */
- last = left; /* elem to v[0] */
- for( i = left + 1; i <= right; i++ )
- {/* SW this could be improved a lot */
- void * item_i = List_Item( v, i );
- void * item_left = List_Item( v, left );
- if( comparison( item_i, item_left ) < 0 )
- List_SwapItems( v, ++last, i );
- }
- List_SwapItems( v, left, last ); /* restore partition elem */
+ size_t i, last;
+
+ if( left >= right ) /* do nothing if array contains */
+ return; /* fewer than two elements */
+ List_SwapItems( v, left, ( left + right ) / 2); /* move partition */
+ last = left; /* elem to v[0] */
+ for( i = left + 1; i <= right; i++ )
+ {/* SW this could be improved a lot */
+ void * item_i = List_Item( v, i );
+ void * item_left = List_Item( v, left );
+ if( comparison( item_i, item_left ) < 0 )
+ List_SwapItems( v, ++last, i );
+ }
+ List_SwapItems( v, left, last ); /* restore partition elem */
/* SW NEED TO THINK ABOUT THIS */
- if( last > 0 ) /* K&R use int, so this isn't an issue for them */
- List_Qsort( v, left, last - 1, comparison );
- List_Qsort( v, last + 1, right, comparison );
+ if( last > 0 ) /* K&R use int, so this isn't an issue for them */
+ List_Qsort( v, left, last - 1, comparison );
+ List_Qsort( v, last + 1, right, comparison );
}
- /*_____________________________________________________________________
- **SortAccordingTo**__________________________________________________
- * Based on the comparison of any two items provided by the comparison
- * function argument, sorts the list.
- * Note here it uses a bubble sort, which is slow but easy to
- * understand. Want something faster? Write your own!
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **SortAccordingTo**__________________________________________________
+ * Based on the comparison of any two items provided by the comparison
+ * function argument, sorts the list.
+ * Note here it uses a bubble sort, which is slow but easy to
+ * understand. Want something faster? Write your own!
+ *______________________________________________________________________
+ */
void
List_SortAccordingTo( PtrList * list, ListSortComparison comparison )
{
- size_t n = List_NumberOfItems( list );
- if( n > 1 )
- List_Qsort( list, 0, n - 1, comparison );
+ size_t n = List_NumberOfItems( list );
+ if( n > 1 )
+ List_Qsort( list, 0, n - 1, comparison );
}
- /*_____________________________________________________________________
- **FirstItemSuchThat**__________________________________________________
- * Takes a ListCondition function, returns the pointer value that
- * satisfies the condition, otherwise returns NULL,
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **FirstItemSuchThat**__________________________________________________
+ * Takes a ListCondition function, returns the pointer value that
+ * satisfies the condition, otherwise returns NULL,
+ *______________________________________________________________________
+ */
void *
List_FirstItemSuchThat( const PtrList *list, ListCondition condition )
{
- const size_t n = List_NumberOfItems( list );
- size_t i;
+ const size_t n = List_NumberOfItems( list );
+ size_t i;
- for( i = 0; i < n; i++ )
- if( condition( List_Item( list, i ) ) )
- return List_Item( list, i );
+ for( i = 0; i < n; i++ )
+ if( condition( List_Item( list, i ) ) )
+ return List_Item( list, i );
- return NULL;
+ return NULL;
}
- /*_____________________________________________________________________
- **FindFirstIndexSuchThat**_____________________________________________
- * Takes a ListCondition function, sets the index pointer to the index
- * of the first pointer in the list that satisfies condition.
- * Otherwise returns PLFALSE.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **FindFirstIndexSuchThat**_____________________________________________
+ * Takes a ListCondition function, sets the index pointer to the index
+ * of the first pointer in the list that satisfies condition.
+ * Otherwise returns PLFALSE.
+ *______________________________________________________________________
+ */
PLBOOL
List_FindFirstIndexSuchThat( const PtrList *list, ListCondition condition,
- size_t * index )
+ size_t * index )
{
- const size_t n = List_NumberOfItems( list );
- size_t i;
+ const size_t n = List_NumberOfItems( list );
+ size_t i;
- for( i = 0; i < n; i++ )
- if( condition( List_Item( list, i ) ) )
- {
- *index = i;
- return PLTRUE;
- }
+ for( i = 0; i < n; i++ )
+ if( condition( List_Item( list, i ) ) )
+ {
+ *index = i;
+ return PLTRUE;
+ }
- return PLFALSE;
+ return PLFALSE;
}
- /*_____________________________________________________________________
- **FreeItemsInListAndEmpty**____________________________________________
- * Lists don't usually delete the things they refer to.
- * This function takes the list and uses it to free the listed items.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **FreeItemsInListAndEmpty**____________________________________________
+ * Lists don't usually delete the things they refer to.
+ * This function takes the list and uses it to free the listed items.
+ *______________________________________________________________________
+ */
void
List_FreeItemsInListAndEmpty( PtrList * this )
{
- size_t i = List_NumberOfItems( this );
- void *item = NULL;
-
- while( i > 0 ) /* Remove items in reverse order for efficeincy */
- {
- i--;
- item = List_Item( this, i );
- List_RemoveItem( this, i ); /* Remove item before deleting */
- /* (for consistency) */
- free( item );
- }
+ size_t i = List_NumberOfItems( this );
+ void *item = NULL;
+
+ while( i > 0 ) /* Remove items in reverse order for efficeincy */
+ {
+ i--;
+ item = List_Item( this, i );
+ List_RemoveItem( this, i ); /* Remove item before deleting */
+ /* (for consistency) */
+ free( item );
+ }
}
- /*_____________________________________________________________________
- **FindItemAddress**____________________________________________________
- * Private utility that gets the page and index relative to the page
- * given the item index. Sets *thePage to NULL if no such index.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **FindItemAddress**____________________________________________________
+ * Private utility that gets the page and index relative to the page
+ * given the item index. Sets *thePage to NULL if no such index.
+ *______________________________________________________________________
+ */
void
List_FindItemAddress( const PtrList *this, size_t itemNo,
- ListPage ** thePage, size_t *thePageIndex )
-{
- ListPage *page = NULL;
- size_t numItemsIncludingThisPage = 0,
- numItemsOnPreviousPages = 0;
-
- *thePage = NULL;
- *thePageIndex = 0;
-
- for( page = this->firstPage; page != NULL; page = page->next )
- {
- numItemsIncludingThisPage += page->numberOfItems;
-
- if( numItemsIncludingThisPage > itemNo )
- {
- *thePage = page;
- *thePageIndex = itemNo - numItemsOnPreviousPages;
- return;
- }
- numItemsOnPreviousPages = numItemsIncludingThisPage;
- }
+ ListPage ** thePage, size_t *thePageIndex )
+{
+ ListPage *page = NULL;
+ size_t numItemsIncludingThisPage = 0,
+ numItemsOnPreviousPages = 0;
+
+ *thePage = NULL;
+ *thePageIndex = 0;
+
+ for( page = this->firstPage; page != NULL; page = page->next )
+ {
+ numItemsIncludingThisPage += page->numberOfItems;
+
+ if( numItemsIncludingThisPage > itemNo )
+ {
+ *thePage = page;
+ *thePageIndex = itemNo - numItemsOnPreviousPages;
+ return;
+ }
+ numItemsOnPreviousPages = numItemsIncludingThisPage;
+ }
}
- /*_____________________________________________________________________
- **Xerox**______________________________________________________________
- * Private utility that makes a duplicate of the pages in the list.
- *______________________________________________________________________
- */
+ /*_____________________________________________________________________
+ **Xerox**______________________________________________________________
+ * Private utility that makes a duplicate of the pages in the list.
+ *______________________________________________________________________
+ */
ListPage *
List_Xerox( const PtrList *list)
{
- ListPage *copy = NULL, *newPage = NULL, *page = list->firstPage;
-
- if( list->firstPage != NULL )
- copy = newPage = ListPage_Dup( list->firstPage );
-
- if( newPage != NULL )
- do
- {
- if( page->next != NULL )
- {
- page = page->next;
- newPage->next = ListPage_Dup( page );
- }
- newPage = newPage->next;
- }
- while( newPage != NULL );
- return copy;
+ ListPage *copy = NULL, *newPage = NULL, *page = list->firstPage;
+
+ if( list->firstPage != NULL )
+ copy = newPage = ListPage_Dup( list->firstPage );
+
+ if( newPage != NULL )
+ do
+ {
+ if( page->next != NULL )
+ {
+ page = page->next;
+ newPage->next = ListPage_Dup( page );
+ }
+ newPage = newPage->next;
+ }
+ while( newPage != NULL );
+ return copy;
}
-