File: options.c

package info (click to toggle)
conquest 8.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,984 kB
  • ctags: 3,086
  • sloc: ansic: 39,393; sh: 8,540; yacc: 446; makefile: 296; lex: 146
file content (888 lines) | stat: -rw-r--r-- 19,500 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
#include "c_defs.h"

/************************************************************************
 *
 * options.c - handle view/edit options feature
 *
 * $Id: options.c,v 1.9 2004/11/24 01:31:12 jon Exp $
 *
 * Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
 *
 ***********************************************************************/

#include "global.h"
#include "conqdef.h"
#include "conqcom.h"
#include "color.h"
#include "ui.h"
#include "conf.h"
#include "clntauth.h"
#include "cd2lb.h"
#include "iolb.h"
#include "client.h"
#include "clientlb.h"

#include "context.h"

struct compile_options {
  char *name;
  char *oneliner;
  int type;			/* We'll use the CTYPE_*'s from conf.h */
  void *value;
};

static void ChangeOption(struct Conf *cdata, int lin);
static void ChangeMacro(int macronum);
static void DisplayCompileOptions(void);
static int ViewEditOptions(struct Conf ConfigData[], int ConfSize, 
			   int editable);
static int ViewEditMacros(struct Conf *ConfigData);
static void DisplayHelpScreen(struct Conf *confitem);

static int ChangedSomething = FALSE;


/*************************************************************************
 * DisplayCompileOptions() - do what name indicates
 *
 *
 *************************************************************************/

static void DisplayCompileOptions(void)
{
  const int settingcol = 60;
  int i,j, vattrib;
  int lin = 0, col = 0;
  static char *header = "Compile Time Options";
  static char *prompt = MTXT_DONE;

  static struct compile_options CompileOptions[] = 
  {
    {"HAVE_SETITIMER", "can do fastupdates (2 per sec)", CTYPE_BOOL, 
#ifdef HAVE_SETITIMER
     (void *)TRUE
#else
     (void *)FALSE
#endif /* HAVE_SETITIMER */
    },

    {"USE_COMMONMLOCK", "can lock common block in memory", CTYPE_BOOL, 
#ifdef USE_COMMONMLOCK
     (void *)TRUE
#else
     (void *)FALSE
#endif /* USE_COMMONMLOCK */
    },

    {"SET_PRIORITY", "can raise process priority", CTYPE_BOOL, 
#ifdef SET_PRIORITY
     (void *)TRUE
#else
     (void *)FALSE
#endif /* SET_PRIORITY */
    },

    {"WARP0CLOAK", "can't be seen when cloaked at warp 0", CTYPE_BOOL,
#ifdef WARP0CLOAK
     (void *)TRUE
#else
     (void *)FALSE
#endif /* WARP0CLOAK */
    },

    {"DO_EXPLODING_SHIPS", "ships explode when they die", CTYPE_BOOL,
#ifdef DO_EXPLODING_SHIPS
     (void *)TRUE
#else
     (void *)FALSE
#endif /* DO_EXPLODING_SHIPS */
    },

				/* last (NULL) entry */
    {NULL, NULL, CTYPE_NULL, (void *)NULL}
  };

  lin = 1;
  col = ((int)(Context.maxcol - strlen(header)) / 2);

  cprintf(lin, col, ALIGN_NONE, "#%d#%s", NoColor, header);
  
  lin += 3;
  col = 2;

  i = 0;

  while (CompileOptions[i].name != NULL)
    {				/* this won't handle more than one screen */
      cprintf(lin, col, ALIGN_NONE, "#%d#%s#%d# - %s#%d#",
	      NoColor, CompileOptions[i].name,
	      InfoColor, CompileOptions[i].oneliner,
	      NoColor);
      
				/* output the value */
      switch(CompileOptions[i].type)
	{
	case CTYPE_BOOL:
	  j = (int) CompileOptions[i].value;

	  if (j == TRUE)
	    vattrib = GreenLevelColor;
	  else
	    vattrib = RedLevelColor;

	  cprintf(lin, settingcol, ALIGN_NONE, "#%d#%s#%d#",
		  vattrib, (j == TRUE) ? "True" : "False",
		  NoColor);
	  lin++;

	  break;

	case CTYPE_STRING:
	  cprintf(lin, settingcol, ALIGN_NONE, "#%d#%s#%d#",
		  InfoColor, (char *) CompileOptions[i].value,
                  NoColor);
	  lin++;

	  break;
	} /* switch */

      i++;
    }

  cdclrl( MSG_LIN1, 2  );
  cdputc(prompt, MSG_LIN1);
  
  /* Get a char */
  (void)iogchar();

return;
}


