File: maintinf.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 (579 lines) | stat: -rw-r--r-- 12,337 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
   /****************************************************************
    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

#ifdef __linux__
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define __NO_CTYPE
#define INF_NEW "inf.new"
#define INF_SYS "inf.sys"
#define __a2__ __attribute__ ((packed, aligned(2)))
#else

#define __a2__
#define INF_NEW "inf.new"
#define INF_SYS "inf.sys"

#endif

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

#define FALSE 0
#define TRUE  1

#define uchar unsigned char
#define ushort unsigned short
#define EXCLUDED(buf) (buf.flags & 0x1)

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 */
	ushort flags;				/* 2  Flags */
	ushort on_base;				/* 2  ON Base number */

	uchar nbl;					/* 1  Lines paging */
	uchar lang;					/* 1  Language */

	long newbanner __a2__;		/* 4  Last Banner date */
	ushort 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 */

typedef struct typindictri
{
	char indic[7];
	long pos;
	struct typindictri *suiv;
}
indictri;

FILE *fichi, *ficho;
char temp[500];
char system_dir[256];
indictri *tete;
int rejet, nbindic;
int ext_call = 0;

static void defauts (void);
static int find (char *s);
static void check (info * bul);
static void err_alloc (void);
static void insere (char *ind, long pos);
static void ouvre_nomenc (void);


#ifdef __linux__
char *strupr (char *txt)
{
	char *scan = txt;

	while (*scan)
	{
		if (islower (*scan))
			*scan = toupper (*scan);
		++scan;
	}

	return (txt);
}

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

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

	return (txt);
}
#endif

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 err_keyword(char *keyword)
{
	fprintf(stderr, "Error : keyword \"%s\"missing in fbb.conf file\n", keyword);
	exit(1);
}

void epure (char *ligne)
{
	int lg;

	lg = strlen (ligne);
	if (ligne[lg - 1] == '\n')
		ligne[lg - 1] = '\0';
	lg = strlen (ligne);
	if (ligne[lg - 1] == '\r')
		ligne[lg - 1] = '\0';
	if (*ligne == '\032')
		*ligne = '\0';
}

