summaryrefslogtreecommitdiff
path: root/globals.c
blob: 0eb0ad7856ed4b43d57999c356ea31fb66c9ec10 (plain)
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
/*

    viDOOM - level editor for DOOM

    Copyright (C) 2000  Ian Cowburn (ianc@noddybox.demon.co.uk)

    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

    -------------------------------------------------------------------------

    Global data

    All the stuff from INI file and from the config files.  Note this object
    also drives other objects so that the list of things they maintain is
    initialised.

*/
static const char rcs_id[]="$Id$";

#include "config.h"
#include "globals.h"

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "ini.h"
#include "gfx.h"
#include "texture.h"
#include "things.h"
#include "linedefs.h"
#include "sectors.h"


/* Constants
*/
#define MAXLEN		1024

#define M_NONE			-1
#define M_THING_TYPES		0
#define M_SECTOR_TYPES		1
#define M_LINEDEF_FLAGS		2
#define M_INCLUDE		3
#define M_THING_FLAGS		4
#define M_LINEDEF_TYPES		5
#define M_LINEDEF_DEFAULTS	6
#define M_SECTOR_STYLES		7
#define M_LINEDEF_FLAGS_EXTRA	8
#define M_EMPTY_TEXTURE_NAME	9
#define M_THING_CLASSES		10
#define M_LINEDEF_CLASSES	11
#define M_SECTOR_CLASSES	12
#define M_NORMAL_TYPES		13
#define M_LINEDEF_CHECK_DEFAULT	14


/* INI sections
*/
#define GAME_INI	"Game"
#define EDITOR_INI	"Editor"
#define VIDOOM_INI	"viDOOM"
#define CLINEDEF_INI	"Check LINEDEF"
#define BUILD_INI	"Node Builder"

#define DOOM_INI	"Doom"
#define ULT_DOOM_INI	"Ultimate Doom"
#define DOOM2_INI	"Doom 2"
#define FINAL_TNT_INI	"TNT:Evilution"
#define FINAL_PLUT_INI	"Plutonia Experiment"
#define ZDOOM_INI	"ZDoom"

/* ------------------------------ Game type
*/
GameType	game=DOOM_2;
LevelStyle	level_style=DOOM_2_LEVELS;
int		ask_for_game_type=FALSE;
char		*game_name="Doom 2 - Hell on Earth";


/* ------------------------------ Paths
*/
char		IWAD_path[PATH_MAX+1]="." DIRSEP "DOOM2.WAD";
char		PWAD_dir[PATH_MAX+1]="." DIRSEP;
char		PWAD_preload[MAX_PRELOAD_LEN]="";
static char	config_file[PATH_MAX+1]="doom2.cfg";


/* ------------------------------ Editor configuration
*/
int		disp_width=640;
int		disp_height=480;
int		grid_onoff=TRUE;
int		grid_lock=TRUE;
int		grid_size=64;
double		gfx_brighten=1.0;
int		vertex_rad=5;
Hover		hover_select=HOVER_NONE;
int		clear_on_move=TRUE;
int		clear_on_menu=FALSE;
Hover		insert_select=HOVER_NONE;
SectorMoveMode	sector_move=MOVE_RIGHT;
int		ask_middle_on_2sided=TRUE;
int		default_light_level=200;
int		default_floor_height=0;
int		default_ceiling_height=256;
NewSelect	new_2sided_select=NEWSELECT_ASK;
LinedefMerge	merge_linedef=MERGE_ASK;
int		auto_block_linedefs=TRUE;
int		default_scale=10;
DefaultEdit	default_edit_mode=EDIT_SECTOR;
int		linedef_select=2;
int		tag_highlight=TRUE;
int		show_full_linedef_info=FALSE;


/* ------------------------------ viDOOM configuration
*/
int		sort_textures=TRUE;
int		sort_flats=TRUE;
int		show_titlepic=TRUE;
int		load_textures=TRUE;
int		load_flats=TRUE;
int		load_sprites=TRUE;
int		map_warn=TRUE;
int		map_exit_warn=TRUE;
int		initial_empty_map=FALSE;
int		overwrite_warning=TRUE;

