"Fossies" - the Fresh Open Source Software Archive 
Member "leafnode-1.12.0/checkgroups.c" (28 Dec 2021, 2546 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 "checkgroups.c" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
1.11.12_vs_1.12.0.
1 /*
2 * Checkgroups: script that updates the description of newsgroups
3 * Input file : a checkgroups script that contains the name of
4 * the newsgroup and its description in one line
5 *
6 * Written and copyrighted by Cornelius Krasel, April 1997
7 * Source code borrows a lot from fetch(1).
8 *
9 * Modified and Copyright of modifications 2001 - 2005 Matthias Andree
10 *
11 * See file COPYING for restrictions on the use of this software.
12 */
13
14 #include "leafnode.h"
15 #include "ln_log.h"
16
17 #include <sys/types.h>
18 #include <ctype.h>
19 #include "system.h"
20 #include <fcntl.h>
21 #include <stdlib.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/stat.h>
26 #include <sys/resource.h>
27 #include <unistd.h>
28
29 int debug = 0;
30 int verbose = 0;
31
32 static void
33 process_input(char *s)
34 {
35 FILE *f;
36 char *l;
37 static time_t now;
38
39 if (!now) now = time(NULL);
40
41 f = fopen(s, "r");
42 if (!f) {
43 fprintf(stderr, "cannot open %s: %s\n", s, strerror(errno));
44 return;
45 }
46
47 while ((l = getaline(f))) {
48 char *p;
49 struct newsgroup *g;
50
51 p = l;
52 if (isalnum((unsigned char)*p)) {
53 while (*p && !isspace((unsigned char)*p))
54 p++;
55 if (*p)
56 *p++ = '\0';
57 if ((g = findgroup(l)) != NULL) {
58 fprintf(stderr, "%s\n", l);
59 if (strlen(p) > 0) {
60 if (g->desc)
61 free(g->desc);
62 g->desc = critstrdup(p, "process_input");
63 }
64 } else {
65 fprintf(stderr, "%s NEW\n", l);
66 insertgroup(l, 1, 0, now);
67 if (*p)
68 newgroupdesc(l, p);
69 }
70 }
71 }
72
73 fclose(f);
74 mergegroups();
75 }
76
77 int
78 main(int argc, char *argv[])
79 {
80 int fd;
81 myopenlog("checkgroups");
82
83 fd = open(".", O_RDONLY);
84 if (fd < 0) {
85 perror("checkgroups: cannot store cwd");
86 exit(EXIT_FAILURE);
87 }
88
89 if (!initvars(argv[0]))
90 exit(EXIT_FAILURE);
91
92 if (fchdir(fd)) {
93 perror("checkgroups: cannot restore cwd");
94 exit(EXIT_FAILURE);
95 }
96 (void)close(fd);
97
98 if (argc != 2) {
99 fprintf(stderr, "Usage: %s checkgroupsfile\n", argv[0]);
100 exit(1);
101 }
102
103 umask(2);
104
105 if (readconfig(0)) {
106 fprintf(stderr, "cannot read configuration.\n");
107 exit(EXIT_FAILURE);
108 }
109
110 if (try_lock(timeout_lock)) {
111 fprintf(stderr, "could not obtain lock.\n");
112 exit(EXIT_FAILURE);
113 }
114
115 readactive(); /* read groupinfo file */
116 if (!active)
117 fakeactive(); /* make sure we have up to date water marks for existing groups */
118 process_input(argv[1]);
119 if (writeactive()) ln_log(LNLOG_SERR, LNLOG_CTOP, "Error writing groupinfo.");
120 unlink(lockfile);
121 freeactive(active);
122 freegetaline();
123 exit(0);
124 }