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