File: ux_init.c

package info (click to toggle)
frotz 2.40-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 468 kB
  • ctags: 891
  • sloc: ansic: 6,774; makefile: 143; sh: 63
file content (906 lines) | stat: -rw-r--r-- 24,356 bytes parent folder | download
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
/*
 * ux_init.c - Unix interface, initialisation
 *	Galen Hazelwood <galenh@micron.net>
 *	David Griffith <dgriffi@cs.csubak.edu>
 *
 * This file is part of Frotz.
 *
 * Frotz 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.
 *
 * Frotz 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
 */

#define __UNIX_PORT_FILE

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

#include <time.h>

#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

#include "getopt.h"


/* We will use our own private getopt functions. */


#ifdef USE_NCURSES_H
#include <ncurses.h>
#else
#include <curses.h>
#endif

#include <termios.h>

#include "frotz.h"
#include "ux_frotz.h"

#define INFORMATION "\
\n\
FROTZ V2.40 - An interpreter for all Infocom and other Z-Machine games.\n\
Complies with standard 1.0 of Graham Nelson's specification.\n\
\n\
Syntax: frotz [options] story-file\n\
\n\
  -a   watch attribute setting  \t -p   plain ASCII output only\n\
  -A   watch attribute testing  \t -P   alter piracy opcode\n\
  -b # background color         \t -r # right margin\n\
  -c # context lines            \t -q   quiet (disable sound effects\n\
  -d   disable color            \t -Q   use old-style save format\n\
  -e   enable sound             \t -s # random number seed value\n\
  -f # foreground colour        \t -S # transcript width\n\
  -F   force color mode         \t -t   set Tandy bit\n\
  -h # screen height            \t -u # slots for multiple undo\n\
  -l # left margin              \t -w # screen width\n\
  -o   watch object movement    \t -x   expand abbreviations g/x/z\n\
  -O   watch object locating"

static int user_disable_color = 0;
static int user_force_color = 0;
static int user_foreground_color = -1;
static int user_background_color = -1;
static int user_screen_width = -1;
static int user_screen_height = -1;
static int user_random_seed = -1;
static int user_tandy_bit = 0;

static int curses_active = 0; /* true if os_init_screen has been run */
int current_text_style = 0;           /* Since I can't use attr_get, which
                        	      would make things easier, I need to
				      use the same hack the MS-DOS port
				      does...keep the current style in a
				      global variable. */
char unix_plain_ascii = 0;    /* true if user wants to disable latin-1 */


char stripped_story_name[FILENAME_MAX+1];
char semi_stripped_story_name[FILENAME_MAX+1];

/*
 * os_fatal
 *
 * Display error message and exit program.
 *
 */

void os_fatal (const char *s)
{

    if (curses_active) {
      /* Solaris 2.6's cc complains if the below cast is missing */
      os_display_string((zchar *)"\n\n");
      beep();
      os_set_text_style(BOLDFACE_STYLE);
      os_display_string((zchar *)"Fatal error: ");
      os_set_text_style(0);
      os_display_string((zchar *)s);
      os_display_string((zchar *)"\n");
      os_reset_screen();
      exit(1);
    }

    fputs ("\nFatal error: ", stderr);
    fputs (s, stderr);
    fputs ("\n\n", stderr);

    exit (1);

}/* os_fatal */

extern char script_name[];
extern char command_name[];
extern char save_name[];
extern char auxilary_name[];

/*
 * os_process_arguments
 *
 * Handle command line switches. Some variables may be set to activate
 * special features of Frotz:
 *
 *     option_attribute_assignment
 *     option_attribute_testing
 *     option_context_lines
 *     option_object_locating
 *     option_object_movement
 *     option_left_margin
 *     option_right_margin
 *     option_ignore_errors
 *     option_piracy
 *     option_undo_slots
 *     option_expand_abbreviations
 *     option_script_cols
 *
 * The global pointer "story_name" is set to the story file name.
 *
 *
 */

