7 #include "pnd_logger.h"
9 #include "pnd_container.h"
10 #include "pnd_discovery.h"
16 mm_category_t g_categories [ MAX_CATS ];
17 unsigned char g_categorycount = 0;
19 unsigned char category_push ( char *catname, pnd_disco_t *app ) {
22 // check category list; if found, append app to the end of it.
23 // if not found, add it to the category list and plop the app in there.
24 // app's are just app-refs, which contain links to the disco-t list -- thus removal is only in one place, and
25 // an app can be in multiple categories if we like..
28 // find or create category
31 if ( ( c = category_query ( catname ) ) ) {
32 // category was found..
34 // category wasn't found..
35 pnd_log ( PND_LOG_DEFAULT, "New category '%s'\n", catname );
36 g_categories [ g_categorycount ].catname = strdup ( catname );
37 g_categories [ g_categorycount ].refs = NULL;
38 c = &(g_categories [ g_categorycount ]);
42 // alloc and populate appref
44 mm_appref_t *ar = malloc ( sizeof(mm_appref_t) );
49 bzero ( ar, sizeof(mm_appref_t) );
53 // plug it into category
54 // and sort it on insert!
56 ar -> next = c -> refs;
59 // if no refs at all, or new guy has no title, just stick it in at head
60 if ( c -> refs && ar -> ref -> title_en ) {
61 mm_appref_t *iter = c -> refs;
62 mm_appref_t *last = NULL;
66 if ( iter -> ref -> title_en ) {
67 if ( strcmp ( ar -> ref -> title_en, iter -> ref -> title_en ) < 0 ) {
68 // new guy is smaller than the current guy!
72 // since new guy must have a name by here, we're bigger than any guy who does not have a name
81 // smaller than the current guy, so stitch in
86 ar -> next = c -> refs;
90 // we're the biggest, just append to last
95 ar -> next = c -> refs;
104 mm_category_t *category_query ( char *catname ) {
107 for ( i = 0; i < g_categorycount; i++ ) {
109 if ( strcasecmp ( g_categories [ i ].catname, catname ) == 0 ) {
110 return ( &(g_categories [ i ]) );
118 void category_dump ( void ) {
121 // WHY AREN'T I SORTING ON INSERT?
124 for ( i = 0; i < g_categorycount; i++ ) {
125 pnd_log ( PND_LOG_DEFAULT, "Category %u: '%s' * %u\n", i, g_categories [ i ].catname, g_categories [ i ].refcount );
126 mm_appref_t *ar = g_categories [ i ].refs;
129 pnd_log ( PND_LOG_DEFAULT, " Appref %s\n", IFNULL(ar -> ref -> title_en,"No Name") );