int main (int ac, char **av)
{
	int rep;
	int auto_rep = 0;
	int monthes;
	info buf;
	long rinfo = 0;
	long i = 0;
	indictri *ptr;
	long temps = time (NULL);
	long timout;

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

#ifdef ENGLISH
	fprintf (stderr, "FBB software MUST be stopped !!    \n\n");
#else
	fprintf (stderr, "Le logiciel FBB Doit etre arr�t� !!\n\n");
#endif

	defauts ();

	rejet = nbindic = 0;
	timout = 86400L * 31L;		/* 31 jours / mois */

	if (ac == 1)
	{
#ifdef ENGLISH
		fprintf (stderr, "Format : MAINTINF Monthes [/A]\n\nMonthes is \"time check\" to kill old callsigns (0 = no check)     \n                 \n");
#else
		fprintf (stderr, "Format : MAINTINF Mois [/A]\n\nMois est le \"Test des dates\" pour supprimer les indicatifs obsoletes\n(0 = pas de test)\n");
#endif
		exit (0);
	}

	monthes = atoi (av[1]);

	timout *= monthes;

	if (ac >= 3)
	{
		ext_call = (strcmp (strupr (av[2]), "/N") == 0);
		if (ext_call)
		{
			--ac;
			++av;
#ifdef ENGLISH
			printf ("No callsign check      \n");
#else
			printf ("Pas de test d'indicatif\n");
#endif
		}
	}

	if (ac == 3)
		auto_rep = (strcmp (strupr (av[2]), "/A") == 0);

#ifdef ENGLISH
	if (monthes)
		printf ("Time check : %d monthes\n", monthes);
	else
		printf ("No Time check    \n");
#else
	if (monthes)
		printf ("Test dates : %d mois   \n", monthes);
	else
		printf ("Pas de test dates\n");
#endif
	sleep (2);

	ouvre_nomenc ();
	if ((tete = (indictri *) malloc (sizeof (indictri))) == NULL)
		err_alloc ();
	tete->suiv = NULL;
	rewind (fichi);
	while (fread ((char *) &buf, (int) sizeof (buf), 1, fichi))
	{
		if ((!EXCLUDED (buf)) && (timout) && ((temps - buf.hcon) > timout))
		{
#ifdef ENGLISH
			printf ("rejects <%s> : Old callsign    \n", buf.indic.call);
#else
			printf ("rej�te <%s> : Indicatif inusit�\n", buf.indic.call);
#endif
			++rejet;
		}
		else if (find (buf.indic.call))
		{
			insere (buf.indic.call, rinfo);
		}
		else
		{

#ifdef ENGLISH
			printf ("rejects <%s> : Incorrect callsign\n", buf.indic.call);
#else
			printf ("rej�te <%s> : Indicatif incorrect\n", buf.indic.call);
#endif
			++rejet;
		}
		++rinfo;
	}

#ifdef ENGLISH
	printf ("%d callsigns ok      \n", nbindic);
	printf ("%d callsigns rejected\n", rejet);
	printf ("---------------------------------------------\n\n");
#else
	printf ("%d indicatifs inse�re�s\n", nbindic);
	printf ("%d indicatifs rejete�s\n", rejet);
	printf ("----------------------------------           \n\n");
#endif

	if (!auto_rep)
	{
		while (TRUE)
		{
#ifdef ENGLISH
			fprintf (stderr, "Create %s      (Y/N) : ", INF_NEW);
#else
			fprintf (stderr, "Creation de %s (O/N) : ", INF_NEW);
#endif
			rep = getchar ();
#ifdef ENGLISH
			if ((rep == 'y') || (rep == 'Y') || (rep == 'n') || (rep == 'N'))
#else
			if ((rep == 'o') || (rep == 'O') || (rep == 'n') || (rep == 'N'))
#endif
				break;
		}
		putchar ('\n');
	}
#ifdef ENGLISH
	if ((auto_rep) || (toupper (rep) == 'Y'))
	{
#else
	if ((auto_rep) || (toupper (rep) == 'O'))
	{
#endif
		char filename[256];

		sprintf (filename, "%s%s", system_dir, INF_NEW);
		if ((ficho = fopen (filename, "wb")) == NULL)
		{
#ifdef ENGLISH
			fprintf (stderr, "Error creating %s     \n", filename);
#else
			fprintf (stderr, "Impossible de creer %s\n", filename);
#endif
		}
		else
		{
			ptr = tete;
			while ((ptr = ptr->suiv) != NULL)
			{
				fseek (fichi, ptr->pos * (long) sizeof (buf), 0);
				fread (&buf, sizeof (buf), 1, fichi);
				check (&buf);
				fwrite (&buf, sizeof (buf), 1, ficho);
				if ((++i % 10) == 0)
#ifdef ENGLISH
					fprintf (stderr, "\r%ld callsigns  ", i);
#else
					fprintf (stderr, "\r%ld indicatifs ", i);
#endif
			}
#ifdef ENGLISH
			fprintf (stderr, "\r%ld callsigns  ", i);
#else
			fprintf (stderr, "\r%ld indicatifs ", i);
#endif
			fclose (ficho);
			fputc ('\r', stderr);
		}
#ifdef ENGLISH
		printf ("\nFile %s created\n\n", INF_NEW);
		printf ("\nYou must now change %s with %s !!\n", INF_SYS, INF_NEW);
		printf ("---------------------------------------------\n\n");
#else
		printf ("\nFichier %s cr��\n\n", INF_NEW);
		printf ("\nRemplacer %s par %s !!           \n", INF_SYS, INF_NEW);
		printf ("----------------------------------           \n\n");
#endif
	}
	fclose (fichi);
	
	return 0;
}


static void check (info * bul)
{
	int i;

	bul->indic.call[6] = '\0';
	for (i = 0; i < 8; i++)
		bul->relai[i].call[6] = '\0';
	bul->nom[17] = '\0';
	bul->prenom[12] = '\0';
	bul->adres[60] = '\0';
	bul->ville[30] = '\0';
	bul->teld[12] = '\0';
	bul->telp[12] = '\0';
	bul->home[40] = '\0';
	bul->qra[6] = '\0';
	bul->priv[12] = '\0';
	bul->filtre[6] = '\0';
	bul->pass[12] = '\0';
	bul->zip[8] = '\0';

	if ((bul->nbcon < 0) || (bul->nbcon > 100000L))
		bul->nbcon = 0L;
	if ((bul->nbl < (uchar) 4) || (bul->nbl > (uchar) 50))
		bul->nbl = (uchar) 25;
	if (bul->lang > (uchar) 99)
		bul->lang = (uchar) 1;
}


static void insere (char *ind, long pos)
{
	int cmp;
	indictri *pprec, *ptr, *ptemp;

	pprec = ptr = tete;
	while ((ptr = ptr->suiv) != NULL)
	{
		cmp = strcmp (ind, ptr->indic);
		if (cmp == 0)
		{
			printf ("rejects <%s> : already inserted\n", ind);
			++rejet;
			return;
		}
		else if (cmp < 0)
			break;
		pprec = ptr;
	}
	if ((ptemp = (indictri *) malloc (sizeof (indictri))) == NULL)
		err_alloc ();

	++nbindic;
	ptemp->suiv = ptr;
	pprec->suiv = ptemp;
	ptemp->pos = pos;
	strcpy (ptemp->indic, ind);
}


static int find (char *s)
{
	char *t = s;
	int n = 0;
	int dernier = 0, chiffre = 0, lettre = 0;

	while (*t)
	{
		if (!isalnum (*t))
			return (FALSE);
		*t = toupper (*t);

		dernier = (isdigit (*t));

		if (isdigit (*t))
			++chiffre;
		else
			++lettre;

		++t;
		++n;
	}

	/*
	   * L'indicatif doit avoir entre 3 et 6 caracteres .
	   *             doit contenir 1 ou 2 chiffres .
	   *             ne doit pas se terminer par un chiffre .
	 */

	if (ext_call)
	{
		/*
		 * L'indicatif doit avoir entre 3 et 6 caracteres .
		 *             doit contenir au moins un chiffre
		 *                  doit contenir au moins une lettre
		 */
		if ((n < 3) || (n > 6) || (chiffre < 1) || (lettre < 1))
			return (0);
	}
	else
	{
		/*
		   * L'indicatif doit avoir entre 3 et 6 caracteres .
		   *             doit contenir 1 ou 2 chiffres .
		   *             ne doit pas se terminer par un chiffre .
		 */

		if ((n < 3) || (n > 6) || (chiffre < 1) || (chiffre > 2) || dernier)
			return (0);
	}

	t = temp;
	while (isalnum (*s))
		*t++ = *s++;
	*t = '\0';
	t = temp;
	return (TRUE);
}


static void ouvre_nomenc (void)
{
	char filename[256];

	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);
	}
}


