FOSSology  4.4.0
Open Source License Compliance by Open Source Software
list.c File Reference

list manipulation functions and str/val Compare functions More...

#include "nomos.h"
#include "list.h"
#include "util.h"
Include dependency graph for list.c:

Go to the source code of this file.

Macros

#define DFL_STARTSIZE   100
 

Functions

static int strCompare (item_t *, item_t *)
 
static int strIcaseCompare (item_t *, item_t *)
 
static int strCompareBasename (item_t *, item_t *)
 
static int valCompareDsc (item_t *, item_t *)
 
static int valCompareAsc (item_t *, item_t *)
 
static int bufCompare (item_t *, item_t *)
 
static void listDoubleSize (list_t *l)
 Double the size of list. More...
 
static void listValidate (list_t *l, int appendFlag)
 Validate list. More...
 
void listInit (list_t *l, int size, char *label)
 intialize a list, if the list is not empty, empty it (initialize it to zero's). More...
 
void listClear (list_t *l, int deallocFlag)
 Destroy list_t. More...
 
item_tlistGetItem (list_t *l, char *s)
 get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist. More...
 
item_tlistAppend (list_t *l, char *s)
 Utility list that isn't sorted - faster for unpacking archives and maintaining lists of files (we only need to sort that list at the end of the unpacking process - this just appends an entry at the bottom/end of the list.
 
item_tlistIterate (list_t *l)
 return a pointer to listitem, returns a NULL_ITEM when no more items to return. More...
 
void listIterationReset (list_t *l)
 Rest list ix to -1. More...
 
int listDelete (list_t *l, item_t *p)
 Delete an item from list. More...
 
void listSort (list_t *l, int sortType)
 Sort the list as per the sortType passed. More...
 
int listCount (list_t *l)
 
void listDump (list_t *l, int verbose)
 print the passed in list More...
 

Detailed Description

list manipulation functions and str/val Compare functions

list.c supplies all of the functions needed to manipulate the list and listitem structures defined in nomos.h. It also supplies the str*Compare* and valCompare* functions.

Version
"$Id: list.c 3676 2010-11-15 23:10:52Z bobgo $"

Definition in file list.c.

Function Documentation

◆ bufCompare()

static int bufCompare ( item_t p1,
item_t p2 
)
static

qsort utility-function to create an alphabetically sorted (ASCENDING) list based on the string value in the item_t 'buf' field

Definition at line 791 of file list.c.

◆ listClear()

void listClear ( list_t l,
int  deallocFlag 
)

Destroy list_t.

Parameters
lList to destroy
deallocFlagSet to also free list memory

Definition at line 106 of file list.c.

◆ listCount()

int listCount ( list_t l)

Be careful about calling this function; some lists use the 'val' field as a flag, others use it as a count!

Definition at line 800 of file list.c.

◆ listDelete()

int listDelete ( list_t l,
item_t p 
)

Delete an item from list.

The function also rearrange list after deletion.

Parameters
lList to delete from
pItem to delete
Returns
0 on error, 1 on success

Definition at line 537 of file list.c.

◆ listDoubleSize()

static void listDoubleSize ( list_t l)
static

Double the size of list.

Creates a new pointer with double the size of current list, copy old list items, free the old list->items and assign new pointer to list->items

Parameters
lList to be doubled

Definition at line 588 of file list.c.

◆ listDump()

void listDump ( list_t l,
int  verbose 
)

print the passed in list

Parameters
*lthe list to dump
verboseflag, print more

Definition at line 829 of file list.c.

Here is the call graph for this function:

◆ listGetItem()

item_t* listGetItem ( list_t l,
char *  s 
)

get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist.

This function searches the str member in the listitem structure, if found, a pointer to that item is returned. If not found, the item is added to the list of items 'in the middle' of the list.

Parameters
list_t*list the list to search/update
*spointer to the string to search for.
Returns
pointer to the item
Todo:
CDB – Change so that there is only one loop variable in the for loop

Definition at line 246 of file list.c.

◆ listInit()

void listInit ( list_t l,
int  size,
char *  label 
)

intialize a list, if the list is not empty, empty it (initialize it to zero's).

sets:
l->name to label
l->size to DFL_STARTSIZE
l->used = 0
l->ix = -1
l->sorted = UNSORTED

Parameters
lList to initialize
labelName of the list
Note
label can't be longer than l->name (64)

Definition at line 54 of file list.c.

◆ listIterate()

item_t* listIterate ( list_t l)

return a pointer to listitem, returns a NULL_ITEM when no more items to return.

Parameters
llist a point to a list
Note
This routine increments the ix member! (bad boy)
Todo:
remove/fix the fact that this routine increments ix.

Definition at line 477 of file list.c.

◆ listIterationReset()

void listIterationReset ( list_t l)

Rest list ix to -1.

Parameters
lList to reset

Definition at line 513 of file list.c.

◆ listSort()

void listSort ( list_t l,
int  sortType 
)

Sort the list as per the sortType passed.

Parameters
[in,out]lList to sort
sortType

Which type of sorting to use.

It can of UNSORTED|SORT_BY_NAME_ICASE|SORT_BY_NAME|SORT_BY_COUNT_DSC| SORT_BY_COUNT_ASC|SORT_BY_ALIAS|SORT_BY_BASENAME

Definition at line 631 of file list.c.

◆ listValidate()

void listValidate ( list_t l,
int  appendFlag 
)
static

Validate list.

Parameters
lList to validate
appendFlagIf set and list is completely used, double its size
Note
Question: do we want to initialize the list here, instead of aborting? It would mean we don't have to initialize EVERY list EVERYWHERE – we could just set the size to zero and start adding/inserting.

Definition at line 207 of file list.c.

◆ strCompare()

static int strCompare ( item_t p1,
item_t p2 
)
static

qsort utility-function to create an alphabetically sorted (ASCENDING) list based on the string value in the item_t 'str' field

Definition at line 753 of file list.c.

◆ strCompareBasename()

static int strCompareBasename ( item_t p1,
item_t p2 
)
static

qsort utility-function to create an alphabetically sorted (ASCENDING) list based on the path-basename of string value in the item_t 'str' field

Definition at line 764 of file list.c.

◆ strIcaseCompare()

static int strIcaseCompare ( item_t p1,
item_t p2 
)
static

qsort utility-function to create an alphabetically sorted (ASCENDING) [case-insensitive] list based on the string value in the item_t 'str' field

Definition at line 742 of file list.c.

◆ valCompareAsc()

static int valCompareAsc ( item_t p1,
item_t p2 
)
static

qsort utility-function to create a numerically sorted (ASCENDING) list based on the integer value in the item_t 'val' field

Definition at line 775 of file list.c.

◆ valCompareDsc()

static int valCompareDsc ( item_t p1,
item_t p2 
)
static

qsort utility-function to create a numerically sorted (DESCENDING) list based on the integer value in the item_t 'val' field

Definition at line 783 of file list.c.