File: lsort.c

package info (click to toggle)
leafnode 1.11.7.rc1-10~lenny0
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,436 kB
  • ctags: 577
  • sloc: ansic: 10,637; sh: 4,107; xml: 650; makefile: 281; perl: 84; sed: 4
file content (69 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (3)
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
/*
lsort - re-sort groupinfo files from versions prior to 1.9.3

Written and Copyright 1999 by Joerg Dietrich <joerg@dietrich.net>
Modified and copyright of the modifications 2002 by Ralf Wildenhues
<ralf.wildenhues@gmx.de>.

See file COPYING for restrictions on the use of this software.
*/

#include "leafnode.h"
#include "critmem.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int verbose = 0;
int debug = 0;

static int
comp(const void *a, const void *b)
{
    return strcasecmp(*(const char *const *)a, *(const char *const *)b);
}

int
main(void)
{
    char *l;
    char *path; /* RATS: ignore */
    size_t l_path;
    const char *tackon = "/leaf.node/groupinfo.old";
    const char *const myname = "lsort";
    char **act = NULL;
    unsigned long acount = 0, allocd = 0;
    unsigned long i;
    FILE *f;

    critsyslog(0);
    l_path = strlen(spooldir) + strlen(tackon) + 1;
    path = critmalloc(l_path + 1, myname);
    xsnprintf(path, l_path, "%s%s", spooldir, tackon);

    f = fopen(path, "r");
    if (f == NULL) {
	fprintf(stderr, "Error: Can't open groupinfo.old!\n");
	exit(1);
    }

    while ((l = getaline(f))) {
	if (acount >= allocd) {
	    allocd ? (allocd <<= 1) : (allocd = 256);
	    act = (char **)critrealloc((char *)act, allocd * sizeof(char *), myname);
	}
	act[acount] = critstrdup(l, myname);
	acount++;
    }
    fclose(f);

    qsort(act, acount, sizeof(char *), &comp);

    for (i = 0; i < acount; i++) {
	printf("%s\n", act[i]);
	free(act[i]);
    }
    free(act);

    return 0;
}