void os_process_arguments (int argc, char *argv[])
{
    int c, i;

    const char *p = NULL;

    char *home;
    char configfile[FILENAME_MAX + 1];

    if ((getuid() == 0) || (geteuid() == 0)) {
	printf("I won't run as root!\n");
	exit(1);
    }

    if ((home = getenv("HOME")) == NULL) {
	printf("Hard drive on fire!\n");
	exit(1);
    }

/* 
 * It doesn't look like Frotz can reliably be resized given its current
 * screen-handling code.  While playing with Nitfol, I noticed that it
 * resized itself fairly reliably, even though the terminal looked rather
 * ugly to begin with.  Since Nitfol uses the Glk library for screen I/O,
 * I think there might be something in Glk that can make resizing easier.
 * Something to think about for later.
 *
 */

/*
    if (signal(SIGWINCH, SIG_IGN) != SIG_IGN)
	signal(SIGWINCH, sig_winch_handler);
*/

    /* First check for a "$HOME/.frotzrc". */
    /* If not found, look for CONFIG_DIR/frotz.conf */
    /* $HOME/.frotzrc overrides CONFIG_DIR/frotz.conf */

    if (home) {
        strncpy(configfile, home, FILENAME_MAX);
        strncat(configfile, "/", 1);
    } else
	configfile[0] = '\0';

    strncat(configfile, USER_CONFIG, strlen(USER_CONFIG));
    if (!getconfig(configfile)) {
	strncpy(configfile, CONFIG_DIR, FILENAME_MAX);
	strncat(configfile, "/", 1);	/* added by DJP */
	strncat(configfile, MASTER_CONFIG, FILENAME_MAX-10);
	getconfig(configfile);  /* we're not concerned if this fails */
    }

    /* Parse the options */

    do {
	c = getopt(argc, argv, "aAb:c:def:Fh:il:oOpPQqr:s:S:tu:w:xZ:");
	switch(c) {
	  case 'a': option_attribute_assignment = 1; break;
	  case 'A': option_attribute_testing = 1; break;
	  case 'b': user_background_color = atoi(optarg);
	            if ((user_background_color < 2) ||
			(user_background_color > 9))
		      user_background_color = -1;
		    break;
	  case 'c': option_context_lines = atoi(optarg); break;
	  case 'd': user_disable_color = 1; break;
	  case 'e': option_sound = 1; break;
	  case 'f': user_foreground_color = atoi(optarg);
	            if ((user_foreground_color < 2) || 
			(user_foreground_color > 9)) 
		      user_foreground_color = -1;
		    break;
	  case 'F': user_force_color = 1; 
		    user_disable_color = 0;
		    break;
          case 'h': user_screen_height = atoi(optarg); break;
/*	  case 'i': option_ignore_errors = 1; break;	*/
	  case 'l': option_left_margin = atoi(optarg); break;
	  case 'o': option_object_movement = 1; break;
	  case 'O': option_object_locating = 1; break;
	  case 'p': unix_plain_ascii = 1; break;
	  case 'P': option_piracy = 1; break;
	  case 'q': option_sound = 0; break;
	  case 'Q': option_save_quetzal = 0; break;
	  case 'r': option_right_margin = atoi(optarg); break;
	  case 's': user_random_seed = atoi(optarg); break;
	  case 'S': option_script_cols = atoi(optarg); break;
	  case 't': user_tandy_bit = 1; break;
	  case 'u': option_undo_slots = atoi(optarg); break;
	  case 'w': user_screen_width = atoi(optarg); break;
	  case 'x': option_expand_abbreviations = 1; break;
	  case 'Z': err_report_mode = atoi(optarg);
		    if ((err_report_mode < ERR_REPORT_NEVER) ||
			(err_report_mode > ERR_REPORT_FATAL))
		      err_report_mode = ERR_DEFAULT_REPORT_MODE;
		    break;
	}

    } while (c != EOF);

    if (optind != argc - 1) {
	puts (INFORMATION);
	printf ("\t-Z # error checking mode (default = %d)\n"
	    "\t     %d = don't report errors   %d = report first error\n"
	    "\t     %d = report all errors     %d = exit after any error\n\n",
	    ERR_DEFAULT_REPORT_MODE, ERR_REPORT_NEVER,
	    ERR_REPORT_ONCE, ERR_REPORT_ALWAYS,
	    ERR_REPORT_FATAL);
	exit (1);
    }

    /* This section is exceedingly messy and really can't be fixed
       without major changes all over the place.
     */

    /* Save the story file name */

    story_name = malloc(FILENAME_MAX + 1);
    strcpy(story_name, argv[optind]); 

    /* Strip path off the story file name */

    p = (char *)story_name;

    for (i = 0; story_name[i] != 0; i++)
        if (story_name[i] == '/')
          p = (char *)story_name + i + 1;

    for (i = 0; p[i] != '\0'; i++)
	semi_stripped_story_name[i] = p[i];
    semi_stripped_story_name[i] = '\0';

    for (i = 0; p[i] != '\0' && p[i] != '.'; i++)
        stripped_story_name[i] = p[i];
    stripped_story_name[i] = '\0';

    /*
     * If possible, saved games go in "$HOME/.infocom/" with extension
     * ".sav" (for quetzal save files) or ".frotz" (for old Frotz
     * save files).  If $HOME is not set, use the current directory.
     */

    save_name[0] = 0;

    if (home) {
        struct stat buf;

        strcpy (save_name, home);
        strcat (save_name, "/.infocom");

        if (stat (save_name, &buf)) {
            if (errno == ENOENT) {
                if (mkdir (save_name, 0777)) {
                    /* error; use cwd */
                    save_name[0] = 0;
                } else {
                    strcat (save_name, "/");
                }
            } else {
                save_name[0] = 0;
            }
        } else {
            if (S_ISDIR(buf.st_mode)) {
                strcat (save_name, "/");
            } else {
                save_name[0] = 0;
            }
        }
    }

    /* Create nice default file names */

    strcpy (script_name, stripped_story_name);
    strcpy (command_name, stripped_story_name);
    strcat (save_name, stripped_story_name);
    strcpy (auxilary_name, stripped_story_name);

    /* Don't forget the extensions */

    strcat (script_name, ".scr");
    strcat (command_name, ".rec");
    if (option_save_quetzal)
        strcat (save_name, ".sav");
    else
        strcat (save_name, ".frotz");
    strcat (auxilary_name, ".aux");

}/* os_process_arguments */