/* ------------------------------ Linedef flags bit and mask
*/
int		side2_bit=-1;
int		side2_mask;
int		block_bit=-1;
int		block_mask;
int		lower_peg_bit=-1;
int		lower_peg_mask;
int		upper_peg_bit=-1;
int		upper_peg_mask;

/* ------------------------------ Normal values
*/
int		normal_linedef=0;
int		normal_sector=0;

/* ------------------------------ LINEDEF checking
*/
int		check_line_assume_yes=FALSE;
int		check_1side_lower=TRUE;
int		check_1side_middle=TRUE;
int		check_1side_upper=TRUE;
int		check_2side_lower=TRUE;
int		check_2side_middle=TRUE;
int		check_2side_same_sector=TRUE;
int		check_2side_upper=TRUE;

/* ------------------------------ Node Builder config
*/
int		use_build=FALSE;
char		build_cmd[PATH_MAX+1]="bsp.exe";
char		build_ignore[PATH_MAX+1]="";
char		build_in[PATH_MAX+1]="%";
char		build_out[PATH_MAX+1]="%";
int		build_in_before_out=TRUE;
int		build_always_view=TRUE;



/* ------------------------------ Texture names
*/
char		empty_texture[256]="-";
char		linedef_check_default[256]="-";


/* ------------------------------ INI tables to data
*/

#define INI_FOR_GAME(g)		{					\
				    INI_STR, g, "iwad",			\
				    IWAD_path, NULL			\
				},					\
				{					\
				    INI_STR, g, "pwad_dir",		\
				    PWAD_dir, NULL			\
				},					\
				{					\
				    INI_TOK, g, "level_style",		\
				    &level_style, level_style_tok	\
				},					\
				{					\
				    INI_STR, g, "preload",		\
				    PWAD_preload, NULL			\
				},					\
				{					\
				    INI_STR, g, "vidoom_config",	\
				    config_file, NULL			\
				}


static TokenTable	game_type_tok[]=
			    {
				{"Doom",DOOM},
				{"Ultimate Doom",ULTIMATE_DOOM},
				{"Doom 2",DOOM_2},
				{"TNT:Evilution",FINAL_TNT},
				{"Plutonia Experiment",FINAL_PLUTONIA},
				{"ZDoom",ZDOOM},
				{NULL,0}
			    };

static TokenTable	level_style_tok[]=
			    {
				{"Doom",DOOM_LEVELS},
				{"Ultimate Doom",ULTIMATE_DOOM_LEVELS},
				{"Doom 2",DOOM_2_LEVELS},
				{NULL,0}
			    };

static TokenTable	hover_type_tok[]=
			    {
				{"none",HOVER_NONE},
				{"add",HOVER_ADD},
				{"single",HOVER_SINGLE},
				{NULL,0}
			    };

static TokenTable	smove_type_tok[]=
			    {
				{"all",MOVE_ALL},
				{"left",MOVE_LEFT},
				{"right",MOVE_RIGHT},
				{NULL,0}
			    };

static TokenTable	new_select_tok[]=
			    {
				{"never",NEWSELECT_NEVER},
				{"ask",NEWSELECT_ASK},
				{"select",NEWSELECT_SELECT},
				{NULL,0}
			    };

static TokenTable	merge_mode_tok[]=
			    {
				{"never",MERGE_NEVER},
				{"ask",MERGE_ASK},
				{"always",MERGE_ALWAYS},
				{NULL,0}
			    };

static TokenTable	edit_mode_tok[]=
			    {
				{"sector",EDIT_SECTOR},
				{"vertex",EDIT_VERTEX},
				{"linedef",EDIT_LINEDEF},
				{"thing",EDIT_THING},
				{"multi",EDIT_MULTI},
				{NULL,0}
			    };


static INI_Table	part1_ini[]=
			    {
			    	/* Game type
				*/
				{
				    INI_TOK, GAME_INI, "game",
				    &game, game_type_tok
				},
				{
				    INI_TOK, GAME_INI, "ask",
				    &ask_for_game_type, ini_yesno
				},
				{
				    INI_INT, EDITOR_INI, "width",
				    &disp_width, NULL
				},
				{
				    INI_INT, EDITOR_INI, "height",
				    &disp_height, NULL
				},
			    };

