File: Command4.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (704 lines) | stat: -rw-r--r-- 21,088 bytes parent folder | download | duplicates (3)
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
/* 
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
*/ 
/* 
 * HISTORY
*/ 
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: Command4.c /main/7 1995/07/13 19:17:16 drk $"
#endif
#endif
/*
*  (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
#include <testlib.h>

#define MAXHISTORY 128
#define MAX_ITEMS 50

void HeightChange();
void WidthChange();
void ProcessListItems();
void PopulateList();
void CommandChanged();
static void    Quit();
void 	       PrintHeaders();
void	       CreateCommandBox();
void CallRedo();

char 	 *Istrings[MAXHISTORY];
XmString itemTable[MAX_ITEMS];

#define NUM_TOGGLES 7

Widget    Command1, Text1;
Widget    toggles[NUM_TOGGLES];
Widget    Frame0, SetB, GetB, Append, Error;
Widget    Scale0, Scale1;
Widget    Layout;


void  main(argc, argv)
    int     argc;
    char  **argv;
{
    register int  n, i;
    Arg           args[MAX_ARGS];
    Widget        Separator1, Frame1;
    Widget        Form2;
    Widget        Scale2, ControlBox;
    Widget        Frame2, RadioBox1;
    Widget        Go, PopB, QuitB, Redo;
    Widget	  Frame3, RowCol;
    static char   *toggle_names[ ] = { 
				      "listVisibleItemCount",
				      "historyVisibleItemCount",
				      "listItemCount",
				      "historyItemCount",
				      "historyMaxItems",
				      "promptString",
				      "command"

				      };
    /* NOTE: If the CONTENTS of this list are changed, you may have to
       change routine PopulateList() !!!! */

    char 	buf[32];
    Dimension 	height;
    Dimension 	width;
    int 	offset;
    XmString    tcs;

#ifdef DEBUG
    printf ("Number of names in name array %d\n", 
	             ((sizeof (toggle_names))/(sizeof(char *))) );
#endif

    CommonTestInit(argc, argv);

    XtRealizeWidget(Shell1);
    

    /* Overall Plan:
       Create Command box whose list/listCount resources can be set
       and gotten by user-driven interface
     */

    n = 0;
    Layout = XmCreateForm (Shell1, "Layout", args, n);
    XtRealizeWidget(Layout);
    XtManageChild(Layout);

    CreateCommandBox(Layout, True, NULL);

    n = 0;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Frame0);	 		n++;
    XtSetArg (args[n], XmNtopOffset, 5);			n++;
    XtSetArg (args[n], XmNrightOffset, 5);			n++;
    XtSetArg (args[n], XmNleftOffset, 5);			n++;
    Frame1 = XmCreateFrame (Layout, "Frame1", args, n);
    XtRealizeWidget(Frame1);
    XtManageChild(Frame1);

#ifdef DEBUG
    n = 0;
    XtSetArg (args[n], XmNtopOffset, &offset); 			n++;
    XtGetValues (Frame1, args, n);
    printf ("Dependent's starting top offset is %d\n", offset);