/*************************************************************************
 * SysOptsMenu() - display System options menu
 *
 *
 *************************************************************************/

void SysOptsMenu(void)
{
  static char *header = "System Options Menu";
  static char *mopts[] = { 
    "View compile-time Options",
    "View/Edit System-wide Options"
  };
  const int numoptions = 2;	/* don't exceed 9 - one char input is used */
  
  static char *prompt = "Enter a number to select an item, any other key to quit.";
  int lin = 0, col = 0;

  int i;
  int ch;
  int Done = FALSE;


  while (Done == FALSE)
    {
				/* First clear the display. */
      cdclear();
      lin = 1;
      col = ((int)(Context.maxcol - strlen(header))/ 2);
      
      cprintf(lin, col, ALIGN_NONE, "#%d#%s", NoColor, header);
      
      lin += 3;
      col = 5;
      
      for (i = 0; i < numoptions; i++)
	{
	  cprintf(lin, col, ALIGN_NONE, "#%d#%d.#%d# %s#%d#", InfoColor, 
		  i + 1, LabelColor, mopts[i], NoColor);
	  lin++;
	}
      
      cdclrl( MSG_LIN1, 2  );
      cdputs(prompt, MSG_LIN1, 1);
      
      /* Get a char */
      ch = iogchar();
      
      switch(ch)
	{
	case '1':			/* compile time options */
	  DisplayCompileOptions();
	  break;
	case '2':			/* sys-wide opts */
	  ChangedSomething = FALSE;
	  ViewEditOptions(SysConfData, SysCfEnd, TRUE);
	  if (ChangedSomething == TRUE)
	    SaveSysConfig();
	  break;
	default:
	  Done = TRUE;
	  break;
	}
    }

  return;
}

/*************************************************************************
 * UserOptsMenu() - display user options menu
 *
 *
 *************************************************************************/

void UserOptsMenu(int unum)
{
  static char *header = "User Options Menu";
  static char *mopts[] = { 
    "View/Edit Options",
    "View/Edit Macros",
    "Change Password"
  };
  const int numoptions = 3;	/* don't exceed 9 - one char input is used */
  static char *prompt = "Enter a number to select an item, any other key to quit.";
  int lin = 0, col = 0;
  int i;
  int ch;
  int Done = FALSE;
  struct Conf *macroptr = NULL;	/* points to macro element of ConfData */

  for (i=0; i < CfEnd; i++)
    {
      if (ConfData[i].ConfType == CTYPE_MACRO)
	macroptr = &ConfData[i];
    }

  if (macroptr == NULL)
    {				/* if this happens, something is
				   seriously confused */
      clog("UserOptsMenu(): ERROR: macroptr == NULL, no CTYPE_MACRO found in ConfData");
    }

  while (Done == FALSE)
    {
				/* First clear the display. */
      cdclear();
      lin = 1;
      col = ((Context.maxcol / 2) - (strlen(header) / 2));
      
      cprintf(lin, col, ALIGN_NONE, "#%d#%s", NoColor, header);
      
      lin += 3;
      col = 5;
      
      for (i = 0; i < numoptions; i++)
	{
	  cprintf(lin, col, ALIGN_NONE, "#%d#%d.#%d# %s#%d#", InfoColor, 
		  i + 1, LabelColor, mopts[i], NoColor);
	  lin++;
	}

      lin++;
      lin++;
      cprintf(lin, col, ALIGN_NONE, "#%d#UDP:  #%d# %s#%d#", LabelColor,
              InfoColor, (cInfo.doUDP) ? "On" : "Off",
              NoColor);

      lin++;
      cprintf(lin, col, ALIGN_NONE, "#%d#Flags:#%d# %s#%d#", LabelColor,
              InfoColor, clntServerFlagsStr(sStat.flags),
              NoColor);
      
      cdclrl( MSG_LIN1, 2  );
      cdputs(prompt, MSG_LIN1, 1);
      
      /* Get a char */
      ch = iogchar();
      
      switch(ch)
	{
	case '1':			/* user opts */
	  ChangedSomething = FALSE; 
	  ViewEditOptions(ConfData, CfEnd, TRUE);
				/* save and reload the config */
	  if (ChangedSomething == TRUE)
	    {
	      SaveUserConfig();
	      /* set new update rate */
	      Context.updsec = UserConf.UpdatesPerSecond;
	      sendCommand(CPCMD_SETRATE, Context.updsec);
	    }
	  break;

	case '2':		/* macros */
	  if (macroptr != NULL)
	    {
	      ChangedSomething = FALSE; 
	      ViewEditMacros(macroptr);
	      if (ChangedSomething == TRUE)
		SaveUserConfig();
	    }

	  break;

	case '3':			/* chg passwd */
	  ChangePassword(unum, FALSE);
	  break;

	default:
	  Done = TRUE;
	  break;
	}
    }

  return;
}