/*
 * os_init_screen
 *
 * Initialise the IO interface. Prepare the screen and other devices
 * (mouse, sound board). Set various OS depending story file header
 * entries:
 *
 *     h_config (aka flags 1)
 *     h_flags (aka flags 2)
 *     h_screen_cols (aka screen width in characters)
 *     h_screen_rows (aka screen height in lines)
 *     h_screen_width
 *     h_screen_height
 *     h_font_height (defaults to 1)
 *     h_font_width (defaults to 1)
 *     h_default_foreground
 *     h_default_background
 *     h_interpreter_number
 *     h_interpreter_version
 *     h_user_name (optional; not used by any game)
 *
 * Finally, set reserve_mem to the amount of memory (in bytes) that
 * should not be used for multiple undo and reserved for later use.
 *
 * (Unix has a non brain-damaged memory model which dosen't require such
 *  ugly hacks, neener neener neener. --GH :)
 *
 */

void os_init_screen (void)
{

    /*trace(TRACE_CALLS);*/
    curses_active = 1;          /* Let os_fatal know curses is running */
    initscr();                  /* Set up curses */
    cbreak();                   /* Raw input mode, no line processing */
    noecho();                   /* No input echo */
    nonl();                     /* No newline translation */
    intrflush(stdscr, TRUE);    /* Flush output on interrupt */
    keypad(stdscr, TRUE);       /* Enable the keypad and function keys */
    scrollok(stdscr, FALSE);    /* No scrolling unless explicitly asked for */

    if (h_version == V3 && user_tandy_bit != 0)
        h_config |= CONFIG_TANDY;

    if (h_version == V3)
	h_config |= CONFIG_SPLITSCREEN;

    if (h_version >= V4)
	h_config |= CONFIG_BOLDFACE | CONFIG_EMPHASIS | CONFIG_FIXED | CONFIG_TIMEDINPUT;

    if (h_version >= V5)
      h_flags &= ~(GRAPHICS_FLAG | MOUSE_FLAG | MENU_FLAG);

#ifdef NO_SOUND
    if (h_version >= V5)
      h_flags &= ~SOUND_FLAG;

    if (h_version == V3)
      h_flags &= ~OLD_SOUND_FLAG;
#else
    if ((h_version >= 5) && (h_flags & SOUND_FLAG))
	h_flags |= SOUND_FLAG;

    if ((h_version == 3) && (h_flags & OLD_SOUND_FLAG))
	h_flags |= OLD_SOUND_FLAG;

#endif

    if (h_version >= V5 && (h_flags & UNDO_FLAG))
        if (option_undo_slots == 0)
            h_flags &= ~UNDO_FLAG;

    getmaxyx(stdscr, h_screen_rows, h_screen_cols);

    if (user_screen_height != -1)
	h_screen_rows = user_screen_height;
    if (user_screen_width != -1)
	h_screen_cols = user_screen_width;

    h_screen_width = h_screen_cols;
    h_screen_height = h_screen_rows;

    h_font_width = 1;
    h_font_height = 1;

    /* Must be after screen dimensions are computed.  */
    if (h_version == V6) {
      if (unix_init_pictures())
	h_config |= CONFIG_PICTURES;
      else
	h_flags &= ~GRAPHICS_FLAG;
    }

    /* Use the ms-dos interpreter number for v6, because that's the
     * kind of graphics files we understand.  Otherwise, use DEC.  */
    h_interpreter_number = h_version == 6 ? INTERP_MSDOS : INTERP_DEC_20;
    h_interpreter_version = 'F';

#ifdef COLOR_SUPPORT
    /* Enable colors if the terminal supports them, the user did not
     * disable colors, and the game or user requested colors.  User
     * requests them by specifying a foreground or background.
     */
    color_enabled = (has_colors()
			&& !user_disable_color
			&& (((h_version >= 5) && (h_flags & COLOUR_FLAG))
			  || (user_foreground_color != -1)
			  || (user_background_color != -1)));

    /* Maybe we don't want to muck about with changing $TERM to
     * xterm-color which some supposedly current Unicies still don't
     * understand.
     */ 
    if (user_force_color)
	color_enabled = TRUE;

    if (color_enabled) {
        h_config |= CONFIG_COLOUR;
        h_flags |= COLOUR_FLAG; /* FIXME: beyond zork handling? */
        start_color();
	h_default_foreground =
	  (user_foreground_color == -1) 
	  	? FOREGROUND_DEF : user_foreground_color;
	h_default_background =  
	  (user_background_color ==-1) 
		? BACKGROUND_DEF : user_background_color;
    } else 
#endif
    {
	/* Set these per spec 8.3.2. */
	h_default_foreground = WHITE_COLOUR;
	h_default_background = BLACK_COLOUR;
	if (h_flags & COLOUR_FLAG) h_flags &= ~COLOUR_FLAG;
    }
    os_set_colour(h_default_foreground, h_default_background);
    os_erase_area(1, 1, h_screen_rows, h_screen_cols);
}/* os_init_screen */

