Changeset 3440

Show
Ignore:
Timestamp:
08/08/07 14:23:25 (1 year ago)
Author:
tg
Message:

support querying the category database
bsearch idea/syntax taken from MirBSD libc's I18N routines

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/common-nfo/tools/nfotiser/categories.c

    r2475 r3440  
    88 
    99#include <stdlib.h> 
     10#include <string.h> 
    1011 
    11 struct categories { 
     12static int category_cmp(const void *, const void *); 
     13 
     14const struct categories { 
    1215        const char *catname; 
    1316        const char *catdesc; 
    1417} categories[] = { 
     18        /* this list MUST be sorted all the time */ 
    1519        { "base",       "Base system" }, 
    16         { "shells",     "Shells" }, 
    17         { "misc",       "Applications" }, 
    18         { "net",        "Networking" }, 
     20        { "comms",      "Serial communications & terminal emulation" }, 
    1921        { "crypto",     "Crypto" }, 
     22        { "fsutils",    "FileSystem related" }, 
    2023        { "ipv6",       "IPv6" }, 
    2124        { "libs",       "Libraries" }, 
     25        { "misc",       "Applications" }, 
    2226        { "multimedia", "Multimedia" }, 
    23         { "comms",      "Serial communications & terminal emulation" }, 
     27        { "net",        "Networking" }, 
     28        { "netbt",      "Bluetooth" }, 
     29        { "shells",     "Shells" }, 
     30        { "sysutils",   "Utilities" }, 
    2431        { "voip",       "Telephony" }, 
    25         { "sysutils",   "Utilities" }, 
    26         { "fsutils",    "FileSystem related" }, 
    27         { "netbt",      "Bluetooth" }, 
    2832        { NULL,         NULL } 
    2933}; 
     34 
     35const char * 
     36category(const char *name) 
     37{ 
     38        return (name == NULL ? NULL : ((struct categories *)bsearch(name, 
     39            categories, (sizeof (categories) / sizeof (categories[0])), 
     40            sizeof (struct categories), category_cmp))->catdesc); 
     41} 
     42 
     43static int 
     44category_cmp(const void *key, const void *item) 
     45{ 
     46        return (strcmp((const char *)key, 
     47            ((const struct categories *)item)->catname)); 
     48} 
  • branches/common-nfo/tools/nfotiser/extern.h

    r2483 r3440  
    1515/* categories.c */ 
    1616extern const char *categories[]; 
     17const char *category(const char *); 
    1718/* dbscheme.S */ 
    1819extern const char dbscheme[];