-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontrol.cc
1027 lines (906 loc) · 28.9 KB
/
control.cc
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
#include "translator.h"
#include "fonts.h"
#ifdef JLAB
#define JLAB true
#else
#define JLAB false
#endif
using std::endl;
using std::cout;
using std::vector;
using std::ifstream;
using std::ofstream;
using std::ostream;
using std::string;
extern fontInfoClass fi;
static char *fptr;
extern bool urgb;
extern bool retitle;
buttonclass::buttonclass(int attr)
{
fill_attrs(attr);
bclr = 0;
open = 1;
}
buttonclass::~buttonclass()
{
}
// process the "choice button" object
int buttonclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
bool stacking = 0;
colormode = 0;
//outd << "In ChoiceButton " << translator::line_ctr << endl;
do {
getline(inf,line);
translator::line_ctr++;
pos = line.find(bopen,0);
if(pos != -1) { open++; }
pos = line.find(bclose,0);
if(pos != -1) { open--; }
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if(!strcmp(s1,"chan")||!strcmp(s1,"ctrl")) {
chan = string(line, eq_pos+1, std::string::npos);;
}
else if(!strcmp(s1,"stacking")) stacking = 1;
else if(!strcmp(s1,"clrmod")) {
if(strstr(s2, "static") != 0x0) colormode = 0;
else if(strstr(s2, "alarm") != 0x0) colormode = 1;
else if(strstr(s2, "discrete") != 0x0) colormode = 2;
}
else outd << "Choice Button Can't decode " << line << endl;
}
} while (open > 0);
outf << endl;
outf << "# (Choice Button)" << endl;
outf << "object activeChoiceButtonClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << BTC_MAJOR_VERSION << endl;
outf << "minor " << BTC_MINOR_VERSION << endl;
outf << "release " << BTC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {
if(colormode == 1) {
// medm shows fg in green for alarm colormode
// edm needs to have fgColor set to green for same behavior
outf << "fgColor rgb " << "0 65535 0" << endl;
} else {
outf << "fgColor rgb " << cmap.getRGB(clr) << endl;
}
outf << "bgColor rgb " << cmap.getRGB(bclr) << endl;
outf << "selectColor rgb " << cmap.getRGB(bclr) << endl;
outf << "inconsistentColor rgb " << cmap.getRGB(clr) << endl;
outf << "topShadowColor rgb " << cmap.getRGB(0) << endl;
outf << "botShadowColor rgb " << cmap.getRGB(14) << endl;
} else {
if(colormode == 1) {
// medm shows fg in green for alarm colormode
// edm needs to have fgColor set to green for same behavior
outf << "fgColor index " << 15 << endl;
} else {
outf << "fgColor index " << clr << endl;
}
outf << "bgColor index " << bclr << endl;
outf << "selectColor index " << bclr << endl;
outf << "inconsistentColor index " << clr << endl;
outf << "topShadowColor index " << 0 << endl;
outf << "botShadowColor index " << 14 << endl;
}
if(colormode == 1) {
outf << "fgAlarm" << endl;
}
outf << "controlPv " << chan << endl;
//outf << "indicatorPv " << chan << endl;
//outf << "labelType \"pvState\"" << endl;
//outf << "3d" << endl;
fptr = fi.bestFittingFont( 12 );
if ( fptr ) {
outf << "font \"" << fptr << "\"" << endl;
} else {
outf << "font \"" << "helvetica-bold-r-12.0" << "\"" << endl;
}
//outf << "objType \"controls\"" << endl;
if(stacking)
outf << "orientation \"horizontal\"" << endl;
outf << "endObjectProperties" << endl;
return 1;
}
valclass::valclass(int attr)
{
fill_attrs(attr);
}
valclass::~valclass()
{
}
// process the "valuator button" object
int valclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
string dPrecision;
bool use_limits = false;
string hoprSrc;
string hoprDefault("-9");
string loprSrc;
string loprDefault("-9");
string precSrc;
string precDefault("1");
int direction = 0;
colormode = 0;
//outd << "In Valuator " << translator::line_ctr << endl;
do {
getline(inf,line);
translator::line_ctr++;
pos = line.find(bopen,0);
if(pos != -1) open++;
pos = line.find(bclose,0);
if(pos != -1) open--;
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if((!strcmp(s1,"chan")) || (!strcmp(s1,"ctrl")) )
chan = string(line, eq_pos+1, std::string::npos);
else if(!strcmp(s1,"dPrecision")) dPrecision = s2;
else if(!strcmp(s1,"hoprSrc")) hoprSrc = s2;
else if(!strcmp(s1,"hoprDefault")) hoprDefault = s2;
else if(!strcmp(s1,"loprSrc")) loprSrc = s2;
else if(!strcmp(s1,"loprDefault")) loprDefault = s2;
else if(!strcmp(s1,"precSrc")) precSrc = s2;
else if(!strcmp(s1,"precDefault")) precDefault = s2;
else if(!strcmp(s1,"label")) {
if(strstr(s2,"limits")) use_limits = true;
}
else if(!strcmp(s1,"direction")) {
if(!strcmp(s1,"right")) direction = 0;
else if(!strcmp(s1,"left")) direction = 0;
else if(!strcmp(s1,"up")) direction = 1;
else if(!strcmp(s1,"down")) direction = 1;
}
else if(!strcmp(s1,"clrmod")) {
// JS Not clear on how to convert this.
// What causes this to alarm in medm?
if(strstr(s2,"alarm")) colormode = 1;
}
else outd << "Motif Slider Can't decode " << line << endl;
}
} while (open > 0);
outf << endl;
outf << "# (Motif Slider)" << endl;
outf << "object activeMotifSliderClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << BTC_MAJOR_VERSION << endl;
outf << "minor " << BTC_MINOR_VERSION << endl;
outf << "release " << BTC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {
outf << "fgColor rgb " << cmap.getRGB(bclr+1) << endl;
outf << "bgColor rgb " << cmap.getRGB(bclr) << endl;
outf << "2ndBgColor rgb " << cmap.getRGB(bclr) << endl;
outf << "topShadowColor rgb " << cmap.getRGB(2) << endl;
outf << "botShadowColor rgb " << cmap.getRGB(12) << endl;
} else {
outf << "fgColor index " << "14" << endl;
outf << "bgColor index " << "51" << endl;
outf << "2ndBgColor index " << 4 << endl;
outf << "topShadowColor index " << 2 << endl;
outf << "botShadowColor index " << 12 << endl;
}
outf << "controlPv " << chan << endl;
outf << "controlLabelType \"pvName\"" << endl;
fptr = fi.bestFittingFont( hgt/4 );
if ( fptr ) {
outf << "font \"" << fptr << "\"" << endl;
} else {
outf << "font \"" << "helvetica-bold-r-12.0" << "\"" << endl;
}
if(direction)
outf << "orientation \"vertical\"" << endl;
if(loprDefault != "-9")
outf << "scaleMin " << loprDefault << endl;
if(hoprDefault != "-9")
outf << "scaleMax " << hoprDefault << endl;
else
outf << "limitsFromDb" << endl;
if(use_limits)
outf << "showLimits" << endl;
string dot(".");
int tpos;
tpos = dPrecision.find(dot,0);
if(tpos != -1){
dPrecision = string(dPrecision, 0, tpos);
outf << "increment " << dPrecision << endl;
}
outf << "endObjectProperties" << endl;
return 1;
}
mbuttonclass::mbuttonclass(int attr)
{
fill_attrs(attr);
bclr = 0;
open = 1;
}
mbuttonclass::~mbuttonclass()
{
}
// process the "message button" object
int mbuttonclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
bool isNum = true;
int ret;
char *ptr;
string squote;
squote = "\"";
string tname;
int tpos;
colormode = 0;
//outd << "In MessageButton " << translator::line_ctr << endl;
do {
getline(inf,line);
translator::line_ctr++;
pos = line.find(bopen,0);
if(pos != -1) open++;
pos = line.find(bclose,0);
if(pos != -1) open--;
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if((!strcmp(s1,"chan")) || (!strcmp(s1,"ctrl")) )
chan = string(line, eq_pos+1, std::string::npos);
else if(!strcmp(s1,"label"))
label = string(line, eq_pos+1, std::string::npos);
else if(!strcmp(s1,"press_msg")) {
press_msg = string(line, eq_pos+1, std::string::npos);
tname = press_msg;
while((tpos = tname.find(squote,0)) != -1)
tname.replace(tpos,1,nil);
strtoul(tname.c_str(), &ptr,0);
if(*ptr != 0x0) isNum = false;
}
else if(!strcmp(s1,"release_msg")) {
release_msg = string(line, eq_pos+1, std::string::npos);
tname = release_msg;
while((tpos = tname.find(squote,0)) != -1)
tname.replace(tpos,1,nil);
strtoul(tname.c_str(), &ptr,0);
if(*ptr != 0x0) isNum = false;
}
else if(!strcmp(s1,"clrmod")) {
// JS Not clear on how to convert this.
// What causes this to alarm in medm?
if(strstr(s2,"alarm")) colormode = 1;
}
else outd << "Message Button Can't decode " << line << endl;
}
} while (open > 0);
outf << endl;
outf << "# (Message Button)" << endl;
outf << "object activeMessageButtonClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << MSGBTC_MAJOR_VERSION << endl;
outf << "minor " << MSGBTC_MINOR_VERSION << endl;
outf << "release " << MSGBTC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {
outf << "fgColor rgb " << cmap.getRGB(clr) << endl;
outf << "onColor rgb " << cmap.getRGB(bclr) << endl;
outf << "offColor rgb " << cmap.getRGB(bclr) << endl;
outf << "topShadowColor rgb " << cmap.getRGB(0) << endl;
outf << "botShadowColor rgb " << cmap.getRGB(14) << endl;
} else {
outf << "fgColor index " << clr << endl;
outf << "onColor index " << bclr << endl;
outf << "offColor index " << bclr << endl;
outf << "topShadowColor index " << 0 << endl;
outf << "botShadowColor index " << 14 << endl;
}
outf << "controlPv " << chan << endl;
outf << "pressValue " << press_msg << endl;
outf << "releaseValue " << release_msg << endl;
outf << "onLabel " << label << endl;
outf << "offLabel " << label << endl;
outf << "3d" << endl;
if (isNum)
outf << "useEnumNumeric" << endl;
fptr = fi.bestFittingFont( (int) (hgt-.3*hgt) );
if ( fptr ) {
outf << "font \"" << fptr << "\"" << endl;
} else {
outf << "font \"" << "helvetica-bold-r-12.0" << "\"" << endl;
}
outf << "endObjectProperties" << endl;
return 1;
}
shellnode::shellnode()
{
}
shellnode::~shellnode()
{
}
shellclass::shellclass(int attr)
{
fill_attrs(attr);
bclr = 0;
}
shellclass::~shellclass()
{
}
// process the "shell command" object
int shellclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
int shell_ctr = 0;
vector <shellnode> shelllist;
shellnode *sh = NULL;
colormode = 0;
//outd << "In Shell " << translator::line_ctr << endl;
do {
getline(inf,line);
translator::line_ctr++;
pos = line.find(bopen,0);
if(pos != -1) open++;
pos = line.find(bclose,0);
if(pos != -1) open--;
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if(sh && strstr(s1, "label")!= 0x0) {
sh->label = string(line, eq_pos+1, std::string::npos);
}
else if(sh && strstr(s1, "name")!= 0x0) {
sh->name = string(line, eq_pos+1, std::string::npos);
}
else if(sh && (strstr(s1, "args")!= 0x0)) {
sh->args = string(line, eq_pos+1, std::string::npos);
}
} else {
if( (strstr(line.c_str(), "command")!= 0x0)) {
sh = new shellnode();
}
else if(sh && (strstr(line.c_str(), "}")!= 0x0)) {
// Copy data to vector
if(sh->name.length() > 2) { // empty item will be ""
shelllist.push_back(*sh);
shell_ctr++;
}
delete sh;
sh = NULL;
}
}
} while (open > 0);
outf << endl;
outf << "# (Shell Command)" << endl;
outf << "object shellCmdClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << SHCMDC_MAJOR_VERSION << endl;
outf << "minor " << SHCMDC_MINOR_VERSION << endl;
outf << "release " << SHCMDC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {
outf << "fgColor rgb " << cmap.getRGB(clr) << endl;
outf << "bgColor rgb " << cmap.getRGB(bclr) << endl;
outf << "topShadowColor rgb " << cmap.getRGB(2) << endl;
outf << "botShadowColor rgb " << cmap.getRGB(12) << endl;
} else {
outf << "fgColor index " << clr << endl;
outf << "bgColor index " << bclr << endl;
outf << "topShadowColor index " << 2 << endl;
outf << "botShadowColor index " << 12 << endl;
}
fptr = fi.bestFittingFont( (int) (hgt-.3*hgt) );
if ( fptr ) {
outf << "font \"" << fptr << "\"" << endl;
} else {
outf << "font \"" << "helvetica-bold-r-12.0" << "\"" << endl;
}
outf << "buttonLabel \"!\"" << endl;
outf << "numCmds " << shell_ctr << endl;
outf << "commandLabel {" << endl;
for (int i=0; i<shell_ctr; i++)
if(shelllist[i].label.length() > 0){
stripQs(shelllist[i].label);
outf << " " << i << " \"" << shelllist[i].label << "\"" << endl;
}
outf << "}" << endl;
outf << "command {" << endl;
for (int i=0; i<shell_ctr; i++)
if(shelllist[i].name.length() > 0){
stripQs(shelllist[i].name);
stripQs(shelllist[i].args);
outf << " " << i << " " << "\"" << shelllist[i].name << " "
<< shelllist[i].args << "\"" << endl;
}
outf << "}" << endl;
outf << "endObjectProperties" << endl;
return 1;
}
relnode::relnode()
{
}
relnode::~relnode()
{
}
relatedclass::relatedclass(int attr)
{
fill_attrs(attr);
bclr = 0;
}
relatedclass::~relatedclass()
{
}
string relatedclass::look_for_file(ostream &outd, string tname)
{
string vname;
struct stat buf;
char *dup0, *dup1, *dup2, *dup3;
string temp, temp0, temp1, temp2, temp3;
string dir, dir0, dir1, dir2, dir3;
string slash("/");
string slash2("//");
int ret;
int tpos;
static int first = 1;
outd << "LFF " << tname << endl;
// "//" causes problems in dirname/basename
while((tpos = tname.find(slash2,0)) != -1)
tname.replace(tpos,1,nil);
// look up the path from the calling adl file
dup0 = strdup(translator::dir.c_str());
dir0 = dirname(dup0);
temp0 = dir0 + slash + tname;
dup1 = strdup(dir0.c_str());
dir1 = dirname(dup1);
temp1 = dir1 + slash + tname;
dup2 = strdup(dir1.c_str());
dir2 = dirname(dup2);
temp2 = dir2 + slash + tname;
dup3 = strdup(dir2.c_str());
dir3 = dirname(dup3);
temp3 = dir3 + slash + tname;
if(first){
outd << "temp0 " << temp0 << endl;
outd << "temp1 " << temp1 << endl;
outd << "temp2 " << temp2 << endl;
outd << "temp3 " << temp3 << endl;
first = 0;
}
ret = stat(temp3.c_str(), &buf);
if(!ret && S_ISREG(buf.st_mode)){
temp = temp3;
outd << "OK1 " << temp << endl;
} else {
ret = stat(temp2.c_str(), &buf);
if(!ret && S_ISREG(buf.st_mode)){
temp = temp2;
outd << "OK2 " << temp << endl;
} else {
ret = stat(temp1.c_str(), &buf);
if(!ret && S_ISREG(buf.st_mode)){
temp = temp1;
outd << "OK3 " << temp << endl;
} else {
ret = stat(temp0.c_str(), &buf);
if(!ret && S_ISREG(buf.st_mode)){
temp = temp0;
outd << "OK4 " << temp << endl;
} else {
temp = tname;
outd << "FOUR STRIKES " << temp << endl;
}
}
}
}
return temp;
}
// process the "related display" object
int relatedclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
bool jlab = JLAB;
int adl_pos;
string echar(".edl");
string adl(".adl");
string medm("medm");
string slash("/");
string tstring;
string title;
string squote;
string saved_name;
squote = "\"";
string nil = "";
int slash_pos;
int rel_ctr = 0;
int tpos;
int ret;
bool invis = false;
string tname;
string vname;
string temp;
struct stat buf;
vector <relnode> rellist;
relnode *rel = NULL;
//outd << "In Related " << translator::line_ctr << endl;
//outd << "retitle:" << retitle << endl;
do {
getline(inf,line);
translator::line_ctr++;
//outd << line << endl;
pos = line.find(bopen,0);
if(pos != -1) open++;
pos = line.find(bclose,0);
if(pos != -1) open--;
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if(!strcmp(s1,"visual")) {
if(strstr(s2, "invisible")!= 0x0)
invis = true;
}
else if(strstr(s1, "label")!= 0x0) {
tstring = string(line, eq_pos+1, std::string::npos);
while((tpos = tstring.find(squote,0)) != -1)
tstring.replace(tpos,1,nil);
if(rel) rel->label = tstring;
else title = tstring;
}
else if(strstr(s1, "policy")!= 0x0) {
tstring = string(line, eq_pos+1, std::string::npos);
while((tpos = tstring.find(squote,0)) != -1)
tstring.replace(tpos,1,nil);
if(rel) rel->policy = tstring;
}
else if(strstr(s1, "name")!= 0x0) {
tname = s2;
while((tpos = tname.find(squote,0)) != -1)
tname.replace(tpos,1,nil);
// outd << "START " << tname << endl;
saved_name = tname;
if(rel && tname.length() != 0) { // medm ignores blank names. edm does not.
adl_pos = tname.find(adl,0);
if(adl_pos != -1){
tname.replace(adl_pos,4,echar);
}
rel->name = tname;
}
else if(!retitle && jlab) {
temp = "";
if ((tpos = tname.find("//")) == 0) tname.replace(tpos,1,nil);
// make absolute paths relative.
if ((tpos = tname.find("/usr/user4/mccops/medm/")) == 0) tname.replace(0, 23,nil);
else if ((tpos = tname.find("/usr/user2/mccops/medm/")) == 0) tname.replace(0, 23,nil);
else if ((tpos = tname.find("/cs/opshome/medm/")) == 0) tname.replace(0, 17,nil);
else if ((tpos = tname.find("./")) == 0) tname.replace(tpos,2,nil);
ret = stat(tname.c_str(), &buf); // look in given path from medm dir
if(!ret && S_ISREG(buf.st_mode)){
outd << "FINAL 1 " << tname << endl;
temp = tname;
} else {
vname = translator::dir + slash + tname;
ret = stat(vname.c_str(), &buf); // look in the calling dir
if(!ret && S_ISREG(buf.st_mode)){
if ((tpos = vname.find("/usr/user4/mccops/medm/")) == 0) vname.replace(0, 23,nil);
outd << "FINAL 2 " << vname << endl;
temp = vname;
}
}
adl_pos = temp.find(adl,0);
if(rel && adl_pos != -1){
temp.replace(adl_pos,4,echar);
rel->name = temp;
}
if(rel && temp.length() == 0) {
if(translator::dir == "/tmp") {
temp = saved_name;
outd << "Web file " << saved_name << endl;
// If caller was a web file, So is this one. Don't change adl to edl!
rel->name = tname;
} else {
// This next call may not be needed once files stabilize.
temp = look_for_file(outd, tname);
if ((tpos = temp.find("/usr/user4/mccops/medm/")) == 0) {
temp.replace(0, 23,nil);
outd << "FINAL 3 " << temp << endl;
adl_pos = temp.find(adl,0);
if(adl_pos != -1)
temp.replace(adl_pos,4,echar);
rel->name = tname;
} else {
rel->name = tname;
// Don't change adl to edl!
}
}
} // end if temp length = 0
if ( rel )
rel->name = temp;
} // end if jlab
else if (retitle) { // Not jlab
adl_pos = tname.find(adl,0);
if(rel && adl_pos != -1){
tname.replace(adl_pos,4,echar);
rel->name = tname;
}
}
// outd << "RelatedDisplay name " << rel->name << endl;
} // end if name
else if(rel && (strstr(s1, "args")!= 0x0)) {
rel->args = string(line, eq_pos, std::string::npos);
// outd << "RelatedDisplay args " << rel->args << endl;
// get rid of leading spaces . See below.
while((tpos = rel->args.find(space,0)) != -1)
rel->args.replace(tpos,1,nil);
}
} // end if eqpos
else {
// Create a new node
if( (strstr(line.c_str(), "display")!= 0x0)) {
rel = new relnode();
// outd << "RelatedDisplay new node" << endl;
} else if(rel && (strstr(line.c_str(), bclose.c_str())!= 0x0)) {
// Some programatically created screens leave rel.name and the rest
// of the fields as "". This is ok for medm. Not for edm.
// So, if the name is "" or blank after stripping quotes,
// we don't push this onto the list.
//outd << "PB? " << rel->name.length() << endl;
if(rel->name.length() > 0) {
rellist.push_back(*rel);
rel_ctr++;
}
delete rel;
rel = NULL;
}
}
} while (open > 0);
outf << endl;
outf << "# (Related Display)" << endl;
outf << "object relatedDisplayClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << RDC_MAJOR_VERSION << endl;
outf << "minor " << RDC_MINOR_VERSION << endl;
outf << "release " << RDC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {
outf << "fgColor rgb " << cmap.getRGB(clr) << endl;
outf << "bgColor rgb " << cmap.getRGB(bclr) << endl;
outf << "topShadowColor rgb " << cmap.getRGB(2) << endl;
outf << "botShadowColor rgb " << cmap.getRGB(12) << endl;
} else {
outf << "fgColor index " << clr << endl;
outf << "bgColor index " << bclr << endl;
outf << "topShadowColor index " << 2 << endl;
outf << "botShadowColor index " << 12 << endl;
}
if ( title.length() ) {
fptr = fi.bestFittingFont( (int) (hgt-.3*hgt) );
} else {
fptr = fi.bestFittingFont( (int) (hgt-.5*hgt) );
}
if ( fptr ) {
outf << "font \"" << fptr << "\"" << endl;
} else {
outf << "font \"" << "helvetica-bold-r-12.0" << "\"" << endl;
}
// A minus sign in front of the title means don't show the lil boxes.
if(title.length()){
string minus("-");
int minus_pos = title.find(minus,0);
if(minus_pos == 0){
title.replace(minus_pos,1,nil);
outf << "buttonLabel \"" << title << "\""<< endl;
} else {
//outf << "buttonLabel \"[ ] " << title << "\""<< endl;
outf << "icon" << endl;
outf << "buttonLabel \"" << title << "\""<< endl;
}
} else {
//outf << "buttonLabel \"[ ]\"" << endl;
outf << "icon" << endl;
//outf << "buttonLabel \"[ ]\"" << endl;
}
// T'is a conundrum!
// To medm, invisible means there is no indication the button exists.
// Visible means that the control widgets rise to the top.
// To edm, invisible is the same as medm.
// Visible means it may or may not appear, depending on whether
// something is on top of it.
// The adl2edl default is that nothing is invisible unless medm makes it so.
// Perhaps the only good solution is to raise control widgets to the top by
// writing them to the file last. This hasn't been done.
// This could be a big problem because of composites, etc.
// One can bring the file into the editor, select each gray
// mouseoveer box, and "raise" them as desired. Side by side adl/edl
// compare helps find 'em.
// Or one can "lower" whatever is obscuring the widgets.
// One can bring the screen into the editor and check invisible to fix
// the ones that do show and shouldn't.
if (invis)
outf << "invisible" << endl;
outf << "numPvs " << 2*rel_ctr << endl;
outf << "numDsps " << rel_ctr << endl;
outf << "displayFileName {" << endl;
for (int i=0; i<rel_ctr; i++) {
outf << " " << i << " \"" << rellist[i].name << "\"" << endl;
//outd << "Rel Disp: " << rellist[i].name << endl;
}
outf << "}" << endl;
outf << "menuLabel {" << endl;
for (int i=0; i<rel_ctr; i++)
outf << " " << i << " \"" << rellist[i].label << "\"" << endl;
outf << "}" << endl;
// Write 'symbol open curly brace' only if there are args
int once = 0;
for (int i=0; i<rel_ctr; i++) {
//if(rellist[i].args.length() > 0){
//outd << "len " << rellist[i].args.length() << "<" << rellist[i].args << ">" << endl;
if(rellist[i].args.length() == 2){
//outd << "changed" << endl;
rellist[i].args = "\" \"";
}
if(!once) {
outf << "symbols {" << endl;
once++;
}
outf << " " << i << " " << rellist[i].args << endl;
//outd << " " << i << "< " << rellist[i].args << ">" << endl;
//}
}
if (once) outf << "}" << endl;
once = 0;
for (int i=0; i<rel_ctr; i++) {
//outd << " " << i << "< " << rellist[i].policy << ">" << endl;
if(strstr(rellist[i].policy.c_str(), "replace")){
if(!once) {
outf << "closeAction {" << endl;
once++;
}
outf << " " << i << " 1" << endl;
}
}
if (once) outf << "}" << endl;
// Simulate medm behaviour by replacing the parent macros
once = 0;
for (int i=0; i<rel_ctr; i++) {
if(!once) {
outf << "replaceSymbols {" << endl;
once++;
}
outf << " " << i << " 1" << endl;
}
if (once) outf << "}" << endl;
once = 0;
for (int i=0; i<rel_ctr; i++) {
if(strstr(rellist[i].policy.c_str(), "replace")){
if(!once) {
outf << "closeDisplay {" << endl;
once++;
}
outf << " " << i << " 1" << endl;
}
}
if (once) outf << "}" << endl;
outf << "endObjectProperties" << endl;
return 1;
}
menuclass::menuclass(int attr)
{
fill_attrs(attr);
bclr = 0;
}
menuclass::~menuclass()
{
}
// process the "menu_button" object
int menuclass::parse(ifstream &inf, ostream &outf, ostream &outd)
{
colormode = 0;
//outd << "In menubutton " << translator::line_ctr << endl;
do {
getline(inf,line);
//outd << line << endl;
translator::line_ctr++;
pos = line.find(bopen,0);
if(pos != -1) open++;
pos = line.find(bclose,0);
if(pos != -1) open--;
eq_pos = line.find(eq,0);
if(eq_pos != -1){
line.replace(eq_pos,1,space);
snum = sscanf(line.c_str(), "%s %s", s1,s2);
if (!strcmp(s1,"x")) x = atoi(s2);
else if(!strcmp(s1,"y")) y = atoi(s2);
else if(!strcmp(s1,"width")) wid = atoi(s2);
else if(!strcmp(s1,"height")) hgt = atoi(s2);
else if(!strcmp(s1,"clr")) clr = atoi(s2);
else if(!strcmp(s1,"bclr")) bclr = atoi(s2);
else if(!strcmp(s1,"chan")|| !strcmp(s1,"ctrl")) {
chan = string(line, eq_pos+1, std::string::npos);
}
else if(!strcmp(s1,"clrmod")) {
if(strstr(s2, "static") != 0x0) colormode = 0;
else if(strstr(s2, "alarm") != 0x0) colormode = 1;
else if(strstr(s2, "discrete") != 0x0) colormode = 2;
}
else outd << "Menu Button Can't decode " << line << endl;
}
} while (open > 0);
outf << endl;
outf << "# (Menu Button)" << endl;
outf << "object activeMenuButtonClass" << endl;
outf << "beginObjectProperties" << endl;
outf << "major " << MBTC_MAJOR_VERSION << endl;
outf << "minor " << MBTC_MINOR_VERSION << endl;
outf << "release " << MBTC_RELEASE << endl;
outf << "x " << x << endl;
outf << "y " << y << endl;
outf << "w " << wid<< endl;
outf << "h " << hgt << endl;
if(urgb) {