"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/activutil_resolve.c" (30 Jan 2009, 1624 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "activutil_resolve.c" see the Fossies "Dox" file reference documentation.

    1 #include "leafnode.h"
    2 #include "activutil.h"
    3 #include "ln_log.h"
    4 #include "critmem.h"
    5 
    6 #include <string.h>
    7 #include <stdlib.h>
    8 #include <ctype.h>
    9 
   10 static void xfree(char *d)
   11 {
   12     if (d)
   13     free(d);
   14 }
   15 
   16 static void
   17 newsgroup_freedata(struct newsgroup *n)
   18 {
   19     xfree(n->name);
   20     xfree(n->desc);
   21 }
   22 
   23 /* count number of capital letters (isupper) in string */
   24 static unsigned long countcaps(const char *s)
   25 {
   26     unsigned long i = 0;
   27     while(*s)
   28     {
   29     if (isupper((unsigned char)*s))
   30         i++;
   31     s++;
   32     }
   33     return i;
   34 }
   35 
   36 /* check if d or s has less caps, and copy that part with less caps in
   37  * its name into d, free the other struct's data
   38  */
   39 static void picklesscaps(struct newsgroup *d, struct newsgroup *s)
   40 {
   41     ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict: %s vs. %s",
   42         d->name, s->name);
   43     if (countcaps(s->name) < countcaps(d->name)) {
   44     newsgroup_freedata(d);
   45     newsgroup_copy(d,s);
   46     } else {
   47     newsgroup_freedata(s);
   48     }
   49     ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict, chose %s",
   50         d->name);
   51 }
   52 
   53 void validateactive(void) {
   54     unsigned long p1, p2;
   55 
   56     for (p1 = p2 = 1 ; p1 < activesize; p1++) {
   57     if (p1 > p2)
   58         newsgroup_copy(&active[p2],&active[p1]);
   59     if (0 == compactive(&active[p2-1], &active[p1])) {
   60         /* duplicate newsgroup */
   61         picklesscaps(&active[p2-1],&active[p1]);
   62     } else {
   63         p2++;
   64     }
   65     }
   66 
   67     if (p2 < p1) {
   68     activesize = p2;
   69     active[p2].name = NULL; /* do NOT free this! it has been copied
   70                    already */
   71     active = (struct newsgroup *)critrealloc((char *)active,
   72         (1 + activesize)
   73         * sizeof(struct newsgroup),
   74         "reallocating active");
   75     }
   76 }