#endif

    n = 0;
    Form2 = XmCreateForm (Frame1, "Form2", args, n);
    XtRealizeWidget(Form2);
    XtManageChild(Form2);

    /* This is to get around Command not REALLY knowing how big it wants
       to be until after Realize. If this is a bug, it's a bug in the
       way XtRealize works */

    n = 0;
    tcs = XmStringCreateSimple ("Width in Pixels");
    XtSetArg (args[n], XmNmappedWhenManaged, False); 		n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNshowValue, True); 			n++;
    XtSetArg (args[n], XmNorientation, XmHORIZONTAL); 		n++;
    XtSetArg (args[n], XmNtitleString, tcs );			n++;
    XtSetArg (args[n], XmNmaximum, 500); 			n++;
    XtSetArg (args[n], XmNminimum, 0); 				n++;
    Scale0 = XmCreateScale (Form2, "Scale0", args, n);
    XtRealizeWidget(Scale0);
    XmStringFree(tcs);
    XtManageChild(Scale0);

    XtAddCallback (Scale0, XmNvalueChangedCallback, WidthChange, NULL); 

    n = 0;
    tcs = XmStringCreateSimple ("Height in Pixels");
    XtSetArg (args[n], XmNmappedWhenManaged, False); 		n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopWidget, Scale0);			n++;
    XtSetArg (args[n], XmNshowValue, True); 			n++;
    XtSetArg (args[n], XmNorientation, XmHORIZONTAL); 		n++;
    XtSetArg (args[n], XmNtitleString, tcs );                   n++;
    XtSetArg (args[n], XmNmaximum, 500); 			n++;
    XtSetArg (args[n], XmNminimum, 0); 				n++;
    Scale1 = XmCreateScale (Form2, "Scale1", args, n);
    XtRealizeWidget(Scale1);
    XmStringFree(tcs);
    XtManageChild(Scale1);

    XtAddCallback (Scale1, XmNvalueChangedCallback, HeightChange, NULL); 

    n = 0;
    tcs = XmStringCreateSimple ("Item Count/Visible Item Count");
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Scale1); 			n++;
    XtSetArg (args[n], XmNshowValue, True); 			n++;
    XtSetArg (args[n], XmNorientation, XmHORIZONTAL); 		n++;
    XtSetArg (args[n], XmNtitleString, tcs );                   n++;
    XtSetArg (args[n], XmNmaximum, MAX_ITEMS); 			n++;
    XtSetArg (args[n], XmNminimum, 0); 				n++;
    Scale2 = XmCreateScale (Form2, "Scale2", args, n);
    XtRealizeWidget(Scale2);
    XmStringFree( tcs );
    XtManageChild(Scale2);

    n = 0;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Scale2); 			n++;
    XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT);		n++;
    Text1 = XmCreateText(Form2, "Text1", args, n);
    XtRealizeWidget(Text1);
    XtManageChild(Text1);

    n = 0;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Text1); 			n++;
    ControlBox = XmCreateRowColumn (Form2, "ControlBox", args, n);
    XtRealizeWidget(ControlBox);
    XtManageChild(ControlBox);
    
    for (i = 0; i <= NUM_TOGGLES - 1; i++)
      {    
		   n = 0;
           tcs = XmStringCreateSimple(toggle_names[i]);
           XtSetArg (args[n], XmNlabelString, tcs ); n++;
  	   XtSetArg (args[n], XmNuserData, (XtPointer)toggle_names[i]);	n++;
           sprintf(buf, "toggleButton%d", i);
	   toggles[i] = XmCreateToggleButtonGadget(ControlBox, buf, args, n);
	   XtRealizeWidget (toggles[i]);
	   XtManageChild (toggles[i]);
           XmStringFree( tcs );
       }

    n = 0;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Frame1); 			n++;
    XtSetArg (args[n], XmNleftOffset, 5); 			n++;
    XtSetArg (args[n], XmNrightOffset, 5); 			n++;
    Frame2 = XmCreateFrame (Layout, "Frame2", args, n);
    XtRealizeWidget(Frame2);
    XtManageChild(Frame2);

    n = 0;
    XtSetArg (args[n], XmNorientation, XmHORIZONTAL); 		n++;
    XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); 		n++;
    RadioBox1 = XmCreateRadioBox (Frame2, "RadioBox1", args, n);
    XtRealizeWidget(RadioBox1);
    XtManageChild(RadioBox1);

    n = 0;
    tcs = XmStringCreateSimple ("Get");
    XtSetArg (args[n], XmNlabelString, tcs );			n++;
    GetB = XmCreateToggleButtonGadget(RadioBox1, "GetB", args, n);
    XtRealizeWidget(GetB);
    XmStringFree(tcs);
    XtManageChild(GetB);

    n = 0;
    tcs = XmStringCreateSimple ("Set");
    XtSetArg (args[n], XmNlabelString, tcs );			n++;
    SetB = XmCreateToggleButtonGadget(RadioBox1, "SetB", args, n);
    XtRealizeWidget(SetB);
    XmStringFree(tcs);
    XtManageChild(SetB);

    n = 0;
    tcs = XmStringCreateSimple ("Append");
    XtSetArg (args[n], XmNlabelString, tcs );			n++; 
    Append = XmCreateToggleButtonGadget(RadioBox1, "Append", args, n);
    XtRealizeWidget(Append);
    XmStringFree(tcs);
    XtManageChild(Append);

    n = 0;
    tcs = XmStringCreateSimple ("Error");
    XtSetArg (args[n], XmNlabelString, tcs );			n++;
    Error = XmCreateToggleButtonGadget(RadioBox1, "Error", args, n);
    XtRealizeWidget(Error);
    XmStringFree(tcs);
    XtManageChild(Error);

    n = 0;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    XtSetArg (args[n], XmNtopWidget, Frame2); 			n++;
    XtSetArg (args[n], XmNleftOffset, 5); 			n++;
    XtSetArg (args[n], XmNrightOffset, 5); 			n++;
    XtSetArg (args[n], XmNbottomOffset, 5); 			n++;
    Frame3 = XmCreateFrame (Layout, "Frame3", args, n);
    XtRealizeWidget(Frame3);
    XtManageChild(Frame3);

    n = 0;
    XtSetArg(args[n], XmNorientation, XmHORIZONTAL);		n++;
    RowCol = XmCreateRowColumn(Frame3, "RowCol", args, n);
    XtRealizeWidget(RowCol);
    XtManageChild(RowCol);

    n = 0;
    tcs = XmStringCreateSimple ("Perform Action");
    XtSetArg (args[n], XmNlabelString, tcs );			n++;
    Go = XmCreatePushButtonGadget(RowCol, "Go", args, n);
    XtRealizeWidget(Go);
    XmStringFree(tcs);
    XtManageChild(Go);

    XtAddCallback (Go, XmNactivateCallback, ProcessListItems, Scale2);

    n = 0;
    tcs = XmStringCreateSimple ("Populate List");
    XtSetArg (args[n], XmNlabelString, tcs );			n++;
    PopB = XmCreatePushButton (RowCol, "PopB", args, n);
    XtRealizeWidget(PopB);
    XmStringFree(tcs);
    XtManageChild(PopB);

    XtAddCallback (PopB, XmNactivateCallback, PopulateList, Scale2);

    n = 0;
    tcs = XmStringCreateSimple("Recreate Command");
    XtSetArg (args[n], XmNlabelString, tcs );		n++;
    Redo = XmCreatePushButtonGadget(RowCol, "Redo", args, n);
    XtRealizeWidget(Redo);
    XmStringFree(tcs);
    XtManageChild(Redo);

    XtAddCallback (Redo, XmNactivateCallback, CallRedo, Frame1);

    n = 0;
    XtSetArg (args[n], XmNlabelString,
	      XmStringCreateSimple ("Quit")); 			n++;
    QuitB = XmCreatePushButtonGadget (RowCol, "QuitB", args, n);
    XtRealizeWidget(QuitB);
    XtManageChild(QuitB);

    XtAddCallback (QuitB, XmNactivateCallback, Quit, NULL);

    
    /* manage widgets */
    XtManageChild(Redo);
    XtManageChild(QuitB);
    XtManageChild(Go);
    XtManageChild(PopB);
    XtManageChild(SetB);
    XtManageChild(GetB);
    XtManageChild(Append);
    XtManageChild(Error);
    XtManageChild(RadioBox1);
    XtManageChild(Frame2);
    XtManageChild(Frame3);
    XtManageChild(ControlBox);
    XtManageChild(Scale0);    
    XtManageChild(Scale1);    
    XtManageChild(Scale2);
    XtManageChild(Text1);
    XtManageChild(Form2);
    XtManageChild(Frame1);
    XtManageChild(Frame3);
    XtManageChild(RowCol);
    XtManageChild(Layout);

    XtRealizeWidget(Shell1);

    /* quick, update the scale to the correct command box width and height */
    n = 0;
    XtSetArg (args[n], XmNheight, &height); 			n++;
    XtSetArg (args[n], XmNheight, &width); 			n++;
    XtGetValues (Command1, args, n);