static INI_Table	part2_ini[]=
			    {
			    	/* Editor
				*/
				{
				    INI_TOK, EDITOR_INI, "grid",
				    &grid_onoff, ini_yesno
				},
				{
				    INI_TOK, EDITOR_INI, "grid_lock",
				    &grid_lock, ini_yesno
				},
				{
				    INI_INT, EDITOR_INI, "grid_size",
				    &grid_size, NULL
				},
				{
				    INI_DOUBLE, EDITOR_INI, "bright",
				    &gfx_brighten, NULL
				},
				{
				    INI_INT, EDITOR_INI, "vertex_radius",
				    &vertex_rad, NULL
				},
				{
				    INI_TOK, EDITOR_INI, "hover_select",
				    &hover_select, hover_type_tok
				},
				{
				    INI_TOK, EDITOR_INI, "clear_on_move",
				    &clear_on_move, ini_yesno
				},
				{
				    INI_TOK, EDITOR_INI, "clear_on_menu",
				    &clear_on_menu, ini_yesno
				},
				{
				    INI_TOK, EDITOR_INI, "insert_select",
				    &insert_select, hover_type_tok
				},
				{
				    INI_TOK, EDITOR_INI, "sector_move",
				    &sector_move, smove_type_tok
				},
				{
				    INI_TOK, EDITOR_INI, "ask_middle_on_2sided",
				    &ask_middle_on_2sided, ini_yesno
				},
				{
				    INI_INT, EDITOR_INI, "default_light_level",
				    &default_light_level, NULL
				},
				{
				    INI_INT, EDITOR_INI, "default_floor_height",
				    &default_floor_height, NULL
				},
				{
				    INI_INT,EDITOR_INI,"default_ceiling_height",
				    &default_ceiling_height, NULL
				},
				{
				    INI_TOK, EDITOR_INI, "new_2sided_select",
				    &new_2sided_select, new_select_tok
				},
				{
				    INI_TOK, EDITOR_INI, "merge_linedef",
				    &merge_linedef, merge_mode_tok
				},
				{
				    INI_TOK, EDITOR_INI, "auto_block_linedefs",
				    &auto_block_linedefs, ini_yesno
				},
				{
				    INI_INT, EDITOR_INI, "default_scale",
				    &default_scale, NULL
				},
				{
				    INI_TOK, EDITOR_INI, "default_edit_mode",
				    &default_edit_mode, edit_mode_tok
				},
				{
				    INI_INT, EDITOR_INI, "linedef_select",
				    &linedef_select, NULL
				},
				{
				    INI_TOK, EDITOR_INI,"tag_highlight",
				    &tag_highlight, ini_yesno
				},
				{
				    INI_TOK,EDITOR_INI,"show_full_linedef_info",
				    &show_full_linedef_info, ini_yesno
				},

				/* viDOOM
				*/
				{
				    INI_TOK, VIDOOM_INI, "sort_texture_names",
				    &sort_textures, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "sort_flat_names",
				    &sort_flats, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "show_titlepic",
				    &show_titlepic, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "load_textures",
				    &load_textures, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "load_flats",
				    &load_flats, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "load_sprites",
				    &load_sprites, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "map_clear_warning",
				    &map_warn, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "map_exit_warning",
				    &map_exit_warn, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "initial_empty_map",
				    &initial_empty_map, ini_yesno
				},
				{
				    INI_TOK, VIDOOM_INI, "overwrite_warning",
				    &overwrite_warning, ini_yesno
				},

				/* Check LINEDEF
				*/
				{
				    INI_TOK, CLINEDEF_INI, "assume_yes",
				    &check_line_assume_yes, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_1side_lower",
				    &check_1side_lower, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_1side_middle",
				    &check_1side_middle, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_1side_upper",
				    &check_1side_upper, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_2side_lower",
				    &check_2side_lower, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_2side_middle",
				    &check_2side_middle, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, 
						    "check_2side_same_sector",
				    &check_2side_same_sector, ini_yesno
				},
				{
				    INI_TOK, CLINEDEF_INI, "check_2side_upper",
				    &check_2side_upper, ini_yesno
				},

				/* Node builder
				*/
				{
				    INI_TOK, BUILD_INI, "use",
				    &use_build, ini_yesno
				},
				{
				    INI_STR, BUILD_INI, "command",
				    build_cmd, NULL
				},
				{
				    INI_STR, BUILD_INI, "ignore",
				    build_ignore, NULL
				},
				{
				    INI_STR, BUILD_INI, "infile",
				    build_in, NULL
				},
				{
				    INI_STR, BUILD_INI, "outfile",
				    build_out, NULL
				},
				{
				    INI_TOK, BUILD_INI, "in_before_out",
				    &build_in_before_out, ini_yesno
				},
				{
				    INI_TOK, BUILD_INI, "always_view_output",
				    &build_always_view, ini_yesno
				},
			    };

