00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "typedefs.h"
00017 #include "f_stccomm.h"
00018
00019 #ifdef RFIO
00020 #define RFIO_open rfio_open
00021 #define RFIO_close rfio_close
00022 #define RFIO_read rfio_read
00023 #define RFIO_lseek rfio_lseek
00024 #include "rawapin.h"
00025 #else
00026 #define RFIO_open open
00027 #define RFIO_close close
00028 #define RFIO_read read
00029 #define RFIO_lseek lseek
00030 #endif
00031
00032 #ifdef GSI__LYNX
00033 #undef unix
00034 #endif
00035
00036 #ifdef GSI__LINUX
00037 #undef unix
00038 #endif
00039
00040 #ifdef GSI__SOLARIS
00041 #undef unix
00042 #endif
00043
00044 #ifdef GSI__WINNT
00045 #endif
00046
00047 #ifdef GSI__AIX
00048 #define AIX_DEC
00049 #endif
00050
00051 #ifdef unix
00052 #define AIX_DEC
00053 #endif
00054 #ifdef GSI__VMS
00055 #include <descrip.h>
00056 static struct dsc$descriptor_vs sd_string;
00057 static INTS4 l_st_ichannel[5]={0,0,0,0,0};
00058 static INTS4 l_st_ochannel[5]={0,0,0,0,0};
00059 #endif
00060
00061 #ifdef GSI__WINNT
00062 #include <time.h>
00063 #include <memory.h>
00064 #include <sys/timeb.h>
00065 #include <sys/types.h>
00066 #include <stdio.h>
00067 #include <stdlib.h>
00068 #include <fcntl.h>
00069 #include <string.h>
00070 #include <sys/stat.h>
00071 #include <fcntl.h>
00072 #define DEF_FILE_ACCE S_IREAD|S_IWRITE
00073 #define GET__OPEN_FLAG O_RDONLY
00074 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00075 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00076 #define PUT__CRT_OPT ""
00077
00078 #include <winsock.h>
00079 #define WS_VERSION_REQD 0x0101
00080 #define WS_VERSION_MAJOR HIBYTE(WS_VERSION_REQD)
00081 #define WS_VERSION_MINOR LOBYTE(WS_VERSION_REQD)
00082 #define MIN_SOCKETS_REQD 6
00083
00084 #endif
00085
00086 #ifdef Linux
00087 #include <stdio.h>
00088 #include <stdlib.h>
00089 #include <fcntl.h>
00090 #include <string.h>
00091 #include <unistd.h>
00092 #include <memory.h>
00093 #include <pwd.h>
00094 #include <sys/time.h>
00095 #include <sys/timeb.h>
00096 #include <sys/types.h>
00097 #include <sys/stat.h>
00098 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00099 #define GET__OPEN_FLAG O_RDONLY
00100 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00101 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00102 #define PUT__CRT_OPT ""
00103 #endif
00104
00105 #ifdef Solaris
00106 #include <stdio.h>
00107 #include <stdlib.h>
00108 #include <fcntl.h>
00109 #include <string.h>
00110 #include <unistd.h>
00111 #include <memory.h>
00112 #include <pwd.h>
00113 #include <sys/time.h>
00114 #include <sys/timeb.h>
00115 #include <sys/types.h>
00116 #include <sys/stat.h>
00117 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00118 #define GET__OPEN_FLAG O_RDONLY
00119 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00120 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00121 #define PUT__CRT_OPT ""
00122 #endif
00123
00124 #ifdef _AIX
00125 #include <stdio.h>
00126 #include <stdlib.h>
00127 #include <fcntl.h>
00128 #include <string.h>
00129 #include <unistd.h>
00130 #include <memory.h>
00131 #include <pwd.h>
00132 #include <sys/time.h>
00133 #include <sys/timeb.h>
00134 #include <sys/types.h>
00135 #include <sys/mode.h>
00136 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00137 #define GET__OPEN_FLAG O_RDONLY
00138 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00139 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00140 #define PUT__CRT_OPT ""
00141 #endif
00142
00143 #ifdef VMS
00144 #include <unixio.h>
00145 #include <unixlib.h>
00146 #include <file.h>
00147 #include <stdio.h>
00148 #include <stdlib.h>
00149 #include <fcntl.h>
00150 #include <string.h>
00151 #include <sys/time.h>
00152 #include <sys/timeb.h>
00153 #include <sys/types.h>
00154 #include <unistd.h>
00155 #define DEF_FILE_ACCE 644
00156 #define GET__OPEN_FLAG O_RDONLY
00157 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00158 #define PUT__CRT_FLAG O_CREAT|O_WRONLY
00159 #define PUT__CRT_OPT "rfm=fix"
00160 #endif
00161
00162 #if MBS_ENDIAN == 1
00163 #include "s_filhe_swap.h"
00164 #else
00165 #include "s_filhe.h"
00166 #endif
00167
00168
00169 #include "fLmd.h"
00170
00171
00172 #include "gps_sc_def.h"
00173 #include "f_evt.h"
00174 #include "f_evcli.h"
00175 #include "portnum_def.h"
00176
00177 INTS4 f_evt_get_newbuf(s_evt_channel *);
00178 INTS4 f_evt_check_buf(CHARS *,INTS4 *, INTS4 *, INTS4 *, INTS4 *);
00179 INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan);
00180 INTS4 f_evt_swap_filhe(s_bufhe *);
00181 INTS4 f_ut_utime(INTS4, INTS4, CHARS *);
00182
00183 static struct s_tcpcomm s_tcpcomm_st_evt;
00184 static CHARS c_temp[MAX_BUF_LGTH];
00185 static int l_gl_rev_port = PORT__EVENT_SERV;
00186 static int l_gl_evt_check = 0;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d,INTS4 *pl_lwords)
00245 {
00246 s_ves10_1 *ps_ves10_1;
00247 INTS4 l_total,l_sub,l_sum;
00248 INTS4 l,ll,l_status,*pl_next;
00249
00250 if(ps_ve10_1 == NULL) return(GETEVT__FAILURE);
00251 pl_next = (INTS4 *) (ps_ve10_1 + 1);
00252 l_total = ps_ve10_1->l_dlen-4;
00253 l_sum = 0;
00254 ll=0;
00255 while(l_sum < l_total)
00256 {
00257 ps_ves10_1 = (s_ves10_1 *) pl_next;
00258 ll++;
00259 if(ll == l_subevent)
00260 {
00261 if(pl_lwords != NULL) *pl_lwords = ps_ves10_1->l_dlen/2-1;
00262 if(pl_se != NULL) *pl_se = (INTS4 *) ps_ves10_1;
00263 if(pl_d != NULL) *pl_d = (INTS4 *) (ps_ves10_1+1);
00264 return(GETEVT__SUCCESS);
00265 }
00266 l_sub = ps_ves10_1->l_dlen+4;
00267 l_sum += l_sub;
00268 pl_next = (INTS4 *)(ps_ves10_1);
00269 pl_next += l_sub/2;
00270 }
00271 if(pl_lwords != NULL) *pl_lwords = ll;
00272 if(pl_se != NULL) *pl_se = NULL;
00273 if(pl_d != NULL) *pl_d = NULL;
00274 if(l_subevent == 0) return(ll);
00275 else return(GETEVT__NOMORE);
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 INTS4 f_evt_type(s_bufhe *ps_bufhe,s_evhe *ps_evhe, INTS4 l_subid,INTS4 l_long,INTS4 l_hex,INTS4 l_data)
00308 {
00309 s_ves10_1 *ps_ves10_1;
00310 s_ve10_1 *ps_ve10_1;
00311 s_filhe *ps_filhe;
00312 INTS2 *pi_data;
00313 INTS4 *pl_data;
00314 INTS4 l_mode,l_s;
00315 INTS4 l,ll,l_status,l_ldata,l_used;
00316 CHARS c_line[132];
00317 CHARS c_full[132];
00318 CHARS c_time[32];
00319
00320 strcpy(c_full," ");
00321 l_ldata=l_data;
00322 if((l_hex+l_long) > 0) l_ldata=1;
00323
00324
00325 if(ps_bufhe != NULL)
00326 {
00327 sprintf(c_line,"--------------------------------------------------------");
00328 printf("%s\n",c_line);
00329
00330 ll=ps_bufhe->l_dlen*2;
00331 if(ll%512 > 0)ll += 512-ll%512;
00332
00333 l_status = f_ut_utime(ps_bufhe->l_time[0],ps_bufhe->l_time[1],c_time);
00334 if(ps_bufhe->i_type == 2000)
00335 {
00336 ps_filhe=(s_filhe *)ps_bufhe;
00337 sprintf(c_line,"File header info:");
00338 printf("%s\n",c_line);
00339 sprintf(c_line,"Size: %d [%d b], used %d [b]",ps_filhe->filhe_dlen,ll,ps_filhe->filhe_used*2);
00340 printf("%s\n",c_line);
00341 sprintf(c_line,"Label: %s",ps_filhe->filhe_label);
00342 printf("%s\n",c_line);
00343 sprintf(c_line,"File: %s",ps_filhe->filhe_file);
00344 printf("%s\n",c_line);
00345 sprintf(c_line,"User: %s",ps_filhe->filhe_user);
00346 printf("%s\n",c_line);
00347 sprintf(c_line,"Time: %s",ps_filhe->filhe_time);
00348 printf("%s\n",c_line);
00349 sprintf(c_line,"Run: %s",ps_filhe->filhe_run);
00350 printf("%s\n",c_line);
00351 sprintf(c_line,"Exp: %s",ps_filhe->filhe_exp);
00352 printf("%s\n",c_line);
00353 for(ll=0;ll<ps_filhe->filhe_lines;ll++)
00354 {
00355 sprintf(c_line,"comment: %s",ps_filhe->s_strings[ll].string);
00356 printf("%s\n",c_line);
00357 }
00358 }
00359 else
00360 {
00361 l_used=ps_bufhe->i_used;
00362 if(ps_bufhe->l_dlen > MAX__DLEN)l_used=ps_bufhe->l_free[2];
00363 sprintf(c_line,"Buffer %9d, Length %5d[w] Size %5d[b] used %5d[w] %s",
00364 ps_bufhe->l_buf,
00365 ps_bufhe->l_dlen,
00366 ll,l_used,
00367 c_time);
00368 printf("%s\n",c_line);
00369 sprintf(c_line," Events %3d Type/Subtype %5d %5d FragEnd=%d FragBegin=%d Total %5d[w]",
00370 ps_bufhe->l_evt,
00371 ps_bufhe->i_type,
00372 ps_bufhe->i_subtype,
00373 ps_bufhe->h_end,
00374 ps_bufhe->h_begin,
00375 ps_bufhe->l_free[1]);
00376 printf("%s\n",c_line);
00377 }
00378 sprintf(c_line,"--------------------------------------------------------");
00379 printf("%s\n",c_line);
00380 }
00381
00382 if(ps_evhe == NULL) return(0);
00383
00384
00385 if(ps_evhe->i_type != 10)
00386 {
00387 sprintf(c_line,"Event type %d, subtype %d, data longwords %d",
00388 ps_evhe->i_type,ps_evhe->i_subtype,ps_evhe->l_dlen/2);
00389 printf("%s\n",c_line);
00390 if((l_ldata != 0) & ((ps_evhe->i_type == 4)|(ps_evhe->i_type == 6)))
00391 {
00392 pl_data = (INTS4 *)ps_evhe;
00393 pl_data += 2;
00394 for(l=0;l<ps_evhe->l_dlen/2;l++)
00395 {
00396 sprintf(c_line,"%08x ",*pl_data);
00397 strcat(c_full,c_line);
00398 pl_data++;
00399 if(l%8 == 7)
00400 {
00401 printf("%s\n",c_full);
00402 strcpy(c_full," ");
00403 }
00404 }
00405 if(strlen(c_full) > 2)printf("%s\n",c_full);
00406 }
00407 return(0);
00408 }
00409
00410
00411 ps_ve10_1 = (s_ve10_1 *)ps_evhe;
00412
00413 sprintf(c_line,"Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d",
00414 ps_ve10_1->l_count,
00415 ps_ve10_1->i_type,
00416 ps_ve10_1->i_subtype,
00417 ps_ve10_1->l_dlen,
00418 ps_ve10_1->i_trigger);
00419 printf("%s\n",c_line);
00420
00421
00422 l_s=0;
00423 l_status=0;
00424 while(l_status == 0)
00425 {
00426 l_s++;
00427 l_status=f_evt_get_subevent(ps_ve10_1,l_s,(INTS4 **)&ps_ves10_1,(INTS4 **)&pl_data,(INTS4 *)&ll);
00428 if(l_status == 0)
00429 {
00430 if((l_subid < 0)|(l_subid == ps_ves10_1->i_procid))
00431 {
00432 sprintf(c_line," SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d",
00433 ps_ves10_1->i_procid,
00434 ps_ves10_1->i_type,
00435 ps_ves10_1->i_subtype,
00436 ps_ves10_1->l_dlen,
00437 ps_ves10_1->h_control,
00438 ps_ves10_1->h_subcrate);
00439 printf("%s\n",c_line);
00440 if(l_ldata != 0)
00441 {
00442 if((l_long != 0) | (l_hex != 0))
00443 {
00444 for(l=0;l<ll;l++)
00445 {
00446 if(l_hex != 0) sprintf(c_line,"%04x.%04x ",(*pl_data>>16)&0xffff,*pl_data&0xffff);
00447 else sprintf(c_line,"%8d ",*pl_data);
00448 strcat(c_full,c_line);
00449 pl_data++;
00450 if(l%8 == 7)
00451 {
00452 printf("%s\n",c_full);
00453 strcpy(c_full," ");
00454 }
00455 }
00456 if(strlen(c_full) > 2)printf("%s\n",c_full);
00457 strcpy(c_full," ");
00458 }
00459 else
00460 {
00461 for(l=0;l<ll;l++)
00462 {
00463 sprintf(c_line,"%8d%8d",*pl_data&0xffff,(*pl_data>>16)&0xffff);
00464 strcat(c_full,c_line);
00465 pl_data++;
00466 if(l%4 == 3)
00467 {
00468 printf("%s\n",c_full);
00469 strcpy(c_full," ");
00470 }
00471 }
00472 if(strlen(c_full) > 2)printf("%s\n",c_full);
00473 strcpy(c_full," ");
00474 }}}
00475 }}
00476 return(0);
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 INTS4 f_evt_rev_port(INTS4 l_port)
00494 {
00495 l_gl_rev_port=l_port;
00496 printf("Use remote event server port %d\n",l_port);
00497 return 0;
00498 }
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan,
00536 CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
00537 {
00538
00539 INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_header_size;
00540 INTS2 *pi;
00541 CHARS c_file[256], *pc_temp;
00542 s_filhe *ps_filhe;
00543 struct s_varstr
00544 {
00545 INTS2 i_varstr;
00546 CHARS c_varstr[128];
00547 } s_varstr_file;
00548 INTS4 l_status,ll;
00549
00550 if((pc_temp=strchr(pc_server,':')) != NULL)
00551 {
00552 l_mode=GETEVT__RFIO;
00553
00554 }
00555 #ifndef RFIO
00556 if(l_mode == GETEVT__RFIO)
00557 {
00558 printf("rfio not supported!\n");
00559 return(GETEVT__NOFILE);
00560 }
00561 #endif
00562
00563 if(ps_info != NULL) *ps_info=NULL;
00564
00565 if(ps_chan->l_timeout==0)ps_chan->l_timeout=-1;
00566 strcpy(ps_chan->c_channel,pc_server);
00567 switch(l_mode) {
00568 case GETEVT__FILE :
00569 strcpy(c_file,pc_server);
00570 if(strlen(c_file) < 5) strcat(c_file,".lmd");
00571 else {
00572 pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
00573 if((strcmp(pc_temp,".LMD") != 0) &&
00574 (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
00575 }
00576 #ifdef VMS
00577 pc_temp = c_temp;
00578 sd_string.dsc$w_maxstrlen = 128;
00579 sd_string.dsc$b_dtype = DSC$K_DTYPE_VT;
00580 sd_string.dsc$b_class = DSC$K_CLASS_VS;
00581 sd_string.dsc$a_pointer = (char *) &s_varstr_file;
00582 strcpy(s_varstr_file.c_varstr,c_file);
00583 s_varstr_file.i_varstr = strlen(c_file);
00584 ps_chan->l_buf_size = MAX_BUF_LGTH;
00585 ps_chan->l_channel_no=-1;
00586 for(ll=1;ll<5;ll++)
00587 {
00588 if(l_st_ichannel[ll] == 0)
00589 {
00590 ps_chan->l_channel_no=ll;
00591 l_st_ichannel[ll] = 1;
00592 break;
00593 }
00594 }
00595 if(ps_chan->l_channel_no==-1)return(GETEVT__NOCHANNEL);
00596 l_status = i$opilf(&ps_chan->l_channel_no,&sd_string,&ps_chan->l_buf_size);
00597 if((l_status&1) != 1)
00598 {
00599 printf("%s: open error %d\n",pc_server,l_status);
00600 l_st_ichannel[ps_chan->l_channel_no]=-1;
00601 return(GETEVT__NOFILE);
00602 }
00603 l_status = i$gtslf(&ps_chan->l_channel_no,&pc_temp,&ps_chan->l_buf_size);
00604 if((l_status&1) != 1)
00605 {
00606 printf("read error %d\n",l_status);
00607 l_status = i$clilf(&ps_chan->l_channel_no);
00608 l_st_ichannel[ps_chan->l_channel_no]=-1;
00609 return(GETEVT__RDERR);
00610 }
00611 l_is_goosybuf = -1;
00612 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_filehead);
00613 if(ps_info != NULL)
00614 {
00615 if( l_is_goosybuf == 0)
00616 {
00617 if(l_swap)
00618 {
00619 l_status = i$clilf(&ps_chan->l_channel_no);
00620 l_status = i$opilf(&ps_chan->l_channel_no,&sd_string,&ps_chan->l_buf_size);
00621 l_status = i$gtslf(&ps_chan->l_channel_no,&pc_temp,&ps_chan->l_buf_size);
00622 ps_filhe=(s_filhe *)c_temp;
00623 f_evt_swap_filhe((s_bufhe *)ps_filhe);
00624 }
00625 *ps_info=c_temp;
00626 }
00627 else
00628 {
00629 *ps_info=NULL;
00630 }
00631 }
00632 if( l_is_goosybuf == 1)
00633 {
00634 l_status = i$clilf(&ps_chan->l_channel_no);
00635 l_status = i$opilf(&ps_chan->l_channel_no,&sd_string,&ps_chan->l_buf_size);
00636 }
00637 #else
00638 if((ps_chan->l_channel_no=open(c_file,GET__OPEN_FLAG))== -1)
00639 {
00640 return(GETEVT__NOFILE);
00641 }
00642
00643 if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
00644 printf("LMD format error: no LMD file: %s\n",c_file);
00645 close(ps_chan->l_channel_no);
00646 ps_chan->l_channel_no=-1;
00647 return(GETEVT__NOLMDFILE);
00648 }
00649
00650 ps_chan->pLmd=NULL;
00651 if((*((INTS4 *)(c_temp+4)) == LMD__TYPE_FILE_HEADER_101_1)||
00652 (*((INTS4 *)(c_temp+4)) == 0x65000100)){
00653 close(ps_chan->l_channel_no);
00654 ps_chan->pLmd=fLmdAllocateControl();
00655 fLmdGetOpen(ps_chan->pLmd,c_file,NULL,LMD__BUFFER,LMD__NO_INDEX);
00656 ps_chan->l_server_type=l_mode;
00657 return GETEVT__SUCCESS;
00658 }
00659
00660
00661 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
00662 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0)) {
00663 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
00664 close(ps_chan->l_channel_no);
00665 ps_chan->l_channel_no=-1;
00666 return(GETEVT__NOLMDFILE);
00667 }
00668
00669
00670 if(l_filehead == 1) {
00671 lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00672 l_header_size=l_size_head;
00673 if(((s_filhe *)c_temp)->filhe_dlen > MAX__DLEN){
00674 l_header_size=((s_filhe *)c_temp)->filhe_used*2+48;
00675
00676 }
00677 if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size){
00678 printf("LMD format error: no LMD file: %s\n",c_file);
00679 close(ps_chan->l_channel_no);
00680 ps_chan->l_channel_no=-1;
00681 return(GETEVT__NOLMDFILE);
00682 }
00683 if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
00684 close(ps_chan->l_channel_no);
00685 ps_chan->l_channel_no=-1;
00686 return(GETEVT__RDERR);
00687 }
00688 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
00689 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head)) {
00690 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
00691 close(ps_chan->l_channel_no);
00692 ps_chan->l_channel_no=-1;
00693 return(GETEVT__NOLMDFILE);
00694 }
00695 }
00696 ps_chan->l_buf_size=l_size_head;
00697 lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00698 if(ps_info != NULL) *ps_info=NULL;
00699
00700 if(l_filehead == 1) {
00701 if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size) {
00702 printf("LMD format error: no LMD file: %s\n",c_file);
00703 close(ps_chan->l_channel_no);
00704 ps_chan->l_channel_no=-1;
00705 return(GETEVT__NOLMDFILE);
00706 }
00707 ps_filhe = (s_filhe *) c_temp;
00708 if(ps_info != NULL) {
00709 if( l_swap_head ==1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
00710 *ps_info=c_temp;
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728 }
00729
00730
00731
00732 #endif
00733 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00734
00735 break;
00736 case GETEVT__STREAM :
00737
00738 if(f_stc_connectserver(pc_server,PORT__STREAM_SERV,&ps_chan->l_channel_no,
00739 &s_tcpcomm_st_evt)!=STC__SUCCESS)
00740 {
00741 return(GETEVT__NOSERVER);
00742 }
00743
00744 l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
00745 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00746 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
00747
00748 if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
00749 ps_chan->l_buf_size=*((INTS4 *)(c_temp+4));
00750 ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
00751
00752 ps_chan->l_stream_bufs = 0;
00753
00754 ps_chan->l_io_buf_size=(ps_chan->l_buf_size)*(ps_chan->l_bufs_in_stream);
00755
00756 ps_chan->pLmd=NULL;
00757 if(*((INTS4 *)(c_temp+12)) == 0) {
00758 ps_chan->pLmd=fLmdAllocateControl();
00759 ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
00760 fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__STREAM_SERV,ps_chan->l_timeout);
00761 ps_chan->l_server_type=l_mode;
00762 return GETEVT__SUCCESS;
00763 }
00764
00765 break;
00766 case GETEVT__TRANS :
00767
00768 if(f_stc_connectserver(pc_server,PORT__TRANSPORT,&ps_chan->l_channel_no,
00769 &s_tcpcomm_st_evt)!=STC__SUCCESS)
00770 {
00771 return(GETEVT__NOSERVER);
00772 }
00773
00774 l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
00775 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00776 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
00777
00778 if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
00779 ps_chan->l_buf_size=*((INTS4 *)(c_temp+4));
00780 ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
00781
00782 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00783
00784 ps_chan->pLmd=NULL;
00785 if(*((INTS4 *)(c_temp+12)) == 0) {
00786 ps_chan->pLmd=fLmdAllocateControl();
00787 ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
00788 fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__TRANSPORT,ps_chan->l_timeout);
00789 ps_chan->l_server_type=l_mode;
00790 return GETEVT__SUCCESS;
00791 }
00792
00793 break;
00794 case GETEVT__REVSERV :
00795 if(f_evcli_con(ps_chan, pc_server, l_gl_rev_port, -1, l_sample)!=STC__SUCCESS)
00796 {
00797 return(GETEVT__NOSERVER);
00798 }
00799 break;
00800 case GETEVT__EVENT :
00801 if(f_evcli_con(ps_chan, pc_server, l_gl_rev_port, -1, l_sample)!=STC__SUCCESS)
00802 {
00803 return(GETEVT__NOSERVER);
00804 }
00805 break;
00806 case GETEVT__RFIO :
00807 ps_chan->l_channel_no=-1;
00808 ps_chan->l_channel_no=RFIO_open(pc_server,GET__OPEN_FLAG,0);
00809 if(ps_chan->l_channel_no < 0) return(GETEVT__NOSERVER);
00810
00811 if(RFIO_read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
00812 {
00813 printf("LMD format error: no LMD file: %s\n",pc_server);
00814 RFIO_close(ps_chan->l_channel_no);
00815 ps_chan->l_channel_no=-1;
00816 return(GETEVT__NOLMDFILE);
00817 }
00818
00819 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
00820 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
00821 {
00822 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
00823 RFIO_close(ps_chan->l_channel_no);
00824 ps_chan->l_channel_no=-1;
00825 return(GETEVT__NOLMDFILE);
00826 }
00827
00828 if(l_filehead == 1)
00829 {
00830 RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00831 if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
00832 {
00833 printf("LMD format error: no LMD file: %s\n",pc_server);
00834 RFIO_close(ps_chan->l_channel_no);
00835 ps_chan->l_channel_no=-1;
00836 return(GETEVT__NOLMDFILE);
00837 }
00838 if(RFIO_read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
00839 {
00840 RFIO_close(ps_chan->l_channel_no);
00841 ps_chan->l_channel_no=-1;
00842 return(GETEVT__RDERR);
00843 }
00844 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
00845 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
00846 {
00847 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
00848 RFIO_close(ps_chan->l_channel_no);
00849 ps_chan->l_channel_no=-1;
00850 return(GETEVT__NOLMDFILE);
00851 }
00852 }
00853 ps_chan->l_buf_size=l_size_head;
00854 RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00855 if(ps_info != NULL)*ps_info=NULL;
00856
00857 if(l_filehead == 1)
00858 {
00859 if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
00860 {
00861 printf("LMD format error: no LMD file: %s\n",pc_server);
00862 RFIO_close(ps_chan->l_channel_no);
00863 ps_chan->l_channel_no=-1;
00864 return(GETEVT__NOLMDFILE);
00865 }
00866 ps_filhe=(s_filhe *)c_temp;
00867 if(ps_info != NULL)
00868 {
00869 if( l_swap_head ==1)f_evt_swap_filhe((s_bufhe *)ps_filhe);
00870 *ps_info=c_temp;
00871 }
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888 }
00889 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00890 break;
00891 default :
00892 if(ps_info != NULL) *ps_info=NULL;
00893 return(GETEVT__NOSERVER);
00894 }
00895
00896 if((l_mode != GETEVT__EVENT)&(l_mode != GETEVT__REVSERV))
00897 {
00898 if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
00899 {
00900 printf("Memory allocation error\n");
00901 exit(2);
00902 }
00903 ps_chan->l_evt_buf_size=ps_chan->l_io_buf_size;
00904 if( (ps_chan->pc_evt_buf=malloc(ps_chan->l_evt_buf_size))==NULL)
00905 {
00906 printf("Memory allocation error\n");
00907 exit(2);
00908 }
00909 }
00910 ps_chan->l_server_type=l_mode;
00911 ps_chan->l_first_get=1;
00912 return GETEVT__SUCCESS;
00913 }
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941 INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
00942 {
00943 INTS4 l_temp,l_prev_ok=1, l_stat, l_used;
00944 s_bufhe *ps_bufhe_cur;
00945 s_ve10_1 *ps_ve10_1;
00946 sMbsHeader *pevt;
00947
00948
00949 if(ps_chan->pLmd != NULL){
00950 if(ps_chan->l_server_type == GETEVT__TRANS)
00951 l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
00952 else if(ps_chan->l_server_type == GETEVT__STREAM)
00953 l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
00954 else if(ps_chan->l_server_type == GETEVT__FILE)
00955 l_stat=fLmdGetElement(ps_chan->pLmd,LMD__NO_INDEX, &pevt);
00956
00957
00958 if(pevt==NULL){
00959 if (ps_chan->l_server_type == GETEVT__FILE){
00960 if(l_stat == GETLMD__NOMORE) return(GETEVT__NOMORE);
00961 if(l_stat == GETLMD__EOFILE) return(GETEVT__NOMORE);
00962 if(l_stat == GETLMD__NOBUFFER) return(GETEVT__FAILURE);
00963 return(GETEVT__RDERR);
00964 } else {
00965 if(l_stat == LMD__TIMEOUT) return(GETEVT__TIMEOUT);
00966 else return (GETEVT__RDERR);
00967 }
00968 }
00969
00970 if(ppl_goobuf)*ppl_goobuf = NULL;
00971 *ppl_buffer = (INTS4 *)pevt;
00972 return(GETEVT__SUCCESS);
00973 }
00974
00975 if((ps_chan->l_server_type == GETEVT__EVENT)|(ps_chan->l_server_type == GETEVT__REVSERV))
00976 {
00977 *ppl_goobuf = NULL;
00978 if(f_evcli_evt(ps_chan) != STC__SUCCESS)
00979 {
00980 l_stat=f_evcli_buf(ps_chan);
00981 if(l_stat == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00982 if(l_stat != STC__SUCCESS) return(GETEVT__FAILURE);
00983 }
00984 *ppl_buffer = (INTS4 *) ps_chan->pc_evt_buf;
00985 return(GETEVT__SUCCESS);
00986 }
00987
00988
00989
00990
00991 if(ps_chan->l_first_get==1)
00992 {
00993 ps_chan->l_buf_posi=0;
00994 ps_chan->l_buf_lmt=0;
00995 ps_chan->l_io_buf_posi=MAX_LONG;
00996 ps_chan->l_first_buf=1;
00997 ps_chan->l_first_get=0;
00998 }
00999
01000
01001
01002
01003
01004 ps_chan->l_evt_buf_posi=0;
01005
01006
01007 while(1)
01008 {
01009
01010
01011 while (ps_chan->l_buf_posi >= ps_chan->l_buf_lmt)
01012 {
01013
01014
01015 if(ps_chan->l_io_buf_posi>=ps_chan->l_io_buf_size)
01016 {
01017 if((l_temp=f_evt_get_newbuf(ps_chan))!=GETEVT__SUCCESS) return(l_temp);
01018 ps_chan->l_io_buf_posi=0;
01019 }
01020 ps_chan->ps_bufhe = (s_bufhe*) (ps_chan->pc_io_buf+ps_chan->l_io_buf_posi);
01021 l_prev_ok = (ps_chan->l_buf_no == (ps_chan->ps_bufhe->l_buf-1));
01022 ps_chan->l_buf_no = ps_chan->ps_bufhe->l_buf;
01023 if(ps_chan->ps_bufhe->i_type == 2000) {
01024 printf("Unsolicited file header found!\n");
01025 ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
01026 ps_chan->l_buf_posi = ps_chan->l_io_buf_posi;
01027 ps_chan->l_buf_lmt = ps_chan->l_io_buf_posi;
01028 } else {
01029 l_used=ps_chan->ps_bufhe->l_free[2];
01030 if(ps_chan->ps_bufhe->l_dlen <= MAX__DLEN)l_used=ps_chan->ps_bufhe->i_used;
01031 ps_chan->l_buf_posi = ps_chan->l_io_buf_posi + sizeof(s_bufhe);
01032 ps_chan->l_buf_lmt = ps_chan->l_buf_posi + l_used*2;
01033 ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
01034 }
01035 }
01036
01037
01038 ps_chan->ps_ve10_1 = (s_ve10_1 *) (ps_chan->pc_io_buf + ps_chan->l_buf_posi);
01039 if( (ps_chan->l_evt_buf_posi != 0) || ((ps_chan->ps_bufhe->h_end==1) && (ps_chan->l_first_buf==1)) ) {
01040 ps_chan->l_buf_posi += sizeof(s_evhe);
01041 ps_chan->l_frag_len = ps_chan->ps_ve10_1->l_dlen*2;
01042 } else
01043 ps_chan->l_frag_len = (ps_chan->ps_ve10_1->l_dlen-4)*2 + sizeof(s_ve10_1);
01044
01045 if(ps_chan->l_frag_len + ps_chan->l_buf_posi > ps_chan->l_buf_lmt)
01046 {
01047 return(GETEVT__FRAGMENT);
01048 }
01049
01050
01051
01052 if((ps_chan->ps_bufhe->h_end==1)&&((ps_chan->l_first_buf==1) || (l_prev_ok == 0))) {
01053
01054 ps_chan->l_first_buf=0;
01055 l_prev_ok=1;
01056 ps_chan->l_evt_buf_posi=0;
01057 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01058
01059 continue;
01060 }
01061
01062 ps_chan->l_first_buf=0;
01063
01064
01065
01066 if( (ps_chan->l_evt_buf_posi==0) &&
01067 ( (ps_chan->ps_bufhe->h_begin==0) || ((ps_chan->l_buf_posi+ps_chan->l_frag_len) < ps_chan->l_buf_lmt) ) )
01068 {
01069 *ppl_buffer = (INTS4 *)(ps_chan->pc_io_buf+ps_chan->l_buf_posi);
01070 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01071 ps_chan->l_evt_buf_posi = 0;
01072 if(ppl_goobuf) *ppl_goobuf = (INTS4 *) (ps_chan->ps_bufhe);
01073 return(GETEVT__SUCCESS);
01074 }
01075
01076
01077 if(ps_chan->l_evt_buf_posi==0)
01078 {
01079 memcpy((CHARS *)&ps_chan->s_bufhe_1,(CHARS *)ps_chan->ps_bufhe,sizeof(s_bufhe));
01080 ps_bufhe_cur=(s_bufhe *)&ps_chan->s_bufhe_1;
01081 }
01082
01083
01084 if(ps_chan->l_evt_buf_size<ps_chan->l_evt_buf_posi+ps_chan->l_frag_len)
01085 {
01086 ps_chan->l_evt_buf_size=ps_chan->l_evt_buf_posi+ps_chan->l_frag_len;
01087 if( (ps_chan->pc_evt_buf=realloc
01088 (ps_chan->pc_evt_buf, ps_chan->l_evt_buf_size))==NULL)
01089 {
01090 printf("Memory allocation error\n");
01091 exit(2);
01092 }
01093 }
01094 memcpy(ps_chan->pc_evt_buf+ps_chan->l_evt_buf_posi,ps_chan->pc_io_buf+ps_chan->l_buf_posi,
01095 ps_chan->l_frag_len);
01096 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01097 if(ps_chan->l_evt_buf_posi == 0)
01098 {
01099 }
01100 ps_chan->l_evt_buf_posi += ps_chan->l_frag_len;
01101
01102 if((ps_chan->ps_bufhe->h_begin!=1)||(ps_chan->l_buf_posi<ps_chan->l_buf_lmt))
01103 {
01104
01105 ((s_ve10_1 *)(ps_chan->pc_evt_buf))->l_dlen=ps_chan->l_evt_buf_posi/2-4;
01106 *ppl_buffer=(INTS4 *)(ps_chan->pc_evt_buf);
01107 if(ppl_goobuf)*ppl_goobuf=(INTS4 *)(ps_bufhe_cur);
01108 return(GETEVT__SUCCESS);
01109 }
01110 }
01111 }
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 INTS4 f_evt_get_close(s_evt_channel * ps_chan)
01132 {
01133 INTS4 l_close_failure;
01134 INTS4 l_status;
01135
01136
01137 if(ps_chan->pLmd != NULL){
01138 if(ps_chan->l_server_type == GETEVT__TRANS)fLmdCloseMbs(ps_chan->pLmd);
01139 else if(ps_chan->l_server_type == GETEVT__STREAM)fLmdCloseMbs(ps_chan->pLmd);
01140 else if(ps_chan->l_server_type == GETEVT__FILE) fLmdGetClose(ps_chan->pLmd);
01141 free(ps_chan->pLmd);
01142 ps_chan->pLmd=NULL;
01143 return GETEVT__SUCCESS;
01144 }
01145
01146 l_close_failure=0;
01147 if(ps_chan->l_channel_no >= 0)
01148 {
01149 switch(ps_chan->l_server_type)
01150 {
01151 case GETEVT__FILE :
01152 #ifdef VMS
01153 l_status = i$clilf(&ps_chan->l_channel_no);
01154 l_st_ichannel[ps_chan->l_channel_no]=0;
01155 #else
01156 if(close(ps_chan->l_channel_no)==-1) l_close_failure=1;
01157 #endif
01158 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01159 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01160 break;
01161 case GETEVT__STREAM :
01162
01163 f_stc_write("CLOSE", 12, ps_chan->l_channel_no);
01164 if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
01165 if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
01166 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01167 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01168 break;
01169 case GETEVT__TRANS :
01170
01171 if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
01172 if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
01173 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01174 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01175 break;
01176 case GETEVT__REVSERV :
01177 case GETEVT__EVENT :
01178 if(f_evcli_close(ps_chan)!=STC__SUCCESS) l_close_failure=1;
01179 break;
01180 case GETEVT__RFIO :
01181 RFIO_close(ps_chan->l_channel_no);
01182 ps_chan->l_channel_no=-1;
01183 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01184 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01185 break;
01186 default :
01187 l_close_failure=1;
01188 }
01189 ps_chan->pc_io_buf=NULL;
01190 ps_chan->l_channel_no=-1;
01191 if(l_close_failure==1) return(GETEVT__CLOSE_ERR);
01192 return GETEVT__SUCCESS;
01193 }
01194 return GETEVT__SUCCESS;
01195
01196 }
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228 INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream,
01229 INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
01230 {
01231 s_filhe *ps_file_head;
01232 INTS4 l_write_size;
01233 INTS4 l_status,ll;
01234 time_t s_timet;
01235 struct timeb s_timeb;
01236
01237 CHARS c_mode[80];
01238 CHARS c_file[256], *pc_temp;
01239 struct s_varstr
01240 {
01241 INTS2 i_varstr;
01242 CHARS c_varstr[128];
01243 } s_varstr_file;
01244
01245
01246 ps_chan->pLmd=NULL;
01247 if(l_stream==0) {
01248 ps_chan->pLmd=fLmdAllocateControl();
01249 l_status=fLmdPutOpen(ps_chan->pLmd,pc_file,NULL,l_size,
01250 LMD__NO_OVERWRITE,LMD__INDEX,LMD__LARGE_FILE);
01251 return(l_status);
01252 }
01253
01254 #ifdef VMS
01255 sd_string.dsc$w_maxstrlen = 128;
01256 sd_string.dsc$b_dtype = DSC$K_DTYPE_VT;
01257 sd_string.dsc$b_class = DSC$K_CLASS_VS;
01258 sd_string.dsc$a_pointer = (char *) &s_varstr_file;
01259 #endif
01260
01261 ps_chan->l_first_put=1;
01262
01263 ps_chan->l_buf_size=l_size;
01264 ps_chan->l_bufs_in_stream=l_stream;
01265 ps_chan->l_buf_type=l_type;
01266 ps_chan->l_buf_subtype=l_subtype;
01267 ps_chan->l_io_buf_size=ps_chan->l_buf_size * ps_chan->l_bufs_in_stream;
01268 if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
01269 {
01270 printf("Memory allocation error\n");
01271 exit(2);
01272 }
01273
01274 strcpy(c_file,pc_file);
01275 if(strlen(c_file) < 5) strcat(c_file,".lmd");
01276 else
01277 {
01278 pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
01279 if((strcmp(pc_temp,".LMD") != 0) &&
01280 (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
01281 }
01282 #ifdef VMS
01283 strcpy(s_varstr_file.c_varstr,c_file);
01284 s_varstr_file.i_varstr = strlen(c_file);
01285 ps_chan->l_buf_size = (INTS2) l_size;
01286 ps_chan->l_channel_no=-1;
01287 for(ll=1;ll<5;ll++)
01288 {
01289 if(l_st_ochannel[ll] == 0)
01290 {
01291 ps_chan->l_channel_no=ll;
01292 l_st_ochannel[ll] = 1;
01293 break;
01294 }
01295 }
01296 if(ps_chan->l_channel_no==-1)return(PUTEVT__NOCHANNEL);
01297 l_status = i$opolf(&ps_chan->l_channel_no,&sd_string,&ps_chan->l_buf_size);
01298 if((l_status&1) != 1) return(PUTEVT__FAILURE);
01299 else
01300 {
01301 if((l_status&1) != 1) return(PUTEVT__FAILURE);
01302 #else
01303 if((ps_chan->l_channel_no=open(c_file,PUT__OPEN_APD_FLAG) )!= -1)
01304 return(PUTEVT__FILE_EXIST);
01305 else
01306 {
01307 if((ps_chan->l_channel_no=open(c_file,PUT__CRT_FLAG, DEF_FILE_ACCE))== -1)
01308 return(PUTEVT__FAILURE);
01309 #endif
01310
01311 else
01312 {
01313
01314 ps_file_head=(s_filhe *)ps_chan->pc_io_buf;
01315
01316 if(ps_filhe != NULL)
01317 {
01318 memcpy(ps_file_head, ps_filhe,ps_chan->l_buf_size );
01319 }
01320 else
01321 {
01322 memset( ps_file_head, '\0', ps_chan->l_buf_size);
01323 sprintf(ps_file_head->filhe_run, "Pid %d\0", getpid());
01324 ps_file_head->filhe_run_l=strlen(ps_file_head->filhe_run);
01325 }
01326 ps_file_head->filhe_dlen=ps_chan->l_buf_size/2;
01327 ps_file_head->filhe_subtype=1;
01328 ps_file_head->filhe_type=2000;
01329 ftime(&s_timeb);
01330 ps_file_head->filhe_stime[0]=(INTS4)s_timeb.time;
01331 ps_file_head->filhe_stime[1]=(INTS4)s_timeb.millitm;
01332 ps_file_head->filhe_free[0]=1;
01333 ps_file_head->filhe_file_l=strlen(c_file);
01334 strcpy(ps_file_head->filhe_file, c_file);
01335 strcpy(ps_file_head->filhe_user, getenv("USER"));
01336 ps_file_head->filhe_user_l=strlen(ps_file_head->filhe_user);
01337 time(&s_timet);
01338 strcpy(c_mode,ctime(&s_timet));
01339 strcpy(ps_file_head->filhe_time, &c_mode[4]);
01340 ps_file_head->filhe_time[20]=' ';
01341 #ifdef VMS
01342 l_status = i$ptslf(&ps_chan->l_channel_no,&ps_file_head,&ps_chan->l_buf_size);
01343 l_write_size=l_size;
01344 #else
01345 l_write_size=write(ps_chan->l_channel_no,(CHARS *)ps_file_head,
01346 ps_chan->l_buf_size);
01347 #endif
01348 if(l_write_size==-1)
01349 {
01350 return(PUTEVT__WRERR);
01351 }
01352 if(l_write_size!=ps_chan->l_buf_size)
01353 {
01354 return(PUTEVT__TOOBIG);
01355 }
01356 return(PUTEVT__SUCCESS);
01357 }
01358 }
01359 }
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382 INTS4 f_evt_put_event(s_evt_channel *ps_chan, INTS4 *pl_evt_buf)
01383 {
01384 INTS4 l_evt_buf_posi;
01385 INTS4 l_buf_remain_size;
01386 INTS4 l_write_size, l_temp, l_free;
01387 INTS4 l_status;
01388 CHARS *pc_addr;
01389 s_bufhe *ps_bufhe;
01390
01391
01392 if(ps_chan->pLmd != NULL){
01393 l_status=fLmdPutElement(ps_chan->pLmd,(sMbsHeader *)pl_evt_buf);
01394 return(l_status);
01395 }
01396
01397 if(ps_chan->l_first_put==1)
01398 {
01399 ps_chan->l_first_put=0;
01400 ps_chan->l_io_buf_posi=0;
01401 ps_chan->l_buf_no=1;
01402 }
01403 l_evt_buf_posi=0;
01404 ps_chan->l_evt_size=( ((s_ve10_1 *)(pl_evt_buf))->l_dlen)*2 + sizeof(s_evhe);
01405
01406
01407 l_buf_remain_size = ps_chan->l_io_buf_size - ps_chan->l_io_buf_posi;
01408 l_temp = (l_buf_remain_size / ps_chan->l_buf_size)*(sizeof(s_bufhe)+sizeof(s_evhe) );
01409 l_buf_remain_size -= l_temp;
01410
01411 if(ps_chan->l_evt_size>l_buf_remain_size)
01412 {
01413 memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0', ps_chan->l_io_buf_size-ps_chan->l_io_buf_posi);
01414
01415 l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01416 if(ps_chan->l_io_buf_posi%ps_chan->l_buf_size == 0) l_temp -= ps_chan->l_buf_size;
01417
01418 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
01419 if(l_temp==0)ps_chan->ps_bufhe->h_end = 0;
01420 else ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
01421 ps_chan->ps_bufhe->h_begin = 0;
01422 for(l_temp=0;l_temp<ps_chan->l_io_buf_size;l_temp+=ps_chan->l_buf_size)
01423 {
01424 pc_addr = ps_chan->pc_io_buf+l_temp;
01425 ps_bufhe=(s_bufhe *)pc_addr;
01426 if(ps_bufhe->l_evt>0)
01427 {
01428 #ifdef VMS
01429 l_status = i$ptslf(&ps_chan->l_channel_no,&pc_addr,&ps_chan->l_buf_size);
01430 l_write_size = (INTS4)ps_chan->l_buf_size;
01431 #else
01432 l_write_size=write(ps_chan->l_channel_no, pc_addr,ps_chan->l_buf_size);
01433 #endif
01434 if(l_write_size==-1) return(PUTEVT__WRERR);
01435 if(l_write_size!=ps_chan->l_buf_size) return(PUTEVT__TOOBIG);
01436 }
01437 else ps_chan->l_buf_no--;
01438 }
01439 ps_chan->l_io_buf_posi=0;
01440 ps_chan->ps_bufhe=(s_bufhe *)ps_chan->pc_io_buf;
01441
01442 l_buf_remain_size = ps_chan->l_io_buf_size;
01443 l_temp = (l_buf_remain_size / ps_chan->l_buf_size) * (sizeof(s_bufhe)+sizeof(s_evhe) );
01444 l_buf_remain_size -= l_temp;
01445 l_buf_remain_size += sizeof(s_evhe);
01446
01447 if(ps_chan->l_evt_size>l_buf_remain_size) return(PUTEVT__TOO_SMALLS);
01448 }
01449
01450 if(ps_chan->l_io_buf_posi==0)f_evt_ini_bufhe(ps_chan);
01451
01452
01453 while(l_evt_buf_posi<ps_chan->l_evt_size)
01454 {
01455 ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
01456 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
01457 {
01458 ps_chan->l_io_buf_posi += sizeof(s_bufhe);
01459 ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
01460 if(l_evt_buf_posi != 0)
01461 {
01462 ps_chan->l_io_buf_posi += sizeof(s_evhe);
01463 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01464
01465 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
01466 ps_chan->ps_bufhe->i_used += sizeof(s_evhe)/2;
01467 }
01468 }
01469 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01470
01471 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
01472 l_write_size = l_write_size + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
01473
01474 if(l_write_size>(ps_chan->l_evt_size-l_evt_buf_posi))
01475 l_write_size=(ps_chan->l_evt_size-l_evt_buf_posi);
01476 memcpy(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi, (CHARS *)pl_evt_buf + l_evt_buf_posi, l_write_size);
01477 ps_chan->ps_bufhe->l_evt ++;
01478 ps_chan->l_io_buf_posi += l_write_size;
01479 l_evt_buf_posi += l_write_size;
01480 ps_chan->ps_bufhe->i_used += l_write_size/2;
01481
01482
01483
01484 l_free=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01485
01486 l_free = l_free + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
01487 if(l_free==ps_chan->l_buf_size)l_free=0;
01488
01489 if(l_free<sizeof(s_ve10_1))ps_chan->l_io_buf_posi += l_free;
01490
01491 if(l_evt_buf_posi!=l_write_size)
01492 {
01493 ps_chan->ps_ve10_1->l_dlen= l_write_size/2;
01494 ps_chan->ps_ve10_1->i_subtype = ps_chan->l_buf_subtype;
01495 ps_chan->ps_ve10_1->i_type = ps_chan->l_buf_type;
01496 }
01497 else ps_chan->ps_ve10_1->l_dlen= (l_write_size-sizeof(s_evhe))/2;
01498 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
01499 {
01500 if(l_evt_buf_posi<ps_chan->l_evt_size) ps_chan->ps_bufhe->h_begin = 1;
01501 if(ps_chan->l_io_buf_posi > ps_chan->l_buf_size)
01502 ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
01503 ps_chan->ps_bufhe->l_free[1] = ((s_ve10_1 *)(pl_evt_buf))->l_dlen;
01504 }
01505
01506 }
01507 return(PUTEVT__SUCCESS);
01508 }
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530 INTS4 f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe)
01531 {
01532 INTS4 l_write_size, l_temp, l_free;
01533 INTS4 l_status;
01534 CHARS *pc_addr;
01535
01536
01537 if(ps_chan->pLmd != NULL){
01538 l_status=fLmdPutBuffer(ps_chan->pLmd,(sMbsHeader *)(ps_bufhe+1),ps_bufhe->l_evt);
01539 return(l_status);
01540 }
01541
01542 ps_chan->l_io_buf_posi = ps_chan->l_buf_size;
01543 ps_chan->l_io_buf_size = ps_chan->l_buf_size;
01544 #ifdef VMS
01545 l_status = i$ptslf(&ps_chan->l_channel_no,&ps_bufhe,&ps_chan->l_buf_size);
01546 l_write_size = (INTS4)ps_chan->l_buf_size;
01547 #else
01548 l_write_size=write(ps_chan->l_channel_no, (CHARS *) ps_bufhe, ps_chan->l_buf_size);
01549 #endif
01550 if(l_write_size==-1)
01551 {
01552 return(PUTEVT__WRERR);
01553 }
01554 if(l_write_size!=ps_chan->l_buf_size)
01555 {
01556 return(PUTEVT__TOOBIG);
01557 }
01558 return PUTEVT__SUCCESS;
01559 }
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581 INTS4 f_evt_put_close(s_evt_channel *ps_chan)
01582 {
01583 INTS4 l_write_size, l_temp, l_temp2;
01584 INTS4 l_status;
01585 CHARS *pc_addr;
01586
01587
01588 if(ps_chan->pLmd != NULL){
01589 l_status=fLmdPutClose(ps_chan->pLmd);
01590 return(l_status);
01591 }
01592
01593 if(ps_chan->l_first_put==1) goto g_close;
01594
01595
01596 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
01597 {
01598 l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01599
01600 memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0',
01601 l_temp+ps_chan->l_buf_size-ps_chan->l_io_buf_posi);
01602
01603 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
01604
01605 ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
01606 ps_chan->ps_bufhe->h_begin = 0;
01607 if(l_temp==0)
01608 ps_chan->ps_bufhe->h_end = 0;
01609 else
01610 ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))
01611 ->h_begin;
01612 ps_chan->ps_bufhe->i_used = (ps_chan->l_io_buf_posi%ps_chan->l_buf_size -
01613 sizeof(s_bufhe))/2;
01614 }
01615
01616
01617 if(ps_chan->l_io_buf_posi!=ps_chan->l_io_buf_size)
01618 {
01619 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
01620 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size+1) *
01621 ps_chan->l_buf_size;
01622 else
01623 l_write_size=ps_chan->l_io_buf_posi;
01624
01625 for(l_temp=0;l_temp<l_write_size;l_temp+=ps_chan->l_buf_size){
01626
01627
01628 #ifdef VMS
01629 pc_addr = ps_chan->pc_io_buf+l_temp;
01630 l_status = i$ptslf(&ps_chan->l_channel_no,&pc_addr,&ps_chan->l_buf_size);
01631 l_temp2 = (INTS4)ps_chan->l_buf_size;
01632 #else
01633 l_temp2=write(ps_chan->l_channel_no, ps_chan->pc_io_buf+l_temp,
01634 ps_chan->l_buf_size);
01635 #endif
01636 if(l_temp2==-1)
01637 {
01638 return(PUTEVT__WRERR);
01639 }
01640 if(l_temp2!=ps_chan->l_buf_size)
01641 {
01642 return(PUTEVT__TOOBIG);
01643 }
01644 }
01645 }
01646
01647 g_close:
01648 free(ps_chan->pc_io_buf);
01649
01650
01651 #ifdef VMS
01652 l_status = i$clolf(&ps_chan->l_channel_no);
01653 l_st_ochannel[ps_chan->l_channel_no]=0;
01654 ps_chan->l_channel_no=-1;
01655 return PUTEVT__SUCCESS;
01656 #else
01657 l_status=close(ps_chan->l_channel_no);
01658 ps_chan->l_channel_no=-1;
01659 if(l_status == -1) return(PUTEVT__CLOSE_ERR);
01660 else return PUTEVT__SUCCESS;
01661 #endif
01662 }
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688 INTS4 f_evt_error( INTS4 l_error , CHARS *pc_dest , INTS4 l_out )
01689 {
01690 CHARS c_line[80];
01691
01692 switch( l_error )
01693 {
01694 case GETEVT__NOFILE :
01695 sprintf(c_line,"-I-f_evt: no such input file");
01696 break;
01697 case GETEVT__NOTAGFILE :
01698 sprintf(c_line,"-I-f_evt: no such tag file");
01699 break;
01700 case GETEVT__NOTAG :
01701 sprintf(c_line,"-I-f_evt: no such event tag");
01702 break;
01703 case GETEVT__TIMEOUT :
01704 sprintf(c_line,"-I-f_evt: time out");
01705 break;
01706 case GETEVT__NOSERVER :
01707 sprintf(c_line,"-I-f_evt: no such server");
01708 break;
01709 case GETEVT__RDERR :
01710 sprintf(c_line,"-I-f_evt: read server error");
01711 break;
01712 case GETEVT__TAGRDERR :
01713 sprintf(c_line,"-I-f_evt: read tag file error");
01714 break;
01715 case GETEVT__TAGWRERR :
01716 sprintf(c_line,"-I-f_evt: write tag file error");
01717 break;
01718 case GETEVT__FRAGMENT :
01719 sprintf(c_line,"-I-f_evt: data format error");
01720 break;
01721 case GETEVT__NOMORE :
01722 sprintf(c_line,"-I-f_evt: no more event");
01723 break;
01724 case GETEVT__CLOSE_ERR:
01725 sprintf(c_line,"-I-f_evt: close server error");
01726 break;
01727 case GETEVT__FAILURE :
01728 sprintf(c_line,"-I-f_evt: failure");
01729 break;
01730 case GETEVT__NOCHANNEL :
01731 sprintf(c_line,"-I-f_evt: too many channels");
01732 break;
01733 case GETEVT__NOLMDFILE :
01734 sprintf(c_line,"-I-f_evt: input file is no LMD file");
01735 break;
01736 case GETEVT__SUCCESS :
01737 sprintf(c_line,"-I-f_evt: success");
01738 break;
01739 case PUTEVT__FILE_EXIST :
01740 sprintf(c_line,"-I-f_evt: output file alread exist");
01741 break;
01742 case PUTEVT__WRERR :
01743 sprintf(c_line,"-I-f_evt: write file error");
01744 break;
01745 case PUTEVT__TOOBIG :
01746 sprintf(c_line,"-I-f_evt: output file too large");
01747 break;
01748 case PUTEVT__TOO_SMALLS:
01749 sprintf(c_line,"-I-f_evt: event can not fit in a stream");
01750 break;
01751 case PUTEVT__CLOSE_ERR :
01752 sprintf(c_line,"-I-f_evt: close output error");
01753 break;
01754 case PUTEVT__FAILURE :
01755 sprintf(c_line,"-I-f_evt: output failure");
01756 break;
01757 case PUTEVT__NOCHANNEL :
01758 sprintf(c_line,"-I-f_evt: too many channels");
01759 break;
01760 default :
01761 sprintf(c_line,"-I-f_evt: unknown message id %d",l_error);
01762 if(l_out==0)printf("%s\n",c_line);
01763 if(l_out==1)strcpy(pc_dest,c_line);
01764 return GETEVT__FAILURE;
01765 }
01766
01767 if(l_out==0)printf("%s\n",c_line);
01768 if(l_out==1)strcpy(pc_dest,c_line);
01769
01770 return GETEVT__SUCCESS;
01771 }
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795 INTS4 f_evt_get_buffer(s_evt_channel *ps_chan, INTS4 *ps_buffer)
01796 {
01797 INTS4 l_temp;
01798 CHARS * pc_temp;
01799 INTS4 l_status;
01800
01801 pc_temp=(CHARS *)ps_chan->pc_io_buf;
01802 switch(ps_chan->l_server_type)
01803 {
01804 case GETEVT__FILE :
01805 #ifdef VMS
01806 l_status = i$gtslf(&ps_chan->l_channel_no,&ps_buffer,&ps_chan->l_buf_size);
01807 if((l_status&1) != 1)
01808 {
01809 ps_chan->l_io_buf_size = 0;
01810 return(GETEVT__NOMORE);
01811 }
01812 ps_chan->l_io_buf_size = (INTS4) ps_chan->l_buf_size;
01813 #else
01814 l_temp=read(ps_chan->l_channel_no,ps_buffer, ps_chan->l_buf_size);
01815 if(l_temp == 0)
01816
01817 {
01818 ps_chan->l_io_buf_size = 0;
01819 return(GETEVT__NOMORE);
01820 }
01821 else if(l_temp == -1)
01822 {
01823 ps_chan->l_io_buf_size = 0;
01824 return(GETEVT__RDERR);
01825 }
01826 #endif
01827 break;
01828 case GETEVT__RFIO :
01829 l_temp=RFIO_read(ps_chan->l_channel_no,(CHARS *)ps_buffer, ps_chan->l_buf_size);
01830 if(l_temp == 0)
01831 {
01832 ps_chan->l_io_buf_size = 0;
01833 return(GETEVT__NOMORE);
01834 }
01835 else if(l_temp == -1)
01836 {
01837 ps_chan->l_io_buf_size = 0;
01838 return(GETEVT__RDERR);
01839 }
01840 break;
01841 case GETEVT__STREAM :
01842 if(ps_chan->l_stream_bufs == 0)
01843 if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
01844 {
01845 return(GETEVT__FAILURE);
01846 }
01847
01848 l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
01849 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
01850 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
01851 ps_chan->l_stream_bufs++;
01852 if(ps_chan->l_stream_bufs == ps_chan->l_bufs_in_stream)ps_chan->l_stream_bufs = 0;
01853 break;
01854 case GETEVT__TRANS :
01855 l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
01856 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
01857 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
01858 break;
01859 case GETEVT__REVSERV :
01860 case GETEVT__EVENT :
01861 default :
01862 return(GETEVT__FAILURE);
01863 }
01864
01865
01866 if( ((s_bufhe *)(ps_buffer))->l_free[0] !=1)
01867 f_evt_swap((CHARS *)ps_buffer, ps_chan->l_buf_size);
01868
01869 return(GETEVT__SUCCESS);
01870 }
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891 INTS4 f_evt_skip_buffer(s_evt_channel *ps_chan, INTS4 l_buffer)
01892 {
01893 INTS4 l_temp;
01894 CHARS * pc_temp;
01895 INTS4 l_status,ii;
01896
01897 pc_temp=(CHARS *)ps_chan->pc_io_buf;
01898 switch(ps_chan->l_server_type)
01899 {
01900 case GETEVT__FILE :
01901 #ifdef VMS
01902 for(ii=0;ii<l_buffer;ii++)
01903 {
01904 l_status = i$gtslf(&ps_chan->l_channel_no,&ps_chan->pc_io_buf,&ps_chan->l_buf_size);
01905 if((l_status&1) != 1) return(GETEVT__NOMORE);
01906 }
01907 ps_chan->l_io_buf_size = (INTS4) ps_chan->l_buf_size;
01908 #else
01909 l_temp=lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
01910 if(l_temp == -1)
01911
01912 {
01913 return(GETEVT__NOMORE);
01914 }
01915 #endif
01916 break;
01917 case GETEVT__RFIO :
01918 l_temp=RFIO_lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
01919 if(l_temp == -1)
01920 {
01921 return(GETEVT__NOMORE);
01922 }
01923 break;
01924 case GETEVT__STREAM :
01925 case GETEVT__TRANS :
01926 case GETEVT__REVSERV :
01927 case GETEVT__EVENT :
01928 default : return(GETEVT__FAILURE);
01929 }
01930
01931 ps_chan->l_first_get=1;
01932 return(GETEVT__SUCCESS);
01933 }
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955 INTS4 f_evt_timeout(s_evt_channel *ps_chan, INTS4 l_sec)
01956 {
01957 ps_chan->l_timeout = l_sec;
01958 return(GETEVT__SUCCESS);
01959 }
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975 INTS4 f_evt_swap(CHARS * pc_source, INTS4 l_length)
01976 {
01977 CHARS * p_s, * p_d;
01978 INTS4 l_save;
01979 CHARS ch_temp;
01980
01981 if(l_length%4 == 2){
01982 ch_temp=*(pc_source+l_length-2);
01983 *(pc_source+l_length-2)=*(pc_source+l_length-1);
01984 *(pc_source+l_length-1)=ch_temp;
01985 }
01986 l_length=(l_length/4)*4;
01987 for(p_d=pc_source,p_s=(CHARS *)&l_save; p_d<pc_source+l_length;)
01988 {
01989 l_save = *((INTS4 *)p_d);
01990 p_s += 4;
01991 *(p_d++) = *(--p_s);
01992 *(p_d++) = *(--p_s);
01993 *(p_d++) = *(--p_s);
01994 *(p_d++) = *(--p_s);
01995 }
01996 return(0);
01997 }
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012 INTS4 f_evt_swap_filhe(s_bufhe *ps_bufhe)
02013 {
02014 CHARS * p_s, * p_d;
02015 INTS4 ii;
02016 INTS2 *pi;
02017 s_filhe *ps_filhe;
02018
02019 f_evt_swap((CHARS *)ps_bufhe,48);
02020 if(ps_bufhe->i_type == 2000)
02021 {
02022 ps_filhe=(s_filhe *)ps_bufhe;
02023 f_evt_swap((CHARS *)&ps_filhe->filhe_lines,4);
02024 ps_filhe->filhe_label_l=ps_filhe->filhe_label_l>>8;
02025 ps_filhe->filhe_file_l =ps_filhe->filhe_file_l >>8;
02026 ps_filhe->filhe_user_l =ps_filhe->filhe_user_l >>8;
02027 ps_filhe->filhe_run_l =ps_filhe->filhe_run_l >>8;
02028 ps_filhe->filhe_exp_l =ps_filhe->filhe_exp_l >>8;
02029 pi=(INTS2 *)&ps_filhe->s_strings;
02030 for(ii=0;ii<ps_filhe->filhe_lines;ii++)
02031 {
02032 *pi=*pi>>8;
02033 pi += 40;
02034 }
02035 }
02036
02037 return(0);
02038 }
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052 CHARS * f_evt_get_buffer_ptr(s_evt_channel *ps_chan)
02053 {
02054 return(ps_chan->pc_io_buf);
02055 }
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073 INTS4 f_evt_get_newbuf(s_evt_channel *ps_chan)
02074 {
02075 INTS4 l_temp;
02076 CHARS * pc_temp;
02077 INTS4 l_status;
02078
02079 pc_temp=(CHARS *)ps_chan->pc_io_buf;
02080 switch(ps_chan->l_server_type)
02081 {
02082 case GETEVT__FILE :
02083 #ifdef VMS
02084 l_status = i$gtslf(&ps_chan->l_channel_no,&ps_chan->pc_io_buf,&ps_chan->l_buf_size);
02085 if((l_status&1) != 1)
02086 {
02087 ps_chan->l_io_buf_size = 0;
02088 return(GETEVT__NOMORE);
02089 }
02090 ps_chan->l_io_buf_size = (INTS4) ps_chan->l_buf_size;
02091 #else
02092 while(1){
02093 l_temp=read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
02094 if(l_temp == 0) return(GETEVT__NOMORE);
02095 if(l_temp == -1) return(GETEVT__RDERR);
02096 if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
02097 break;
02098 }
02099 #endif
02100 break;
02101 case GETEVT__STREAM :
02102 if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
02103 {
02104 return(GETEVT__FAILURE);
02105 }
02106
02107 for(l_temp=0; l_temp<ps_chan->l_bufs_in_stream; l_temp++)
02108 {
02109 l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
02110 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
02111 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
02112 pc_temp+=ps_chan->l_buf_size;
02113 }
02114
02115 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_evt == 0) {printf("empy stream\n");return(GETEVT__TIMEOUT);}
02116 break;
02117 case GETEVT__TRANS :
02118 l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
02119 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
02120 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
02121 break;
02122 case GETEVT__RFIO :
02123 l_temp=RFIO_read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
02124 if(l_temp == 0) return(GETEVT__NOMORE);
02125 if(l_temp == -1) return(GETEVT__RDERR);
02126 if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
02127 break;
02128 case GETEVT__REVSERV :
02129 case GETEVT__EVENT :
02130 default :
02131 return(GETEVT__FAILURE);
02132 }
02133
02134
02135 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1)
02136 f_evt_swap(ps_chan->pc_io_buf, ps_chan->l_io_buf_size);
02137
02138 return(GETEVT__SUCCESS);
02139 }
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160 INTS4 f_evt_check_buf(CHARS *pc_head, INTS4 *pl_size, INTS4 *pl_is_goosybuf, INTS4 *pl_swap, INTS4 *pl_filehead)
02161 {
02162 INTU4 l_size;
02163
02164 *pl_is_goosybuf=0;
02165 *pl_filehead=0;
02166 *pl_size=0;
02167 *pl_swap=0;
02168
02169 if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
02170 (((s_filhe *)(pc_head))->filhe_type==2000) )
02171 {
02172 *pl_swap=0;
02173 *pl_is_goosybuf=0;
02174 *pl_filehead=1;
02175 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02176 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02177 if((l_size>>24) > 0) *pl_size=0;
02178 else *pl_size=l_size;
02179 return(PUTEVT__SUCCESS);
02180 }
02181 f_evt_swap(pc_head, sizeof(s_filhe));
02182 if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
02183 (((s_filhe *)(pc_head))->filhe_type==2000) )
02184 {
02185 *pl_swap=1;
02186 *pl_is_goosybuf=0;
02187 *pl_filehead=1;
02188 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02189 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02190 if((l_size>>24) > 0) *pl_size=0;
02191 else *pl_size=l_size;
02192 return(PUTEVT__SUCCESS);
02193 }
02194
02195
02196 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02197 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02198 if( (((l_size>>24)== 0)&&(l_size > 0))&&
02199 (((s_bufhe *)(pc_head))->h_begin<2)&&
02200 (((s_bufhe *)(pc_head))->h_begin>=0)&&
02201 (((s_bufhe *)(pc_head))->h_end<2)&&
02202 (((s_bufhe *)(pc_head))->h_end>=0)&&
02203
02204 ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
02205
02206 ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
02207 (((s_bufhe *)(pc_head))->l_free[0]==0)||
02208
02209 (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
02210 {
02211 *pl_swap=1;
02212 *pl_is_goosybuf=1;
02213 *pl_size=l_size;
02214 return(PUTEVT__SUCCESS);
02215 }
02216 f_evt_swap(pc_head, sizeof(s_filhe));
02217 l_size=((s_bufhe *)(pc_head))->l_dlen*2+sizeof(s_bufhe);
02218 if( (((l_size>>24)== 0)&&(l_size > 0))&&
02219 (((s_bufhe *)(pc_head))->l_dlen>0)&&
02220 (((s_bufhe *)(pc_head))->h_begin<2)&&
02221 (((s_bufhe *)(pc_head))->h_begin>=0)&&
02222 (((s_bufhe *)(pc_head))->h_end<2)&&
02223 (((s_bufhe *)(pc_head))->h_end>=0)&&
02224
02225 ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
02226
02227 ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
02228 (((s_bufhe *)(pc_head))->l_free[0]==0)||
02229
02230 (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
02231 {
02232 *pl_swap=0;
02233 *pl_is_goosybuf=1;
02234 *pl_size=l_size;
02235 return(PUTEVT__SUCCESS);
02236 }
02237 return(PUTEVT__SUCCESS);
02238 }
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251 INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan)
02252 {
02253 INTS4 l_temp;
02254 struct timeb s_timeb;
02255
02256
02257
02258 for(l_temp=0; l_temp<ps_chan->l_io_buf_size; l_temp += ps_chan->l_buf_size)
02259 {
02260 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
02261 ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
02262 ps_chan->ps_bufhe->i_subtype = ps_chan->l_buf_subtype;
02263 ps_chan->ps_bufhe->i_type = ps_chan->l_buf_type;
02264 ps_chan->ps_bufhe->h_begin = 0;
02265 ps_chan->ps_bufhe->h_end = 0;
02266 ps_chan->ps_bufhe->i_used = 0;
02267 ps_chan->ps_bufhe->l_buf = ps_chan->l_buf_no; ps_chan->l_buf_no++;
02268 ps_chan->ps_bufhe->l_evt = 0;
02269 ps_chan->ps_bufhe->l_current_i = 0;
02270 ftime(&s_timeb);
02271 ps_chan->ps_bufhe->l_time[0]=(INTS4)s_timeb.time;
02272 ps_chan->ps_bufhe->l_time[1]=(INTS4)s_timeb.millitm;
02273 ps_chan->ps_bufhe->l_free[0] = 1;
02274 ps_chan->ps_bufhe->l_free[1] = 0;
02275 ps_chan->ps_bufhe->l_free[2] = 0;
02276 ps_chan->ps_bufhe->l_free[3] = 0;
02277 }
02278 return(PUTEVT__SUCCESS);
02279 }
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307 INTS4 f_evt_tag_filter(s_ve10_1 *ps_ve10_1)
02308 {
02309
02310 return(1);
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324 }
02325 INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag,INTS4 (*e_filter)())
02326 {
02327 INTS4 ii,l_take_it,l_temp,l_chan,l_out,l_file_pos=0,l_bufnr=0,l_events=0;
02328 INTS4 l_firste,*pl,l_len,l_last=-1,l_lin=0,l_fragsize, la_head[2];
02329 INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_evsize,l_evt_buf_size=0;
02330 INTS2 *pi;
02331 INTU4 *ps,*pd;
02332 CHARS c_lmd[128], c_tag[128], *pc_temp,*pc_evt_buf=NULL;
02333 s_ve10_1 *ps_ve10_1;
02334 s_bufhe *ps_bufhe;
02335 s_taghe s_taghe;
02336 s_tag s_tag;
02337
02338 ps_bufhe = (s_bufhe *)c_temp;
02339 printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
02340
02341 if((l_chan=open(pc_lmd,GET__OPEN_FLAG))== -1) return(GETEVT__NOFILE);
02342
02343 if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
02344 {
02345 close(l_chan);
02346 return(GETEVT__RDERR);
02347 }
02348
02349 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
02350 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
02351 {
02352 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
02353 close(l_chan);
02354 return(GETEVT__NOLMDFILE);
02355 }
02356
02357 if(l_filehead == 1)
02358 {
02359 lseek(l_chan, 0, SEEK_SET);
02360 if(read(l_chan,c_temp,l_size_head)!=l_size_head)
02361 {
02362 close(l_chan);
02363 return(GETEVT__RDERR);
02364 }
02365 if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
02366 {
02367 close(l_chan);
02368 return(GETEVT__RDERR);
02369 }
02370 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
02371 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
02372 {
02373 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
02374 close(l_chan);
02375 return(GETEVT__NOLMDFILE);
02376 }
02377 }
02378
02379 lseek(l_chan, 0, SEEK_SET);
02380
02381 printf("Buffer swap %d, File header %d, LMD buffer %d, size %d[b]\n",l_swap,l_filehead,l_is_goosybuf,l_size);
02382
02383
02384 if(l_filehead == 1)
02385 {
02386 if(read(l_chan,c_temp,l_size)!=l_size)
02387 {
02388 close(l_chan);
02389 return(GETEVT__RDERR);
02390 }
02391 l_file_pos += l_size;
02392 l_bufnr++;
02393 }
02394
02395
02396 if((l_out=open(pc_tag,PUT__CRT_FLAG,DEF_FILE_ACCE))== -1) return(GETEVT__NOFILE);
02397 write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe));
02398
02399
02400 if(e_filter != NULL) ii=(*e_filter)(NULL);
02401
02402 while(read(l_chan,c_temp,l_size)==l_size)
02403 {
02404 l_file_pos=l_bufnr*l_size;
02405 if(l_swap) f_evt_swap(c_temp,l_size);
02406 if((ps_bufhe->h_end)&(ps_bufhe->h_begin)&(ps_bufhe->l_evt==1))
02407 {
02408
02409
02410 l_bufnr++;
02411 continue;
02412 }
02413 ps_ve10_1=(s_ve10_1 *)(ps_bufhe + 1);
02414 pl = (INTS4 *)ps_ve10_1;
02415 l_file_pos += sizeof(s_bufhe);
02416
02417 if(ps_bufhe->h_end)
02418 {
02419 l_len = (*pl>>1)+2;
02420 l_file_pos += (l_len<<2);
02421 ps_ve10_1=(s_ve10_1 *)(pl+l_len);
02422 pl = (INTS4 *)ps_ve10_1;
02423 ps_bufhe->l_evt--;
02424
02425 }
02426 for(ii=1;ii<ps_bufhe->l_evt;ii++)
02427 {
02428
02429 if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
02430 else l_take_it=1;
02431 l_len = (*pl>>1)+2;
02432 s_tag.l_event=ps_ve10_1->l_count;
02433 s_tag.l_offset=l_file_pos;
02434 if(l_take_it)
02435 {
02436 l_events++;
02437 if(ps_ve10_1->l_count != (l_last+1))
02438 {
02439 l_lin++;
02440 if(l_lin == 1)l_firste=ps_ve10_1->l_count;
02441
02442 }
02443 l_last=ps_ve10_1->l_count;
02444 if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
02445 {
02446 close(l_chan);
02447 close(l_out);
02448 return(GETEVT__TAGWRERR);
02449 }
02450 }
02451 l_file_pos += (l_len<<2);
02452 ps_ve10_1=(s_ve10_1 *)(pl+l_len);
02453 pl = (INTS4 *)ps_ve10_1;
02454 }
02455
02456 if(ps_bufhe->l_evt > 0)
02457 {
02458 if(ps_ve10_1->l_dlen < 4) printf("Buffer %d Event fragment %10d dlen %d ts %d %d trigger %d\n"
02459 ,l_bufnr,ps_ve10_1->l_count,ps_ve10_1->l_dlen,ps_ve10_1->i_type,
02460 ps_ve10_1->i_subtype,ps_ve10_1->i_trigger);
02461 s_tag.l_event=ps_ve10_1->l_count;
02462 if(ps_bufhe->h_begin)
02463 {
02464
02465 if(e_filter != NULL)
02466 {
02467
02468 l_evsize=ps_bufhe->l_free[1]+4;
02469 if(l_evt_buf_size < l_evsize*2)
02470 {
02471 if(pc_evt_buf != NULL)free(pc_evt_buf);
02472 l_evt_buf_size=l_evsize*2;
02473 pc_evt_buf=(CHARS *)malloc(l_evt_buf_size);
02474 }
02475
02476 ps=(INTU4 *)ps_ve10_1;
02477 pd=(INTU4 *)pc_evt_buf;
02478 l_fragsize = ps_ve10_1->l_dlen+4;
02479 for(ii=0;ii<l_fragsize/2;ii++) *pd++ = *ps++;
02480
02481 while(l_fragsize < l_evsize)
02482 {
02483 if(read(l_chan,c_temp,l_size) != l_size)break;
02484 l_bufnr++;
02485 if(l_swap) f_evt_swap(c_temp,l_size);
02486 ps = (INTU4 *) (ps_bufhe+1);
02487 l_temp=(INTS4)*ps;
02488 ps += 2;
02489 for(ii=0;ii<l_temp/2;ii++) *pd++ = *ps++;
02490 l_fragsize += l_temp;
02491 }
02492 if(l_fragsize < l_evsize)break;
02493 ps_ve10_1 = (s_ve10_1 *)pc_evt_buf;
02494 ps_ve10_1->l_dlen=l_evsize-4;
02495
02496 l_bufnr--;
02497 lseek(l_chan, -l_size, SEEK_CUR);
02498 }
02499 s_tag.l_offset=-l_file_pos;
02500
02501 }
02502 else
02503 {
02504 s_tag.l_offset=l_file_pos;
02505
02506 }
02507 if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
02508 else l_take_it=1;
02509 if(l_take_it)
02510 {
02511 l_events++;
02512 if(ps_ve10_1->l_count != (l_last+1))
02513 {
02514 l_lin++;
02515 if(l_lin == 1)l_firste=ps_ve10_1->l_count;
02516
02517 }
02518 l_last=ps_ve10_1->l_count;
02519 if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
02520 {
02521 close(l_chan);
02522 close(l_out);
02523 return(GETEVT__TAGWRERR);
02524 }
02525 }
02526 }
02527 l_bufnr++;
02528
02529 }
02530 lseek(l_out, 0, SEEK_SET);
02531 s_taghe.l_endian = 1;
02532 s_taghe.l_version = 1;
02533 s_taghe.l_bufsize = l_size;
02534 s_taghe.l_buffers = l_bufnr;
02535 s_taghe.l_events = l_events;
02536 s_taghe.l_filesize = sizeof(s_tag)*l_events;
02537 s_taghe.l_linear = (l_lin == 1);
02538 s_taghe.l_first = l_firste;
02539 s_taghe.l_last = s_tag.l_event;
02540 if(write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe)) != sizeof(s_taghe))
02541 {
02542 close(l_chan);
02543 close(l_out);
02544 return(GETEVT__TAGWRERR);
02545 }
02546 close(l_chan);
02547 close(l_out);
02548 printf("Buffers %6d, of size %d, Events %10d, first %d, last %d "
02549 ,s_taghe.l_buffers
02550 ,s_taghe.l_bufsize
02551 ,s_taghe.l_events
02552 ,s_taghe.l_first
02553 ,s_taghe.l_last);
02554 if(s_taghe.l_linear)printf("linear\n");
02555 else printf("not linear\n");
02556
02557 return(GETEVT__SUCCESS);
02558 }
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587 INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan,CHARS *pc_tag,CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
02588 {
02589 INTS4 l_temp,ii;
02590 s_bufhe *ps_bufhe;
02591
02592 ps_chan->ps_tag = NULL;
02593 ps_chan->ps_taghe = NULL;
02594 if(l_prihe)printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
02595
02596 if((ps_chan->l_tagfile_no=open(pc_tag,GET__OPEN_FLAG))== -1)
02597 {
02598
02599
02600 ii=f_evt_get_open(GETEVT__FILE, pc_lmd, ps_chan, (CHARS **) &ps_bufhe,0,0);
02601 *ps_head = (CHARS *) ps_bufhe;
02602 if(ii!=GETEVT__SUCCESS)
02603 {
02604 printf("Error opening input file %s\n",pc_lmd);
02605 return (ii);
02606 }
02607
02608 if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
02609 return(GETEVT__SUCCESS);
02610 }
02611
02612
02613 ps_chan->ps_taghe = (s_taghe *)malloc(sizeof(s_taghe));
02614 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_taghe,sizeof(s_taghe))!=sizeof(s_taghe))
02615 {
02616 free(ps_chan->ps_taghe);
02617 ps_chan->ps_taghe = NULL;
02618 close(ps_chan->l_tagfile_no);
02619 return(GETEVT__TAGRDERR);
02620 }
02621 if(ps_chan->ps_taghe->l_endian != 1)ps_chan->l_tagswap=1;
02622 if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_chan->ps_taghe,sizeof(s_taghe));
02623 if(l_prihe)
02624 {
02625 printf("Buffers %6d, of size %d, Events %10d, first %d, last %d"
02626 ,ps_chan->ps_taghe->l_buffers
02627 ,ps_chan->ps_taghe->l_bufsize
02628 ,ps_chan->ps_taghe->l_events
02629 ,ps_chan->ps_taghe->l_first
02630 ,ps_chan->ps_taghe->l_last);
02631 if(ps_chan->ps_taghe->l_linear)printf(" linear\n");
02632 else printf(" not linear\n");
02633 }
02634 if((ps_chan->l_channel_no=open(pc_lmd,GET__OPEN_FLAG))== -1)
02635 {
02636 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02637 ps_chan->ps_taghe = NULL;
02638 close(ps_chan->l_tagfile_no);
02639 return(GETEVT__NOFILE);
02640 }
02641
02642 ps_bufhe = (s_bufhe *)c_temp;
02643 if(read(ps_chan->l_channel_no,c_temp,ps_chan->ps_taghe->l_bufsize)!=ps_chan->ps_taghe->l_bufsize)
02644 {
02645 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02646 ps_chan->ps_taghe = NULL;
02647 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02648 ps_chan->ps_tag = NULL;
02649 close(ps_chan->l_tagfile_no);
02650 close(ps_chan->l_channel_no);
02651 return(GETEVT__RDERR);
02652 }
02653 if(ps_chan->ps_taghe->l_linear == 0)
02654 {
02655 ps_chan->ps_tag = (s_tag *)malloc(ps_chan->ps_taghe->l_filesize);
02656 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_tag,ps_chan->ps_taghe->l_filesize)!=ps_chan->ps_taghe->l_filesize)
02657 {
02658 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02659 ps_chan->ps_taghe = NULL;
02660 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02661 ps_chan->ps_tag = NULL;
02662 close(ps_chan->l_tagfile_no);
02663 close(ps_chan->l_channel_no);
02664 return(GETEVT__TAGRDERR);
02665 }
02666 }
02667 if(ps_bufhe->l_free[0] != 1)ps_chan->l_lmdswap=1;
02668 if(ps_chan->l_lmdswap)f_evt_swap_filhe(ps_bufhe);
02669 if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
02670 if(ps_head != NULL)
02671 {
02672 if(ps_bufhe->i_type == 2000) *ps_head = (CHARS *)ps_bufhe;
02673 }
02674 ps_chan->l_evt_buf_size=0;
02675 ps_chan->pc_evt_buf=NULL;
02676 ps_chan->l_io_buf_posi=0;
02677 return(GETEVT__SUCCESS);
02678 }
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704 INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan,INTS4 l_skip, INTS4 **pl_event)
02705 {
02706 INTS4 ii,*pl,kk;
02707
02708
02709 if(ps_chan->ps_taghe == NULL)
02710 {
02711 for(kk=0;kk<=l_skip;kk++)
02712 {
02713 ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
02714 if(ii != GETEVT__SUCCESS) break;
02715 }
02716 }
02717
02718 else
02719 {
02720
02721 ii=f_evt_get_tagevent(ps_chan,ps_chan->l_io_buf_posi+l_skip+1,1,(INTS4 **)&pl);
02722 }
02723 if(pl_event != NULL) *pl_event=pl;
02724 return(ii);
02725 }
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753 INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan,INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
02754 {
02755 INTS4 l_temp,l_chan,l_tag,ii,kk,lb,l_tagbufs,l_tagrest,l_evt,l_off,l_typ,l_val,l_evsize,l_fragsize;
02756 INTS4 la_head[2],*pl;
02757 CHARS *pc;
02758 s_ve10_1 *ps_ve10_1;
02759 s_bufhe *ps_bufhe;
02760 s_tag *ps_tag;
02761 s_tag s_tag_l;
02762 s_filhe *ps_filhe;
02763 s_evt_channel s_chan_i;
02764
02765 l_typ=l_type;
02766 l_val=l_value;
02767
02768
02769 if(ps_chan->ps_taghe == NULL)
02770 {
02771
02772 if(l_type == 1)
02773 {
02774 if(l_val == 0) l_val=1;
02775 for(kk=0;kk<l_val;kk++)
02776 {
02777 ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
02778 if(ii != GETEVT__SUCCESS)return(ii);
02779 }
02780 *pl_event=pl;
02781 }
02782 else
02783 {
02784 ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
02785 if(ii != GETEVT__SUCCESS)return(ii);
02786 while(ps_ve10_1->l_count != l_val)
02787 {
02788 ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
02789 if(ii != GETEVT__SUCCESS)return(ii);
02790 }
02791 *pl_event = (INTS4 *)ps_ve10_1;
02792 }
02793 return(GETEVT__SUCCESS);
02794 }
02795
02796 ps_ve10_1 = (s_ve10_1 *)c_temp;
02797 ps_bufhe = (s_bufhe *)c_temp;
02798
02799
02800
02801 if(ps_chan->ps_taghe->l_linear)
02802 {
02803 if(l_typ == 0)l_val=l_value-ps_chan->ps_taghe->l_first+1;
02804 l_typ=1;
02805 }
02806
02807 if(l_typ == 1)
02808 {
02809 if(l_val > ps_chan->ps_taghe->l_events)
02810 {
02811 printf("Event index %d not found\n",l_val);
02812 return(GETEVT__NOTAG);
02813 }
02814 if(l_val == 0) l_val=1;
02815 ps_tag=(s_tag *)&s_tag_l;
02816 lseek(ps_chan->l_tagfile_no, (l_val-1)*sizeof(s_tag)+sizeof(s_taghe), SEEK_SET);
02817 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_tag,sizeof(s_tag))!=sizeof(s_tag))
02818 {
02819 return(GETEVT__TAGRDERR);
02820 }
02821 if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_tag,sizeof(s_tag));
02822 ps_chan->l_io_buf_posi=l_val;
02823 }
02824 else
02825 {
02826 ps_tag=ps_chan->ps_tag;
02827 for(ii=1;ii<=ps_chan->ps_taghe->l_events;ii++)
02828 {
02829 if(ps_tag->l_event == l_val) break;
02830 ps_tag++;
02831 }
02832 if(ps_tag->l_event != l_val)
02833 {
02834 printf("Event number %d not found\n",l_val);
02835 return(GETEVT__NOTAG);
02836 }
02837 ps_chan->l_io_buf_posi=ii;
02838 }
02839
02840 l_off=ps_tag->l_offset;
02841 if(l_off < 0) l_off=((-l_off)/ps_chan->ps_taghe->l_bufsize)*ps_chan->ps_taghe->l_bufsize;
02842 l_evt=ps_tag->l_event;
02843
02844 if(ps_tag->l_offset > 0)
02845 {
02846 ps_ve10_1 = (s_ve10_1 *)c_temp;
02847 lseek(ps_chan->l_channel_no, l_off, SEEK_SET);
02848 if(read(ps_chan->l_channel_no,c_temp,8)!=8) return(GETEVT__RDERR);
02849 if(ps_chan->l_lmdswap)f_evt_swap(c_temp,8);
02850 if(read(ps_chan->l_channel_no,(CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
02851 if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2);
02852
02853 }
02854 else
02855
02856 {
02857 lseek(ps_chan->l_channel_no, l_off, SEEK_SET);
02858 if(read(ps_chan->l_channel_no,c_temp,sizeof(s_bufhe))!=sizeof(s_bufhe)) return(GETEVT__RDERR);
02859 if(ps_chan->l_lmdswap)f_evt_swap(c_temp,sizeof(s_bufhe));
02860
02861 l_evsize=ps_bufhe->l_free[1]+4;
02862 if(ps_chan->l_evt_buf_size < l_evsize*2)
02863 {
02864 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
02865 ps_chan->l_evt_buf_size=l_evsize*2;
02866 ps_chan->pc_evt_buf=(CHARS *)malloc(ps_chan->l_evt_buf_size);
02867 }
02868 l_fragsize=0;
02869 ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
02870 lseek(ps_chan->l_channel_no, -ps_tag->l_offset, SEEK_SET);
02871 if(read(ps_chan->l_channel_no,ps_chan->pc_evt_buf,8)!=8) return(GETEVT__RDERR);
02872 if(ps_chan->l_lmdswap)f_evt_swap(ps_chan->pc_evt_buf,8);
02873 pc=ps_chan->pc_evt_buf+8;
02874
02875 if(read(ps_chan->l_channel_no,pc,ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
02876 l_fragsize += ps_ve10_1->l_dlen+4;
02877 pc += ps_ve10_1->l_dlen*2;
02878 ps_ve10_1->l_dlen=l_evsize-4;
02879
02880 while(l_fragsize < l_evsize)
02881 {
02882 l_off += ps_chan->ps_taghe->l_bufsize;
02883 lseek(ps_chan->l_channel_no,l_off+sizeof(s_bufhe), SEEK_SET);
02884 if(read(ps_chan->l_channel_no,(CHARS *)&la_head,8)!=8) return(GETEVT__RDERR);
02885 if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&la_head,8);
02886 if(read(ps_chan->l_channel_no,pc,la_head[0]*2)!=la_head[0]*2) return(GETEVT__RDERR);
02887 pc += la_head[0]*2;
02888 l_fragsize += la_head[0];
02889 }
02890
02891 pc=ps_chan->pc_evt_buf+8;
02892 ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
02893 if(ps_chan->l_lmdswap)f_evt_swap(pc,ps_ve10_1->l_dlen*2);
02894 }
02895 *pl_event = (INTS4 *)ps_ve10_1;
02896 return(GETEVT__SUCCESS);
02897 }
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913 INTS4 f_evt_get_tagclose(s_evt_channel *ps_chan)
02914 {
02915
02916 if(ps_chan->ps_taghe == NULL)
02917 {
02918 f_evt_get_close(ps_chan);
02919 return(GETEVT__SUCCESS);
02920 }
02921
02922 free(ps_chan->ps_taghe);
02923 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02924 if(ps_chan->pc_evt_buf != NULL) free(ps_chan->pc_evt_buf);
02925 close(ps_chan->l_tagfile_no);
02926 close(ps_chan->l_channel_no);
02927 memset((void *)ps_chan, 0, sizeof(s_evt_channel));
02928 return(GETEVT__SUCCESS);
02929 }
02930 s_evt_channel *f_evt_control(){
02931 s_evt_channel *x;
02932 x=(s_evt_channel *)malloc(sizeof(s_evt_channel));
02933 memset(x,0,sizeof(s_evt_channel));
02934 return(x);
02935 }
02936
02937