-
Notifications
You must be signed in to change notification settings - Fork 1
/
scroll.c
1718 lines (1523 loc) · 51.9 KB
/
scroll.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) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* 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.
\*************************************************************************/
/* Scroll.c */
/************************DESCRIPTION***********************************
This file contains the routines for viewing the alarm
configuration, alarm log file and operator modification
log file. It uses scrolled text window to display the text.
Opened scrolled window also displays the most current
events recorded in log files.
**********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <ctype.h>
#ifndef WIN32
#include <dirent.h>
#endif
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/Form.h>
#include <Xm/LabelG.h>
#include <Xm/Protocols.h>
#include <Xm/PushB.h>
#include <Xm/ScrollBar.h>
#include <Xm/Text.h>
#include <Xm/PanedW.h>
#include <Xm/Label.h>
#include <Xm/ToggleB.h>
#include <Xm/RowColumn.h>
#include <Xm/TextF.h>
#include <X11/Intrinsic.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include "alh.h"
#include "ax.h"
extern Display *display;
extern int _global_flag;
extern int _description_field_flag;
#define MAX_NUM_OF_LOG_FILES 5000 /* # of log files for browser */
static XmTextPosition positionSearch;
static int lenSearch;
extern char FS_filename[128]; /*FileName from FileSelectBox for AlLogV. */
static Widget findShell, findText;
static Widget text_with,text_fy,text_fmo,text_fd,text_fh,text_fmi,
text_ty,text_tmo,text_td,text_th,text_tmi;
/* forward declarations */
static void closeFileViewWindow_callback( Widget w, int operandFile, caddr_t call_data);
static void closeFileViewShell( Widget w, int operandFile, caddr_t call_data);
static void findForward(Widget,XtPointer,XtPointer);
static void findReverse(Widget,XtPointer,XtPointer);
static void findDismiss(Widget,XtPointer,XtPointer);
static void searchCallback(Widget,XtPointer,XmAnyCallbackStruct *);
static void allDigit(Widget,XtPointer,XmTextVerifyCallbackStruct *);
static void showAllCallback(Widget,XtPointer,XtPointer);
static void showSelectedCallback(Widget,XtPointer,XtPointer);
static void compactDataAscMonth(char *,char *,char *,char *,char *,char *);
static void compactData(char *,char *,char *,char *,char *,char *);
static char *digitalMonth(char *);
static Boolean extensionIsDate(char *);
char *Strncat(
char *dest,
const char *src,
int max );
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? a : b)
#endif
static int viewFileUsedLength[N_LOG_FILES]; /* used length of file. */
static int viewFileMaxLength[N_LOG_FILES]; /* max length of file. */
static char *viewFileString[N_LOG_FILES]; /* contents of file. */
static Widget viewTextWidget[N_LOG_FILES] = {0,0,0}; /* view text widget */
static Widget browserWidget;
static Widget viewFilenameWidget[N_LOG_FILES] = {0,0,0}; /* view filename widget */
extern int alarmLogFileOffsetBytes; /* alarm log file current offset in bytes */
extern int alarmLogFileStringLength; /* alarm log file record length*/
extern int alarmLogFileMaxRecords; /* alarm log file maximum # records */
extern int DEBUG;
extern struct setup psetup; /* current file setup */
static char error_file_size[] = {
" Sorry: file size too big to view."
};
typedef struct fplistTag {
struct fplistTag *flink;
struct fplistTag *blink;
FILE *f;
} fplistType, *fplistPtr;
static fplistPtr g_head;
#define MAXCONFIGFILELINE 1023
#ifdef WIN32
#define strtok_r strtok_s
#endif
static void readFile (
fplistPtr cur,
char *buf,
int *max,
int *size,
int *depth
) {
char line[MAXCONFIGFILELINE+1], *result, *tk, *ctx, incFile[1023+1];
fplistPtr new;
int i, l;
if ( cur->f ) {
do {
result = fgets( line, MAXCONFIGFILELINE, cur->f );
if ( result ) {
*size += strlen(line) + *depth * 3;
if ( *size+10 > *max ) {
*max = (int)(*size + 0.5 * *size);
buf = (char *) XtRealloc( buf, *max );
}
for ( i=0; i<*depth; i++ ) strcat( buf, " " );
strcat( buf, line );
ctx = NULL;
tk = strtok_r( line, " \t\n", &ctx );
if ( tk ) {
if ( strcmp( tk, "INCLUDE" ) == 0 ) {
tk = strtok_r( NULL, " \t\n", &ctx );
if ( tk ) {
tk = strtok_r( NULL, " \t\n", &ctx );
if ( tk ) {
new = (fplistPtr) calloc( 1, sizeof(fplistType) );
g_head->blink->flink = new;
new->blink = g_head->blink;
new->flink = g_head;
g_head->blink = new;
if ( psetup.configDir ) {
strncpy( incFile, psetup.configDir, 1023 );
incFile[1023] = 0;
l = strlen( incFile );
if ( l > 0 ) {
if ( incFile[l-1] != '/' ) {
Strncat( incFile, "/", 1023 );
incFile[1023] = 0;
}
}
}
else {
strcpy( incFile, "" );
}
Strncat( incFile, tk, 1023 );
incFile[1023] = 0;
new->f = fopen( incFile, "r" );
(*depth)++;
*size += strlen("----------------------------\n") +
*depth * 3;
if ( *size+10 > *max ) {
*max = (int)(*size + 0.5 * *size);
buf = (char *) XtRealloc( buf, *max );
}
for ( i=0; i<*depth; i++ ) strcat( buf, " " );
strcat( buf, "----------------------------\n" );
readFile( new, buf, max, size, depth );
*size += strlen("----------------------------\n") + *depth * 3;
if ( *size+10 > *max ) {
*max = (int)(*size + 0.5 * *size);
buf = (char *) XtRealloc( buf, *max );
}
for ( i=0; i<*depth; i++ ) strcat( buf, " " );
strcat( buf, "----------------------------\n" );
(*depth)--;
if ( new->f ) fclose( new->f );
new->blink->flink = new->flink;
new->flink->blink = new->blink;
free( new );
}
}
}
}
}
} while ( result );
}
}
static void readAll (
char *buf,
int max,
int num,
FILE *fp
) {
fplistPtr cur;
int size = 0;
int depth = 0;
g_head = (fplistPtr) calloc( 1, sizeof(fplistType) );
g_head->f = NULL;
g_head->flink = g_head;
g_head->blink = g_head;
cur = (fplistPtr) calloc( 1, sizeof(fplistType) );
cur->f = fp;
/* link */
cur->blink = g_head->blink;
g_head->blink->flink = cur;
cur->flink = g_head;
g_head->blink = cur;
readFile( cur, buf, &max, &size, &depth );
cur->blink->flink = cur->flink;
cur->flink->blink = cur->blink;
free( cur );
free( g_head );
}
/**************************************************************************
create scroll window for file view
**************************************************************************/
void fileViewWindow(Widget w,int option,Widget menuButton)
{
static Widget config_shell=NULL,alarm_shell=NULL,opmod_shell=NULL;
Widget app_shell=NULL,title,button;
Widget previous;
struct stat statbuf; /* Information on a file. */
FILE *fp = NULL; /* Pointer to open file. */
char filename[120];
int operandFile=0;
long operandFileLong;
Arg al[20];
int ac;
XmString str=NULL;
switch (option) {
case CONFIG_FILE:
operandFile = CONFIG_FILE;
app_shell = config_shell;
strcpy(filename,psetup.configFile);
break;
case ALARM_FILE:
operandFile = ALARM_FILE;
app_shell = alarm_shell;
strcpy(filename,psetup.logFile);
break;
case OPMOD_FILE:
operandFile = OPMOD_FILE;
app_shell = opmod_shell;
strcpy(filename,psetup.opModFile);
break;
}
if (app_shell && XtIsManaged(app_shell)) {
viewFileUsedLength[option] = 0;
viewFileMaxLength[option] = 0;
XtFree(viewFileString[option]);
viewFileString[option]=NULL;
XtUnmanageChild(app_shell);
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
return;
}
XtVaSetValues(menuButton, XmNset, TRUE, NULL);
if (stat(filename, &statbuf) == 0)
viewFileUsedLength[operandFile] = statbuf.st_size;
else
viewFileUsedLength[operandFile] = 1000000; /* arbitrary file length */
if (statbuf.st_size > 1000000)
{
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
createDialog(XtParent(w),XmDIALOG_ERROR,filename, &error_file_size[0]);
return;
}
/* allocate space for the file string */
viewFileMaxLength[operandFile] = MAX(INITIAL_FILE_LENGTH,
2*viewFileUsedLength[operandFile]);
viewFileString[operandFile] = (char *)
XtCalloc(1,viewFileMaxLength[operandFile]);
if(!viewFileString[operandFile]) {
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
createDialog(XtParent(w),XmDIALOG_ERROR,"no free memory","");
return;
}
/* read the file string */
if ((fp = fopen(filename, "r")) == NULL) {
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
fprintf(stderr,"fileViewWindow: file %s not found\n",filename);
return; /* bail out if no file found */
}
switch (option) {
case CONFIG_FILE:
readAll( viewFileString[operandFile],
viewFileUsedLength[operandFile], 1, fp );
break;
default:
fread(viewFileString[operandFile],
viewFileUsedLength[operandFile],1, fp);
break;
}
clearerr(fp);
if (fclose(fp)) fprintf(stderr,
"fileViewWindow: unable to close file %s.\n",filename);
/* create view window dialog */
if (!app_shell) {
ac = 0;
XtSetArg (al[ac], XmNy, 47);
ac++;
XtSetArg (al[ac], XmNx, 77);
ac++;
/*
XtSetArg (al[ac], XmNallowShellResize, FALSE); ac++;
*/
XtSetArg (al[ac], XmNallowOverlap, FALSE);
ac++;
XtSetArg(al[ac], XmNautoUnmanage, FALSE);
ac++;
switch (option) {
case CONFIG_FILE:
str = XmStringLtoRCreate("Configuration File", XmSTRING_DEFAULT_CHARSET);
break;
case ALARM_FILE:
str = XmStringLtoRCreate("Alarm Log File", XmSTRING_DEFAULT_CHARSET);
break;
case OPMOD_FILE:
str = XmStringLtoRCreate("Operator Mod File", XmSTRING_DEFAULT_CHARSET);
break;
}
XtSetArg(al[ac], XmNdialogTitle, str);
ac++;
app_shell = XmCreateFormDialog(XtParent(w), "SCROLL", al, ac);
XmStringFree(str);
XtVaSetValues(app_shell, XmNallowOverlap, FALSE, NULL);
/* Modify the window manager menu "close" callback */
{
Atom WM_DELETE_WINDOW;
XtVaSetValues(XtParent(app_shell),
XmNdeleteResponse, XmDO_NOTHING, NULL);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(XtParent(app_shell)),
"WM_DELETE_WINDOW", False);
operandFileLong=operandFile;
XmAddWMProtocolCallback(XtParent(app_shell),WM_DELETE_WINDOW,
(XtCallbackProc)closeFileViewShell, (XtPointer)operandFileLong);
}
switch (option) {
case CONFIG_FILE:
config_shell = app_shell;
break;
case ALARM_FILE:
alarm_shell = app_shell;
break;
case OPMOD_FILE:
opmod_shell = app_shell;
break;
}
/* add close button */
ac = 0;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNtopOffset, 5);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNleftOffset, 5);
ac++;
XtSetArg (al[ac], XmNuserData, menuButton);
ac++;
button = XtCreateManagedWidget("Close",xmPushButtonWidgetClass,
app_shell, al, ac);
operandFileLong=operandFile;
XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)closeFileViewWindow_callback,
(XtPointer) operandFileLong);
previous = button;
/* create file name widget */
ac = 0;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNtopOffset, 6);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg (al[ac], XmNleftWidget, button);
ac++;
XtSetArg (al[ac], XmNleftOffset, 6);
ac++;
viewFilenameWidget[operandFile] = XtCreateManagedWidget(filename,xmLabelGadgetClass,
app_shell,al, ac);
/* add titles */
if ( option == ALARM_FILE) {
ac = 0;
/*
XtSetArg (al[ac], XmNwidth,800);
ac++;
XtSetArg (al[ac], XmNheight,30);
ac++;
*/
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg (al[ac], XmNtopWidget, button);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
if (!_description_field_flag) {
if (_global_flag)
title = XtCreateManagedWidget(" TIME_STAMP PROCESS_VARIABLE_NAME STATUS SEVERITY UNACK_SEV ACKT VALUE",
xmLabelGadgetClass,app_shell,al,ac);
else title = XtCreateManagedWidget(" TIME_STAMP PROCESS_VARIABLE_NAME STATUS SEVERITY VALUE",
xmLabelGadgetClass,app_shell,al,ac);
} else { /* _description_field_flag is ON */
if (_global_flag)
title = XtCreateManagedWidget(
" TIME RECORD DESCRIPTION VALUE STATUS / SEVERITY / UNACK_SEV / ACKT",
xmLabelGadgetClass,app_shell,al,ac);
else title = XtCreateManagedWidget(
" TIME RECORD DESCRIPTION VALUE STATUS / SEVERITY",
xmLabelGadgetClass,app_shell,al,ac);
}
previous = title;
}
/* create text widget */
ac = 0;
XtSetArg (al[ac], XmNrows, 24);
ac++;
XtSetArg (al[ac], XmNcolumns, 130);
ac++;
XtSetArg (al[ac], XmNscrollVertical, True);
ac++;
XtSetArg (al[ac], XmNscrollHorizontal, True);
ac++;
XtSetArg (al[ac], XmNeditMode, XmMULTI_LINE_EDIT);
ac++;
XtSetArg (al[ac], XmNeditable, FALSE);
ac++;
XtSetArg (al[ac], XmNcursorPositionVisible, FALSE);
ac++;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg (al[ac], XmNtopWidget, previous);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNrightAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNbottomAttachment, XmATTACH_FORM);
ac++;
viewTextWidget[operandFile]=XmCreateScrolledText(app_shell, "text", al, ac);
/* make appropriate item sensitive */
XtSetSensitive(viewTextWidget[operandFile], True);
XmAddTabGroup(viewTextWidget[operandFile]);
XtManageChild(viewTextWidget[operandFile]);
}
/* update the file name string */
str = XmStringLtoRCreate(filename, XmSTRING_DEFAULT_CHARSET);
XtVaSetValues(viewFilenameWidget[operandFile], XmNlabelString, str, NULL);
XmStringFree(str);
/* add the file string to the text widget */
XmTextSetString(viewTextWidget[operandFile], viewFileString[operandFile]);
if (operandFile == ALARM_FILE && alarmLogFileOffsetBytes ) {
XtVaSetValues(viewTextWidget[operandFile],
XmNcursorPosition, alarmLogFileOffsetBytes-1,
NULL);
XmTextShowPosition(viewTextWidget[operandFile], alarmLogFileOffsetBytes-1);
viewFileUsedLength[operandFile] = alarmLogFileOffsetBytes;
} else {
XtVaSetValues(viewTextWidget[operandFile],
XmNcursorPosition, viewFileUsedLength[operandFile]-1,
NULL);
XmTextShowPosition(viewTextWidget[operandFile], viewFileUsedLength[operandFile]-1);
}
XtManageChild(app_shell);
}
/**************************************************************************
close scroll window for file view
**************************************************************************/
static void closeFileViewShell(Widget w,int operandFile,caddr_t call_data)
{
Widget menuButton;
WidgetList children;
XtVaGetValues(w, XmNchildren, &children, NULL);
XtUnmanageChild(children[0]);
XtVaGetValues(children[0], XmNchildren, &children, NULL);
XtVaGetValues(children[0], XmNuserData, &menuButton, NULL);
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
viewFileUsedLength[operandFile] = 0;
viewFileMaxLength[operandFile] = 0;
XtFree(viewFileString[operandFile]);
viewFileString[operandFile]=NULL;
}
/**************************************************************************
close scroll window for file view
**************************************************************************/
static void closeFileViewWindow_callback(Widget w,int operandFile,
caddr_t call_data)
{
Widget menuButton;
XtVaGetValues(w, XmNuserData, &menuButton, NULL);
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
viewFileUsedLength[operandFile] = 0;
viewFileMaxLength[operandFile] = 0;
XtFree(viewFileString[operandFile]);
viewFileString[operandFile]=NULL;
XtUnmanageChild(XtParent(w));
}
/******************************************************************
updateLog in scroll window
*****************************************************************/
void updateLog(int fileIndex,char *string)
{
#if 0
struct stat statbuf; /* Information on a file. */
FILE *fp = NULL; /* Pointer to open file */
char filename[120];
#endif
char *tmp;
int stringLength = strlen(string);
int oldUsedLength = viewFileUsedLength[fileIndex];
if (viewTextWidget[fileIndex] == NULL) return;
/* simply return if the file string does not exist */
if (viewFileString[fileIndex] == NULL) return;
if (viewFileUsedLength[fileIndex] + stringLength <=
viewFileMaxLength[fileIndex]) {
/* string fits, insert */
strcat((char *)viewFileString[fileIndex],string);
viewFileUsedLength[fileIndex] = viewFileUsedLength[fileIndex] +
stringLength;
XmTextReplace(viewTextWidget[fileIndex],oldUsedLength,
oldUsedLength,string);
} else {
/* string doesn't fit - reallocate to get enough room */
viewFileMaxLength[fileIndex] = MAX(INITIAL_FILE_LENGTH,
2*viewFileMaxLength[fileIndex]);
tmp = (char *)XtCalloc(1,viewFileMaxLength[fileIndex]);
strcpy(tmp,(const char *)viewFileString[fileIndex]);
XtFree(viewFileString[fileIndex]);
viewFileString[fileIndex] = (char*)tmp;
if (viewFileUsedLength[fileIndex] + stringLength <=
viewFileMaxLength[fileIndex]) {
/* string fits, insert */
strcat(viewFileString[fileIndex],string);
viewFileUsedLength[fileIndex] = viewFileUsedLength[fileIndex] +
stringLength;
XmTextReplace(viewTextWidget[fileIndex],oldUsedLength,
oldUsedLength,string);
}
#if 0
switch(fileIndex) {
case ALARM_FILE:
strcpy(filename,psetup.logFile);
break;
case OPMOD_FILE:
strcpy(filename,psetup.opModFile);
break;
}
if (stat(filename, &statbuf) == 0)
viewFileUsedLength[fileIndex] = statbuf.st_size;
else
viewFileUsedLength[fileIndex] = 1000000; /* arbitrary file length */
/* read the file string */
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr,"updateLog: file %s open error.\n",filename);
return; /* bail out if no file found */
}
fread(viewFileString[fileIndex], sizeof(char),
viewFileUsedLength[fileIndex], fp);
if (fclose(fp)) fprintf(stderr,
"updateLog: unable to close file %s.\n",filename);
/* add the file string to the text widget */
XmTextSetString(viewTextWidget[fileIndex], viewFileString[fileIndex]);
#endif
}
XtVaSetValues(viewTextWidget[fileIndex],
XmNcursorPosition, viewFileUsedLength[fileIndex]-1,
NULL);
XmTextShowPosition(viewTextWidget[fileIndex], viewFileUsedLength[fileIndex]-1);
}
/******************************************************************
updateAlarmLog in scroll window
*****************************************************************/
void updateAlarmLog(int fileIndex,char *string)
{
updateLog(fileIndex,string);
#if 0
char str[MAX_STRING_LENGTH];
int stringLength = strlen(string);
int startPosition,endPosition;
int pos=0;
if (viewTextWidget[fileIndex] == NULL) return;
XtVaGetValues(viewTextWidget[fileIndex], XmNcursorPosition, &pos, NULL);
/* simply return if the file string does not exist */
if (viewFileString[fileIndex] == NULL) return;
if (viewFileUsedLength[fileIndex] + stringLength <=
viewFileMaxLength[fileIndex])
{
/* put string at end */
strcat(viewFileString[fileIndex],string);
viewFileUsedLength[fileIndex] = viewFileUsedLength[fileIndex] + stringLength;
XmTextSetString(viewTextWidget[fileIndex], viewFileString[fileIndex]);
} else
{
startPosition=alarmLogFileOffsetBytes-alarmLogFileStringLength;
endPosition=alarmLogFileOffsetBytes;
XmTextReplace(viewTextWidget[fileIndex],startPosition, endPosition,string);
memset(str,' ',alarmLogFileStringLength);
startPosition=alarmLogFileOffsetBytes;
endPosition=alarmLogFileOffsetBytes+alarmLogFileStringLength;
XmTextReplace(viewTextWidget[fileIndex],startPosition, endPosition,str);
}
XtVaSetValues(viewTextWidget[fileIndex], XmNcursorPosition, pos, NULL);
XmTextShowPosition(viewTextWidget[fileIndex],pos);
#endif
}
/**************************************************************************
create scroll window for AlarmLog browser.
**************************************************************************/
void browser_fileViewWindow(Widget w,int option,Widget menuButton)
{
static Widget alarm_shell=NULL;
static Widget opmod_shell=NULL;
Widget app_shell=NULL,title=0,button,button1;
Widget previous;
char sbuf[120];
#ifndef WIN32
DIR *directory;
#endif
struct stat statbuf; /* Information on a file. */
FILE *fp = NULL; /* Pointer to open file. */
char filename[120];
int operandFile=0;
long operandFileLong;
long optionLong;
/* definitions for search widgets: */
Arg al[20];
int ac;
XmString str=NULL;
Dimension height, margin_height;
Widget findPane, findBox, findLabel, findButtonBox,
findForwardButton, findReverseButton, findDismissButton;
Widget rowcol1,rowcol2,showButton,showAllButton;
time_t timeofday;
struct tm *tms;
char buf[120];
char defaultString_fy[5],defaultString_fmo[3],defaultString_fd[3],defaultString_fh[3]="00",defaultString_fmi[3]="00";
char defaultString_ty[5],defaultString_tmo[3],defaultString_td[3],defaultString_th[3]="24",defaultString_tmi[3]="00";
/* End definitions for search routins */
switch (option) {
case ALARM_FILE:
operandFile = ALARM_FILE;
app_shell = alarm_shell;
break;
case OPMOD_FILE:
operandFile = OPMOD_FILE;
app_shell = opmod_shell;
break;
}
if (app_shell && XtIsManaged(app_shell)) {
viewFileUsedLength[option] = 0;
viewFileMaxLength[option] = 0;
XtFree(viewFileString[option]);
viewFileString[option]=NULL;
XtUnmanageChild(app_shell);
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
return;
}
XtVaSetValues(menuButton, XmNset, TRUE, NULL);
strcpy(filename,FS_filename);
#ifndef WIN32
directory = opendir(filename);
if (directory) {
closedir(directory);
sprintf(sbuf, "%s is a directory\n",filename);
createDialog(w,XmDIALOG_WARNING,sbuf," ");
return;
}
#endif
if ((fp = fopen(filename, "r")) == NULL) {
sprintf(sbuf, "fileViewWindow: Can't open file %s\n",filename);
createDialog(w,XmDIALOG_WARNING,sbuf," ");
fprintf(stderr, "Can't open file %s\n",filename);
return;
}
if (stat(filename, &statbuf) == 0)
viewFileUsedLength[operandFile] = statbuf.st_size;
else
viewFileUsedLength[operandFile] = 1000000; /* arbitrary file length */
if (statbuf.st_size > 1000000)
{
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
createDialog(XtParent(w),XmDIALOG_ERROR,filename, &error_file_size[0]);
return;
}
/* read the file string */
viewFileMaxLength[operandFile] = MAX(INITIAL_FILE_LENGTH,
2*viewFileUsedLength[operandFile]);
if (alarmLogFileMaxRecords)
viewFileMaxLength[operandFile] = alarmLogFileStringLength*alarmLogFileMaxRecords;
viewFileString[operandFile] = (char *)
XtCalloc(1,viewFileMaxLength[operandFile]);
if(!viewFileString[operandFile]) {
XtVaSetValues(menuButton, XmNset, FALSE, NULL);
createDialog(XtParent(w),XmDIALOG_ERROR,"no free memory","");
return;
}
fread(viewFileString[operandFile], sizeof(char),
viewFileUsedLength[operandFile], fp);
/* close up the file */
fclose (fp) ;
if (!app_shell) {
/* create view window dialog */
ac = 0;
XtSetArg (al[ac], XmNy, 47);
ac++;
XtSetArg (al[ac], XmNx, 77);
ac++;
/*
XtSetArg (al[ac], XmNallowShellResize, FALSE); ac++;
*/
XtSetArg (al[ac], XmNallowOverlap, FALSE);
ac++;
XtSetArg(al[ac], XmNautoUnmanage, FALSE);
ac++;
switch (option) {
case CONFIG_FILE:
str = XmStringLtoRCreate("Configuration File", XmSTRING_DEFAULT_CHARSET);
break;
case ALARM_FILE:
str = XmStringLtoRCreate("Alarm Log File", XmSTRING_DEFAULT_CHARSET);
break;
case OPMOD_FILE:
str = XmStringLtoRCreate("Operator Mod File", XmSTRING_DEFAULT_CHARSET);
break;
}
XtSetArg(al[ac], XmNdialogTitle, str);
ac++;
app_shell = XmCreateFormDialog(XtParent(w), "SCROLL", al, ac);
XmStringFree(str);
XtVaSetValues(app_shell, XmNallowOverlap, FALSE, NULL);
/* Modify the window manager menu "close" callback */
{
Atom WM_DELETE_WINDOW;
XtVaSetValues(XtParent(app_shell),
XmNdeleteResponse, XmDO_NOTHING, NULL);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(XtParent(app_shell)),
"WM_DELETE_WINDOW", False);
operandFileLong = operandFile;
XmAddWMProtocolCallback(XtParent(app_shell),WM_DELETE_WINDOW,
(XtCallbackProc)closeFileViewShell, (XtPointer)operandFileLong);
}
switch (option) {
case ALARM_FILE:
alarm_shell = app_shell;
break;
case OPMOD_FILE:
opmod_shell = app_shell;
break;
}
/* add close button */
ac = 0;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNtopOffset, 5);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNleftOffset, 5);
ac++;
XtSetArg (al[ac], XmNuserData, menuButton);
ac++;
button = XtCreateManagedWidget("Close",xmPushButtonWidgetClass,
app_shell, al, ac);
operandFileLong = operandFile;
XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)closeFileViewWindow_callback,
(XtPointer) operandFileLong);
previous = button;
/* create file name widget */
ac = 0;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNtopOffset, 6);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg (al[ac], XmNleftWidget, button);
ac++;
XtSetArg (al[ac], XmNleftOffset, 6);
ac++;
viewFilenameWidget[operandFile] = XtCreateManagedWidget(filename,xmLabelGadgetClass,
app_shell,al, ac);
/* For Search Widgets.
We define "Search" button in AlLogViewPanel.
*/
ac = 0;
XtSetArg (al[ac], XmNtopAttachment, XmATTACH_FORM);
ac++;
XtSetArg (al[ac], XmNtopOffset, 5);
ac++;
XtSetArg (al[ac], XmNleftAttachment, XmATTACH_WIDGET);
ac++;
XtSetArg (al[ac], XmNleftWidget,viewFilenameWidget[operandFile] );
ac++;
XtSetArg (al[ac], XmNleftOffset, 5);
ac++;
XtSetArg (al[ac], XmNuserData, menuButton);
ac++;
button1 = XtCreateManagedWidget("Search",xmPushButtonWidgetClass,
app_shell, al, ac);
XtAddCallback(button1, XmNactivateCallback, (XtCallbackProc)searchCallback, app_shell );
ac = 0;
XtSetArg(al[ac], XmNallowShellResize, (XtArgVal) True);
ac++;
XtSetArg(al[ac], XmNmappedWhenManaged, (XtArgVal) False);
ac++;
findShell=XtVaCreatePopupShell("pshell",transientShellWidgetClass,app_shell,
NULL);
findPane = XtVaCreateManagedWidget("findPane", xmPanedWindowWidgetClass,
findShell,NULL);
ac = 0;
XtSetArg(al[ac], XmNhorizontalSpacing, (XtArgVal) 5);
ac++;
XtSetArg(al[ac], XmNverticalSpacing, (XtArgVal) 5);
ac++;
findBox = XtCreateManagedWidget("findBox", xmRowColumnWidgetClass,
findPane, al, ac);
ac = 0;
XtSetArg(al[ac], XmNleftAttachment, (XtArgVal) XmATTACH_FORM);
ac++;
XtSetArg(al[ac], XmNrightAttachment, (XtArgVal) XmATTACH_FORM);
ac++;
XtSetArg(al[ac], XmNtopAttachment, (XtArgVal) XmATTACH_FORM);
ac++;
str= XmStringCreateLtoR("Search:",XmFONTLIST_DEFAULT_TAG);
XtSetArg(al[ac], XmNlabelString, str);
ac++;
XtSetArg(al[ac], XmNalignment, (XtArgVal) XmALIGNMENT_CENTER);
ac++;
findLabel = XtCreateManagedWidget("findLabel", xmLabelWidgetClass,
findBox, al, ac);
XmStringFree(str);
ac = 0;
XtSetArg(al[ac], XmNleftAttachment, (XtArgVal) XmATTACH_FORM);
ac++;
XtSetArg(al[ac], XmNrightAttachment, (XtArgVal) XmATTACH_FORM);
ac++;
XtSetArg(al[ac], XmNtopAttachment, (XtArgVal) XmATTACH_WIDGET);
ac++;
XtSetArg(al[ac], XmNtopWidget, (XtArgVal) findLabel);
ac++;
XtSetArg(al[ac], XmNcolumns, (XtArgVal) 40);
ac++;
findText = XtCreateManagedWidget("findText", xmTextWidgetClass, findBox,
al, ac);
XtAddCallback(findText, XmNactivateCallback, (XtCallbackProc)findForward, NULL);
ac = 0;
XtSetArg(al[ac], XmNborderWidth, (XtArgVal) 0);
ac++;
XtSetArg(al[ac], XmNorientation, (XtArgVal) XmHORIZONTAL);
ac++;
findButtonBox=XtCreateManagedWidget("findButtonBox", xmRowColumnWidgetClass,
findPane, al, ac);
ac = 0;
str= XmStringCreateLtoR("Forward",XmFONTLIST_DEFAULT_TAG);
XtSetArg(al[ac], XmNlabelString,str);
ac++;
findForwardButton = XtCreateManagedWidget("findForwardButton",
xmPushButtonWidgetClass, findButtonBox, al, ac);
XtAddCallback(findForwardButton, XmNactivateCallback, (XtCallbackProc)findForward,
app_shell);
XmStringFree(str);
ac = 0;
str= XmStringCreateLtoR("Reverse",XmFONTLIST_DEFAULT_TAG);
XtSetArg(al[ac], XmNlabelString, str);
ac++;
findReverseButton = XtCreateManagedWidget("findReverseButton",
xmPushButtonWidgetClass, findButtonBox, al, ac);
XtAddCallback(findReverseButton,XmNactivateCallback,(XtCallbackProc)findReverse,app_shell);
XmStringFree(str);
ac = 0;
str= XmStringCreateLtoR("Dismiss",XmFONTLIST_DEFAULT_TAG);
XtSetArg(al[ac], XmNlabelString, str);
ac++;
findDismissButton = XtCreateManagedWidget("findDismissButton",