Commit e918e648 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added function for sorting channel list


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@31 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent caf84817
......@@ -70,5 +70,21 @@ char *nmxp_chan_lookupName(uint32_t key, NMXP_CHAN_LIST *channelList);
*/
NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dataType);
/*! Sort list by channel key
*
* \param channelList Channel List
*
*/
void nmxp_chan_sortByKey(NMXP_CHAN_LIST *channelList);
/*! Sort list by channel name
*
* \param channelList Channel List
*
*/
void nmxp_chan_sortByName(NMXP_CHAN_LIST *channelList);
#endif
......@@ -63,3 +63,36 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
return ret_channelList;
}
// Comparison Key Function
int chan_key_compare(const void *a, const void *b)
{
int ret = 0;
NMXP_CHAN_KEY *pa = (NMXP_CHAN_KEY *) a;
NMXP_CHAN_KEY *pb = (NMXP_CHAN_KEY *) b;
if(pa->key > pb->key) {
ret = 1;
} else if(pa->key < pb->key) {
ret = -1;
}
return ret;
}
void nmxp_chan_sortByKey(NMXP_CHAN_LIST *channelList) {
qsort (channelList->channel, channelList->number, sizeof (NMXP_CHAN_KEY), chan_key_compare);
}
// Comparison Name Function
int chan_name_compare(const void *a, const void *b)
{
NMXP_CHAN_KEY *pa = (NMXP_CHAN_KEY *) a;
NMXP_CHAN_KEY *pb = (NMXP_CHAN_KEY *) b;
return strcmp(pa->name, pb->name);
}
void nmxp_chan_sortByName(NMXP_CHAN_LIST *channelList) {
qsort (channelList->channel, channelList->number, sizeof (NMXP_CHAN_KEY), chan_name_compare);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment