File: init.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 (1131 lines) | stat: -rw-r--r-- 21,438 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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
   /****************************************************************
    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.
    ****************************************************************/

/*
 * INIT.C
 *
 */

#include "serv.h"

static void aff_heure (void);
static void cree_tpstat (void);
static int init_dir (void);
static void init_tpstat (void);
static void initarbre (void);
static void initmessage (void);
static void start_bbs (void);

#ifdef __MSDOS__
static void init_bufscreen (Screen *);
static void val_screen (void);

#endif

extern char _video[];

#ifdef __MSDOS__
void initialisations (void)
{
	int bbs_init = 1;
	fprintf (stderr, "\nMSDOS defined  init.c INITIALISATIONS\n");

	while (!step_initialisations (bbs_init))
		++bbs_init;
}
#endif

int step_initialisations (int niveau)
{
	int i;
#ifdef __WINDOWS__
	unsigned long dMem;
#endif

	InitText ("");

/*	fprintf (stderr, "FBB step_initialisations niveau:%d\n",niveau);*/
		
	switch (niveau)
	{

	case 1:
		{
			/* Check endian */
			long val = 1;
			moto = (*((char *)(&val)) == '\0');
		}
		debug_ptr = NULL;
		operationnel = -1;

		h_ok = 1;
		MAXTACHE = MAXTASK;

		init_semaine ();

#ifdef __WINDOWS__
		/* Allocation du buffer partage ... */
		dMem = GlobalDosAlloc (400ul);
		if (dMem == 0ul)
		{
			cprintf ("Can't allocate shared buffer\r\n");
			exit (1);
		}
		BufSeg = HIWORD (dMem);
		BufSel = LOWORD (dMem);
		BufReel = (char far *) ((unsigned long) BufSel << 16);

#endif

		sed = 1;

		EditorOff = TRUE;
		editor_request = 0;
		errno = 0;
		fast_fwd = 1;
		lastaff = -1;
		reply = 0;
		snd_io = 0;
		test_message = 2;
		h_screen = 25;
		bid_ptr = NULL;
		log_ptr = NULL;
		throute = NULL;
		tbroute = NULL;
		p_port = NULL;
		def_cur.nbmess = def_cur.nbnew = 0;
		def_cur.coord = 0xffff;
		memcpy (def_cur.indic, "NULL", 5);
		test_fichiers = 0;
#ifdef __MSDOS__
		ton_bip = 0;
		kam_timer = 0;
#endif
		vlang = -1;
		time_bcl = 0;
		blank = 0;
		nb_hold = 0;
		ok_aff = 1;
		aut_ui = 1;
		doubl = 0;
		v_aff = -1;
		console = 0;
		editor = 0;
		cmd_fct = 0;
		print = 0;
		def_mask = 0;
		t_tell = -1;
		v_tell = 0;
		ch_fen = 0;
		inexport = 0;
		nb_error = 0;
		temp_sec = SECONDE;
		d_blanc = 0;
		include_size = 0;
		p_forward = 0;
		time_include = NULL;
		mem_alloue = 0L;
		t_bbs = 0L;
		t_appel = 0L;
		hour_time = -1;
		t_iliste.suiv = NULL;
		tete_fwd = NULL;
		tete_serv = NULL;
		tete_pg = NULL;
		bbs_ptr = NULL;
		p_port = NULL;
		*t_iliste.indic = '\0';
		p_iliste = &t_iliste;
		NBVOIES = 1;
		for (i = 0; i < NBLIG; i++)
			af_voie[i] = -1;
#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("Reading INIT.SRV\r\n");
#else
		cprintf ("Lecture INIT.SRV\r\n");
#endif
#endif
		init_voie (CONSOLE);	/* Init console */
		voiecur = CONSOLE;
		pvoie = svoie[voiecur];
		if (!init_admin ())
			return (0);
		if (!init_dir ())
			return (0);
		port_log (0, 0, 'S', "I *** BBS Initialize");
		deb_io ();
		operationnel = 0;
		window_connect (ALLCHAN);
		window_connect (CONSOLE);
		window_connect (MMONITOR);
		free_mem ();
		return 0;

	case 2:
		init_exms ();
		initexte ();
		aff_date ();
		free_mem ();
		ferme(ouvre_sat(), 0);
		return 0;

	case 3:
		init_tpstat ();
		free_mem ();

#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("RS232 ports set-up            \r\n");
#else
		cprintf ("Initialisation des ports RS232\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("RS232 ports set-up            \n");
#else
		cprintf ("Initialisation des ports RS232\n");
#endif
#endif
		init_watchdog (watchport);
		initport ();
		return 0;

	case 4:
		initcom ();
#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("TNC set-up            \r\n");
#else
		cprintf ("Initialisation des TNC\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("TNC set-up            \n");
#else
		cprintf ("Initialisation des TNC\n");
#endif
#endif
		inittnc ();
		return 0;

	case 5:
		affich_serveurs (2);
		affich_pg (2);
		t_label();
		free_mem ();
		return 0;

	case 6:
#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("BID set-up            \r\n");
#else
		cprintf ("Initialisation des BID\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("BID set-up            \n");
#else
		cprintf ("Initialisation des BID\n");
#endif
#endif
		cree_bid ();
		free_mem ();
		return 0;

	case 7:
		initarbre ();
		free_mem ();
		return 0;

	case 8:
		/*  epure_messages() ; */
		load_dirmes ();
		initmessage ();
		return 0;

	case 9:
		if (!init_white_pages ())
			cree_routes ();
		else
			h_ok = 0;
		free_mem ();
#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("Files set-up complete           \r\n");
#else
		cprintf ("Fin des initialisations Fichiers\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("Files set-up complete           \n");
#else
		cprintf ("Fin des initialisations Fichiers\n");
#endif
#endif
		return 0;

	case 10:
		fwd_file = NULL;
		fwd_size = 0;

#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("FORWARD set-up           \r\n");
#else
		cprintf ("Initialisation du forward\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("FORWARD set-up           \n");
#else
		cprintf ("Initialisation du forward\n");
#endif
#endif
		init_buf_fwd ();
		init_buf_swap ();
		init_buf_rej ();
		return 0;

	case 11:
		init_bbs ();
		init_part ();
		free_mem ();
		read_heard ();
		init_etat ();
		tst_appel ();
		return 0;

	case 12:
		init_hold ();
		init_pfh();
		load_themes ();
#ifdef __FBBDOS__
#ifdef ENGLISH
		cprintf ("Set-up complete        \r\n");
#else
		cprintf ("Fin des initialisations\r\n");
#endif
#endif
#ifdef __linux__
#ifdef ENGLISH
		cprintf ("Set-up complete        \n");
#else
		cprintf ("Fin des initialisations\n");
#endif
#endif
		vlang = 0;
		com_error = old_com_error = 0;
		aff_ind_console ();
		free_mem ();
		aff_date ();
		aff_heure ();
		fin_io ();
		canaff = v_aff;
		winlig = h_screen - 1 - M_LIG;
#ifdef TRACE
		open_trace ();
#endif
		if (*BBS_UP)
		{
			char *pptr = BBS_UP;
#ifdef __linux__
			call_nbdos (&pptr, 1, NO_REPORT_MODE, NULL, TOOLDIR, NULL);
#else
			call_nbdos (&pptr, 1, NO_REPORT_MODE, NULL, NULL, NULL);
#endif
		}
		start_bbs ();
		return 1;
	}

	return 1;
}

static void start_bbs (void)
{
	int port = 1;
	char buffer[300];
	int nb;


	df ("io", 0);

	deb_io ();
	voiecur = 1;
	type_sortie = 1;
	save_fic = 0;
	aff_date ();

	operationnel = 1;
	env_date ();
	for (port = 1; port < NBPORT; port++)
	{
		if (p_port[port].pvalid)
		{
			switch (p_port[port].typort)
			{
			case TYP_DED:
				sprintf (buffer, "H 18");
				tnc_commande (port, buffer, PORTCMD);
				sprintf (buffer, "H 1");
				tnc_commande (port, buffer, PORTCMD);
				sprintf (buffer, "H 2");
				tnc_commande (port, buffer, PORTCMD);
				/* Ajouter la validation des ports */
				break;
			case TYP_PK:
				break;
			}
		}
	}
	for (nb = 1; nb < NBVOIES; nb++)
	{
		programm_indic (nb);
		set_bs(nb, TRUE);
	}

	test_disque ();
 	sprintf (buffer, "A *** BBS Online (%s)", version());
 	port_log (0, 0, 'S', buffer);
/*	port_log (0, 0, 'S', "A *** BBS Online");*/
	fin_io ();

	start_tasks ();
	mem_alloue = 0L;
	free_mem ();
	dde_wp_serv = 1;


	/* Amorce les TNCs en mode DED */
	for (nb = 0; nb < NBPORT; nb++)
	{
		int i;

		/* positionnel le mult_sel au 1er multi dans chaque COM */

		for (i = 0; i < 8; i++)
		{
			if (p_com[nb].multi[i])
			{
				int port = p_com[nb].multi[i];

				p_com[nb].mult_sel = port;
				break;
			}
		}
	}
	ff ();
}

static int dir_found (char *dir)
{
	int nb;
	char path[256];
	char str[256];

	strcpy (path, dir);
	nb = strlen (path);
	if ((nb > 1) && (path[1] == ':'))
	{
		if ((nb > 3) && (path[nb - 1] == '\\'))
			path[nb - 1] = '\0';
	}
	else
	{
		if ((nb > 1) && (path[nb - 1] == '\\'))
			path[nb - 1] = '\0';
	}

	if (!is_dir (path))
	{
		sprintf (str, "Directory %s not found", back2slash (path));
		ShowError ("FBB TREE", str, 0);
		fbb_quit (0);
		WinSleep (10);
		return (0);
	}
	return (1);
}

static int init_dir (void)
{
  /* Cree l'arbre des repertoires */
	int i;
	char dir[128];

	/* Arborescence MAIL */
	if (!dir_found (MESSDIR))
		return (0);
	for (i = 0; i < 10; i++)
	{
		sprintf (dir, "%smail%d", MESSDIR, i);
		if (!dir_found (dir))
			return (0);
	}

	/* Arborescence BINMAIL */
	if (!dir_found (MBINDIR))
		return (0);
	for (i = 0; i < 10; i++)
	{
		sprintf (dir, "%smail%d", MBINDIR, i);
		if (!dir_found (dir))
			return (0);
	}

	/* Repertoire WP */
	sprintf (dir, "%swp", DATADIR);
	if (!dir_found (dir))
		return (0);

	/* Repertoire DOCS */
	if (!dir_found (DOCSDIR))
		return (0);

	/* Repertoires DOS */
	for (i = 1; i < 8; i++)
	{
		if (*PATH[i])
			if (!dir_found (PATH[i]))
				return (0);
	}

	/* Repertoire YAPP */
	if (!dir_found (YAPPDIR))
		return (0);

	/* Repertoire PG */
	/* if (!dir_found (PGDIR))
		return (0); */

	return (1);
}

void init_semaine (void)
{
	long temps = time (NULL);
	struct tm *sdate = localtime (&temps);

	int ny = sdate->tm_yday;	/* Numero du jour dans l'annee */
	int nw = sdate->tm_wday;	/* Numero du jour dans la semaine */

	if (nw == 0)
		nw = 6;
	else
		--nw;					/* 0 = dimanche -> 0 = lundi */

	if (ny < nw)				/* Premiere semaine de l'annee ? */
	{
		temps -= (3600L * 24L * (ny + 1));
		sdate = localtime (&temps);
		ny = sdate->tm_yday;	/* Numero du jour de l'annee precedente */
		nw = sdate->tm_wday;	/* Numero du jour de la semaine avant */
		if (nw == 0)
			nw = 6;
		else
			--nw;				/* 0 = dimanche -> 0 = lundi */
	}
	num_semaine = (7 - nw + ny) / 7;
}

void start_tasks (void)
{
	trait_time = 0;
#ifdef ENGLISH
	cprintf ("Starting multitasking ...");
#else
	cprintf ("D�marre le multit�ches...");
#endif
#ifdef __MSDOS__
	init_keyboard ();
#endif
	cprintf (" ok\r\n");

}

void end_voies (void)
{
	int i;

	/* Inclut la voie Warnings (NBVOIES+1) */
	for (i = 0; i < NBVOIES + 1; i++)
	{
		if (svoie[i])
			m_libere (svoie[i], sizeof (Svoie));
	}
}

void init_voie (int voie)
{
	int i;
	Svoie *vptr;

	svoie[voie] = vptr = (Svoie *) m_alloue (sizeof (Svoie));
	time_yapp[voie] = -1;
	vptr->timout = time_n;
	init_timout (voie);
	vptr->msg_held = 0;
	vptr->rzsz_pid = -1;
	vptr->temp1 = vptr->mess_recu = 1;
	vptr->fbb = bin_fwd;
	/* vptr->wp = */ vptr->clock = '\0';
	vptr->ret = 0;	
	vptr->sid = vptr->aut_nc = vptr->ind_mess = vptr->warning = 0;
	vptr->ask = vptr->seq = vptr->dde_int = vptr->stop = 0;
	vptr->mbl = vptr->sta.stat = vptr->sta.connect = vptr->deconnect = 0;
	vptr->sta.mem = 32000;
	vptr->sr_mem = vptr->memoc = vptr->nb_err = 0;
	vptr->niv1 = vptr->niv2 = vptr->niv3 = 0;
	vptr->maj_ok = vptr->conf = vptr->dde_marche = 0;
	vptr->groupe = vptr->kiss = vptr->ch_mon = vptr->cross_connect = -1;
	vptr->cur_bull = -1L;
	vptr->localmode = vptr->binary = vptr->sta.ret = vptr->sta.ack = 0;
	vptr->type_yapp = 0;
	vptr->maxbuf = 8;
	vptr->emis = NULL;
	vptr->ctnc = NULL;
	vptr->outptr = NULL;
	vptr->msgtete = NULL;
	vptr->l_mess = vptr->l_yapp = vptr->entmes.numero = 0L;
	vptr->inbuf.nblig = vptr->inbuf.nbcar = vptr->inbuf.nocar = 0;
	vptr->inbuf.tete = NULL;
	vptr->inbuf.curr = NULL;
	vptr->inbuf.ptr = NULL;
	vptr->curfwd = NULL;
	vptr->t_read = NULL;
	vptr->t_list = NULL;
	vptr->llabel = NULL;
	vptr->r_tete = NULL;
	vptr->ncur = &def_cur;
	vptr->mbl_ext = 1;
	vptr->nb_egal = 0;
	vptr->nb_prompt = 0;
	vptr->prot_fwd = prot_fwd;
	vptr->tete_edit.liste = NULL;
	vptr->entmes.bid[0] = '\0';
	vptr->sta.callsign.call[0] = '\0';
	vptr->sta.callsign.num = 0;
	vptr->sta.indicatif.call[0] = '\0';
	vptr->sta.indicatif.num = 0;
	for (i = 0; i < 8; i++)
	{
		vptr->sta.relais[i].call[0] = '\0';
		vptr->sta.relais[i].num = 0;
	}
	init_fb_mess (voie);
}


static void aff_heure (void)
{
	struct tm *sdate;
	long temps = time (NULL);

	sdate = gmtime (&temps);
	cprintf ("GMT %02d:%02d", sdate->tm_hour, sdate->tm_min);
	sdate = localtime (&temps);
	cprintf (" - LOCAL %02d:%02d\r\n", sdate->tm_hour, sdate->tm_min);
}

void lit_appel (void)
{
	FILE *fptr;

	sed = 1;
	fptr = fopen (d_disque ("OPTIONS.SYS"), "rb");
	if (fptr)
	{
		fread (&bip, sizeof (short), 1, fptr);
		fread (&ok_tell, sizeof (short), 1, fptr);
		fread (&ok_aff, sizeof (short), 1, fptr);
		fread (&separe, sizeof (short), 1, fptr);
		fread (&doub_fen, sizeof (short), 1, fptr);
		fread (&gate, sizeof (short), 1, fptr);
		fread (&just, sizeof (short), 1, fptr);
		fread (&p_forward, sizeof (short), 1, fptr);
		fread (&sed, sizeof (short), 1, fptr);
		fread (&aff_inexport, sizeof (short), 1, fptr);
		fread (&aff_popsmtp, sizeof (short), 1, fptr);

		fclose (fptr);
	}

	if (separe < M_LIG + 5)
		separe = M_LIG + 5;
	if (separe > h_screen - 4)
		separe = h_screen - 4;
	/*  printf("%d %d %d %d %d\n", bip, ok_tell, ok_aff, separe, doub_fen) ; */
#if defined(__WINDOWS__) || defined(__linux__)
	maj_menu_options ();
#endif
}

void cree_dir (int erreur)
{
	bullist lbul;
	FILE *fptr;

	if ((fptr = fopen (d_disque ("DIRMES.SYS"), "wb")) == NULL)
	{
		fbb_error (ERR_CREATE, d_disque ("DIRMES.SYS"), erreur);
	}
	lbul.type = '\0';
	lbul.numero = 100L;
	fwrite (&lbul, sizeof (bullist), 1, fptr);
	fclose (fptr);
}


void cree_info (void)
{
	FILE *fptr;

	if ((fptr = fopen (d_disque ("INF.SYS"), "wb")) == NULL)
	{
		fbb_error (ERR_CREATE, d_disque ("INF.SYS"), 0);
	}
	fclose (fptr);
}


void cree_stat (void)
{
	FILE *fptr;

	if ((fptr = fopen (d_disque ("statis.dat"), "wb")) == NULL)
	{
		fbb_error (ERR_CREATE, d_disque ("statis.dat"), 0);
	}
	fclose (fptr);
}


void cree_sat (void)
{
	FILE *fptr;

	if ((fptr = fopen (d_disque ("SAT\\SATEL.DAT"), "wb")) == NULL)
	{
		fbb_error (ERR_CREATE, d_disque ("SAT\\SATEL.DAT"), 0);
	}
	fclose (fptr);
}


static void cree_tpstat (void)
{
	int i;
	FILE *fichier;

	if ((fichier = fopen (d_disque ("TPSTAT.SYS"), "wb")) == NULL)
	{
		fbb_error (ERR_CREATE, d_disque ("TPSTAT.SYS"), 0);
	}
	for (i = 0; i < NBRUB; i++)
		stemps[i] = 0L;
	fwrite ((char *) stemps, sizeof (*stemps) * NBRUB, 1, fichier);
	fclose (fichier);
}


int err_ouvert (char *nomfic)
{
	int c;
	char s[80];

	deb_io ();
#ifdef ENGLISH
	cprintf ("Cannot open %s     \r\n", nomfic);
#else
	cprintf ("Erreur ouverture %s\r\n", nomfic);
#endif
	c = 0;

#ifdef ENGLISH
	sprintf (s, "Creating file %s      ", nomfic);
#else
	sprintf (s, "Creation du fichier %s", nomfic);
#endif
	if (sel_option (s, &c))
	{
#ifdef ENGLISH
		cprintf ("\rCreating file %s      \r\n", nomfic);
#else
		cprintf ("\rCreation du fichier %s\r\n", nomfic);
#endif
	}
	fin_io ();
	return (c);
}

static void init_tpstat (void)
{
	FILE *fichier;

	fichier = ouvre_stats ();
	fclose (fichier);

	while (TRUE)
	{
		if ((fichier = fopen (d_disque ("TPSTAT.SYS"), "r+b")) == NULL)
		{
			if (err_ouvert ("TPSTAT.SYS"))
				cree_tpstat ();
			else
				fbb_error (ERR_CREATE, d_disque ("TPSTAT.SYS"), 0);
		}
		else
			break;
	}
	fread ((char *) stemps, sizeof (*stemps) * NBRUB, 1, fichier);
	fclose (fichier);
}

static void initarbre (void)
{
	int offset;
	int i = 0;
	info buf2;
	char buf[40];
	FILE *fptr;
	bloc_indic *bptr;

#ifdef __linux__
#ifdef ENGLISH
	cprintf ("Callsign set-up                  \n");
#else
	cprintf ("Initialisation de la nomenclature\n");
#endif
#else
#ifdef ENGLISH
	cprintf ("Callsign set-up                  \r\n");
#else
	cprintf ("Initialisation de la nomenclature\r\n");
#endif
#endif
	deb_io ();
#ifdef __linux__
#ifdef ENGLISH
	cprintf ("Callsigns set-up             \n");
#else
	cprintf ("Initialisation des indicatifs\n");
#endif
#else
#ifdef ENGLISH
	cprintf ("Callsigns set-up             \r\n");
#else
	cprintf ("Initialisation des indicatifs\r\n");
#endif
#endif
	rinfo = 0;

	racine = bptr = new_bloc_info ();
	offset = 0;

	strcpy (bptr->st_ind[0].indic, "TOUS");
	bptr->st_ind[0].nbmess = (short) 0;
	bptr->st_ind[0].nbnew = (short) 0;
	bptr->st_ind[0].coord = 0xffff;
	++offset;

	fptr = ouvre_nomenc ();
	*buf2.indic.call = '\0';

	while (fread ((char *) &buf2, (int) sizeof (buf2), 1, fptr))
	{
		if (find (buf2.indic.call))
		{
			if (offset == T_BLOC_INFO)
			{
				bptr->suiv = new_bloc_info ();
				bptr = bptr->suiv;
				offset = 0;
			}
#ifdef __linux__
			if ((i++ % 50) == 0)
			{
				InitText (itoa (i, buf, 10));
			}
#endif
#ifdef __WINDOWS__
			if ((i++ % 50) == 0)
			{
				InitText (itoa (i, buf, 10));
			}
#endif
#ifdef __MSDOS__
			if (tempo == 0)
			{
				cprintf ("%-6s\r", buf2.indic.call);
				tempo = CADENCE;
			}
#endif
			inscoord (rinfo, &buf2, &(bptr->st_ind[offset]));
			++offset;
		}
		++rinfo;
	}
#ifdef __WINDOWS__
	InitText (itoa (i, buf, 10));
#else
#ifdef __linux__
	cprintf ("%-6s\n", buf2.indic.call);
#else
	cprintf ("%-6s\r", buf2.indic.call);
#endif
#endif
	ferme (fptr, 4);
	fin_io ();
}

void fwd_cpy (recfwd * dest, bullist * orig)
{
	int i;

	dest->type = orig->type;
	dest->bin = orig->bin;
	dest->kb = (unsigned char) ((orig->taille + 500) / 1000);
	dest->date = orig->date;
	dest->nomess = orig->numero;
	for (i = 0; i < NBMASK; i++)
		dest->fbbs[i] = orig->fbbs[i];
	strncpy (dest->bbsv, bbs_via (orig->bbsv), 6);
}

lfwd *cree_bloc_fwd (lfwd * ptr)
{
	int i;

	if (ptr)
	{
		ptr->suite = (lfwd *) m_alloue (sizeof (lfwd));
		ptr = ptr->suite;
	}
	else
		ptr = (lfwd *) m_alloue (sizeof (lfwd));
	ptr->suite = NULL;
	for (i = 0; i < NBFWD; i++)
		ptr->fwd[i].type = '\0';
	return (ptr);
}

int fwd_mask (char *masque)
{
	int i;

	for (i = 0; i < NBMASK; i++)
		if (*masque++)
			return (1);
	return (0);
}

bloc_mess *new_bloc_mess (void)
{
	int i;

	bloc_mess *bptr = (bloc_mess *) m_alloue (sizeof (bloc_mess));

	bptr->suiv = NULL;
	for (i = 0; i < T_BLOC_MESS; i++)
	{
		bptr->st_mess[i].noenr = 0;
		bptr->st_mess[i].nmess = 0L;
		bptr->st_mess[i].no_indic = 0;
	}
	return (bptr);
}

void end_messages (void)
{
	bloc_mess *bptr;
	lfwd *ptr_fwd;

	/* Libere la liste des forwards */
	while (tete_fwd)
	{
		ptr_fwd = tete_fwd;
		tete_fwd = tete_fwd->suite;
		m_libere (ptr_fwd, sizeof (lfwd));
	}

	/* Libere la liste des messages */
	while (tete_dir)
	{
		bptr = tete_dir;
		tete_dir = tete_dir->suiv;
		m_libere (bptr, sizeof (bloc_mess));
	}
}

static void initmessage (void)
{
	char buf[40];
	bloc_mess *bptr;
	unsigned no_indic;
	unsigned offset = 0;
	bullist bufdir;
	unsigned rmess = 0;
	char stat;
	int pos, nbfwd;
	int i = 0;
	lfwd *ptr_fwd;

	pos = nbfwd = 0;
	ptr_fwd = tete_fwd = cree_bloc_fwd (NULL);

#ifdef __linux__
#ifdef ENGLISH
	cprintf ("Message set-up             \n");
#else
	cprintf ("Initialisation des messages\n");
#endif
#else
#ifdef ENGLISH
	cprintf ("Message set-up             \r\n");
#else
	cprintf ("Initialisation des messages\r\n");
#endif
#endif
	deb_io ();
	nbmess = 0;

	ouvre_dir ();
	read_dir (rmess++, &bufdir);
	nomess = bufdir.numero;
#ifdef __linux__
#ifdef ENGLISH
	cprintf ("Next message %ld  \r\n", nomess + 1);
#else
	cprintf ("Prochain message %ld\n", nomess + 1);
#endif
#else
#ifdef ENGLISH
	cprintf ("Next message %ld   \r\n", nomess + 1,);
#else
	cprintf ("Prochain message %ld\r\n", nomess + 1);
#endif
#endif

	bptr = tete_dir = new_bloc_mess ();

	while (read_dir (rmess, &bufdir))
	{
		if (bufdir.type)
		{
#ifdef __linux__
			if ((i++ % 50) == 0)
			{
				InitText (itoa (i, buf, 10));
			}
#endif
#ifdef __WINDOWS__
			if ((i++ % 50) == 0)
			{
				InitText (itoa (i, buf, 10));
			}
#endif
#ifdef __MSDOS__
			if (tempo == 0)
			{
				cprintf ("%ld %-6s %d\r", bufdir.numero, bufdir.exped, nbfwd);
				tempo = CADENCE;
			}
#endif
			if (offset == T_BLOC_MESS)
			{
				bptr->suiv = new_bloc_mess ();
				bptr = bptr->suiv;
				offset = 0;
			}
			no_indic = insarbre (&bufdir);
			bptr->st_mess[offset].nmess = bufdir.numero;
			bptr->st_mess[offset].noenr = rmess;
			bptr->st_mess[offset].no_indic = no_indic;
			stat = bufdir.status;
			if ((stat != 'A') && (stat != 'K'))
			{
				++nbmess;
				if ((stat != 'F') && (stat != 'X') && (stat != 'H'))
				{
					if ((bufdir.numero) && (fwd_mask (bufdir.fbbs)))
					{
						if (pos == NBFWD)
						{
							pos = 0;
							ptr_fwd = cree_bloc_fwd (ptr_fwd);
						}
						fwd_cpy (&ptr_fwd->fwd[pos], &bufdir);
						++pos;
						++nbfwd;
					}
				}
				else if (stat == 'H')
					++nb_hold;
			}
			ins_iliste (&bufdir);
			++offset;
		}
		++rmess;
	}

#ifdef __WINDOWS__
	InitText (itoa (i, buf, 10));
#else
#ifdef __linux__
	if (bufdir.type)
	{
		cprintf ("%ld %-6s %d\n", bufdir.numero, bufdir.exped, nbfwd);
	}
#else
	if (bufdir.type)
	{
		cprintf ("%ld %-6s %d\r", bufdir.numero, bufdir.exped, nbfwd);
	}
#endif
#endif
	ferme_dir ();
	fin_io ();
#ifdef __linux__
#ifdef ENGLISH
	cprintf ("End - %d forward(s)\n", nbfwd);
#else
	cprintf ("Fin - %d forward(s)\n", nbfwd);
#endif
#else
#ifdef ENGLISH
	cprintf ("End - %d forward(s)\r\n", nbfwd);
#else
	cprintf ("Fin - %d forward(s)\r\n", nbfwd);
#endif
#endif
}