/*
 * os_reset_screen
 *
 * Reset the screen before the program stops.
 *
 */

void os_reset_screen (void)
{

    os_set_text_style(0);
    os_display_string((zchar *) "[Hit any key to exit.]");
    os_read_key(0, FALSE);
    scrollok(stdscr, TRUE); scroll(stdscr);
    refresh(); endwin();

}/* os_reset_screen */

/*
 * os_restart_game
 *
 * This routine allows the interface to interfere with the process of
 * restarting a game at various stages:
 *
 *     RESTART_BEGIN - restart has just begun
 *     RESTART_WPROP_SET - window properties have been initialised
 *     RESTART_END - restart is complete
 *
 */

void os_restart_game (int stage)
{
}

/*
 * os_random_seed
 *
 * Return an appropriate random seed value in the range from 0 to
 * 32767, possibly by using the current system time.
 *
 */

int os_random_seed (void)
{

    if (user_random_seed == -1)
      /* Use the epoch as seed value */
      return (time(0) & 0x7fff);
    else return user_random_seed;

}/* os_random_seed */


/*
 * os_path_open
 *
 * Open a file in the current directory.  If this fails, then search the
 * directories in the ZCODE_PATH environmental variable.  If that's not
 * defined, search INFOCOM_PATH.
 *
 */

