-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathdwscope.c
2659 lines (2550 loc) · 88.6 KB
/
dwscope.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2017, Massachusetts Institute of Technology All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*------------------------------------------------------------------------------
Name: DWScope
Type: C main program
Author: Tom Fredian
Date: 6-JUN-1990
Purpose: Scope replacement main program
------------------------------------------------------------------------------
Call sequence:
$ dwcope [-default setup]
------------------------------------------------------------------------------
Copyright (c) 1989
Property of Massachusetts Institute of Technology, Cambridge MA 02139.
This program cannot be copied or distributed in any form for non-MIT
use without specific written approval of MIT Plasma Fusion Center
Management.
---------------------------------------------------------------------------
Description:
------------------------------------------------------------------------------*/
#include <mdstypes.h>
#include <mdsplus/mdsconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Mrm/MrmPublic.h>
#include <Xm/XmP.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Scale.h>
#include <Xm/MessageB.h>
#include <Xm/SashP.h>
#include <Xm/ToggleB.h>
#include <Xm/PushBG.h>
#include <Xm/FileSB.h>
#include <Xm/ToggleBG.h>
#include <pthread.h>
#include <Xmds/XmdsWaveform.h>
#include "dwscope.h"
#include "dwscope_icon.xbm"
#ifndef _NO_DXm
#include <DXm/DXmPrint.h>
#include <DXm/DECspecific.h>
#endif
#if defined __GNUC__ && 800 <= __GNUC__ * 100 + __GNUC_MINOR__
_Pragma("GCC diagnostic ignored \"-Wcast-function-type\"")
#endif
pthread_mutex_t event_mutex;
extern void XmdsInitialize();
extern void XmdsDestroyWidgetCallback();
extern void XmdsManageChildCallback();
extern void XmdsRegisterWidgetCallback();
extern void XmdsUnmanageChildCallback();
extern void SetupEvent(String event, Boolean *received, void **id);
extern void SetupEventInput(XtAppContext app_context, Widget w);
extern Boolean ConvertSelectionToWave(Widget w, Atom result_type,
unsigned long length, XtPointer header,
WaveInfo *info);
extern Boolean ConvertWaveToSelection(Widget w, String prefix, WaveInfo *wave,
Atom target, Atom *type,
XtPointer *header, unsigned long *length,
int *format);
extern Boolean ReplaceString(String *old, String new, Boolean free);
extern String GetResource(XrmDatabase db, String resource,
String default_answer);
extern String WaveToText(String prefix, WaveInfo *wave, Dimension height,
int *ctx);
extern void LoadDataSetup(Widget w, String title, WaveInfo *info);
extern void /*XtCallbackProc */ DisplayHelp(Widget w, XtPointer client_data,
XtPointer callback_data);
extern void GetDataSetup(Widget w, WaveInfo *info, int *change_mask);
extern void GetWaveFromDb(XrmDatabase db, String prefix, int row, int col,
WaveInfo *info);
extern Boolean GetWaveZoomFromDb(XrmDatabase db, String prefix, int row,
int col, float *zoom);
extern void ResetWave(WaveInfo *info);
extern void SetDirMask(Widget w, String *file, XtPointer callback_data);
extern XrmDatabase GetFileDatabase(String file_spec);
extern void /*XtCallbackProc */
DisableGlobalDefault(Widget w, XtPointer client_data, XtPointer callback_data);
extern void /*XtCallbackProc */
InitDefaultsSetupWidget(Widget w, XtPointer client_data,
XtPointer callback_data);
extern void /*XtCallbackProc */ ExpandReset(Widget w, int *tag,
XtPointer callback_data);
extern void /*XtCallbackProc */ ExpandCancel(Widget w, int *tag,
XtPointer callback_data);
extern void /*XtCallbackProc */ ExpandOk(Widget w, int *tag,
XtPointer callback_data);
extern void PositionPopupMenu(Widget w, XButtonEvent *event);
extern void PopupComplaint(Widget parent, String string);
extern Boolean EvaluateData(Boolean brief, int row, int col, int index,
Boolean *event, String database, String shot,
String default_node, String x, String y,
XmdsWaveformValStruct *x_ret,
XmdsWaveformValStruct *y_ret, String *error);
extern Boolean EvaluateText(String text, String error_prefix, String *text_ret,
String *error);
extern void CloseDataSources();
static String GlobalShot();
static void RaiseWindows();
static Boolean /*XtConvertSelectionProc */
ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type,
XtPointer *value, unsigned long *length, int *format);
static int UpdateWaveform(Boolean complain, WaveInfo *info, Boolean event,
int global_change_mask, int change_mask);
static void /*XtCallbackProc */ GridStyle(Widget w, XtPointer client_data,
XmAnyCallbackStruct *cb);
static void Shrink();
static void Expand();
static void MoveVerticalPane(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void Resize(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void /*XtActionProc */ EqualPanes(Widget w, XEvent *event,
String *string, Cardinal *num_strings);
static void /*XtActionProc */ Paste(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void /*XtCallbackProc */
ApplyCustomizeWindow(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
ApplyCustomizePrint(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
ApplyFont(Widget w, XtPointer client_data,
XmSelectionBoxCallbackStruct *callback_data);
static void /*XtCallbackProc */
CreateCustomizeFont(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Crosshairs(Widget w, XtPointer client_data,
XmdsWaveformCrosshairsCBStruct *cb);
static void /*XtCallbackProc */ Exit(Widget w, XtPointer client_data,
XmAnyCallbackStruct *reason);
static void /*XtCallbackProc */ SetPointerMode(Widget w, int *mode,
int *reason);
static void /*XtCallbackProc */ SetPointerModeMenu(Widget w, int *mode,
int *reason);
static void /*XtCallbackProc */ Align(int w, XtPointer client_data,
XmdsWaveformLimitsCBStruct *l);
static void /*XtCallbackProc */ Ok(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Autoscale(Widget w, String type,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Refresh(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
Restore(Widget w, int *option, XmFileSelectionBoxCallbackStruct *reason);
static void /*XtCallbackProc */ Save(Widget w, int *option,
XmFileSelectionBoxCallbackStruct *reason);
static void /*XtCallbackProc */
ResetDataSetup(Widget w, int *global, XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
ResetCustomizeFont(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
ResetCustomizePrint(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
ResetCustomizeWindow(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ ApplyDataSetup(Widget w, int *mode,
XtPointer callback_data);
static void /*XtCallbackProc */ ApplyOverride(Widget w, int *mode,
XtPointer callback_data);
static void /*XtCallbackProc */ Updates(Widget w, int *mode,
XtPointer callback_data);
static void /*XtCallbackProc */ UpdatesMenuButton(Widget w, int *mode,
XtPointer callback_data);
static void /*XtCallbackProc */ PrintAll(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Print(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Clear(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */ Cut(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_struct);
static void /*XtCallbackProc */
RegisterPane(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
RegisterWave(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void /*XtCallbackProc */
RegisterSash(Widget w, XtPointer client_data,
XmAnyCallbackStruct *callback_data);
static void Setup(Widget w, XtPointer client_data, XButtonEvent *event,
Boolean *continue_to_dispatch);
void /*XtInputCallbackProc */ EventUpdate(XtPointer client_data, int *source,
XtInputId *id);
static void /*XtLoseSelectionProc */ LoseSelection(Widget w, Atom *selection);
static void /*XtSelectionCallbackProc */
PasteComplete(Widget w, WaveInfo *info, Atom *selection, Atom *type,
XtPointer value, unsigned long *length, int *format);
static void /*XtSelectionCallbackProc */
PasteTypesComplete(Widget w, XtPointer cdata, Atom *selection, Atom *type,
XtPointer value, unsigned long *length, int *format);
static void Complain(WaveInfo *info, char mode, String error);
static void CopyWave(WaveInfo *in, WaveInfo *out);
static void FreeWave(WaveInfo *info);
static void Busy();
static void ManageWaveforms();
static void RemoveZeros(String string, int *length);
static void Unbusy();
static void ClearWaveform(WaveInfo *info);
static void RestoreDatabase(String dbname, Widget w);
static void WriteDatabase(String dbname, Boolean zoom);
static void GetNewLimits(WaveInfo *info, float **xmin, float **xmax,
float **ymin, float **ymax);
static void SetWindowTitles();
static WaveInfo *GetPending(Widget w);
static Window CreateBusyWindow(Widget w);
static String SetupTitle();
static XrmDatabase MdsGetFileDatabase(String file_spec);
static char *GetPrinterList();
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define PlotsWidget XtNameToWidget(MainWidget, "plots")
#define MaxCols 4
#define MaxRows 16
#define XA_DWSCOPE_PANEL XInternAtom(XtDisplay(TopWidget), "DWSCOPE_PANEL", 0)
#define XA_TARGETS XInternAtom(XtDisplay(TopWidget), "TARGETS", 0)
static Widget TopWidget;
static Widget MainWidget;
static Widget LockScalesWidget = 0;
static Widget DataSetupWidget;
static Widget DefaultsSetupWidget;
static Widget Pane[MaxCols];
static Widget Sash[MaxCols - 1];
static Widget CustomizeWindowWidget;
static Widget CustomizePrintWidget = 0;
static Widget CustomizeFontWidget = 0;
static Widget Button3Widget;
static String ScopeTitle;
static String ScopeIcon;
static int NumWaves = 0;
static int NumPanes = 0;
static int NumSashs = 0;
static WaveInfo Wave[MaxCols][MaxRows];
static WaveInfo *CurrentWave;
static WaveInfo *PendingWave;
static WaveInfo *SelectedWave = 0;
static WaveInfo GlobalWave;
static Boolean CloseDataSourcesEventReceived = 0;
static Boolean ScopePrintEventReceived = 0;
static Boolean ScopeTitleEventReceived = 0;
static String ScopePrintEvent = 0;
static String ScopeTitleEvent = 0;
static String ScopePrintFile = 0;
static Boolean ScopePrintPortrait = 0;
static String ScopePrinter = 0;
static int ScopeTempFileIdx = 0;
static int ScopePrintWindowTitle = 0;
static int ScopePrintToFile = 0;
static void *ScopePrintEventId = 0;
static void *ScopeTitleEventId = 0;
static int pointermode = XmdsPOINTER_MODE_ZOOM;
static int Rows[MaxCols];
static int Columns;
static Window BusyWindow;
static int MenusHeight;
static int ApplyStatus;
static int BusyLevel = 0;
static Boolean PreventResize = FALSE;
static String defaultfile;
static Boolean UpdatesOn = TRUE;
static Boolean UpdateWhenExpand = FALSE;
static Widget DeltaWaveWidget = 0;
static Widget MarkWidget = 0;
static float DeltaX;
static float DeltaY;
static XtAppContext AppContext;
static XtWorkProcId UpdateWaveformsWorkProcID;
int main(int argc, String *argv)
{
int i;
static String hierarchy_names[] = {"dwscope.uid"};
String fallback_resources[] = {
"*default_label.labelString: Default node:",
"*exp_label.labelString: Experiment:", "*brief_errors.set: true", NULL};
static MrmRegisterArg register_list[] = {
{"Align", (XtPointer)Align},
{"ApplyCustomizePrint", (XtPointer)ApplyCustomizePrint},
{"ApplyCustomizeWindow", (XtPointer)ApplyCustomizeWindow},
{"ApplyDataSetup", (XtPointer)ApplyDataSetup},
{"ApplyFont", (XtPointer)ApplyFont},
{"ApplyOverride", (XtPointer)ApplyOverride},
{"Autoscale", (XtPointer)Autoscale},
{"Clear", (XtPointer)Clear},
{"Close", (XtPointer)CloseDataSources},
{"CreateCustomizeFont", (XtPointer)CreateCustomizeFont},
{"Crosshairs", (XtPointer)Crosshairs},
{"Cut", (XtPointer)Cut},
{"DisableGlobalDefault", (XtPointer)DisableGlobalDefault},
{"Exit", (XtPointer)Exit},
{"InitDefaultsSetupWidget", (XtPointer)InitDefaultsSetupWidget},
{"Ok", (XtPointer)Ok},
{"Paste", (XtPointer)Paste},
{"Print", (XtPointer)Print},
{"PrintAll", (XtPointer)PrintAll},
{"Refresh", (XtPointer)Refresh},
{"RegisterPane", (XtPointer)RegisterPane},
{"RegisterSash", (XtPointer)RegisterSash},
{"RegisterWave", (XtPointer)RegisterWave},
{"ResetCustomizePrint", (XtPointer)ResetCustomizePrint},
{"ResetCustomizeFont", (XtPointer)ResetCustomizeFont},
{"ResetCustomizeWindow", (XtPointer)ResetCustomizeWindow},
{"ResetDataSetup", (XtPointer)ResetDataSetup},
{"Restore", (XtPointer)Restore},
{"Save", (XtPointer)Save},
{"DisplayHelp", (XtPointer)DisplayHelp},
{"SetPointerMode", (XtPointer)SetPointerMode},
{"SetPointerModeMenu", (XtPointer)SetPointerModeMenu},
{"Button3Widget", (XtPointer)&Button3Widget},
{"CustomizeWindowWidget", (XtPointer)&CustomizeWindowWidget},
{"CustomizeFontWidget", (XtPointer)&CustomizeFontWidget},
{"CustomizePrintWidget", (XtPointer)&CustomizePrintWidget},
{"DataSetupWidget", (XtPointer)&DataSetupWidget},
{"DefaultsSetupWidget", (XtPointer)&DefaultsSetupWidget},
{"expand_ok", (XtPointer)ExpandOk},
{"expand_reset", (XtPointer)ExpandReset},
{"expand_cancel", (XtPointer)ExpandCancel},
{"Updates", (XtPointer)Updates},
{"UpdatesMenuButton", (XtPointer)UpdatesMenuButton},
{"GridStyle", (XtPointer)GridStyle},
{"XmdsDestroyWidgetCallback", (XtPointer)XmdsDestroyWidgetCallback},
{"XmdsManageChildCallback", (XtPointer)XmdsManageChildCallback},
{"XmdsRegisterWidgetCallback", (XtPointer)XmdsRegisterWidgetCallback},
{"XmdsUnmanageChildCallback", (XtPointer)XmdsUnmanageChildCallback}};
static XtActionsRec actions[] = {{"MoveVerticalPane", MoveVerticalPane},
{"EqualPanes", EqualPanes},
{"Resize", Resize},
{"Shrink", Shrink},
{"Expand", Expand}};
MrmType class;
typedef struct
{
String defaultfile;
Boolean icon_update;
} AppResourcesRec;
static AppResourcesRec appRes;
static XrmOptionDescRec options[] = {
{"-defaults", "*defaults", XrmoptionSepArg, NULL},
{"-icon_update", "*icon_update", XrmoptionNoArg, "True"}};
static XtResource resources[] = {
{"defaults", "Defaults", XtRString, sizeof(String),
XtOffsetOf(AppResourcesRec, defaultfile), XtRString, "*"},
{"icon_update", "Icon_update", XtRBoolean, sizeof(Boolean),
XtOffsetOf(AppResourcesRec, icon_update), XtRImmediate,
(XtPointer)False}};
Cursor cursor;
int r;
int c;
void *cds_id = 0;
MrmHierarchy drm_hierarchy;
char *printers = GetPrinterList();
pthread_mutex_init(&event_mutex, NULL);
MrmInitialize();
#ifndef _NO_DXm
DXmInitialize();
#endif
XmdsInitialize();
MrmRegisterClass(MrmwcUnknown, "XmdsWaveformWidgetClass",
"XmdsCreateWaveform", (Widget(*)(void))XmdsCreateWaveform,
xmdsWaveformWidgetClass);
MrmRegisterNames(register_list, XtNumber(register_list));
TopWidget =
XtVaAppInitialize(&AppContext, "DwScope", options, XtNumber(options),
&argc, argv, fallback_resources, XmNallowShellResize, 1,
XmNminWidth, 320, XmNminHeight, 100, NULL);
XtGetApplicationResources(TopWidget, &appRes, resources, XtNumber(resources),
(Arg *)NULL, 0);
defaultfile = appRes.defaultfile;
defaultfile =
strlen(defaultfile) ? XtNewString(defaultfile) : XtNewString("my.scope");
XtAppAddActions(AppContext, actions, XtNumber(actions));
XtAugmentTranslations(TopWidget, XtParseTranslationTable(
"#augment <ResizeRequest> : Resize() \n\
<Unmap> : Shrink()\n\
<Map> : Expand()"));
MrmOpenHierarchy(XtNumber(hierarchy_names), hierarchy_names, 0,
&drm_hierarchy);
MrmFetchWidget(drm_hierarchy, "scope", TopWidget, &MainWidget, &class);
MrmCloseHierarchy(drm_hierarchy);
if (!MainWidget)
{
printf("Problem loading UID\n");
exit(1);
}
LockScalesWidget = XtNameToWidget(MainWidget, "*lockScales");
if (appRes.icon_update)
{
XmToggleButtonGadgetSetState(
XtNameToWidget(TopWidget, "*disable_icon_updates"), False, False);
}
SetupEventInput(AppContext, TopWidget);
SetDirMask(XtNameToWidget(TopWidget, "*file_dialog"), &defaultfile, 0);
XtVaSetValues(Pane[0], XmNleftAttachment, XmATTACH_FORM, NULL);
for (c = 1; c < NumPanes; c++)
XtVaSetValues(Pane[c], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNleftWidget, Sash[c - 1], XmNleftOffset, 2, NULL);
if (printers)
{
Widget printers_pulldown =
XtNameToWidget(MainWidget, "*printer_select_pulldown");
Arg arglist[] = {{XmNlabelString, 0}};
int num;
Widget *children;
char *printer;
for (printer = strtok(printers, "\n"); printer; printer = strtok(0, "\n"))
{
arglist[0].value = (long)XmStringCreateSimple(printer);
XmCreatePushButtonGadget(printers_pulldown, printer, arglist,
XtNumber(arglist));
}
XtVaGetValues(printers_pulldown, XmNnumChildren, &num, XmNchildren,
&children, NULL);
XtManageChildren(children, num);
}
XtManageChild(MainWidget);
RestoreDatabase(defaultfile, MainWidget);
cursor = XCreateFontCursor(XtDisplay(TopWidget), XC_crosshair);
for (i = 0; i < NumSashs; i++)
XDefineCursor(XtDisplay(TopWidget), XtWindow(Sash[i]), cursor);
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
{
int p_r = (r + 1) % MaxRows;
int p_c = p_r ? c : (c + 1) % MaxCols;
XtVaSetValues(Wave[c][r].w, XmdsNpanWith, Wave[p_c][p_r].w, NULL);
}
BusyWindow = CreateBusyWindow(PlotsWidget);
XtAddEventHandler(PlotsWidget, ButtonPressMask | ButtonReleaseMask, False,
(XtEventHandler)Setup, 0);
XtVaSetValues(
TopWidget, XtNiconPixmap,
XCreatePixmapFromBitmapData(XtDisplay(TopWidget), XtWindow(TopWidget),
(char *)dwscope_icon_bits, dwscope_icon_width,
dwscope_icon_height,
BlackPixelOfScreen(XtScreen(TopWidget)),
WhitePixelOfScreen(XtScreen(TopWidget)), 1),
NULL);
SetupEvent("DWSCOPE_CLOSE_FILES", &CloseDataSourcesEventReceived, &cds_id);
XmProcessTraversal(XtNameToWidget(MainWidget, "*override_shot"),
XmTRAVERSE_CURRENT);
XtAppMainLoop(AppContext);
return 0;
}
#include <errno.h>
#include <mdsdescrip.h>
static void DoPrint(char *filename)
{
char cmd[512];
int num =
snprintf(cmd, sizeof(cmd), "dwscopePrint %s %s", filename, ScopePrinter);
if (num > 0 && num <= (int)sizeof(cmd))
if (system(cmd) != 0)
printf("Error invoking dwscopePrint\n");
}
static char *GetPrinterList()
{
char *printers = 0;
FILE *fp = popen("ScopePrinters", "r");
if (fp != NULL)
{
char buff[256];
size_t bytes;
while ((bytes = fread(buff, 1, sizeof(buff) - 1, fp)))
{
buff[bytes] = 0;
if (printers)
{
printers = realloc(printers, strlen(printers) + 1 + bytes);
strcat(printers, buff);
}
else
{
printers = strcpy(malloc(bytes + 1), buff);
}
}
}
pclose(fp);
return printers;
}
static void Shrink(Widget w, XEvent *event __attribute__((unused)))
{
if (XmToggleButtonGadgetGetState(
XtNameToWidget(w, "*disable_icon_updates")))
{
UpdateWhenExpand =
XmToggleButtonGadgetGetState(XtNameToWidget(w, "*updates"));
XmToggleButtonGadgetSetState(XtNameToWidget(w, "*updates"), FALSE, TRUE);
}
}
static void Expand(Widget w, XEvent *event __attribute__((unused)))
{
if (XmToggleButtonGadgetGetState(
XtNameToWidget(w, "*disable_icon_updates")) &&
UpdateWhenExpand)
XmToggleButtonGadgetSetState(XtNameToWidget(w, "*updates"), TRUE, TRUE);
}
static void /*XtCallbackProc */
UpdatesMenuButton(Widget w, int *mode __attribute__((unused)),
XtPointer callback_data __attribute__((unused)))
{
XmToggleButtonGadgetSetState(XtNameToWidget(MainWidget, "*updates"),
!XmToggleButtonGadgetGetState(w), TRUE);
}
static String XYString(float x, float y)
{
static char label[42] = {'['};
int length;
String ptr = (String)&label[1];
sprintf(ptr, "%g%n", x, &length);
RemoveZeros(ptr + 1, &length);
ptr[length] = ',';
ptr = &ptr[length + 1];
sprintf(ptr, "%g%n", y, &length);
RemoveZeros(ptr, &length);
ptr[length] = ']';
ptr[length + 1] = 0;
return (String)label;
}
void PositionMark()
{
if (!MarkWidget)
MarkWidget = XtNameToWidget(MainWidget, "*crosshairs_mark");
if (DeltaWaveWidget && XtIsManaged(DeltaWaveWidget))
{
float *xmin, *xmax, *ymin, *ymax;
Position plots_rootx, plots_rooty;
Position wave_rootx, wave_rooty;
Position x, y;
Position xpos, ypos;
XtVaGetValues(DeltaWaveWidget, XmdsNxMin, &xmin, XmdsNxMax, &xmax,
XmdsNyMin, &ymin, XmdsNyMax, &ymax, NULL);
XtTranslateCoords(DeltaWaveWidget, 0, 0, &wave_rootx, &wave_rooty);
XtTranslateCoords(PlotsWidget, 0, 0, &plots_rootx, &plots_rooty);
x = wave_rootx - plots_rootx;
y = wave_rooty - plots_rooty;
xpos = ((DeltaX - *xmin) / (*xmax - *xmin) * XtWidth(DeltaWaveWidget) + x -
5) /
XtWidth(PlotsWidget) * 1000;
ypos = ((*ymax - DeltaY) / (*ymax - *ymin) * XtHeight(DeltaWaveWidget) + y -
5) /
XtHeight(PlotsWidget) * 1000;
if (xpos < 0 || ypos < 0 || xpos > 1000 || ypos > 1000)
XtUnmanageChild(MarkWidget);
else
{
XtVaSetValues(MarkWidget, XmNleftPosition, xpos, XmNtopPosition, ypos,
NULL);
XtManageChild(MarkWidget);
}
}
else
XtUnmanageChild(MarkWidget);
}
static void /*XtCallbackProc */ Crosshairs(Widget w,
XtPointer client_data
__attribute__((unused)),
XmdsWaveformCrosshairsCBStruct *cb)
{
static Widget value_w = 0;
int r;
int c;
float display_x;
float display_y;
String label;
if (!value_w)
value_w = XtNameToWidget(MainWidget, "*crosshairs_value");
if (cb->event->xbutton.type == ButtonPress)
{
if (cb->event->xbutton.state & ShiftMask)
{
DeltaWaveWidget = DeltaWaveWidget ? 0 : w;
if (DeltaWaveWidget)
{
DeltaX = cb->x;
DeltaY = cb->y;
}
PositionMark();
}
}
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
if (Wave[c][r].w != w)
XmdsWaveformSetCrosshairs(Wave[c][r].w, &cb->x, &cb->y, 0);
display_x = cb->x;
display_y = cb->y;
if (DeltaWaveWidget)
{
display_x -= DeltaX;
display_y -= DeltaY;
}
label = XYString(display_x, display_y);
XmTextFieldSetString(value_w, label);
if (cb->event->xbutton.type == ButtonRelease)
XmTextFieldSetSelection(value_w, 0, strlen(label), cb->event->xbutton.time);
}
static void /*XtCallbackProc */ Exit(Widget w __attribute__((unused)),
XtPointer client_data
__attribute__((unused)),
XmAnyCallbackStruct *reason
__attribute__((unused)))
{
exit(1);
}
static void /*XtCallbackProc */
SetPointerMode(Widget w, int *mode, int *reason __attribute__((unused)))
{
if (XmToggleButtonGetState(w))
{
int r;
int c;
pointermode = *mode;
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XmdsWaveformSetPointerMode(Wave[c][r].w, pointermode);
if (pointermode == XmdsPOINTER_MODE_POINT && DeltaWaveWidget)
PositionMark();
else if (MarkWidget)
XtUnmanageChild(MarkWidget);
}
}
static void /*XtCallbackProc */
SetPointerModeMenu(Widget w __attribute__((unused)), int *mode,
int *reason __attribute__((unused)))
{
int r;
int c;
switch (*mode)
{
case XmdsPOINTER_MODE_POINT:
XmToggleButtonSetState(XtNameToWidget(MainWidget, "*Point"), 1, 1);
break;
case XmdsPOINTER_MODE_ZOOM:
XmToggleButtonSetState(XtNameToWidget(MainWidget, "*Zoom"), 1, 1);
break;
case XmdsPOINTER_MODE_DRAG:
XmToggleButtonSetState(XtNameToWidget(MainWidget, "*Drag"), 1, 1);
break;
case XmdsPOINTER_MODE_EDIT:
XmToggleButtonSetState(XtNameToWidget(MainWidget, "*Copy"), 1, 1);
break;
default:
pointermode = *mode;
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XmdsWaveformSetPointerMode(Wave[c][r].w, pointermode);
}
}
static void RemoveZeros(String string, int *length)
{
int i;
int done = 0;
while (!done)
{
done = 1;
for (i = *length; i > 0; i--)
{
if (((string[i] == 'e') && (string[i + 1] == '0')) ||
((string[i] == '-') && (string[i + 1] == '0')) ||
((string[i] == '+') && (string[i + 1] == '0')))
{
int j;
for (j = i + 1; j < *length; j++)
string[j] = string[j + 1];
(*length)--;
done = 0;
}
else if ((string[i] == '0') && (string[i + 1] == 'e'))
{
int j;
for (j = i; j < *length; j++)
string[j] = string[j + 1];
(*length)--;
done = 0;
}
else if ((string[i] == '.') && (string[i + 1] == 'e'))
{
int j;
for (j = i; j < *length; j++)
string[j] = string[j + 1];
(*length)--;
}
}
}
return;
}
static void /*XtCallbackProc */ Align(int w __attribute__((unused)),
XtPointer client_data
__attribute__((unused)),
XmdsWaveformLimitsCBStruct *l)
{
int r;
int c;
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, l->xminval, XmdsNxMax, l->xmaxval,
NULL);
}
static void /*XtCallbackProc */ GridStyle(Widget w __attribute__((unused)),
XtPointer client_data
__attribute__((unused)),
XmAnyCallbackStruct *cb
__attribute__((unused)))
{
int lines = XmToggleButtonGadgetGetState(w);
int r;
int c;
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNgridStyle,
lines ? XmdsGRID_STYLE_LINES : XmdsGRID_STYLE_TICKS, NULL);
}
static void /*XtCallbackProc */
Ok(Widget w, XtPointer client_data __attribute__((unused)),
XmAnyCallbackStruct *callback_data __attribute__((unused)))
{
if (ApplyStatus & 1)
XtUnmanageChild(XtParent(w));
}
static String SetupTitle()
{
int c;
int r;
static char title[80];
for (c = 0; c < Columns; c++)
for (r = 0; r < Rows[c]; r++)
if (&Wave[c][r] == CurrentWave)
goto found;
strcpy(title, "Global Default Settings");
return title;
found:
sprintf(title, "Setup for plot at row %d, column %d", r + 1, c + 1);
return title;
}
static void /*XtCallbackProc */ Autoscale(Widget w __attribute__((unused)),
String type,
XmAnyCallbackStruct *callback_data
__attribute__((unused)))
{
int r;
int c;
switch (type[0])
{
case 'y':
XtVaSetValues(PendingWave->w, XmdsNyMin, NULL, XmdsNyMax, NULL, NULL);
break;
case 'x':
XtVaSetValues(PendingWave->w, XmdsNxMin, NULL, XmdsNxMax, NULL, NULL);
break;
case 'b':
XtVaSetValues(PendingWave->w, XmdsNxMin, NULL, XmdsNxMax, NULL, XmdsNyMin,
NULL, XmdsNyMax, NULL, NULL);
break;
case 'Y':
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNyMin, NULL, XmdsNyMax, NULL, NULL);
break;
case 'X':
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, NULL, XmdsNxMax, NULL, NULL);
break;
case 'B':
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, NULL, XmdsNxMax, NULL, XmdsNyMin,
NULL, XmdsNyMax, NULL, NULL);
break;
case '0':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
XtVaGetValues(PendingWave->w, XmdsNxMin, &xMin, XmdsNxMax, &xMax, XmdsNyMin,
&yMin, XmdsNyMax, &yMax, NULL);
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
if (PendingWave->w != Wave[c][r].w)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, xMin, XmdsNxMax, xMax,
XmdsNyMin, yMin, XmdsNyMax, yMax, NULL);
break;
}
case '1':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
XtVaGetValues(PendingWave->w, XmdsNxMin, &xMin, XmdsNxMax, &xMax, XmdsNyMin,
&yMin, XmdsNyMax, &yMax, NULL);
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
if (PendingWave->w != Wave[c][r].w)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, xMin, XmdsNxMax, xMax, NULL);
break;
}
case '2':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
XtVaGetValues(PendingWave->w, XmdsNxMin, &xMin, XmdsNxMax, &xMax, XmdsNyMin,
&yMin, XmdsNyMax, &yMax, NULL);
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
if (PendingWave->w != Wave[c][r].w)
XtVaSetValues(Wave[c][r].w, XmdsNyMin, yMin, XmdsNyMax, yMax, NULL);
break;
}
case '3':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
XtVaGetValues(PendingWave->w, XmdsNxMin, &xMin, XmdsNxMax, &xMax, XmdsNyMin,
&yMin, XmdsNyMax, &yMax, NULL);
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
XtVaSetValues(Wave[c][r].w, XmdsNxMin, xMin, XmdsNxMax, xMax, XmdsNyMin,
NULL, XmdsNyMax, NULL, NULL);
break;
}
case '4':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
Boolean update = PendingWave->update;
PendingWave->update = TRUE;
GetNewLimits(PendingWave, &xMin, &xMax, &yMin, &yMax);
PendingWave->update = update;
XtVaSetValues(PendingWave->w, XmdsNxMin, xMin, XmdsNxMax, xMax, XmdsNyMin,
yMin, XmdsNyMax, yMax, NULL);
break;
}
case '5':
{
float *xMin;
float *xMax;
float *yMin;
float *yMax;
for (c = 0; c < MaxCols; c++)
for (r = 0; r < MaxRows; r++)
{
Boolean update = Wave[c][r].update;
Wave[c][r].update = TRUE;
GetNewLimits(&Wave[c][r], &xMin, &xMax, &yMin, &yMax);
Wave[c][r].update = update;
XtVaSetValues(Wave[c][r].w, XmdsNxMin, xMin, XmdsNxMax, xMax, XmdsNyMin,
yMin, XmdsNyMax, yMax, NULL);
}
break;
}
}
PositionMark();
}
static void /*XtCallbackProc */ Refresh(Widget w __attribute__((unused)),
XtPointer client_data
__attribute__((unused)),
XmAnyCallbackStruct *callback_data
__attribute__((unused)))
{
UpdateWaveform(0, PendingWave, 0, -1, -1);
}
static void /*XtCallbackProc */
Restore(Widget w, int *option, XmFileSelectionBoxCallbackStruct *reason)
{
int opt = option ? *option : 0;
switch (opt)
{
case 0:
{
if (reason->length)
{
String filename;
filename = XmStringUnparse(reason->value, NULL, 0, XmCHARSET_TEXT, NULL,
0, XmOUTPUT_ALL);
if (filename)
{
int length = strlen(filename);
if (length)
{
RestoreDatabase(filename, w);
if (defaultfile)
XtFree(defaultfile);
defaultfile = filename;
}
else
XtFree(filename);
}
}
break;
}
case 1:
RestoreDatabase(defaultfile, TopWidget);
break;
case 2:
{
Widget w = XtNameToWidget(TopWidget, "*file_dialog");
XmString title = XmStringCreateSimple("Restore Current Settings From");
XmString label =
XmStringCreateSimple("Select Name of Configuration File: ");
XmString deffile = XmStringCreateSimple(defaultfile);
XmString dirmask;
XtRemoveAllCallbacks(w, XmNokCallback);
XtAddCallback(w, XmNokCallback, (XtCallbackProc)Restore, 0);
SetDirMask(XtNameToWidget(TopWidget, "*file_dialog"), &defaultfile, 0);
XtVaGetValues(w, XmNdirMask, &dirmask, NULL);
XmFileSelectionDoSearch(w, dirmask);
XtVaSetValues(w, XmNdialogTitle, title, XmNselectionLabelString, label,
XmNtextString, deffile, NULL);
XtManageChild(w);
XmStringFree(title);
XmStringFree(label);
XmStringFree(deffile);
break;