#ifdef DEBUG
    printf ("Height of Command received is %d\n", (int) height);
    printf ("Width of Command received is %d\n", (int) width);
#endif

    n = 0;
    XtSetArg (args[n], XmNmappedWhenManaged, True); 		n++;
    XtSetArg (args[n], XmNvalue, (int) height); 		n++;
    XtSetValues (Scale1, args, n);

    n = 0;
    XtSetArg (args[n], XmNmappedWhenManaged, True); 		n++;
    XtSetArg (args[n], XmNvalue, (int) width); 			n++;
    XtSetValues (Scale0, args, n);

    XtMapWidget (Scale0);
    XtMapWidget (Scale1);

    CommonPause();

    XtAppMainLoop(app_context);
}


void CallRedo(w, client_data, call_data)
    Widget w;
    XtPointer client_data, call_data;

{
    Dimension width, height;
    Arg args[2];
    int n;

    CreateCommandBox (Layout, False, (Widget) client_data);

    /* quick, update the scale to the correct command box width and height */
    n = 0;
    XtSetArg (args[n], XmNheight, &height); 			n++;
    XtSetArg (args[n], XmNheight, &width); 			n++;
    XtGetValues (Command1, args, n);

#ifdef DEBUG
    printf ("Height of Command received is %d\n", (int) height);
    printf ("Width of Command received is %d\n", (int) width);
#endif

    n = 0;
    XtSetArg (args[n], XmNmappedWhenManaged, True); 		n++;
    XtSetArg (args[n], XmNvalue, (int) height); 		n++;
    XtSetValues (Scale1, args, n);

    n = 0;
    XtSetArg (args[n], XmNmappedWhenManaged, True); 		n++;
    XtSetArg (args[n], XmNvalue, (int) width); 			n++;
    XtSetValues (Scale0, args, n);

}