FILE *os_path_open(const char *name, const char *mode)
{
	FILE *fp;
	char buf[FILENAME_MAX + 1];
	char *p;

	/* Let's see if the file is in the currect directory */
	/* or if the user gave us a full path. */
	if ((fp = fopen(name, mode))) {
		return fp;
	}

	/* If zcodepath is defined in a config file, check that path. */
	/* If we find the file a match in that path, great. */
	/* Otherwise, check some environmental variables. */
	if (option_zcode_path != NULL) {
		if ((fp = pathopen(name, option_zcode_path, mode, buf)) != NULL) {
			strncpy(story_name, buf, FILENAME_MAX);
			return fp;
		}
	}

	if ( (p = getenv(PATH1) ) == NULL)
		p = getenv(PATH2);

	if (p != NULL) {
		fp = pathopen(name, p, mode, buf);
		strncpy(story_name, buf, FILENAME_MAX);
		return fp;
	}
	return NULL;	/* give up */
} /* os_path_open() */

/*
 * pathopen
 *
 * Given a standard Unix-style path and a filename, search the path for
 * that file.  If found, return a pointer to that file and put the full
 * path where the file was found in fullname.
 *
 */

FILE *pathopen(const char *name, const char *p, const char *mode, char *fullname)
{
	FILE *fp;
	char buf[FILENAME_MAX + 1];
	char *bp, lastch;

	lastch = 'a';	/* makes compiler shut up */

	while (*p) {
		bp = buf;
		while (*p && *p != PATHSEP)
			lastch = *bp++ = *p++;
		if (lastch != DIRSEP)
			*bp++ = DIRSEP;
		strcpy(bp, name);
		if ((fp = fopen(buf, mode)) != NULL) {
			strncpy(fullname, buf, FILENAME_MAX);
			return fp;
		}
		if (*p)
			p++;
	}
	return NULL;
} /* FILE *pathopen() */


/*
 * getconfig
 *
 * Parse a <variable> <whitespace> <value> config file.
 * The til-end-of-line comment character is the COMMENT define.  I use '#'
 * here.  This code originally appeared in my q2-wrapper program.  Find it
 * at metalab.cs.unc.edu or assorted Quake2 websites.
 *
 * This section must be modified whenever new options are added to 
 * the config file.  Ordinarily I would use yacc and lex, but the grammar
 * is too simple to involve those resources, and I can't really expect all
 * compile targets to have those two tools installed.
 *
 */