static INI_Table	doom_ini[]={INI_FOR_GAME(DOOM_INI)};
static INI_Table	ult_doom_ini[]={INI_FOR_GAME(ULT_DOOM_INI)};
static INI_Table	doom_2_ini[]={INI_FOR_GAME(DOOM2_INI)};
static INI_Table	tnt_ini[]={INI_FOR_GAME(FINAL_TNT_INI)};
static INI_Table	plut_ini[]={INI_FOR_GAME(FINAL_PLUT_INI)};
static INI_Table	zdoom_ini[]={INI_FOR_GAME(ZDOOM_INI)};



/* ------------------------------ TYPES
*/
typedef struct
	    {
	    char	*str;
	    int		val;
	    } StrList;


/* ------------------------------ PRIVATE FUNCTIONS
*/

static void CheckVals(void)
{
    FILE *fp;

    grid_size=MAX(grid_size,2);
    default_light_level=default_light_level%256;
    linedef_select=MAX(linedef_select,1);

    /* Check config file exists
    */
    if (!(fp=fopen(config_file,"r")))
    	GFX_exit(EXIT_FAILURE,"Couldn't open config file %s\n",config_file);

    fclose(fp);
}


static int StrToInt(StrList s[],char *val,int def)
{
    int f;
    int m;

    f=0;
    m=def;

    while((s[f].str)&&(m==def))
	{
	if (STREQ(s[f].str,val))
	    m=s[f].val;
	f++;
	}

    return(m);
}


static char *GetLine(FILE *fp)
{
    static char s[MAXLEN+1];
    int l,f;

    fgets(s,MAXLEN,fp);

    if (feof(fp))
	return(FALSE);

    l=strlen(s)-1;

    if ((l>=0)&&(s[l]=='\n'))
	s[l]=0;

    l=strlen(s)-1;

    if ((l>=0)&&(s[l]=='\r'))
	s[l]=0;

    l=strlen(s);
    for(f=0;f<l;f++)
	if (!isspace(s[f]))
	    if (s[f]=='#')
		return(GetLine(fp));
	    else
		return(s+f);

    return(GetLine(fp));
}


