-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobeFormat.c
341 lines (299 loc) · 8.87 KB
/
probeFormat.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
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/PanedW.h>
#include <Xm/BulletinB.h>
/*
* System includes for CA
*/
#include <cadef.h>
#include <alarm.h>
#include "probe.h"
/*
* data structure for format
*/
char *buttonsLabels[] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15" };
char *eFButtonsLabels[] = {
"%f format",
"%e format"
};
char infoFormatStr[255];
/*
* data structure for CA
*/
extern int changed;
/*
* data structure for info
*/
extern short infoUp;
/*
* data structure for hist
*/
extern short histUp;
/*
* X's stuff
*/
extern XmFontList fontList;
extern XFontStruct *font;
extern XmFontList fontList1;
extern XFontStruct *font1;
void initFormat(atom *channel)
{
channel->format.defaultDecimalPlaces = DEFAULT_DECIMAL_PLACES;
channel->format.defaultWidth = DEFAULT_WIDTH;
channel->format.defaultFormat = DEFAULT_FORMAT;
channel->format.defaultUnits[0] = 0;
strcpy(channel->format.str,DEFAULT_FORMAT_STR);
strcpy(channel->format.str1,DEFAULT_FORMAT_STR);
}
/* Note that format is only used for float and double so this routine
* doesn't handle the others */
void setChannelDefaults(atom *channel)
{
int i = 0;
int j = 0;
/* Escape any characters that might appear in a format string */
while ((channel->format.defaultUnits[i] = channel->info.data.D.units[j++])) {
switch (channel->format.defaultUnits[i]) {
case '%' :
i++; channel->format.defaultUnits[i] = '%';
break;
case '\\' :
i++; channel->format.defaultUnits[i] = '\\';
break;
default :
break;
}
i++;
}
if ((ca_field_type(channel->chId) == DBF_DOUBLE) ||
(ca_field_type(channel->chId) == DBF_FLOAT)) {
if (channel->info.data.D.precision > 15) {
channel->format.defaultDecimalPlaces = 15;
} else
if (channel->info.data.D.precision < 0) {
channel->format.defaultDecimalPlaces = 0;
} else {
channel->format.defaultDecimalPlaces = channel->info.data.D.precision;
}
}
}
void makeInfoFormatStr(atom *channel)
{
char str[81];
char str1[81];
sprintf(str,"%%-%d.%d%c",channel->format.defaultWidth,
channel->format.defaultDecimalPlaces,channel->format.defaultFormat);
sprintf(str1,"%%.%d%c",channel->format.defaultDecimalPlaces,
channel->format.defaultFormat);
sprintf(channel->info.formatStr,"%%sprecision = %%-5d RISC_pad0 = %%d\n");
sprintf(channel->info.formatStr,"%sunits = %%s\n\n",channel->info.formatStr);
sprintf(channel->info.formatStr,"%sHOPR = %s LOPR = %s\n",
channel->info.formatStr, str, str1);
sprintf(channel->info.formatStr,"%sDRVH = %s DRVL = %s\n\n",
channel->info.formatStr, str, str1);
sprintf(channel->info.formatStr,"%sHIHI = %s LOLO = %s\n",
channel->info.formatStr, str, str1);
sprintf(channel->info.formatStr,"%sHIGH = %s LOW = %s",
channel->info.formatStr, str, str1);
}
void makeHistFormatStr(atom *channel)
{
char str[81];
sprintf(str,"%%-%d.%d%c",channel->format.defaultWidth,
channel->format.defaultDecimalPlaces,channel->format.defaultFormat);
sprintf(channel->hist.formatStr,"Start Time - %%s\n\nmax = %s - %%s\nmin = %s - %%s\n\n",
str,str);
}
void makeDataFormatStr(atom *channel)
{
sprintf(channel->format.str,"%%.%d%c %s",
channel->format.defaultDecimalPlaces,
channel->format.defaultFormat,channel->format.defaultUnits);
sprintf(channel->format.str1,"%%.%d%c",
channel->format.defaultDecimalPlaces,
channel->format.defaultFormat);
}
void updateFormat(atom *channel,int dummy)
{
int n, i;
Arg wargs[5];
if (channel->upMask & FORMAT_UP) {
for (i=0;i<16;i++) {
n = 0;
if (i == channel->format.defaultDecimalPlaces) {
XtSetArg(wargs[n],XmNset,TRUE); n++;
} else {
XtSetArg(wargs[n],XmNset,FALSE); n++;
}
XtSetValues(channel->format.toggleButtons[i],wargs,n);
}
channel->updateMask &= ~UPDATE_FORMAT;
}
}
void formatCancelCallback(Widget w, XtPointer clientData,
XtPointer callbackStruct)
{
atom *channel = (atom *) clientData;
XtUnmanageChild(channel->format.dialog);
XtDestroyWidget(channel->format.dialog);
channel->format.dialog = NULL;
channel->upMask &= ~FORMAT_UP;
channel->d[FORMAT].w = NULL;
channel->d[FORMAT].proc = NULL;
}
void formatDialogCallback(Widget w, XtPointer clientData,
XtPointer callbackStruct)
{
atom *channel = (atom *) clientData;
XmToggleButtonCallbackStruct *call_data =
(XmToggleButtonCallbackStruct *) callbackStruct;
int n, Id;
if (!call_data->set) return;
n = 0;
Id = -1;
while (n<2) {
if (w == channel->format.eFButtons[n]) Id = n;
n++;
}
if (Id == 0) {
channel->format.defaultFormat = 'f';
} else if (Id == 1) {
channel->format.defaultFormat = 'e';
} else {
n = 0;
Id = -1;
while (n<16) {
if (channel->format.toggleButtons[n] == w) {
channel->format.defaultDecimalPlaces = n;
Id = n;
}
n++;
}
}
if (Id != -1) {
makeDataFormatStr(channel);
makeHistFormatStr(channel);
makeInfoFormatStr(channel);
channel->updateMask |= UPDATE_DISPLAY1 | UPDATE_HIST | UPDATE_INFO;
}
if (channel->updateMask != NO_UPDATE)
updateDisplay(channel);
}
void formatCallback(Widget w, XtPointer clientData,
XtPointer callbackStruct)
{
atom *channel = (atom *) clientData;
int n,i;
Arg wargs[5];
Widget formatPanel;
Widget decimalPlacesLabel, decimalPlacesPanel;
Widget radioBox1,radioBox2;
Widget cancel;
if (channel->upMask & FORMAT_UP) return;
/*
* Create the message dialog to display the help.
*/
n = 0;
if (font) {
XtSetArg(wargs[n], XmNtextFontList, fontList); n++;
}
XtSetArg(wargs[n], XmNautoUnmanage, FALSE); n++;
channel->format.dialog = (Widget) XmCreateBulletinBoardDialog(w,
"Format", wargs, n);
/*
* Create a XmPanedWindow widget to hold everything.
*/
formatPanel = XtVaCreateManagedWidget("panel",
xmPanedWindowWidgetClass,
channel->format.dialog,
XmNsashWidth, 1,
XmNsashHeight, 1,
NULL);
n = 0;
decimalPlacesPanel = XtCreateManagedWidget("decimalPlacesPanel",
xmRowColumnWidgetClass,
formatPanel,wargs,n);
n = 0;
decimalPlacesLabel = XtCreateManagedWidget("DECIMAL PLACES",
xmLabelWidgetClass,
decimalPlacesPanel, wargs, n);
n = 0;
XtSetArg(wargs[n], XmNentryClass, xmToggleButtonWidgetClass); n++;
XtSetArg(wargs[n], XmNnumColumns, 4); n++;
radioBox1 = XmCreateRadioBox(decimalPlacesPanel, "format1", wargs, n);
n = 0;
XtSetArg(wargs[n], XmNentryClass, xmToggleButtonWidgetClass); n++;
XtSetArg(wargs[n], XmNradioAlwaysOne, TRUE); n++;
radioBox2 = XmCreateRadioBox(formatPanel, "format2", wargs, n);
for (i=0;i<16;i++) {
n = 0;
if (i == channel->format.defaultDecimalPlaces) {
XtSetArg(wargs[n],XmNset,TRUE); n++;
}
channel->format.toggleButtons[i] = XmCreateToggleButton(radioBox1,
buttonsLabels[i],wargs,n);
XtAddCallback(channel->format.toggleButtons[i],
XmNvalueChangedCallback,formatDialogCallback,channel);
}
for (i=0;i<2;i++) {
n = 0;
if (((i == 0) && (channel->format.defaultFormat == 'f'))
|| ((i == 1) && (channel->format.defaultFormat == 'e'))) {
XtSetArg(wargs[n],XmNset,TRUE); n++;
}
channel->format.eFButtons[i] = XmCreateToggleButton(radioBox2,
eFButtonsLabels[i],wargs,n);
XtAddCallback(channel->format.eFButtons[i],
XmNvalueChangedCallback,formatDialogCallback,channel);
}
/*
* Create cancel button
*/
n = 0;
if (font1) {
XtSetArg(wargs[n], XmNfontList, fontList1); n++;
}
cancel = XtCreateManagedWidget("Close",
xmPushButtonWidgetClass,
formatPanel, wargs, n);
XtAddCallback(cancel, XmNactivateCallback,
formatCancelCallback,channel);
channel->upMask |= FORMAT_UP;
channel->d[FORMAT].w = NULL;
channel->d[FORMAT].proc = updateFormat;
XtManageChildren(channel->format.toggleButtons,16);
XtManageChildren(channel->format.eFButtons,2);
XtManageChild(radioBox1);
XtManageChild(radioBox2);
XtManageChild(channel->format.dialog);
}