int getconfig(char *configfile)
{
	FILE	*fp;

	int	num, num2;

	char	varname[LINELEN + 1];
	char	value[LINELEN + 1];


	/*
	 * We shouldn't care if the config file is unreadable or not
	 * present.  Just use the defaults.
	 *
	 */

	if ((fp = fopen(configfile, "r")) == NULL)
		return FALSE;

	while (fgets(varname, LINELEN, fp) != NULL) {

		/* If we don't get a whole line, dump the rest of the line */
		if (varname[strlen(varname)-1] != '\n')
			while (fgetc(fp) != '\n')
			;

		/* Remove trailing whitespace and newline */
		for (num = strlen(varname) - 1; isspace(varname[num]); num--)
		;
		varname[num+1] = 0;

		/* Drop everything past the comment character */
		for (num = 0; num <= strlen(varname)+1; num++) {
			if (varname[num] == COMMENT)
				varname[num] = 0;
		}

		/* Find end of variable name */
		for (num = 0; !isspace(varname[num]) && num < LINELEN; num++);

		for (num2 = num; isspace(varname[num2]) && num2 < LINELEN; num2++);

		/* Find the beginning of the value */
		strncpy(value, &varname[num2], LINELEN);
		varname[num] = 0; /* chop off value from the var name */

		/* varname now contains the variable name */


		/* First, boolean config stuff */
		if (strcmp(varname, "attrib_set") == 0) {
			option_attribute_assignment = getbool(value);
		}
		else if (strcmp(varname, "attrib_test") == 0) {
			option_attribute_testing =  getbool(value);
		}

/*		else if (strcmp(varname, "error_halt") == 0) {
			option_ignore_errors = !getbool(value);
		}
*/
		else if (strcmp(varname, "color") == 0) {
			user_disable_color = !getbool(value);
		}
		else if (strcmp(varname, "colour") == 0) {
			user_disable_color = !getbool(value);
		}
		else if (strcmp(varname, "force_color") == 0) {
			user_force_color = getbool(value);
		}
		else if (strcmp(varname, "obj_move") == 0) {
			option_object_movement = getbool(value);
		}
		else if (strcmp(varname, "obj_loc") == 0) {
			option_object_locating = getbool(value);
		}
		else if (strcmp(varname, "piracy") == 0) {
			option_piracy = getbool(value);
		}
		else if (strcmp(varname, "ascii") == 0) {
			unix_plain_ascii = getbool(value);
		}
		else if (strcmp(varname, "sound") == 0) {
			option_sound = getbool(value);
		}
		else if (strcmp(varname, "quetzal") == 0) {
			option_save_quetzal = getbool(value);
		}
		else if (strcmp(varname, "tandy") == 0) {
			user_tandy_bit = getbool(value);
		}
		else if (strcmp(varname, "expand_abb") == 0) {
			option_expand_abbreviations = getbool(value);
		}

		/* now for stringtype yet still numeric variables */
		else if (strcmp(varname, "background") == 0) {
			user_background_color = getcolor(value);
		}
		else if (strcmp(varname, "foreground") == 0) {
			user_foreground_color = getcolor(value);
		}
		else if (strcmp(varname, "context_lines") == 0) {
			option_context_lines = atoi(value);
		}
		else if (strcmp(varname, "screen_height") == 0) {
			user_screen_height = atoi(value);
		}
		else if (strcmp(varname, "left_margin") == 0) {
			option_left_margin = atoi(value);
		}
		else if (strcmp(varname, "right_margin") == 0) {
			option_right_margin = atoi(value);
		}
		else if (strcmp(varname, "randseed") == 0) {
			user_random_seed = atoi(value);
		}
		else if (strcmp(varname, "script_width") == 0) {
			option_script_cols = atoi(value);
		}
		else if (strcmp(varname, "undo_slots") == 0) {
			option_undo_slots = atoi(value);
		}
		else if (strcmp(varname, "screen_width") == 0) {
			user_screen_width = atoi(value);
		}
		/* default is set in main() by call to init_err() */
		else if (strcmp(varname, "errormode") == 0) {
			err_report_mode = geterrmode(value);
		}

		/* now for really stringtype variable */

		else if (strcmp(varname, "zcode_path") == 0) {
			option_zcode_path = malloc(strlen(value) * sizeof(char) + 1);
			strncpy(option_zcode_path, value, strlen(value) * sizeof(char));
		}

		/* The big nasty if-else thingy is finished */		
	} /* while */

	return TRUE;
} /* getconfig() */