static void DoLoadConfig(char *fn)
{
    static StrList mode_list[]={{"%THING_TYPES",M_THING_TYPES},
			        {"%SECTOR_TYPES",M_SECTOR_TYPES},
			        {"%LINEDEF_TYPES",M_LINEDEF_TYPES},
			        {"%INCLUDE_FILES",M_INCLUDE},
			        {"%THING_FLAGS",M_THING_FLAGS},
			        {"%LINEDEF_FLAGS",M_LINEDEF_FLAGS},
				{"%LINEDEF_DEFAULTS",M_LINEDEF_DEFAULTS},
				{"%SECTOR_STYLES",M_SECTOR_STYLES},
				{"%LINEDEF_FLAGS_EXTRA",M_LINEDEF_FLAGS_EXTRA},
				{"%EMPTY_TEXTURE_NAME",M_EMPTY_TEXTURE_NAME},
				{"%THING_CLASSES",M_THING_CLASSES},
				{"%LINEDEF_CLASSES",M_LINEDEF_CLASSES},
				{"%SECTOR_CLASSES",M_SECTOR_CLASSES},
				{"%NORMAL_TYPES",M_NORMAL_TYPES},
				{"%LINEDEF_CHECK_DEFAULT",
						M_LINEDEF_CHECK_DEFAULT},
			        {NULL,0}};

    FILE *fp;
    char *line;
    char orig[MAXLEN+1];
    int mode;
    char *err;

    mode=M_NONE;

    if (!(fp=fopen(fn,"r")))
    	GFX_exit(EXIT_FAILURE,"Couldn't open config file %s\n",fn);

    while((line=GetLine(fp)))
	{
	strcpy(orig,line);
	err=NULL;

	if (*line=='%')
	    {
	    mode=StrToInt(mode_list,line,M_NONE);

	    switch(mode)
	    	{
		case M_SECTOR_STYLES:
		    StartSectorStyles();
		    break;
		default:
		    break;
		}
	    }
	else
	    switch(mode)
	        {
		case M_THING_CLASSES:
		    {
		    char *p[2];

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
			ThingNewClass(p[0],ATOI(p[1]));
		    else
			err="THING_CLASSES";

		    break;
		    }

		case M_LINEDEF_CLASSES:
		    LinedefNewClass(line);
		    break;

		case M_SECTOR_CLASSES:
		    SectorNewClass(line);
		    break;

		case M_THING_TYPES:
		    {
		    char *p[5];
		    int f;

		    p[0]=strtok(line,"|");

		    for(f=1;(f<5)&&(p[f-1]);f++)
		    	p[f]=strtok(NULL,"|");

		    if (p[4])
			ThingAdd(p[0],p[1],ATOI(p[2]),ATOI(p[3]),
				    (load_sprites ? DecodeGraphicsLump(p[4]) :
				    		    NULL));
		    else
		    	err="THING_TYPES";

		    break;
		    }

		case M_SECTOR_TYPES:
		    {
		    char *p[4];
		    int f;

		    p[0]=strtok(line,"|");

		    for(f=1;(f<4)&&(p[f-1]);f++)
		    	p[f]=strtok(NULL,"|");

		    if (p[3])
			SectorAdd(p[0],ATOI(p[1]),p[2],p[3]);
		    else
			err="SECTOR_TYPES";

		    break;
		    }

		case M_LINEDEF_TYPES:
		    {
		    char *p[3];

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
		    	p[2]=strtok(NULL,"|");

		    if (p[2])
			LinedefAdd(p[0],p[2],ATOI(p[1]));
		    else
			err="LINEDEF_TYPES";

		    break;
		    }

		case M_LINEDEF_FLAGS:
		    {
		    char *p[3];
		    int f;

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
		    	p[2]=strtok(NULL,"|");

		    f=ATOI(p[0]);

		    if ((f>=0)&&(f<=15)&&(p[2]))
			LinedefFlag(f,p[1],*p[2]);
		    else
		    	err="LINEDEF_FLAGS";

		    break;
		    }

		case M_INCLUDE:
		    {
		    char s[PATH_MAX];

		    strcpy(s,line);
		    DoLoadConfig(s);
		    break;
		    }

		case M_THING_FLAGS:
		    {
		    char *p[3];
		    int f;

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
		    	p[2]=strtok(NULL,"|");

		    f=ATOI(p[0]);

		    if ((f>=0)&&(f<=15)&&(p[2]))
			ThingFlag(f,p[1],p[2]);
		    else
		    	err="THING_FLAGS";

		    break;
		    }

		case M_LINEDEF_DEFAULTS:
		    {
		    int flags;
		    char *p[2];

		    if (side2_bit==-1)
		    	GFX_exit
			   (EXIT_FAILURE,
			    "LINEDEF_DEFAULTS appeared before "
					    "LINEDEF_FLAGS_EXTRA\n");

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
			{
			flags=ATOI(p[1]);
			AddLinedefType(p[0],flags,flags&side2_mask);
			}
		    else
		    	err="LINEDEF_DEFAULTS";

		    break;
		    }

		case M_SECTOR_STYLES:
		    {
		    char *p[7];
		    int f;

		    p[0]=strtok(line,"|");

		    for(f=1;(f<7)&&(p[f-1]);f++)
		    	p[f]=strtok(NULL,"|");

		    if (p[6])
			AddSectorStyle(p[1],ATOI(p[0]),p[2],p[3],
				       p[4],p[5],p[6]);
		    else
		    	err="SECTOR_STYLES";

		    break;
		    }

		case M_LINEDEF_FLAGS_EXTRA:
		    {
		    char *p[4];
		    int f;

		    p[0]=strtok(line,"|");

		    for(f=1;(f<4)&&(p[f-1]);f++)
		    	p[f]=strtok(NULL,"|");

		    if (p[3])
			{
			side2_bit=ATOI(p[0]);
			side2_mask=1<<side2_bit;

			block_bit=ATOI(p[1]);
			block_mask=1<<block_bit;

			upper_peg_bit=ATOI(p[2]);
			upper_peg_mask=1<<upper_peg_bit;

			lower_peg_bit=ATOI(p[3]);
			lower_peg_mask=1<<lower_peg_bit;
			}
		    else
		    	err="LINEDEF_FLAGS_EXTRA";

		    break;
		    }

		case M_EMPTY_TEXTURE_NAME:
		    strncpy(empty_texture,line,sizeof(empty_texture)-1);
		    empty_texture[sizeof(empty_texture)-1]=0;
		    break;

		case M_NORMAL_TYPES:
		    {
		    char *p[2];

		    p[0]=strtok(line,"|");

		    if (p[0])
		    	p[1]=strtok(NULL,"|");

		    if (p[1])
			{
			normal_sector=ATOI(p[0]);
			normal_linedef=ATOI(p[1]);
			}
		    else
		    	err="NORMAL_TYPES";

		    break;
		    }

		case M_LINEDEF_CHECK_DEFAULT:
		    strncpy(linedef_check_default,line,
		    		sizeof(linedef_check_default)-1);
		    linedef_check_default[sizeof(linedef_check_default)-1]=0;
		    break;

		case M_NONE:
		    break;
		}

	if (err)
	    GFX_exit
		(EXIT_FAILURE,
		 "%s: section %s\nError in line '%s'\n",fn,err,orig);
	}

    fclose(fp);
}