/*************************************************************************
 * ChangeOption() - change an option (or prompt for new value)
 *
 *
 *************************************************************************/

static void ChangeOption(struct Conf *cdata, int lin)
{
#define CBUFLEN 1024
  int j, rv;
  char buf[CBUFLEN];

  switch(cdata->ConfType)
    {
    case CTYPE_BOOL:
      j = *(int *)(cdata->ConfValue);
      
      if (j == TRUE)
	j = FALSE;
      else
	j = TRUE;

      *(int *)(cdata->ConfValue) = j;

				/* signal that something has been changed */
      ChangedSomething = TRUE;

      break;

				/* these will need prompting on line 'lin' */
    case CTYPE_STRING:
      if (cdata->max > CBUFLEN)
	{
	  clog("ChangeOption: conf data max exceeds local buffer size.");
	  break;
	}
      cdclrl(lin, 1);
      strncpy(buf, ((char *)cdata->ConfValue), CBUFLEN);
      buf[CBUFLEN - 1] = 0;
      rv = cdgets("Value: ", lin, 1, buf, cdata->max - 1);

      if (rv != ERR)
	{
	  strncpy((char *)cdata->ConfValue, buf, cdata->max);
	  ((char *)cdata->ConfValue)[cdata->max - 1] = 0;
				/* signal that something has been changed */
	  ChangedSomething = TRUE;
	}

      break;
      
    case CTYPE_NUMERIC:
      cdclrl(lin, 1);
      rv = cdgetn("Enter a number: ", lin, 1, &j);

      if (rv != ERR)
	{
	  if (j >= cdata->min && j <= cdata->max)
	    {
	      *(int *)(cdata->ConfValue) = j;
	      /* signal that something has been changed */
	      ChangedSomething = TRUE;
	    }
	}

      break;
    }

  return;
}

/*************************************************************************
 * ChangeMacro() - change a macro... duh...
 *
 *
 *************************************************************************/

static void ChangeMacro(int macronum)
{
  int lin;
  static char *prmpt2 = "Enter Conquest commands.  ([RETURN] = \\r, [TAB] = \\t)";
  char buf[MAX_MACRO_LEN + 1];
  char prmpt[BUFFER_SIZE];
  int ch;
  lin = MSG_LIN1;
  
  

  cdclrl(lin, 2);
  cdputs(prmpt2, MSG_LIN2, 1);
  sprintf(prmpt, "f%2d = ", macronum);

  strcpy(buf, Macro2Str(UserConf.MacrosF[macronum - 1]));
  ch = cdgetx(prmpt, lin, 1, TERMS, buf, MAX_MACRO_LEN - 1, TRUE);

  if (ch == TERM_ABORT)
    {
      return;			/* if abort, cancel */
    }
      
  strncpy(UserConf.MacrosF[macronum - 1], Str2Macro(buf), MAX_MACRO_LEN);
  UserConf.MacrosF[macronum - 1][MAX_MACRO_LEN - 1] = EOS;
  
  ChangedSomething = TRUE;

  return;
}