/* 
 * getbool
 *
 * Check a string for something that means "yes" and return TRUE.
 * Otherwise return FALSE.
 *
 */
int getbool(char *value)
{
	int num;

	/* Be case-insensitive */
	for (num = 0; value[num] !=0; num++)
		value[num] = tolower(value[num]);

	if (strncmp(value, "y", 1) == 0)
		return TRUE;
	if (strcmp(value, "true") == 0)
		return TRUE;
	if (strcmp(value, "on") == 0)
		return TRUE;
	if (strcmp(value, "1") == 0)
		return TRUE;

	return FALSE;
} /* getbool() */


/* 
 * getcolor
 *
 * Figure out what color this string might indicate and returns an integer 
 * corresponding to the color macros defined in frotz.h.
 *
 */
int getcolor(char *value)
{	
	int num;

	/* Be case-insensitive */
	for (num = 0; value[num] !=0; num++)
		value[num] = tolower(value[num]);

	if (strcmp(value, "black") == 0)
		return BLACK_COLOUR;
	if (strcmp(value, "red") == 0)
		return RED_COLOUR;
	if (strcmp(value, "green") == 0)
		return GREEN_COLOUR;
	if (strcmp(value, "blue") == 0)
		return BLUE_COLOUR;
	if (strcmp(value, "magenta") == 0)
		return MAGENTA_COLOUR;
	if (strcmp(value, "cyan") == 0)
		return CYAN_COLOUR;
	if (strcmp(value, "white") == 0)
		return WHITE_COLOUR;

	if (strcmp(value, "purple") == 0)
		return MAGENTA_COLOUR;
	if (strcmp(value, "violet") == 0)
		return MAGENTA_COLOUR;
	if (strcmp(value, "aqua") == 0)
		return CYAN_COLOUR;

	/* If we can't tell what that string means, 
	 * we tell caller to use the default.
	 */

	return -1;	

} /* getcolor() */


/*
 * geterrmode
 *
 * Parse for "never", "once", "always", or "fatal" and return a macro
 * defined in ux_frotz.h related to the error reporting mode.
 *
 */
int geterrmode(char *value)
{
	int num;

        /* Be case-insensitive */
	for (num = 0; value[num] !=0; num++)
		value[num] = tolower(value[num]);

	if (strcmp(value, "never") == 0)
		return ERR_REPORT_NEVER;
	if (strcmp(value, "once") == 0)
		return ERR_REPORT_ONCE;
	if (strcmp(value, "always") == 0)
		return ERR_REPORT_ALWAYS;
	if (strcmp(value, "fatal") == 0)
		return ERR_REPORT_FATAL;

	return ERR_DEFAULT_REPORT_MODE;
} /* geterrmode() */


/*
 * sig_winch_handler
 *
 * Called whenever Frotz recieves a SIGWINCH signal to make curses 
 * cleanly resize the window.
 *
 */

void sig_winch_handler(int sig)
{
/* 
There are some significant problems involved in getting resizes to work
properly with at least this implementation of the Z Machine and probably
the Z-Machine standard itself.  See the file BUGS for a detailed 
explaination for this.  Because of this trouble, I've left this function
currently does nothing.
*/

/*
	signal(sig, SIG_DFL);
	signal(sig, SIG_IGN);


	signal(SIGWINCH, sig_winch_handler);
*/
}

void redraw(void)
{
	/* not implemented */
}