/* ------------------------------ EXPORTED FUNCTIONS
*/

void LoadGlobalsPart1(void)
{
    INI_Load("vidoom.ini");
    INI_GetTable(part1_ini,INI_TAB_SIZE(part1_ini));
}


void LoadGlobalsPart2(void)
{
    INI_GetTable(part2_ini,INI_TAB_SIZE(part2_ini));

    switch(game)
    	{
	case DOOM:
	    INI_GetTable(doom_ini,INI_TAB_SIZE(doom_ini));
	    game_name="Doom - Knee Deep in The Dead";
	    break;
	case ULTIMATE_DOOM:
	    INI_GetTable(ult_doom_ini,INI_TAB_SIZE(ult_doom_ini));
	    game_name="Utlimate Doom - Thy Flesh Consumed";
	    break;
	case DOOM_2:
	    INI_GetTable(doom_2_ini,INI_TAB_SIZE(doom_2_ini));
	    game_name="Doom 2 - Hell On Earth";
	    break;
	case FINAL_TNT:
	    INI_GetTable(tnt_ini,INI_TAB_SIZE(tnt_ini));
	    game_name="Final Doom - TNT:Evilution";
	    break;
	case FINAL_PLUTONIA:
	    INI_GetTable(plut_ini,INI_TAB_SIZE(plut_ini));
	    game_name="Final Doom - The Plutonia Experiment";
	    break;
	case ZDOOM:
	    INI_GetTable(zdoom_ini,INI_TAB_SIZE(zdoom_ini));
	    game_name="ZDoom/BOOM extensions to Doom";
	    break;
	}

    CheckVals();
}


void SaveGlobals(void)
{
    INI_PutTable(part1_ini,INI_TAB_SIZE(part1_ini));
    INI_PutTable(part2_ini,INI_TAB_SIZE(part2_ini));

    switch(game)
    	{
	case DOOM:
	    INI_PutTable(doom_ini,INI_TAB_SIZE(doom_ini));
	    break;
	case ULTIMATE_DOOM:
	    INI_PutTable(ult_doom_ini,INI_TAB_SIZE(ult_doom_ini));
	    break;
	case DOOM_2:
	    INI_PutTable(doom_2_ini,INI_TAB_SIZE(doom_2_ini));
	    break;
	case FINAL_TNT:
	    INI_PutTable(tnt_ini,INI_TAB_SIZE(tnt_ini));
	    break;
	case FINAL_PLUTONIA:
	    INI_PutTable(plut_ini,INI_TAB_SIZE(plut_ini));
	    break;
	case ZDOOM:
	    INI_PutTable(zdoom_ini,INI_TAB_SIZE(zdoom_ini));
	    break;
	}

    INI_Save();
}


void LoadConfig(void)
{
    DoLoadConfig(config_file);
}


/* END OF FILE */