/*************************************************************************
 * ViewEditOptions() - View or edit an options array
 *
 *
 *************************************************************************/

static int ViewEditOptions(struct Conf ConfigData[], int ConfSize, 
			   int editable)
{
  int i, j, k;
  static char *uheader = "User Configurable Options";
  static char *sheader = "System-wide Configurable Options";
  static char *header;
  static char *eprompt = "Arrow keys to select an item, [SPACE] to change, any other key to quit.";
  static char *vprompt = MTXT_DONE;
  static char *eprompt2 = "Type '?' for help on an item.";
  int Done = FALSE;
  int ch;
  int lin = 0, col = 0, flin, llin, clin, maxllin;
  const int settingcol = 65;
  int vattrib;
#define MAXOPTCOLS 128
  int cvec[MAXOPTCOLS];		/* hopefully big enough */
  int usingSysOpts;

  usingSysOpts = ((ConfigData == SysConfData) ? TRUE : FALSE);

  if (usingSysOpts)
    header = sheader;
  else
    header = uheader;

  cdclear();			/* First clear the display. */

  flin = 4;			/* first option line */
  maxllin = MSG_LIN1 - 2;	/* max last option line */
  llin = 0;			/* last option line */
  clin = 0;			/* current option line (also idx into cvec) */

				/* clear out cvec */

  for (i=0; i < MAXOPTCOLS; i++)
    cvec[i] = -1;

  while (Done == FALSE)
    {
      cdclrl( 1, MSG_LIN2);	/* clear screen area */
      lin = 1;
      col = ((int)(Context.maxcol - strlen(header))/ 2);

      cprintf(lin, col, ALIGN_NONE, "#%d#%s", NoColor, header);
      
      lin = flin;
      col = 1;
      
      i = 0;			/* start at index 0 */
      k = 0;			/* init cvec */

      while (i < ConfSize)
	{
#ifdef DEBUG_OPTIONS
	  clog("ViewEditOptions(): ConfSize = %d, i = %d, type = %d, %s", 
	       ConfSize, i, ConfigData[i].ConfType,  
	       ConfigData[i].OneLineDesc);	  
#endif
	  if (ConfigData[i].ConfType != CTYPE_STRING && 
	      ConfigData[i].ConfType != CTYPE_BOOL &&
	      ConfigData[i].ConfType != CTYPE_NUMERIC)
	    {		/* skip special elements */
#ifdef DEBUG_OPTIONS
	      clog("ViewEditOptions():\tSKIPPING");
#endif
	      i++;
	      continue;
	    }

	  cvec[k++] = i;
	  
	  cprintf(lin, col, ALIGN_NONE, "#%d#%s#%d#",
		  InfoColor, ConfigData[i].OneLineDesc,
		  NoColor);

	  switch(ConfigData[i].ConfType)
	    {
	    case CTYPE_BOOL:
	      j = *(int *)ConfigData[i].ConfValue;
	      
	      if (j == TRUE)
		vattrib = GreenLevelColor;
	      else
		vattrib = RedLevelColor;
	      
	      cprintf(lin, settingcol, ALIGN_NONE, "#%d#%s#%d#",
		      vattrib, (j == TRUE) ? "True" : "False",
		      NoColor);
	      break;
	      
	    case CTYPE_STRING:
	      cprintf(lin, settingcol, ALIGN_NONE, "#%d#%13s#%d#",
		      InfoColor, (char *) ConfigData[i].ConfValue,
		      NoColor);
	      break;

	    case CTYPE_NUMERIC:
	      j = *(int *)ConfigData[i].ConfValue;
              cprintf(lin, settingcol, ALIGN_NONE, "#%d#%d#%d#",
                      NoColor, j,
                      NoColor);
              break;


	    } /* switch */
	  lin++;
	  i++;
	}

				/* now the editing phase */
      llin = k - 1;

#ifdef DEBUG_OPTIONS
clog("ViewEditOptions(): maxllin = %d, llin = %d, k = %d", maxllin, llin, k);
#endif

      cdclrl( MSG_LIN1, 2  );
      if (editable)
	{
	  cdputs(eprompt, MSG_LIN1, 1);
	  cdputs(eprompt2, MSG_LIN2, 1);
	  cdmove(flin + clin, 1); 
	}
      else
	cdputc(vprompt, MSG_LIN1);
      
      /* Get a char */
      ch = iogchar();
      
      if (!editable)
	{
	  Done = TRUE;
	  break;		/* exit here after viewing */
	}

      switch(ch)
	{
	case KEY_UP:		/* up */
	case KEY_LEFT:
	case 'w':
	case 'k':
	  clin--;
	  if (clin < 0)
	    {
	      clin = llin; 
	    }
	  break;

	case KEY_DOWN:		/* down */
	case KEY_RIGHT:
	case 'x':
	case 'j':
	  clin++;
	  if (clin > llin)
	    {
	      clin = 0; 
	    }
	  break;

	case ' ':	/* change something */
	  ChangeOption(&ConfigData[cvec[clin]], MSG_LIN1);
	  break;

	case '?':
	  DisplayHelpScreen(&ConfigData[cvec[clin]]);
	  break;

	default:		/* everything else */
	  Done = TRUE;
	  break;
	}

#ifdef DEBUG_OPTIONS
      clog("ViewEditOptions():###\tllin = %d, clin = %d", llin, clin);
#endif
    }

  return TRUE;
}