static void err_alloc (void)
{
#ifdef ENGLISH
	fprintf (stderr, "Memory allocation error  \n");
#else
	fprintf (stderr, "Erreur allocation memoire\n");
#endif
	exit (1);
}

static void defauts (void)
{
	unsigned int flag;
	char *ptr;
	char temp[20];

	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);				/* and users base directory */
	}

	ptr = find_fbb_conf("vers", 0);
	if (ptr == NULL)
	{
#ifdef ENGLISH
		fprintf (stderr, "Version number missing in fbb.conf\n");
#else
		fprintf (stderr, "Pas de num�ro dans le fbb.conf\n");
#endif
		exit (1);
	}

	sprintf (temp, "FBB%d.%02d", MAJEUR, MINEUR);
	if (strncasecmp (temp, ptr, 7) != 0)
	{
#ifdef ENGLISH
		fprintf (stderr, "Wrong version number in fbb.conf\n");
#else
		fprintf (stderr, "Num�ro de version erron� dans fbb.conf\n");
#endif
		exit (1);
	}
	fprintf (stderr, "Configuration version : %s\r\n", ptr);

	/* 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)));

	/* flags */
	ptr = find_fbb_conf("fbbf", 0);
	if (ptr == NULL)
		ptr = def_fbb_conf("fbbf");
	if (ptr == NULL)
		err_keyword("fbbf");
	flag = 0;
	sscanf (ptr, "%s %u", temp, &flag);
	ext_call = ((flag & 4096) != 0);
}