void CreateCommandBox(parent, firstTime, dependent)
    Widget parent;
    Boolean firstTime;
    Widget dependent;
{
    Arg args[10];
    int n;
#ifdef DEBUG
    XmFormWidget DEBUGW;
    int offset;

    DEBUGW = (XmFormWidget) parent;
#endif

    if (!firstTime) {
   	n = 0;
     	XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); 	n++;
     	XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
	XtSetArg (args[n], XmNtopOffset, 5);			n++;
	XtSetArg (args[n], XmNleftOffset, 5);			n++;
     	XtSetValues (dependent, args, n);
	XtDestroyWidget (Frame0);
  	XtDestroyWidget (Command1);

    }

    n = 0;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); 	n++;
    XtSetArg (args[n], XmNtopOffset, 5);			n++;
    XtSetArg (args[n], XmNleftOffset, 5);			n++;
    Frame0 = XmCreateFrame(parent, "Frame0", args, n);
    XtRealizeWidget(Frame0);
    XtManageChild(Frame0);

    n = 0;
    Command1 = XmCreateCommand(Frame0, "Command1", args, n);
    XtRealizeWidget(Command1);
    XtManageChild(Command1);

    XtAddCallback (Command1, XmNcommandChangedCallback, CommandChanged, 
		   (XtPointer) 1);
    XtAddCallback (Command1, XmNcommandEnteredCallback, CommandChanged, 
		   (XtPointer) 2);

    XtManageChild (Command1);

    if (!firstTime) {
    	n = 0;
    	XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); 	n++;
    	XtSetArg (args[n], XmNtopWidget, Frame0); n++;
    	XtSetValues (dependent, args, n);

#ifdef DEBUG
    	n = 0;
    	XtSetArg (args[n], XmNtopOffset, &offset); 		n++;
    	XtGetValues (dependent, args, n);
    	printf ("Dependent's top offset is %d\n", offset);
#endif
    }

}


void CommandChanged(w, client_data, call_data)
    Widget w;
    XtPointer client_data;
    XtPointer call_data;
    
{
    static int i = 0;
    
    switch ((int) client_data) {
    	case 1:  printf ("Received CommandChangedCallback number %d\n", ++i);
       	         break;
    	case 2:  printf ("Received CommandEnteredCallback *********\n\n");
             	 break;
    	default: printf ("Received some bogus callback, HELP !!!!!!\n");
		 break;
    }
    
}


void WidthChange (w, client_data, call_data)
    Widget w;
    XtPointer client_data, call_data;
    
{
    Arg args[1];
    
    XtSetArg (args[0], XmNwidth, 
    	  ((Dimension)(((XmScaleCallbackStruct *)call_data)->value)));
    XtSetValues (Command1, args, 1);
    
}


void HeightChange (w, client_data, call_data)
    Widget w;
    XtPointer client_data, call_data;
    
{
    Arg args[1];
    
    XtSetArg (args[0], XmNheight, 
    	  ((Dimension)(((XmScaleCallbackStruct *)call_data)->value)));
    XtSetValues (Command1, args, 1);
    
}


void ProcessListItems (w, client_data, call_data)
    Widget w;
    XtPointer client_data, call_data;

/* figure out what setting of each toggle is */
/* and do appropriate thing */
/* client data is widget ID of Scale2 */