/*************************************************************************
 * ViewEditMacros() - view and edit your macros ;-)
 *
 *
 *************************************************************************/

static int ViewEditMacros(struct Conf *ConfigData)
{
  int i, k;
  static char *header = "View/Edit Macros";
  static char *header2fmt = "(Page %d of %d)";
  static char headerbuf[BUFFER_SIZE];
  static char header2buf[BUFFER_SIZE];
  static char *nodef = "<Not Defined>";
  static char *eprompt = "Arrow keys to select a macro, [SPACE] to change, any other key to quit.";
  static char *eprompt2 = "Type '?' for help.";
  int Done = FALSE;
  int ch, vattrib;
  char *dispmac;
  int lin = 0, col = 0, flin, llin, clin, pages, curpage;
  const int macros_per_page = 18;
  char *macrovec[MAX_MACROS];

				/* this is the number of required pages,
				   though page accesses start at 0 */
  if (MAX_MACROS >= macros_per_page)
    {
      pages = MAX_MACROS / macros_per_page;
      if ((MAX_MACROS % macros_per_page) != 0)
	pages++;		/* for runoff */
    }
  else
    pages = 1;


				/* init the macrovec array */
  for (i=0; i < MAX_MACROS; i++)
  {
    macrovec[i] = (char *)(((char *)ConfigData->ConfValue)
                                        + (i * MAX_MACRO_LEN));
  }

  curpage = 0;

  cdclear();			/* First clear the display. */

  flin = 4;			/* first macro line */
  llin = 0;			/* last macro line on this page */
  clin = 0;			/* current macro line */


  while (Done == FALSE)
    {
      sprintf(header2buf, header2fmt, curpage + 1, pages);
      sprintf(headerbuf, "%s %s", header, header2buf);

      cdclrl( 1, MSG_LIN2);	/* clear screen area */
      lin = 1;
      col = ((int)(Context.maxcol - strlen(headerbuf)) / 2);

      cprintf(lin, col, ALIGN_NONE, "#%d#%s", NoColor, headerbuf);
      
      lin = flin;
      col = 1;
      
      i = 0;			/* start at index 0 */

				/* figure out the last editable line on
				   this page */

      if (curpage == (pages - 1)) /* last page - might be less than full */
	llin = (MAX_MACROS % macros_per_page);	/* ..or more than empty? ;-) */
      else
	llin = macros_per_page;

      i = 0;
      while (i < llin)
	{			/* display this page */
				/* get the macro number for this line */
	  k = (curpage * macros_per_page) + i; 

	  if (macrovec[k][0] == EOS)
	    {			/* not defined */
	      dispmac = nodef;
	      vattrib = RedLevelColor;
	    }
	  else
	    {
	      dispmac = Macro2Str(macrovec[k]);
	      vattrib = GreenLevelColor;
	    }

#ifdef DEBUG_OPTIONS
	  clog("ViewEditMacros(): k = %d, dispmac = '%s'", 
	       k, 
	       dispmac);
#endif

	  cprintf(lin, col, ALIGN_NONE, "#%d#f%2d = #%d#%s#%d#",
		  InfoColor, k + 1, vattrib, 
		  dispmac,
		  NoColor);

	  lin++;
	  i++;
	}

				/* now the editing phase */
      cdclrl( MSG_LIN1, 2  );
      cdputs(eprompt, MSG_LIN1, 1);
      cdputs(eprompt2, MSG_LIN2, 1);

      if (clin >= llin)
	clin = llin - 1;

      cdmove(flin + clin, 1); 
      
      /* Get a char */
      ch = iogchar();
      

      switch(ch)
	{
	case KEY_UP:		/* up */
	case KEY_LEFT:
	case 'w':
	case 'k':
	  clin--;
	  if (clin < 0)
	    {
	      if (pages != 1)
		{
		  curpage--;
		  if (curpage < 0)
		    {
		      curpage = pages - 1;
		    }
		}

				/* setup llin  for current page */
	      if (curpage == (pages - 1)) 
		llin = (MAX_MACROS % macros_per_page);
	      else
		llin = macros_per_page;

	      clin = llin - 1; 
	    }
	  break;

	case KEY_DOWN:		/* down */
	case KEY_RIGHT:
	case 'x':
	case 'j':
	  clin++;
	  if (clin >= llin)
	    {
	      if (pages != 1)
		{
		  curpage++;
		  if (curpage >= pages)
		    {
		      curpage = 0;
		    }
		}
	      
	      clin = 0; 
	    }
	  break;

	case KEY_PPAGE:		/* prev page */
	  if (pages != 1)
	    {
	      curpage--;
	      if (curpage < 0)
		{
		  curpage = pages - 1;
		}
	    }

	  break;

	case KEY_NPAGE:		/* next page */
	  if (pages != 1)
	    {
	      curpage++;
	      if (curpage >= pages)
		{
		  curpage = 0;
		}
	    }

	  break;

	case ' ':	/* change something */
	  ChangeMacro((curpage * macros_per_page) + clin + 1);
	  break;

	case '?':
	  DisplayHelpScreen(ConfigData); /* macro */
	  break;

	default:		/* everything else */
	  Done = TRUE;
	  break;
	}

#ifdef DEBUG_OPTIONS
      clog("ViewEditMacros():###\tllin = %d, clin = %d, curpage = %d", 
	   llin, clin, curpage);
#endif
    }

  return TRUE;
}

/* DisplayHelpScreen() - display a help (actually the conf item comment)
 *                       screen for a Configuration item.
 */
static void DisplayHelpScreen(struct Conf *confitem)
{
  int i, col, lin;

  cdclear();

  lin = 1;
  col = 0;

  cprintf(lin, col, ALIGN_CENTER, "#%d#%s#%d#", 
	  NoColor, confitem->OneLineDesc, NoColor);

  lin += 2;

  i = 0;
  uiPutColor(InfoColor);

  while (confitem->ConfComment[i] != NULL)
    {
      if (confitem->ConfComment[i][0] != EOS)
	{
	  cdputs(&(confitem->ConfComment[i][1]), lin, col);
	  lin++;
	}
      i++;
    }

  uiPutColor(NoColor);
  cdclrl( MSG_LIN1, 2  );
  cdputc(MTXT_DONE, MSG_LIN2);

  /* Get a char */
  (void)iogchar();

  return;
}