File: activutil_resolve.c

package info (click to toggle)
leafnode 1.11.11-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,468 kB
  • sloc: ansic: 10,914; sh: 1,748; xml: 628; makefile: 291; perl: 84; sed: 4
file content (76 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "leafnode.h"
#include "activutil.h"
#include "ln_log.h"
#include "critmem.h"

#include <string.h>
#include <stdlib.h>
#include <ctype.h>

static void xfree(char *d)
{
    if (d)
	free(d);
}

static void
newsgroup_freedata(struct newsgroup *n)
{
    xfree(n->name);
    xfree(n->desc);
}

/* count number of capital letters (isupper) in string */
static unsigned long countcaps(const char *s)
{
    unsigned long i = 0;
    while(*s)
    {
	if (isupper((unsigned char)*s))
	    i++;
	s++;
    }
    return i;
}

/* check if d or s has less caps, and copy that part with less caps in
 * its name into d, free the other struct's data
 */
static void picklesscaps(struct newsgroup *d, struct newsgroup *s)
{
    ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict: %s vs. %s",
	    d->name, s->name);
    if (countcaps(s->name) < countcaps(d->name)) {
	newsgroup_freedata(d);
	newsgroup_copy(d,s);
    } else {
	newsgroup_freedata(s);
    }
    ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict, chose %s",
	    d->name);
}

void validateactive(void) {
    unsigned long p1, p2;

    for (p1 = p2 = 1 ; p1 < activesize; p1++) {
	if (p1 > p2)
	    newsgroup_copy(&active[p2],&active[p1]);
	if (0 == compactive(&active[p2-1], &active[p1])) {
	    /* duplicate newsgroup */
	    picklesscaps(&active[p2-1],&active[p1]);
	} else {
	    p2++;
	}
    }

    if (p2 < p1) {
	activesize = p2;
	active[p2].name = NULL; /* do NOT free this! it has been copied
				   already */
	active = (struct newsgroup *)critrealloc((char *)active,
		(1 + activesize)
		* sizeof(struct newsgroup),
		"reallocating active");
    }
}