{
    int n, i;
    Arg args[1];
    char *resource_name;
    char *reg_string;
    int  countValue;
    XmString textString, tcs;

printf ("Processing List items....\n");

if (XmToggleButtonGetState (GetB))     /* get is true */
  { PrintHeaders();

    for (i = 0; i <= NUM_TOGGLES - 1; i++)
	{  /* if a reztoggle is on, get value of that */
	   /* Command resource */
           /* the userData of the togglebutton is the index into toggle_names*/
	   /* that contains the string to be set */
           
	  if (XmToggleButtonGadgetGetState(toggles[i]))
	    { 
	      XtSetArg (args[0], XmNuserData, &resource_name);
	      XtGetValues (toggles[i], args, 1);
	     
	      if ((strcmp(resource_name, "promptString") != 0) &&
		  (strcmp(resource_name, "command") !=0) ) {
	      	XtSetArg (args[0], resource_name, &countValue);
	      	XtGetValues (Command1, args, 1);

	      	printf ("%25s\t%d\n", resource_name, countValue);
	      }
	      else {
		XtSetArg (args[0], resource_name, &textString);
		XtGetValues (Command1, args, 1);

		printf("%25s\t%s\n", resource_name, CommonCsToRs(textString));
	      }
	      
	    }
	}
    }
else   
  if (XmToggleButtonGetState (SetB)) {   /* set */
       XtSetArg (args[0], XmNvalue, &countValue);
       XtGetValues ((Widget) client_data, args, 1);
   
       reg_string = XmTextGetString(Text1);
       tcs = XmStringCreateSimple(reg_string);

       for (i = 0; i <= NUM_TOGGLES - 1; i++)
	  if (XmToggleButtonGadgetGetState(toggles[i]))
	    {
	      XtSetArg (args[0], XmNuserData, &resource_name);
	      XtGetValues (toggles[i], args, 1);
	     
	      if ((strcmp(resource_name, "promptString") != 0) &&
		  (strcmp(resource_name, "command") !=0) ) {
	      		XtSetArg (args[0], resource_name, countValue);
	      		XtSetValues (Command1, args, 1);	      
	      }
	      else {
			if (strcmp(resource_name, "command") ==0)
				XmCommandSetValue(Command1, tcs);
			else {
				XtSetArg (args[0], resource_name, tcs);
				XtSetValues (Command1, args, 1);

			}
			XmTextSetString(Text1, NULL);
	      }
	    }
         XtFree(reg_string);
         XmStringFree(tcs);
   }
   else 
	if (XmToggleButtonGetState (Append) ||
	    XmToggleButtonGetState (Error)) {
	    reg_string = XmTextGetString(Text1);
	    tcs = XmStringCreateSimple(reg_string);

	    for (i = 0; i <= NUM_TOGGLES - 1; i++)
		if (XmToggleButtonGadgetGetState(toggles[i])) {

	    		XtSetArg (args[0], XmNuserData, &resource_name);
	    		XtGetValues (toggles[i], args, 1);

			if (strcmp(resource_name, "command") != 0)
				printf("Inappropriate append for resource %s\n",
					resource_name);
			else {
				if (XmToggleButtonGetState (Append))
	    				XmCommandAppendValue(Command1, tcs);
				else
					XmCommandError(Command1, tcs);
				XmTextSetString(Text1, NULL);
			}
		}
           XtFree(reg_string);
           XmStringFree(tcs);
	}
			
fflush (stdout);
}


void PopulateList (w, client_data, call_data)
    Widget w;
    XtPointer client_data, call_data; /* client data Widget ID of Scale2 */
{
    char buf[32];
    int value;
    register int i;
    Arg args[2];
    
    /* change Command's history list to contain # of items set by Scale */
    /* we'll set either the historyItems or listItems depending on what's */
    /* on: listItemCount or historyItemCount */
    /* historyItem will be the default */
    /* first, create a list of items, number of items scale's value */
    
    XmScaleGetValue ((Widget)client_data, &value);
    
    printf ("Creating %d strings\n", value);
    
    for (i = 0; i <= (value - 1); i++) {
     	 sprintf (buf, "ListItem%d", i);
       	 itemTable[i] = XmStringCreateSimple (buf);
    }
    
    /* we SHOULD look through all items and figure out which are 
       listItemCount and histItemCount but for now, we'll just KNOW
       they are in toggles[2,3] */
    
    if  ( (XmToggleButtonGadgetGetState (toggles[2])) &&
          (!(XmToggleButtonGadgetGetState(toggles[3]))) ) {
         	XtSetArg (args[0], XmNlistItems, itemTable);
          	XtSetArg (args[1], XmNlistItemCount, value);
          	XtSetValues(Command1, args, 2);
    }
    else {
         	XtSetArg (args[0], XmNhistoryItems, itemTable);
          	XtSetArg (args[1], XmNhistoryItemCount, value);
          	XtSetValues(Command1, args, 2);
    }
}


void PrintHeaders()

{
    printf ("\n%25s\tValue\n", "Resource Name");
    printf ("%25s\t=====\n\n", "=============");
    fflush (stdout);
}


static void  Quit()
{
     printf("Begin exiting ... please standby ... \n");
     fflush(stdout);
     exit(0);
}