File: clr_user.c

package info (click to toggle)
fbb 7.07-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,244 kB
  • ctags: 8,123
  • sloc: ansic: 87,810; sh: 2,324; makefile: 297
file content (218 lines) | stat: -rw-r--r-- 5,044 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
   /****************************************************************
    Copyright (C) 1986-2000 by

    F6FBB - Jean-Paul ROUBELAT
    6, rue George Sand
    31120 - Roquettes - France
	jpr@f6fbb.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Parts of code have been taken from many other softwares.
    Thanks for the help.
    ****************************************************************/

#define ENGLISH

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
#include "version.h"
#include "fbb_conf.h"

#define FALSE 0
#define TRUE  1

#ifdef __linux__

#define __a2__ __attribute__ ((packed, aligned(2)))

#else

#define __a2__

#endif

#define INF_SYS "inf.sys"
#define BUFFSIZE 256

typedef struct typindic
{
	char call[7];
	char num;
}
indicat;

typedef struct {

	indicat indic     ;	/* 8  Callsign */
	indicat relai[8]  ;	/* 64 Digis path */
	long	lastmes __a2__  ;	/* 4  Last L number */
	long	nbcon   __a2__  ;	/* 4  Number of connexions */
	long	hcon    __a2__  ;	/* 4  Last connexion date */
	long	lastyap __a2__  ;	/* 4  Last YN date */
	unsigned short	flags    ;	/* 2  Flags */
	unsigned short	on_base  ;	/* 2  ON Base number */

	unsigned char	nbl       ;	/* 1  Lines paging */
	unsigned char	lang      ;	/* 1  Language */

	long	newbanner __a2__;	/* 4  Last Banner date */
	unsigned short 	download  ;	/* 2  download size (KB) = 100 */
	char	free[20]  ;	/* 20 Reserved */
	char	theme     ;	/* 1  Current topic */

	char	nom[18]   ;	/* 18 1st Name */
	char	prenom[13];	/* 13 Christian name */
	char	adres[61] ;	/* 61 Address */
	char	ville[31] ;	/* 31 City */
	char	teld[13]  ;	/* 13 home phone */
	char	telp[13]  ;	/* 13 modem phone */
	char	home[41]  ;	/* 41 home BBS */
	char	qra[7]    ;	/* 7  Qth Locator */
	char	priv[13]  ;	/* 13 PRIV directory */
	char	filtre[7] ;	/* 7  LC choice filter */
	char	pass[13]  ;	/* 13 Password */
	char	zip[9]    ;	/* 9  Zipcode */

} info ;                /* Total : 360 bytes */

FILE *fichi;
char* system_dir;

char *strlwr (char *txt)
{
	char *scan = txt;

	while (*scan)
	{
		if (isupper (*scan))
			*scan = tolower (*scan);
		++scan;
	}

	return (txt);
}

void err_keyword(char *keyword)
{
	fprintf(stderr, "Error : keyword \"%s\" missing in fbb.conf file\n", keyword);
	exit(1);
}

char *test_back_slash (char *chaine)
{
	if ((strlen(chaine) == 0)
#ifdef __linux__
		|| (chaine[strlen (chaine) - 1] != '/'))
			strcat(chaine, "/");
#else
		|| (chaine[strlen (chaine) - 1] != '\\'))
			strcat(chaine, "\\");
#endif
	return (chaine);
}

void ouvre_nomenc (void)
{
	char *filename = (char *) (calloc(BUFFSIZE , sizeof(char)));

	sprintf (filename, "%s%s", system_dir, INF_SYS);
	
	if ((fichi = fopen (filename, "rb")) == NULL)
	{
#ifdef ENGLISH
		fprintf (stderr, "Cannot find %s !!     \n", filename);
#else
		fprintf (stderr, "Erreur ouverture %s !!\n", filename);
#endif
		exit (1);
	}
	else
		fprintf (stderr, "%s file found\n",filename);
}


int main (int ac, char **av)
{
	info buf;
	char *ptr;
	long rinfo = 0L;
	long tot_dw = 0L;
	long nb_users = 0L;
	long temps = time (NULL);
	struct tm *tm = localtime (&temps);

	system_dir = (char *) (calloc(BUFFSIZE , sizeof(char)));

	fprintf (stderr, "CLR_USER V %d.%d\n\n", MAJEUR, MINEUR);

	/* if (tm->tm_wday != 0)
	   return(0);
	 */

	putchar ('\n');
	puts (asctime (tm));
	
	if (read_fbb_conf(NULL) > 0)
	{
#ifdef ENGLISH
		fprintf (stderr, "Cannot open fbb.conf file        \n");
#else
		fprintf (stderr, "Erreur ouverture fichier fbb.conf\n");
#endif

		exit (1);
	}

	/* path of conf files */
	ptr = find_fbb_conf("data", 0);
	if (ptr == NULL)
		ptr = def_fbb_conf("data");
	if (ptr == NULL)
		err_keyword("data");
	strcpy (system_dir, test_back_slash(strlwr (ptr)));

	ouvre_nomenc();

	while (fread ((char *) &buf, (int) sizeof (buf), 1, fichi))
	{
		tot_dw += (long) buf.download;
		if (buf.download)
		{
			printf ("%6s : %dKB\n", buf.indic.call, buf.download);
			buf.download = 0;
			fseek (fichi, rinfo, 0);
			fwrite ((char *) &buf, (int) sizeof (buf), 1, fichi);
		}
		rinfo += sizeof (buf);
		fseek (fichi, rinfo, 0);
		++nb_users;
	}

	fclose (fichi);

#ifdef ENGLISH
	printf ("%ld callsigns ok      \n", nb_users);
	printf ("%ld KB downloaded     \n", tot_dw);
#else
	printf ("%ld indicatifs        \n", nb_users);
	printf ("%ld KB envoy�s        \n", tot_dw);
#endif
	return (0);
}