GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_evt.c
Go to the documentation of this file.
1 // $Id: f_evt.c 795 2011-09-06 17:42:19Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 #include "f_stccomm.h"
16 
17 
18 
19 #ifdef GSI__LYNX
20 #undef unix
21 #endif
22 
23 #ifdef GSI__LINUX /* Linux */
24 #undef unix
25 #endif
26 
27 #ifdef GSI__SOLARIS /* Solaris */
28 #undef unix
29 #endif
30 
31 #ifdef GSI__WINNT /* Windows NT */
32 #endif
33 
34 #ifdef GSI__AIX
35 #define AIX_DEC
36 #endif
37 
38 #ifdef unix /* DEC OSF/1 */
39 #define AIX_DEC
40 #endif
41 
42 #ifdef GSI__WINNT
43 #include <time.h>
44 #include <memory.h>
45 #include <sys/timeb.h>
46 #include <sys/types.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <fcntl.h>
50 #include <string.h>
51 #include <sys/stat.h>
52 #include <fcntl.h>
53 #define DEF_FILE_ACCE S_IREAD|S_IWRITE /* rw */
54 #define GET__OPEN_FLAG O_RDONLY|O_BINARY
55 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
56 #define PUT__CRT_FLAG O_CREAT|O_RDWR
57 #define PUT__CRT_OPT ""
58 
59 #include <winsock.h>
60 #define WS_VERSION_REQD 0x0101
61 #define WS_VERSION_MAJOR HIBYTE(WS_VERSION_REQD)
62 #define WS_VERSION_MINOR LOBYTE(WS_VERSION_REQD)
63 #define MIN_SOCKETS_REQD 6
64 // WSADATA wsaData;
65 #endif
66 
67 #ifdef Linux /* Linux */
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include <fcntl.h>
71 #include <string.h>
72 #include <unistd.h>
73 #include <memory.h>
74 #include <pwd.h>
75 #include <sys/time.h>
76 #include <sys/timeb.h>
77 #include <sys/types.h>
78 #include <sys/stat.h>
79 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
80 #define GET__OPEN_FLAG O_RDONLY
81 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
82 #define PUT__CRT_FLAG O_CREAT|O_RDWR
83 #define PUT__CRT_OPT ""
84 #endif
85 
86 #ifdef Solaris /* Linux */
87 #include <stdio.h>
88 #include <stdlib.h>
89 #include <fcntl.h>
90 #include <string.h>
91 #include <unistd.h>
92 #include <memory.h>
93 #include <pwd.h>
94 #include <sys/time.h>
95 #include <sys/timeb.h>
96 #include <sys/types.h>
97 #include <sys/stat.h>
98 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
99 #define GET__OPEN_FLAG O_RDONLY
100 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
101 #define PUT__CRT_FLAG O_CREAT|O_RDWR
102 #define PUT__CRT_OPT ""
103 #endif
104 
105 #ifdef Darwin /* MaxOS X */
106 #include <stdio.h>
107 #include <stdlib.h>
108 #include <fcntl.h>
109 #include <string.h>
110 #include <unistd.h>
111 #include <memory.h>
112 #include <pwd.h>
113 #include <sys/time.h>
114 #include <sys/timeb.h>
115 #include <sys/types.h>
116 #include <sys/stat.h>
117 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
118 #define GET__OPEN_FLAG O_RDONLY
119 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
120 #define PUT__CRT_FLAG O_CREAT|O_RDWR
121 #define PUT__CRT_OPT ""
122 #endif
123 
124 
125 
126 #ifdef _AIX
127 #include <stdio.h>
128 #include <stdlib.h>
129 #include <fcntl.h>
130 #include <string.h>
131 #include <unistd.h>
132 #include <memory.h>
133 #include <pwd.h>
134 #include <sys/time.h>
135 #include <sys/timeb.h>
136 #include <sys/types.h>
137 #include <sys/mode.h>
138 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
139 #define GET__OPEN_FLAG O_RDONLY
140 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
141 #define PUT__CRT_FLAG O_CREAT|O_RDWR
142 #define PUT__CRT_OPT ""
143 #endif
144 
145 #if MBS_ENDIAN == 1
146 #include "s_filhe_swap.h"
147 #else
148 #include "s_filhe.h"
149 #endif
150 
151 
152 #ifdef RFIO
153 #define RFIO_open rfio_open
154 #define RFIO_close rfio_close
155 #define RFIO_read rfio_read
156 #define RFIO_lseek rfio_lseek
157 #include "rawapin.h" /* RFIO stuff */
158 #else
159 #define RFIO_open open
160 #define RFIO_close close
161 #define RFIO_read read
162 #define RFIO_lseek lseek
163 #endif
164 
165 
166 
167 // DABC
168 #include "fLmd.h"
169 // -- DABC
170 
171 #include "gps_sc_def.h"
172 #include "f_evt.h"
173 #include "f_evcli.h"
174 #include "portnum_def.h"
175 
181 
184 static int l_gl_source_port = 0;
185 static int l_gl_evt_check = 0;
186 
187 /*1+ C Procedure *************+****************************************/
188 /* */
189 /*+ Module : f_evt__example */
190 /* */
191 /*--------------------------------------------------------------------*/
192 /*+ CALLING : Examples for calling event API */
193 /*--------------------------------------------------------------------*/
194 /* */
195 /*+ PURPOSE : See f_evt_examples.c */
196 /* */
197 /* */
198 /*2+Implementation************+****************************************/
199 /*+ User Example : In m_lea_user.c */
200 /*+ Channel structure : defined in f_evt.h */
201 /*+ File name : f_evt.c */
202 /*+ Version : 1.01 */
203 /*+ Author : H.Essel */
204 /*+ Created : 16-Feb-2000 */
205 /*+ Updates : Date Purpose */
206 /*1- C Procedure *************+****************************************/
207 
208 
209 /*****************+***********+****************************************/
210 /* */
211 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
212 /* Postfach 11 05 52 */
213 /* D-64220 Darmstadt */
214 /* */
215 /*1+ C Procedure *************+****************************************/
216 /* */
217 /*+ Module : f_evt_get_subevent */
218 /* */
219 /*--------------------------------------------------------------------*/
220 /*+ CALLING : l_sts = f_evt_get_subevent(ve10_1 *,subevent,**head,**data,*lwords) */
221 /*--------------------------------------------------------------------*/
222 /* */
223 /*+ PURPOSE : get subevent pointer */
224 /* */
225 /*+ ARGUMENTS : */
226 /* */
227 /*+ ve10_1 : (s_ve10_1 *) event header pointer */
228 /*+ subevent : subevent number (1,2,3...) */
229 /* If = 0, f_evt_get_subevent returns the number of */
230 /* subevents. In this case the following arguments */
231 /* might be NULL. */
232 /*+ head : Address of s_ves10_1 subevent header pointer */
233 /*+ data : Address of INTS4 event data pointer */
234 /*+ lwords : Address of INTS4 to get number of data longwords */
235 /* */
236 /*+ Return type : int */
237 /*- GETEVT__SUCCESS : Found subevent. */
238 /*- GETEVT__NOMORE : No more subevents. */
239 /*+ Declaration : */
240 /* INTS4 f_evt_get_subevent( */
241 /* s_ve10_1 *, INTS4, INTS4 **, INTS4 **, INTS4 *); */
242 /*1- C Procedure *************+****************************************/
243 INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d,INTS4 *pl_lwords)
244 {
245  s_ves10_1 *ps_ves10_1;
246  INTS4 l_total,l_sub,l_sum;
247  INTS4 l,ll,l_status,*pl_next;
248 
249  if(ps_ve10_1 == NULL) return(GETEVT__FAILURE);
250  pl_next = (INTS4 *) (ps_ve10_1 + 1);
251  l_total = ps_ve10_1->l_dlen-4; /* total words in subevents */
252  l_sum = 0;
253  ll=0;
254  while(l_sum < l_total)
255  {
256  ps_ves10_1 = (s_ves10_1 *) pl_next;
257  ll++;
258  if(ll == l_subevent)
259  {
260  if(pl_lwords != NULL) *pl_lwords = ps_ves10_1->l_dlen/2-1;
261  if(pl_se != NULL) *pl_se = (INTS4 *) ps_ves10_1;
262  if(pl_d != NULL) *pl_d = (INTS4 *) (ps_ves10_1+1);
263  return(GETEVT__SUCCESS);
264  }
265  l_sub = ps_ves10_1->l_dlen+4; /* total words of subevent */
266  l_sum += l_sub;
267  pl_next = (INTS4 *)(ps_ves10_1);
268  pl_next += l_sub/2;
269  }
270  if(pl_lwords != NULL) *pl_lwords = ll;
271  if(pl_se != NULL) *pl_se = NULL;
272  if(pl_d != NULL) *pl_d = NULL;
273  if(l_subevent == 0) return(ll);
274  else return(GETEVT__NOMORE);
275 }
276 /*****************+***********+****************************************/
277 /* */
278 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
279 /* Postfach 11 05 52 */
280 /* D-64220 Darmstadt */
281 /* */
282 /*1+ C Procedure *************+****************************************/
283 /* */
284 /*+ Module : f_evt_type */
285 /* */
286 /*--------------------------------------------------------------------*/
287 /*+ CALLING : l_status = f_evt_type(bufhe,evhe,sid,long,hex,data) */
288 /*--------------------------------------------------------------------*/
289 /* */
290 /*+ PURPOSE : print event */
291 /* */
292 /*+ ARGUMENTS : */
293 /* */
294 /*+ bufhe : (s_bufhe *) buffer header pointer (=NULL no output) */
295 /*+ evhe : (s_evhe *) event header pointer (=NULL no output) */
296 /*+ sid : subevent ID (-1 is all) */
297 /*+ long : output longwords */
298 /*+ hex : output hex longwords */
299 /*+ data : output data */
300 /* */
301 /*+ Return type : int */
302 /*+ Declaration : */
303 /* INTS4 f_evt_type( */
304 /* s_bufhe *,s_evhe *, INTS4, INTS4, INTS4, INTS4); */
305 /*1- C Procedure *************+****************************************/
306 INTS4 f_evt_type(s_bufhe *ps_bufhe,s_evhe *ps_evhe, INTS4 l_subid,INTS4 l_long,INTS4 l_hex,INTS4 l_data)
307 {
308  s_ves10_1 *ps_ves10_1;
309  s_ve10_1 *ps_ve10_1;
310  s_filhe *ps_filhe;
311  INTS2 *pi_data;
312  INTS4 *pl_data;
313  INTS4 l_mode,l_s;
314  INTS4 l,ll,l_status,l_ldata,l_used;
315  CHARS c_line[132];
316  CHARS c_full[132];
317  CHARS c_time[32];
318 
319  strcpy(c_full," ");
320  l_ldata=l_data;
321  if((l_hex+l_long) > 0) l_ldata=1;
322 
323  /* Print buffer header (file header) */
324  if(ps_bufhe != NULL)
325  {
326  sprintf(c_line,"--------------------------------------------------------");
327  printf("%s\n",c_line);
328  /* calculate real buffer size */
329  ll=ps_bufhe->l_dlen*2;
330  if(ll%512 > 0)ll += 512-ll%512;
331  /* file header */
332  l_status = f_ut_utime(ps_bufhe->l_time[0],ps_bufhe->l_time[1],c_time);
333  if(ps_bufhe->i_type == 2000)
334  {
335  ps_filhe=(s_filhe *)ps_bufhe;
336  sprintf(c_line,"File header info:");
337  printf("%s\n",c_line);
338  sprintf(c_line,"Size: %d [%d b], used %d [b]",ps_filhe->filhe_dlen,ll,ps_filhe->filhe_used*2);
339  printf("%s\n",c_line);
340  sprintf(c_line,"Label: %s",ps_filhe->filhe_label);
341  printf("%s\n",c_line);
342  sprintf(c_line,"File: %s",ps_filhe->filhe_file);
343  printf("%s\n",c_line);
344  sprintf(c_line,"User: %s",ps_filhe->filhe_user);
345  printf("%s\n",c_line);
346  sprintf(c_line,"Time: %s",ps_filhe->filhe_time);
347  printf("%s\n",c_line);
348  sprintf(c_line,"Run: %s",ps_filhe->filhe_run);
349  printf("%s\n",c_line);
350  sprintf(c_line,"Exp: %s",ps_filhe->filhe_exp);
351  printf("%s\n",c_line);
352  for(ll=0;ll<ps_filhe->filhe_lines;ll++)
353  {
354  sprintf(c_line,"comment: %s",ps_filhe->s_strings[ll].string);
355  printf("%s\n",c_line);
356  }
357  }
358  else
359  {
360  l_used=ps_bufhe->i_used;
361  if(ps_bufhe->l_dlen > MAX__DLEN)l_used=ps_bufhe->l_free[2];
362  sprintf(c_line,"Buffer %9d, Length %5d[w] Size %5d[b] used %5d[w] %s",
363  ps_bufhe->l_buf,
364  ps_bufhe->l_dlen,
365  ll,l_used,
366  c_time);
367  printf("%s\n",c_line);
368  sprintf(c_line," Events %3d Type/Subtype %5d %5d FragEnd=%d FragBegin=%d Total %5d[w]",
369  ps_bufhe->l_evt,
370  ps_bufhe->i_type,
371  ps_bufhe->i_subtype,
372  ps_bufhe->h_end,
373  ps_bufhe->h_begin,
374  ps_bufhe->l_free[1]);
375  printf("%s\n",c_line);
376  }
377  sprintf(c_line,"--------------------------------------------------------");
378  printf("%s\n",c_line);
379  }
380 
381  if(ps_evhe == NULL) return(0);
382 
383  /* print event 4,x or 6,x */
384  if(ps_evhe->i_type != 10)
385  {
386  sprintf(c_line,"Event type %d, subtype %d, data longwords %d",
387  ps_evhe->i_type,ps_evhe->i_subtype,ps_evhe->l_dlen/2);
388  printf("%s\n",c_line);
389  if((l_ldata != 0) & ((ps_evhe->i_type == 4)|(ps_evhe->i_type == 6)))
390  { /* output data, assume data as longword */
391  pl_data = (INTS4 *)ps_evhe;
392  pl_data += 2;
393  for(l=0;l<ps_evhe->l_dlen/2;l++)
394  {
395  sprintf(c_line,"%08x ",*pl_data);
396  strcat(c_full,c_line);
397  pl_data++;
398  if(l%8 == 7) {
399  printf("%s\n",c_full);
400  strcpy(c_full," ");
401  }
402  }
403  if(strlen(c_full) > 2) printf("%s\n",c_full);
404  }
405  return(0);
406  }
407 
408  /* Print event 10,1 */
409  ps_ve10_1 = (s_ve10_1 *)ps_evhe;
410  /* Print event header */
411  sprintf(c_line,"Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d",
412  ps_ve10_1->l_count,
413  ps_ve10_1->i_type,
414  ps_ve10_1->i_subtype,
415  ps_ve10_1->l_dlen,
416  ps_ve10_1->i_trigger);
417  printf("%s\n",c_line);
418 
419  /********************/
420  l_s=0;
421  l_status=0;
422  while(l_status == 0)
423  {
424  l_s++;
425  l_status=f_evt_get_subevent(ps_ve10_1,l_s,(INTS4 **)&ps_ves10_1,(INTS4 **)&pl_data,(INTS4 *)&ll);
426  if(l_status == 0)
427  {
428  if((l_subid < 0)|(l_subid == ps_ves10_1->i_procid))
429  {
430  sprintf(c_line," SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d",
431  ps_ves10_1->i_procid,
432  ps_ves10_1->i_type,
433  ps_ves10_1->i_subtype,
434  ps_ves10_1->l_dlen,
435  ps_ves10_1->h_control,
436  ps_ves10_1->h_subcrate);
437  printf("%s\n",c_line);
438  if(l_ldata != 0)
439  { /* output data */
440  if((l_long != 0) | (l_hex != 0))
441  { /* In this case we assume data as one longword per channel */
442  for(l=0;l<ll;l++)
443  {
444  if(l_hex != 0) sprintf(c_line,"%04x.%04x ",(*pl_data>>16)&0xffff,*pl_data&0xffff);
445  else sprintf(c_line,"%8d ",*pl_data);
446  strcat(c_full,c_line);
447  pl_data++;
448  if(l%8 == 7)
449  {
450  printf("%s\n",c_full);
451  strcpy(c_full," ");
452  }
453  }
454  if(strlen(c_full) > 2)printf("%s\n",c_full);
455  strcpy(c_full," ");
456  }
457  else
458  { /* In this case we assume data as two words per channel */
459  for(l=0;l<ll;l++)
460  {
461  sprintf(c_line,"%8d%8d",*pl_data&0xffff,(*pl_data>>16)&0xffff);
462  strcat(c_full,c_line);
463  pl_data++;
464  if(l%4 == 3)
465  {
466  printf("%s\n",c_full);
467  strcpy(c_full," ");
468  }
469  }
470  if(strlen(c_full) > 2)printf("%s\n",c_full);
471  strcpy(c_full," ");
472  }
473  }
474  }
475  }
476  }
477  return(0);
478 }
479 
480 /*1+ C Main ****************+******************************************/
481 /*+ Module : f_evt_source_port */
482 /*--------------------------------------------------------------------*/
483 /*+ CALLING : f_evt_source_port(long l_port) */
484 /*--------------------------------------------------------------------*/
485 /* */
486 /*+ PURPOSE : f_evt_source_port sets port number for event source */
487 /*+ ARGUMENTS : */
488 /*+ l_port : Port number: */
489 /*+ Return type : int. */
490 /*+ Status codes: */
491 /*- GETEVT__SUCCESS : success. */
492 /*+ Declaration : */
493 /* INTS4 f_evt_source_port(INTS4); */
494 /*1- C Main ****************+******************************************/
496 {
497  l_gl_source_port=l_port;
498  if (l_port>0) printf("Use MBS source port %d\n",l_port);
499  return 0;
500 }
501 
502 
503 /*1+ C Main ****************+******************************************/
504 /*+ Module : f_evt_rev_port */
505 /*--------------------------------------------------------------------*/
506 /*+ CALLING : f_evt_rev_port(long l_port) */
507 /*--------------------------------------------------------------------*/
508 /* */
509 /*+ PURPOSE : f_evt_rev_port sets port number for event server */
510 /*+ ARGUMENTS : */
511 /*+ l_port : Port number: */
512 /*+ Return type : int. */
513 /*+ Status codes: */
514 /*- GETEVT__SUCCESS : success. */
515 /*+ Declaration : */
516 /* INTS4 f_evt_rev_port(INTS4); */
517 /*1- C Main ****************+******************************************/
519 {
520  l_gl_source_port=l_port;
521  if (l_port>0) printf("Use MBS source port %d\n",l_port);
522  return 0;
523 }
524 
525 /*1+ C Main ****************+******************************************/
526 /*+ Module : f_evt_get_open */
527 /*--------------------------------------------------------------------*/
528 /*+ CALLING : f_evt_get_open(long l_mode, char &c_server[], s_evt_channel &s_chan, */
529 /* char **ps_info, long l_sample,l_para)*/
530 /*--------------------------------------------------------------------*/
531 /* */
532 /*+ PURPOSE : f_evt_get_open opens an event stream from specified*/
533 /* channel. */
534 /*+ ARGUMENTS : */
535 /*+ l_mode : Type of server: */
536 /*- GETEVT__FILE : Input from file */
537 /*- GETEVT__STREAM : Input from MBS stream server */
538 /*- GETEVT__TRANS : Input from MBS transport */
539 /*- GETEVT__EVENT : Input from MBS event server */
540 /*- GETEVT__REVSERV: Input from remote event server */
541 /*+ c_server : Node of server or file name. */
542 /*+ s_chan : structure s_evt_channel, must be allocated. */
543 /*+ ps_info : address of pointer. If it is not NULL, then */
544 /* try to return file header or other information */
545 /* about server. If it is NULL, then returns nothing. */
546 /*+ l_sample : used by event server to send only every */
547 /* 'l_sample' event. */
548 /*+ l_para : currently not used */
549 /*+ Return type : int. */
550 /*+ Status codes: */
551 /*- GETEVT__SUCCESS : success. */
552 /*- GETEVT__NOFILE : file does not exist. */
553 /*- GETEVT__RDERR : read server error. */
554 /*- GETEVT__NOSERVER : can not connect server. */
555 /*+ Declaration : */
556 /* INTS4 f_evt_get_open( */
557 /* INTS4, CHARS *, s_evt_channel *, CHARS **, INTS4, INTS4); */
558 /*+ FUNCTION : Opens the input channel and save context in s_chan. */
559 /*+ NOTE : Up to four input channels can be opened. */
560 /*1- C Main ****************+******************************************/
561 INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan,
562  CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
563 {
564 
565  INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_header_size, l_port;
566  INTS2 *pi;
567  CHARS c_file[256], *pc_temp;
568  s_filhe *ps_filhe;
569  struct s_varstr
570  {
571  INTS2 i_varstr;
572  CHARS c_varstr[128];
573  } s_varstr_file;
574  INTS4 l_status,ll;
575 
576  l_port = l_gl_source_port;
577 
578 
579 #ifndef GSI__WINNT
580 // disable automatic detection of RFIO on Windows while file name can contain ":"
581  if((pc_temp=strchr(pc_server,':')) != NULL) {
582  l_mode=GETEVT__RFIO;
583  /* printf("rfio file %s\n",pc_server);*/
584  }
585 #endif
586 
587 #ifndef RFIO
588  if(l_mode == GETEVT__RFIO)
589  {
590  printf("rfio not supported!\n");
591  return(GETEVT__NOFILE);
592  }
593 #endif
594 
595  if(ps_info != NULL) *ps_info=NULL;
596  // when timeout is already set by f_evt_timeout(), do not overwrite
597  if(ps_chan->l_timeout==0)ps_chan->l_timeout=-1; /* no timeout */
598  strcpy(ps_chan->c_channel,pc_server);
599  switch(l_mode) {
600  case GETEVT__FILE :
601  strcpy(c_file,pc_server);
602  if(strlen(c_file) < 5) strcat(c_file,".lmd");
603  else {
604  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
605  if((strcmp(pc_temp,".LMD") != 0) &&
606  (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
607  }
608 
609  if((ps_chan->l_channel_no=open(c_file,GET__OPEN_FLAG))== -1)
610  {
611  return(GETEVT__NOFILE);
612  }
613  /* read first 512 bytes */
614  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
615  printf("LMD format error: no LMD file: %s\n",c_file);
616  close(ps_chan->l_channel_no);
617  ps_chan->l_channel_no=-1;
618  return(GETEVT__NOLMDFILE);
619  }
620 // DABC
621  ps_chan->pLmd=NULL;
622  if((*((INTS4 *)(c_temp+4)) == LMD__TYPE_FILE_HEADER_101_1)||
623  (*((INTS4 *)(c_temp+4)) == 0x65000100)){
624  close(ps_chan->l_channel_no);
625  ps_chan->pLmd=fLmdAllocateControl();
626  fLmdGetOpen(ps_chan->pLmd,c_file,NULL,LMD__BUFFER,LMD__NO_INDEX);
627  ps_chan->l_server_type=l_mode;
628  return GETEVT__SUCCESS;
629  }
630 // -- DABC
631  /* check for file header, return size and swap */
632  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
633  if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0)) {
634  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
635  close(ps_chan->l_channel_no);
636  ps_chan->l_channel_no=-1;
637  return(GETEVT__NOLMDFILE);
638  }
639 
640  /* read file header and first buffer and check for goosy header */
641  if(l_filehead == 1) {
642  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
643  l_header_size=l_size_head;
644  if(((s_filhe *)c_temp)->filhe_dlen > MAX__DLEN){
645  l_header_size=((s_filhe *)c_temp)->filhe_used*2+48;
646  // printf("Large buffer, read short header %d bytes\n",l_header_size);
647  }
648  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size){
649  printf("LMD format error: no LMD file: %s\n",c_file);
650  close(ps_chan->l_channel_no);
651  ps_chan->l_channel_no=-1;
652  return(GETEVT__NOLMDFILE);
653  }
654  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
655  close(ps_chan->l_channel_no);
656  ps_chan->l_channel_no=-1;
657  return(GETEVT__RDERR);
658  }
659  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
660  if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head)) {
661  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
662  close(ps_chan->l_channel_no);
663  ps_chan->l_channel_no=-1;
664  return(GETEVT__NOLMDFILE);
665  }
666  }/* check buffer behind header */
667  ps_chan->l_buf_size=l_size_head;
668  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
669  if(ps_info != NULL) *ps_info=NULL;
670  /* found file header */
671  if(l_filehead == 1) {
672  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size) {
673  printf("LMD format error: no LMD file: %s\n",c_file);
674  close(ps_chan->l_channel_no);
675  ps_chan->l_channel_no=-1;
676  return(GETEVT__NOLMDFILE);
677  }
678  ps_filhe = (s_filhe *) c_temp;
679  if(ps_info != NULL) {/* if user want file header be returned */
680  if( l_swap_head ==1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
681  *ps_info=c_temp; /* now , get file header and return */
682  }
683  /*
684  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
685  printf("strings %d %d %d %d %d %x\n",
686  ps_filhe->filhe_label_l,
687  ps_filhe->filhe_file_l,
688  ps_filhe->filhe_user_l,
689  ps_filhe->filhe_run_l,
690  ps_filhe->filhe_exp_l,
691  ps_filhe->filhe_lines);
692  pi=(INTS2 *)&ps_filhe->s_strings;
693  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
694  {
695  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
696  pi += 40;
697  }
698  */
699  } /* file header */
700 
701  /* points to a real buffer start */
702  /* and read header buffer, if there */
703  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
704  /* may larger, but must multiplexed */
705  break;
706  case GETEVT__STREAM :
707 
708  if (l_port<=0) l_port = PORT__STREAM_SERV;
709 
710  /* initialize connection with stream server */
711  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
713  {
714  return(GETEVT__NOSERVER);
715  }
716 
717  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
718  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
719  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
720 
721  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
722  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
723  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
724  /* # buffers per stream */
725  ps_chan->l_stream_bufs = 0; /* counter */
726 
727  ps_chan->l_io_buf_size=(ps_chan->l_buf_size)*(ps_chan->l_bufs_in_stream);
728 // DABC
729  ps_chan->pLmd=NULL;
730  if(*((INTS4 *)(c_temp+12)) == 0) {
731  ps_chan->pLmd=fLmdAllocateControl();
732  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
733  // SL: we should deliver default portnumber while it is used only to identify transport
734  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);
735  printf("f_evt_get_open for STREAM: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
736 
737  ps_chan->l_server_type=l_mode;
738  return GETEVT__SUCCESS;
739  }
740 // -- DABC
741  break;
742  case GETEVT__TRANS :
743 
744  if (l_port<=0) l_port = PORT__TRANSPORT;
745 
746  /* initialize connection with stream server */
747  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
749  {
750  return(GETEVT__NOSERVER);
751  }
752 
753  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
754  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
755  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
756 
757  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
758  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
759  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
760  /* # buffers per stream */
761  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
762 // DABC
763  ps_chan->pLmd=NULL;
764  if(*((INTS4 *)(c_temp+12)) == 0) {
765  ps_chan->pLmd=fLmdAllocateControl();
766  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
767  fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__TRANSPORT,ps_chan->l_timeout);
768  printf("f_evt_get_open for TRANSPORT: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
769  ps_chan->l_server_type=l_mode;
770  return GETEVT__SUCCESS;
771  }
772 // -- DABC
773  break;
774  case GETEVT__REVSERV :
775  if (l_port<=0) l_port = PORT__EVENT_SERV;
776  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
777  {
778  return(GETEVT__NOSERVER);
779  }
780  break;
781  case GETEVT__EVENT :
782  if (l_port<=0) l_port = PORT__EVENT_SERV;
783  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
784  {
785  return(GETEVT__NOSERVER);
786  }
787  break;
788  case GETEVT__RFIO :
789  ps_chan->l_channel_no=-1;
790  ps_chan->l_channel_no=RFIO_open(pc_server,GET__OPEN_FLAG,0);
791  if(ps_chan->l_channel_no < 0) return(GETEVT__NOSERVER);
792  /* read first 512 bytes */
794  {
795  printf("LMD format error: no LMD file: %s\n",pc_server);
796  RFIO_close(ps_chan->l_channel_no);
797  ps_chan->l_channel_no=-1;
798  return(GETEVT__NOLMDFILE);
799  }
800  /* check for file header, return size and swap */
801  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
802  if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
803  {
804  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
805  RFIO_close(ps_chan->l_channel_no);
806  ps_chan->l_channel_no=-1;
807  return(GETEVT__NOLMDFILE);
808  }
809  /* read file header and first buffer and check for goosy header */
810  if(l_filehead == 1)
811  {
812  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
813  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
814  {
815  printf("LMD format error: no LMD file: %s\n",pc_server);
816  RFIO_close(ps_chan->l_channel_no);
817  ps_chan->l_channel_no=-1;
818  return(GETEVT__NOLMDFILE);
819  }
821  {
822  RFIO_close(ps_chan->l_channel_no);
823  ps_chan->l_channel_no=-1;
824  return(GETEVT__RDERR);
825  }
826  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
827  if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
828  {
829  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
830  RFIO_close(ps_chan->l_channel_no);
831  ps_chan->l_channel_no=-1;
832  return(GETEVT__NOLMDFILE);
833  }
834  }/* check buffer behind header */
835  ps_chan->l_buf_size=l_size_head;
836  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
837  if(ps_info != NULL)*ps_info=NULL;
838  /* found file header */
839  if(l_filehead == 1)
840  {
841  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
842  {
843  printf("LMD format error: no LMD file: %s\n",pc_server);
844  RFIO_close(ps_chan->l_channel_no);
845  ps_chan->l_channel_no=-1;
846  return(GETEVT__NOLMDFILE);
847  }
848  ps_filhe=(s_filhe *)c_temp;
849  if(ps_info != NULL) /* if user want file header be returned */
850  {
851  if( l_swap_head ==1)f_evt_swap_filhe((s_bufhe *)ps_filhe);
852  *ps_info=c_temp; /* now , get file header and return */
853  }
854  /*
855  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
856  printf("strings %d %d %d %d %d %x\n",
857  ps_filhe->filhe_label_l,
858  ps_filhe->filhe_file_l,
859  ps_filhe->filhe_user_l,
860  ps_filhe->filhe_run_l,
861  ps_filhe->filhe_exp_l,
862  ps_filhe->filhe_lines);
863  pi=(INTS2 *)&ps_filhe->s_strings;
864  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
865  {
866  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
867  pi += 40;
868  }
869  */
870  }/* file header */
871  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
872  break;
873  default :
874  if(ps_info != NULL) *ps_info=NULL;
875  return(GETEVT__NOSERVER);
876  } /* end of switch */
877 
878  if((l_mode != GETEVT__EVENT)&(l_mode != GETEVT__REVSERV))
879  {
880  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
881  {
882  printf("Memory allocation error\n");
883  exit(2);
884  }
885  ps_chan->l_evt_buf_size=ps_chan->l_io_buf_size;
886  if( (ps_chan->pc_evt_buf=malloc(ps_chan->l_evt_buf_size))==NULL)
887  {
888  printf("Memory allocation error\n");
889  exit(2);
890  }
891  } /* l_mode != GETEVT__EVENT */
892  ps_chan->l_server_type=l_mode;
893  ps_chan->l_first_get=1; /* so we will first call f_getvet_get */
894  return GETEVT__SUCCESS;
895 } /* end of f_evt_get_open */
896 
897 /*1+ C Main ****************+******************************************/
898 /*+ Module : f_evt_get_event */
899 /*--------------------------------------------------------------------*/
900 /*+ CALLING : f_evt_get_event(s_evt_channel &s_chan, long **ppl_buffer, long **ppl_goobuf) */
901 /*--------------------------------------------------------------------*/
902 /* */
903 /*+ PURPOSE : f_evt_get_event returnes address of event */
904 /*+ ARGUMENTS : */
905 /*+ s_chan : Input channel from open. */
906 /*+ ppl_buffer: Address of pointer. Returns address of event. */
907 /*+ ppl_goobuf: Address of pointer. Returns address of buffer. */
908 /*+ Return type : int. */
909 /*+ Status codes: */
910 /*- GETEVT__SUCCESS : success. */
911 /*- GETEVT__FRAGMENT : Event fragment found. */
912 /*- GETEVT__NOMORE : No more events. */
913 /*- GETEVT__RDERR : read server or file error */
914 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
915 /*+ Declaration : */
916 /* INTS4 f_evt_get_event( */
917 /* s_evt_channel *, INTS4 **, INTS4 **); */
918 /*+ FUNCTION : Get next event and returnes pointer. The pointer */
919 /* may point to the event in the buffer or internal */
920 /* event buffer (spanned events). The content of the */
921 /* pointer may be destroyed by next call. */
922 /*1- C Main ****************+******************************************/
923 INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
924 {
925  INTS4 l_temp,l_prev_ok=1, l_stat, l_used;
926  s_bufhe *ps_bufhe_cur;
927  s_ve10_1 *ps_ve10_1;
928  sMbsHeader *pevt;
929 
930 // DABC
931  if(ps_chan->pLmd != NULL){
932  if(ps_chan->l_server_type == GETEVT__TRANS)
933  l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
934  else if(ps_chan->l_server_type == GETEVT__STREAM)
935  l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
936  else if(ps_chan->l_server_type == GETEVT__FILE)
937  l_stat=fLmdGetElement(ps_chan->pLmd,LMD__NO_INDEX, &pevt);
938 
939 // any error, then pointer is null
940 if(pevt==NULL){
941  if (ps_chan->l_server_type == GETEVT__FILE){
942  if(l_stat == GETLMD__NOMORE) return(GETEVT__NOMORE);
943  if(l_stat == GETLMD__EOFILE) return(GETEVT__NOMORE);
944  if(l_stat == GETLMD__NOBUFFER) return(GETEVT__FAILURE);
945  return(GETEVT__RDERR);
946  } else {
947  if(l_stat == LMD__TIMEOUT) return(GETEVT__TIMEOUT);
948  else return (GETEVT__RDERR);
949  }
950 }
951 // OK
952  if(ppl_goobuf)*ppl_goobuf = NULL;
953  *ppl_buffer = (INTS4 *)pevt;
954  return(GETEVT__SUCCESS);
955  }
956 // -- DABC
957  if((ps_chan->l_server_type == GETEVT__EVENT)|(ps_chan->l_server_type == GETEVT__REVSERV))
958  {
959  *ppl_goobuf = NULL;
960  if(f_evcli_evt(ps_chan) != STC__SUCCESS) /* no more event, get new buffer */
961  {
962  l_stat=f_evcli_buf(ps_chan);
963  if(l_stat == STC__TIMEOUT) return(GETEVT__TIMEOUT);
964  if(l_stat != STC__SUCCESS) return(GETEVT__FAILURE);
965  }
966  *ppl_buffer = (INTS4 *) ps_chan->pc_evt_buf;
967  return(GETEVT__SUCCESS);
968  }
969 
970  /* e.g. read_buffer is 16384, GOOSY buffer may be only 2048, *
971  * this ps_chan->l_io_buf_posi indicats when the read_buffer is finished */
972 
973  if(ps_chan->l_first_get==1)
974  {
975  ps_chan->l_buf_posi=0; /* goosy buffer position */
976  ps_chan->l_buf_lmt=0; /* end of this goosy buffer */
977  ps_chan->l_io_buf_posi=MAX_LONG; /* Iuput buffer(for read file) position */
978  ps_chan->l_first_buf=1; /* boolean */
979  ps_chan->l_first_get=0; /* boolean */
980  }
981  /* why we need this part codes? beacause we may (open, get, close) *
982  * and (open, get, close) again!!! Especially when we use m-histo *
983  * so the second or later (open,get,close) should reset these *
984  * static value */
985 
986  ps_chan->l_evt_buf_posi=0;
987 /* above, internal event buffer position, internal buffer will be returned */
988 
989  while(1)
990  {
991  /* if previous goosy buffer has finished, read a new buffer from i/o buffer,
992  or from file if i/o buffer is all readout */
993  while (ps_chan->l_buf_posi >= ps_chan->l_buf_lmt)
994  {
995  /* if this i/o buffer is read to end */
996  /* end of this read_buffer which may contain several GOOSY buffers*/
997  if(ps_chan->l_io_buf_posi>=ps_chan->l_io_buf_size)
998  {
999  if((l_temp=f_evt_get_newbuf(ps_chan))!=GETEVT__SUCCESS) return(l_temp);
1000  ps_chan->l_io_buf_posi=0;
1001  } /* end of real read server */
1002  ps_chan->ps_bufhe = (s_bufhe*) (ps_chan->pc_io_buf+ps_chan->l_io_buf_posi);
1003  l_prev_ok = (ps_chan->l_buf_no == (ps_chan->ps_bufhe->l_buf-1));
1004  ps_chan->l_buf_no = ps_chan->ps_bufhe->l_buf;
1005  if(ps_chan->ps_bufhe->i_type == 2000) { /* file header */
1006  printf("Unsolicited file header found!\n");
1007  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
1008  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi;
1009  ps_chan->l_buf_lmt = ps_chan->l_io_buf_posi;
1010  } else {
1011  l_used=ps_chan->ps_bufhe->l_free[2]; // large buffers HE, Oct 2007
1012  if(ps_chan->ps_bufhe->l_dlen <= MAX__DLEN)l_used=ps_chan->ps_bufhe->i_used;
1013  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi + sizeof(s_bufhe);
1014  ps_chan->l_buf_lmt = ps_chan->l_buf_posi + l_used*2;
1015  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
1016  }
1017  } /* end of read file while loop */
1018 
1019  /* now, ps_chan->l_buf_posi points to start of an event or spanned event */
1020  ps_chan->ps_ve10_1 = (s_ve10_1 *) (ps_chan->pc_io_buf + ps_chan->l_buf_posi);
1021  if( (ps_chan->l_evt_buf_posi != 0) || ((ps_chan->ps_bufhe->h_end==1) && (ps_chan->l_first_buf==1)) ) { /* if this is a spanned part of an event */
1022  ps_chan->l_buf_posi += sizeof(s_evhe);
1023  ps_chan->l_frag_len = ps_chan->ps_ve10_1->l_dlen*2;
1024  } else /* if this is a real start of an event */
1025  ps_chan->l_frag_len = (ps_chan->ps_ve10_1->l_dlen-4)*2 + sizeof(s_ve10_1);
1026 
1027  if(ps_chan->l_frag_len + ps_chan->l_buf_posi > ps_chan->l_buf_lmt)
1028  {
1029  return(GETEVT__FRAGMENT);
1030  }
1031 
1032  /* if ps_chan->l_buf_posi is not start of an event and ps_chan->l_first_buf =1 *
1033  * then skip to next event */
1034  if((ps_chan->ps_bufhe->h_end==1)&&((ps_chan->l_first_buf==1) || (l_prev_ok == 0))) {
1035  /* if the first buffer is spanned at begin, then skip */
1036  ps_chan->l_first_buf=0; /* 24-Apr-1996 */
1037  l_prev_ok=1; /* 2001 HE */
1038  ps_chan->l_evt_buf_posi=0; /* 2001 HE stuff in event buffer obsolete */
1039  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1040  /* now,ps_chan->l_buf_posi points to start of an event or spanned event */
1041  continue; /* continue "while" loop */
1042  }
1043 
1044  ps_chan->l_first_buf=0;
1045 
1046  /* if ps_chan->l_buf_posi is start of an event and the event is not *
1047  * spanned, then return pointer */
1048  if( (ps_chan->l_evt_buf_posi==0) &&
1049  ( (ps_chan->ps_bufhe->h_begin==0) || ((ps_chan->l_buf_posi+ps_chan->l_frag_len) < ps_chan->l_buf_lmt) ) )
1050  {
1051  *ppl_buffer = (INTS4 *)(ps_chan->pc_io_buf+ps_chan->l_buf_posi);
1052  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1053  ps_chan->l_evt_buf_posi = 0;
1054  if(ppl_goobuf) *ppl_goobuf = (INTS4 *) (ps_chan->ps_bufhe);
1055  return(GETEVT__SUCCESS);
1056  }
1057 
1058  /* 2001 HE if we start a spanned event, save buffer header of first buffer */
1059  if(ps_chan->l_evt_buf_posi==0)
1060  {
1061  memcpy((CHARS *)&ps_chan->s_bufhe_1,(CHARS *)ps_chan->ps_bufhe,sizeof(s_bufhe));
1062  ps_bufhe_cur=(s_bufhe *)&ps_chan->s_bufhe_1;
1063  }
1064  /* copy the part of this event which in this buffer into *
1065  * internal buffer, data will be moved by realloc function */
1066  if(ps_chan->l_evt_buf_size<ps_chan->l_evt_buf_posi+ps_chan->l_frag_len)
1067  {
1068  ps_chan->l_evt_buf_size=ps_chan->l_evt_buf_posi+ps_chan->l_frag_len;
1069  if( (ps_chan->pc_evt_buf=realloc
1070  (ps_chan->pc_evt_buf, ps_chan->l_evt_buf_size))==NULL)
1071  {
1072  printf("Memory allocation error\n");
1073  exit(2);
1074  }
1075  }
1076  memcpy(ps_chan->pc_evt_buf+ps_chan->l_evt_buf_posi,ps_chan->pc_io_buf+ps_chan->l_buf_posi,
1077  ps_chan->l_frag_len);
1078  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1079  if(ps_chan->l_evt_buf_posi == 0)
1080  {
1081  }
1082  ps_chan->l_evt_buf_posi += ps_chan->l_frag_len;
1083 
1084  if((ps_chan->ps_bufhe->h_begin!=1)||(ps_chan->l_buf_posi<ps_chan->l_buf_lmt))
1085  {
1086  /* change event header's l_dlen */
1087  ((s_ve10_1 *)(ps_chan->pc_evt_buf))->l_dlen=ps_chan->l_evt_buf_posi/2-4;
1088  *ppl_buffer=(INTS4 *)(ps_chan->pc_evt_buf);
1089  if(ppl_goobuf)*ppl_goobuf=(INTS4 *)(ps_bufhe_cur);
1090  return(GETEVT__SUCCESS);
1091  }
1092  }/* if this event spanned to next buffer, then loop */
1093 } /* end of f_evt_get_event */
1094 
1095 /*1+ C Main ******************+****************************************/
1096 /*+ Module : f_evt_get_close */
1097 /*--------------------------------------------------------------------*/
1098 /*+ CALLING : f_evt_get_close( s_evt_channel &s_chan) */
1099 /*--------------------------------------------------------------------*/
1100 /* */
1101 /*+ PURPOSE : f_evt_get_close closes event stream of specified */
1102 /* channel. */
1103 /*+ ARGUMENTS : */
1104 /*+ s_chan : Input channel from open. */
1105 /*+ Return type : int. */
1106 /*+ Status codes: */
1107 /*- GETEVT__SUCCESS : success. */
1108 /*- GETEVT__CLOSE_ERR : close server or file error */
1109 /*+ Declaration : */
1110 /* INTS4 f_evt_get_close(s_evt_channel *); */
1111 /*+ FUNCTION : Closes the specified input channel. */
1112 /*1- C Main ******************+****************************************/
1114 {
1115  INTS4 l_close_failure;
1116  INTS4 l_status;
1117 
1118 // DABC
1119  if(ps_chan->pLmd != NULL){
1120  if(ps_chan->l_server_type == GETEVT__TRANS)fLmdCloseMbs(ps_chan->pLmd);
1121  else if(ps_chan->l_server_type == GETEVT__STREAM)fLmdCloseMbs(ps_chan->pLmd);
1122  else if(ps_chan->l_server_type == GETEVT__FILE) fLmdGetClose(ps_chan->pLmd);
1123  free(ps_chan->pLmd);
1124  ps_chan->pLmd=NULL;
1125  return GETEVT__SUCCESS;
1126  }
1127 // -- DABC
1128  l_close_failure=0;
1129  if(ps_chan->l_channel_no >= 0)
1130  {
1131  switch(ps_chan->l_server_type)
1132  {
1133  case GETEVT__FILE :
1134  if(close(ps_chan->l_channel_no)==-1) l_close_failure=1;
1135  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1136  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1137  break;
1138  case GETEVT__STREAM :
1139  /* disconnect with stream server */
1140  f_stc_write("CLOSE", 12, ps_chan->l_channel_no);
1141  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1142  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1143  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1144  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1145  break;
1146  case GETEVT__TRANS :
1147  /* disconnect with stream server */
1148  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1149  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1150  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1151  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1152  break;
1153  case GETEVT__REVSERV :
1154  case GETEVT__EVENT :
1155  if(f_evcli_close(ps_chan)!=STC__SUCCESS) l_close_failure=1;
1156  break;
1157  case GETEVT__RFIO :
1158  RFIO_close(ps_chan->l_channel_no);
1159  ps_chan->l_channel_no=-1;
1160  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1161  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1162  break;
1163  default :
1164  l_close_failure=1;
1165  } /* end of switch */
1166  ps_chan->pc_io_buf=NULL;
1167  ps_chan->l_channel_no=-1;
1168  if(l_close_failure==1) return(GETEVT__CLOSE_ERR);
1169  return GETEVT__SUCCESS;
1170  }
1171 return GETEVT__SUCCESS;
1172 
1173 } /* end of f_evt_get_close */
1174 
1175 
1176 /*1+ C Main ****************+******************************************/
1177 /*+ Module : f_evt_put_open */
1178 /*--------------------------------------------------------------------*/
1179 /*+ CALLING : f_evt_put_open(char *c_file[], long l_size, long l_stream, long l_type, */
1180 /* long l_subtype, s_evt_channel *ps_chan, char *ps_filhe) */
1181 /*--------------------------------------------------------------------*/
1182 /* */
1183 /*+ PURPOSE : f_evt_put_open opens an event output stream. */
1184 /*+ ARGUMENTS : */
1185 /*+ c_file : Name of file. */
1186 /*+ l_size : Size of output buffers in bytes. */
1187 /*+ l_stream : Number of buffers with spanning events. */
1188 /*+ l_type : Buffer type number */
1189 /*+ l_subtype : Buffer subtype number */
1190 /*+ ps_chan : Address of channel structure which will be returned.*/
1191 /*+ ps_filhe : Address of user specified file header */
1192 /*+ Return type : int. */
1193 /*+ Status codes: */
1194 /*- PUTEVT__SUCCESS : success. */
1195 /*- PUTEVT__FILE_EXIST: file already exists. */
1196 /*- PUTEVT__FAILURE : failure. */
1197 /*+ Declaration : */
1198 /* INTS4 f_evt_put_open( */
1199 /* CHARS *,INTS4,INTS4,INTS4,INTS4,s_evt_channel *,CHARS *); */
1200 /*+ FUNCTION : Opens the output channel and save context in */
1201 /* s_evt_channel structure. */
1202 /*+ NOTE : Up to four output channels can be opened. */
1203 /* User Example : In m_lea_user.c */
1204 /*1- C Main ****************+******************************************/
1205 INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream,
1206  INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
1207 {
1208  s_filhe *ps_file_head;
1209  INTS4 l_write_size;
1210  INTS4 l_status,ll;
1211  time_t s_timet;
1212  struct timeb s_timeb;
1213  /* because "timeb" is not "typedef", so we must use "struct" */
1214  CHARS c_mode[80];
1215  CHARS c_file[256], *pc_temp;
1216  struct s_varstr
1217  {
1218  INTS2 i_varstr;
1219  CHARS c_varstr[128];
1220  } s_varstr_file;
1221 
1222 // DABC
1223  ps_chan->pLmd=NULL;
1224  if(l_stream==0) {
1225  ps_chan->pLmd=fLmdAllocateControl();
1226  l_status=fLmdPutOpen(ps_chan->pLmd,pc_file,NULL,l_size,
1228  return(l_status);
1229  }
1230 // -- DABC
1231 
1232  ps_chan->l_first_put=1;
1233 
1234  ps_chan->l_buf_size=l_size;
1235  ps_chan->l_bufs_in_stream=l_stream;
1236  ps_chan->l_buf_type=l_type;
1237  ps_chan->l_buf_subtype=l_subtype;
1238  ps_chan->l_io_buf_size=ps_chan->l_buf_size * ps_chan->l_bufs_in_stream;
1239  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
1240  {
1241  printf("Memory allocation error\n");
1242  exit(2);
1243  }
1244 
1245  strcpy(c_file,pc_file);
1246  if(strlen(c_file) < 5) strcat(c_file,".lmd");
1247  else
1248  {
1249  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
1250  if((strcmp(pc_temp,".LMD") != 0) &&
1251  (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
1252  }
1253  if((ps_chan->l_channel_no=open(c_file,PUT__OPEN_APD_FLAG) )!= -1)
1254  return(PUTEVT__FILE_EXIST);
1255  else
1256  {
1257  if((ps_chan->l_channel_no=open(c_file,PUT__CRT_FLAG,
1258  DEF_FILE_ACCE) )== -1)
1259  return(PUTEVT__FAILURE);
1260  /* open OK */
1261  else
1262  {
1263  /* output file header */
1264  ps_file_head=(s_filhe *)ps_chan->pc_io_buf;
1265  /* if user specify file header */
1266  if(ps_filhe != NULL)
1267  {
1268  memcpy(ps_file_head, ps_filhe,ps_chan->l_buf_size );
1269  }
1270  else
1271  {
1272  memset( ps_file_head, '\0', ps_chan->l_buf_size);
1273  sprintf(ps_file_head->filhe_run, "Pid %d\0", getpid());
1274  ps_file_head->filhe_run_l=strlen(ps_file_head->filhe_run);
1275  }
1276  ps_file_head->filhe_dlen=ps_chan->l_buf_size/2;
1277  ps_file_head->filhe_subtype=1;
1278  ps_file_head->filhe_type=2000;
1279  ftime(&s_timeb);
1280  ps_file_head->filhe_stime[0]=(INTS4)s_timeb.time;
1281  ps_file_head->filhe_stime[1]=(INTS4)s_timeb.millitm;
1282  ps_file_head->filhe_free[0]=1;
1283  ps_file_head->filhe_file_l=strlen(c_file);/* not include \0 */
1284  strcpy(ps_file_head->filhe_file, c_file);
1285  strcpy(ps_file_head->filhe_user, getenv("USER"));/* user name */
1286  ps_file_head->filhe_user_l=strlen(ps_file_head->filhe_user);
1287  time(&s_timet);/* get calendar time */
1288  strcpy(c_mode, ctime(&s_timet));
1289  strcpy(ps_file_head->filhe_time, &c_mode[4]);
1290  ps_file_head->filhe_time[20]=' ';
1291  l_write_size=write(ps_chan->l_channel_no,(CHARS *)ps_file_head,
1292  ps_chan->l_buf_size);
1293  if(l_write_size==-1)
1294  {
1295  return(PUTEVT__WRERR);
1296  }
1297  if(l_write_size!=ps_chan->l_buf_size)
1298  {
1299  return(PUTEVT__TOOBIG);
1300  }
1301  return(PUTEVT__SUCCESS);
1302  }
1303  }
1304 } /* end of f_evt_put_open */
1305 
1306 /*1+ C Main ****************+******************************************/
1307 /*+ Module : f_evt_put_event */
1308 /*--------------------------------------------------------------------*/
1309 /*+ CALLING : f_evt_put_event(s_evt_channel *ps_chan, long &la_evt_buf[]) */
1310 /*--------------------------------------------------------------------*/
1311 /* */
1312 /*+ PURPOSE : f_evt_put_event outputs event */
1313 /*+ ARGUMENTS : */
1314 /*+ ps_chan : Address of channel structure as returned from */
1315 /* f_evt_put_open. */
1316 /*+ la_evt_buf : event data array. Standard GSI event structure. */
1317 /*+ Return type : int. */
1318 /*+ Status codes: */
1319 /*- PUTEVT__SUCCESS : success. */
1320 /*- PUTEVT__WRERR : read server or file error */
1321 /*+ Declaration : */
1322 /* INTS4 f_evt_put_event(s_evt_channel *, INTS4 *); */
1323 /*+ FUNCTION : Copies current event into output buffer. Writes */
1324 /* buffer to file, when full. */
1325 /*1- C Main ****************+******************************************/
1326 
1328 {
1329  INTS4 l_evt_buf_posi;
1330  INTS4 l_buf_remain_size; /* net free space of I/O buffer */
1331  INTS4 l_write_size, l_temp, l_free;
1332  INTS4 l_status;
1333  CHARS *pc_addr;
1334  s_bufhe *ps_bufhe;
1335 
1336 // DABC
1337  if(ps_chan->pLmd != NULL){
1338  l_status=fLmdPutElement(ps_chan->pLmd,(sMbsHeader *)pl_evt_buf);
1339  return(l_status);
1340  }
1341 // -- DABC
1342  if(ps_chan->l_first_put==1)
1343  {
1344  ps_chan->l_first_put=0;
1345  ps_chan->l_io_buf_posi=0;
1346  ps_chan->l_buf_no=1;
1347  }
1348  l_evt_buf_posi=0;
1349  ps_chan->l_evt_size=( ((s_ve10_1 *)(pl_evt_buf))->l_dlen)*2 + sizeof(s_evhe);
1350 
1351  /* get l_buf_remain_size is available size in stream */
1352  l_buf_remain_size = ps_chan->l_io_buf_size - ps_chan->l_io_buf_posi;
1353  l_temp = (l_buf_remain_size / ps_chan->l_buf_size)*(sizeof(s_bufhe)+sizeof(s_evhe) );
1354  l_buf_remain_size -= l_temp;/* minus space occupied by buffer header and spanned event header */
1355 
1356  if(ps_chan->l_evt_size>l_buf_remain_size)/* output this i/o buffer */
1357  {
1358  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);
1359  /* clear rest of this GOOSY buffer */
1360  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1361  if(ps_chan->l_io_buf_posi%ps_chan->l_buf_size == 0) l_temp -= ps_chan->l_buf_size;
1362  /* l_temp points to start of last GOOSY buf in i/o buf area */
1363  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1364  if(l_temp==0)ps_chan->ps_bufhe->h_end = 0; /* first buf in stream, no end */
1365  else ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1366  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1367  for(l_temp=0;l_temp<ps_chan->l_io_buf_size;l_temp+=ps_chan->l_buf_size)
1368  {
1369  pc_addr = ps_chan->pc_io_buf+l_temp;
1370  ps_bufhe=(s_bufhe *)pc_addr;
1371  if(ps_bufhe->l_evt>0)/* do not write empty buffers */
1372  {
1373  l_write_size=write(ps_chan->l_channel_no, pc_addr,ps_chan->l_buf_size);
1374  if(l_write_size==-1) return(PUTEVT__WRERR);
1375  if(l_write_size!=ps_chan->l_buf_size) return(PUTEVT__TOOBIG);
1376  }
1377  else ps_chan->l_buf_no--; /* decrement buffer number for not written buffer */
1378  } /* buffer output loop */
1379  ps_chan->l_io_buf_posi=0;
1380  ps_chan->ps_bufhe=(s_bufhe *)ps_chan->pc_io_buf;
1381  /* get l_buf_remain_size of new stream */
1382  l_buf_remain_size = ps_chan->l_io_buf_size;
1383  l_temp = (l_buf_remain_size / ps_chan->l_buf_size) * (sizeof(s_bufhe)+sizeof(s_evhe) );
1384  l_buf_remain_size -= l_temp; /* minus space occupied by buf header and spanned event header */
1385  l_buf_remain_size += sizeof(s_evhe);/* 1st buf always no span */
1386  /* if event can not fit in a new stream, then error */
1387  if(ps_chan->l_evt_size>l_buf_remain_size) return(PUTEVT__TOO_SMALLS);
1388  }
1389 
1390  if(ps_chan->l_io_buf_posi==0)f_evt_ini_bufhe(ps_chan);/* init all buffer headers */
1391 
1392  /* write event into i/o buf till end of event, change ps_chan->l_io_buf_posi */
1393  while(l_evt_buf_posi<ps_chan->l_evt_size)
1394  {
1395  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
1396  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
1397  {
1398  ps_chan->l_io_buf_posi += sizeof(s_bufhe);
1399  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);/* behind header */
1400  if(l_evt_buf_posi != 0)
1401  {
1402  ps_chan->l_io_buf_posi += sizeof(s_evhe); /* behind element header */
1403  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1404  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1405  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1406  ps_chan->ps_bufhe->i_used += sizeof(s_evhe)/2;
1407  }
1408  }
1409  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1410  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1411  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1412  l_write_size = l_write_size + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1413  /* l_write_size is remain free space in this GOOSY buf */
1414  if(l_write_size>(ps_chan->l_evt_size-l_evt_buf_posi))
1415  l_write_size=(ps_chan->l_evt_size-l_evt_buf_posi);
1416  memcpy(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi, (CHARS *)pl_evt_buf + l_evt_buf_posi, l_write_size);
1417  ps_chan->ps_bufhe->l_evt ++; /* number of fragments */
1418  ps_chan->l_io_buf_posi += l_write_size;
1419  l_evt_buf_posi += l_write_size;
1420  ps_chan->ps_bufhe->i_used += l_write_size/2;
1421  /* if the remain free space of GOOSY buffer does not large enough *
1422  * to hold even a event header, then turn to next GOOSY buffer and *
1423  * fill buffer header. or 8 long words aligned ???????? */
1424  l_free=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1425  /* l_free points to start of this GOOSY buf in i/o buf area */
1426  l_free = l_free + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1427  if(l_free==ps_chan->l_buf_size)l_free=0;
1428  /* l_free is remain free space in this GOOSY buf */
1429  if(l_free<sizeof(s_ve10_1))ps_chan->l_io_buf_posi += l_free;
1430  /* change spanned evt header l_dlen */
1431  if(l_evt_buf_posi!=l_write_size)
1432  {
1433  ps_chan->ps_ve10_1->l_dlen= l_write_size/2;
1434  ps_chan->ps_ve10_1->i_subtype = ps_chan->l_buf_subtype;
1435  ps_chan->ps_ve10_1->i_type = ps_chan->l_buf_type;
1436  }
1437  else ps_chan->ps_ve10_1->l_dlen= (l_write_size-sizeof(s_evhe))/2; /* header of first frag */
1438  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
1439  {
1440  if(l_evt_buf_posi<ps_chan->l_evt_size) ps_chan->ps_bufhe->h_begin = 1;
1441  if(ps_chan->l_io_buf_posi > ps_chan->l_buf_size) /* so first buf in stream */
1442  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1443  ps_chan->ps_bufhe->l_free[1] = ((s_ve10_1 *)(pl_evt_buf))->l_dlen; /* lgth of last event in buf */
1444  } /* end of processs prev buffer head and ... */
1445 
1446  } /* end of write event into i/o buf till end of event */
1447  return(PUTEVT__SUCCESS);
1448 } /* end of f_evt_put_event */
1449 
1450 /*1+ C Main ****************+******************************************/
1451 /*+ Module : f_evt_put_buffer */
1452 /*--------------------------------------------------------------------*/
1453 /*+ CALLING : f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe) */
1454 /*--------------------------------------------------------------------*/
1455 /* */
1456 /*+ PURPOSE : f_evt_put_buffer outputs buffer */
1457 /*+ ARGUMENTS : */
1458 /*+ ps_chan : Address of channel structure as returned from */
1459 /* f_evt_put_open. */
1460 /*+ ps_bufhe : Buffer. */
1461 /*+ Return type : int. */
1462 /*+ Status codes: */
1463 /*- PUTEVT__SUCCESS : success. */
1464 /*- PUTEVT__WRERR : read server or file error */
1465 /*+ Declaration : */
1466 /* INTS4 f_evt_put_buffer(s_evt_channel *, s_bufhe *); */
1467 /*+ FUNCTION : Writes buffer to file. */
1468 /*1- C Main ****************+******************************************/
1469 
1471 {
1472  INTS4 l_write_size, l_temp, l_free;
1473  INTS4 l_status;
1474  CHARS *pc_addr;
1475 
1476 // DABC
1477  if(ps_chan->pLmd != NULL){
1478  l_status=fLmdPutBuffer(ps_chan->pLmd,(sMbsHeader *)(ps_bufhe+1),ps_bufhe->l_evt);
1479  return(l_status);
1480  }
1481 // -- DABC
1482  ps_chan->l_io_buf_posi = ps_chan->l_buf_size;
1483  ps_chan->l_io_buf_size = ps_chan->l_buf_size;
1484  l_write_size=write(ps_chan->l_channel_no, (CHARS *) ps_bufhe, ps_chan->l_buf_size);
1485  if(l_write_size==-1)
1486  {
1487  return(PUTEVT__WRERR);
1488  }
1489  if(l_write_size!=ps_chan->l_buf_size)
1490  {
1491  return(PUTEVT__TOOBIG);
1492  }
1493  return PUTEVT__SUCCESS;
1494 } /* end of f_evt_put_buffer */
1495 
1496 /*1+ C Main ****************+******************************************/
1497 /*+ Module : f_evt_put_close */
1498 /*--------------------------------------------------------------------*/
1499 /*+ CALLING : f_evt_put_close(s_evt_channel *ps_chan) */
1500 /*--------------------------------------------------------------------*/
1501 /* */
1502 /*+ PURPOSE : f_evt_put_close closes specified channel. */
1503 /*+ ARGUMENTS : */
1504 /*+ channel : Channel number. */
1505 /*+ Return type : int. */
1506 /*+ Status codes: */
1507 /*- PUTEVT__SUCCESS : success. */
1508 /*- PUTEVT__FAILURE : failure. */
1509 /*- PUTEVT__CLOSE_ERR : close server or file error */
1510 /*+ Declaration : */
1511 /* INTS4 f_evt_put_close(s_evt_channel *); */
1512 /*+ FUNCTION : Closes the specified output channel after writing */
1513 /* last buffer. */
1514 /*1- C Main ****************+******************************************/
1515 
1517 {
1518  INTS4 l_write_size, l_temp, l_temp2;
1519  INTS4 l_status;
1520  CHARS *pc_addr;
1521 
1522 // DABC
1523  if(ps_chan->pLmd != NULL){
1524  l_status=fLmdPutClose(ps_chan->pLmd);
1525  return(l_status);
1526  }
1527 // -- DABC
1528  if(ps_chan->l_first_put==1) goto g_close;
1529 
1530  /* if not the end of GOOSY buf, fill buffer header */
1531  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
1532  {
1533  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1534  /* l_temp points to start of this GOOSY buf in i/o buf area */
1535  memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0',
1536  l_temp+ps_chan->l_buf_size-ps_chan->l_io_buf_posi);
1537  /* clear rest of this GOOSY buffer */
1538  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1539 
1540  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
1541  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1542  if(l_temp==0) /* so fisrt buf in stream */
1543  ps_chan->ps_bufhe->h_end = 0;
1544  else
1545  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))
1546  ->h_begin;
1547  ps_chan->ps_bufhe->i_used = (ps_chan->l_io_buf_posi%ps_chan->l_buf_size -
1548  sizeof(s_bufhe))/2;
1549  } /* end of process of infilished buffer header */
1550 
1551  /* if at the end of io buf, need not flush */
1552  if(ps_chan->l_io_buf_posi!=ps_chan->l_io_buf_size)
1553  {
1554  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
1555  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size+1) *
1556  ps_chan->l_buf_size;
1557  else
1558  l_write_size=ps_chan->l_io_buf_posi;
1559 
1560  for(l_temp=0;l_temp<l_write_size;l_temp+=ps_chan->l_buf_size){
1561 /* why use this loop instead of write the whole io_buf out? because in
1562  VMS side, the record can only be l_buf_size big, not l_write_size big */
1563  l_temp2=write(ps_chan->l_channel_no, ps_chan->pc_io_buf+l_temp,
1564  ps_chan->l_buf_size);
1565  if(l_temp2==-1)
1566  {
1567  return(PUTEVT__WRERR);
1568  }
1569  if(l_temp2!=ps_chan->l_buf_size)
1570  {
1571  return(PUTEVT__TOOBIG);
1572  }
1573  }
1574  } /* end of flush */
1575 
1576 g_close:
1577  free(ps_chan->pc_io_buf);
1578  /* free io buffer Memory */
1579 
1580  l_status=close(ps_chan->l_channel_no);
1581  ps_chan->l_channel_no=-1;
1582  if(l_status == -1) return(PUTEVT__CLOSE_ERR);
1583  else return PUTEVT__SUCCESS;
1584 } /* end of f_evt_put_close */
1585 
1586 /*1+ C Main ****************+******************************************/
1587 /*+ Module : f_evt_error */
1588 /*--------------------------------------------------------------------*/
1589 /*+ CALLING : f_evt_error( long l_error , char &c_string[], long l_out ) */
1590 /*--------------------------------------------------------------------*/
1591 /* */
1592 /*+ PURPOSE : f_evt_error displays error messages. */
1593 /*+ ARGUMENTS : */
1594 /*+ l_error : The error id as returned from other calls */
1595 /*+ c_string : The string into f_evt_error() copies the message....*/
1596 /*+ l_out : specifies the output device for the error message. */
1597 /*- out = 1 : error message is copied to string. */
1598 /*- out = 0 : error message is printed on terminal. */
1599 /*+ Return type : int (longword). */
1600 /*+ Status codes: */
1601 /*- GETEVT__SUCCESS : success. */
1602 /*- GETEVT__FAILURE : failure */
1603 /*+ Declaration : */
1604 /* INTS4 f_evt_error( INTS4 , CHARS * , INTS4 ); */
1605 /*+ FUNCTION : f_evt_error displays the error message for the */
1606 /* error id ( l_error ). If out = 1 the error */
1607 /* message is copied into string, else */
1608 /* f_evt_error prints the message on terminal. */
1609 /*1- C Main ******************+****************************************/
1610 INTS4 f_evt_error( INTS4 l_error , CHARS *pc_dest , INTS4 l_out )
1611 {
1612  CHARS c_line[80];
1613 
1614  switch( l_error )
1615  {
1616  case GETEVT__NOFILE :
1617  sprintf(c_line,"-I-f_evt: no such input file");
1618  break;
1619  case GETEVT__NOTAGFILE :
1620  sprintf(c_line,"-I-f_evt: no such tag file");
1621  break;
1622  case GETEVT__NOTAG :
1623  sprintf(c_line,"-I-f_evt: no such event tag");
1624  break;
1625  case GETEVT__TIMEOUT :
1626  sprintf(c_line,"-I-f_evt: time out");
1627  break;
1628  case GETEVT__NOSERVER :
1629  sprintf(c_line,"-I-f_evt: no such server");
1630  break;
1631  case GETEVT__RDERR :
1632  sprintf(c_line,"-I-f_evt: read server error");
1633  break;
1634  case GETEVT__TAGRDERR :
1635  sprintf(c_line,"-I-f_evt: read tag file error");
1636  break;
1637  case GETEVT__TAGWRERR :
1638  sprintf(c_line,"-I-f_evt: write tag file error");
1639  break;
1640  case GETEVT__FRAGMENT :
1641  sprintf(c_line,"-I-f_evt: data format error");
1642  break;
1643  case GETEVT__NOMORE :
1644  sprintf(c_line,"-I-f_evt: no more event");
1645  break;
1646  case GETEVT__CLOSE_ERR:
1647  sprintf(c_line,"-I-f_evt: close server error");
1648  break;
1649  case GETEVT__FAILURE :
1650  sprintf(c_line,"-I-f_evt: failure");
1651  break;
1652  case GETEVT__NOCHANNEL :
1653  sprintf(c_line,"-I-f_evt: too many channels");
1654  break;
1655  case GETEVT__NOLMDFILE :
1656  sprintf(c_line,"-I-f_evt: input file is no LMD file");
1657  break;
1658  case GETEVT__SUCCESS :
1659  sprintf(c_line,"-I-f_evt: success");
1660  break;
1661  case PUTEVT__FILE_EXIST :
1662  sprintf(c_line,"-I-f_evt: output file already exist");
1663  break;
1664  case PUTEVT__WRERR :
1665  sprintf(c_line,"-I-f_evt: write file error");
1666  break;
1667  case PUTEVT__TOOBIG :
1668  sprintf(c_line,"-I-f_evt: output file too large");
1669  break;
1670  case PUTEVT__TOO_SMALLS:
1671  sprintf(c_line,"-I-f_evt: event can not fit in a stream");
1672  break;
1673  case PUTEVT__CLOSE_ERR :
1674  sprintf(c_line,"-I-f_evt: close output error");
1675  break;
1676  case PUTEVT__FAILURE :
1677  sprintf(c_line,"-I-f_evt: output failure");
1678  break;
1679  case PUTEVT__NOCHANNEL :
1680  sprintf(c_line,"-I-f_evt: too many channels");
1681  break;
1682  default :
1683  sprintf(c_line,"-I-f_evt: unknown message id %d",l_error);
1684  if(l_out==0)printf("%s\n",c_line);
1685  if(l_out==1)strcpy(pc_dest,c_line);
1686  return GETEVT__FAILURE;
1687  } /* end switch( l_error ) */
1688 
1689  if(l_out==0)printf("%s\n",c_line);
1690  if(l_out==1)strcpy(pc_dest,c_line);
1691 
1692  return GETEVT__SUCCESS;
1693 } /* end of f_evt_error */
1694 
1695 
1696 /*1+ C Main ****************+******************************************/
1697 /*+ Module : f_evt_get_buffer */
1698 /*--------------------------------------------------------------------*/
1699 /*+ CALLING : f_evt_get_buffer(s_evt_channel &s_chan, INTS4 *pl_buffer) */
1700 /*--------------------------------------------------------------------*/
1701 /* */
1702 /*+ PURPOSE : f_evt_get_buffer read one buffer from server into */
1703 /* user buffer. */
1704 /*+ ARGUMENTS : */
1705 /*+ s_chan : structure s_evt_channel. */
1706 /*+ pl_buffer : Address of user buffer */
1707 /*+ Return type : int. */
1708 /*+ Status codes: */
1709 /*- GETEVT__SUCCESS : success. */
1710 /*- GETEVT__FAILURE : failure */
1711 /*- GETEVT__RDERR : read server or file error */
1712 /*- GETEVT__NOMORE : No more events. */
1713 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1714 /*+ Declaration : */
1715 /* INTS4 f_evt_get_buffer(s_evt_channel *, INTS4 *); */
1716 /*1- C Main ****************+******************************************/
1718 {
1719  INTS4 l_temp;
1720  CHARS * pc_temp;
1721  INTS4 l_status;
1722 
1723  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1724  switch(ps_chan->l_server_type)
1725  {
1726  case GETEVT__FILE :
1727  l_temp=read(ps_chan->l_channel_no,ps_buffer, ps_chan->l_buf_size);
1728  if(l_temp == 0)
1729  /* if end of file, then exit */
1730  {
1731  ps_chan->l_io_buf_size = 0;
1732  return(GETEVT__NOMORE);
1733  }
1734  else if(l_temp == -1)
1735  {
1736  ps_chan->l_io_buf_size = 0;
1737  return(GETEVT__RDERR);
1738  }
1739  break;
1740  case GETEVT__RFIO :
1741  l_temp=RFIO_read(ps_chan->l_channel_no,(CHARS *)ps_buffer, ps_chan->l_buf_size);
1742  if(l_temp == 0)
1743  {
1744  ps_chan->l_io_buf_size = 0;
1745  return(GETEVT__NOMORE);
1746  }
1747  else if(l_temp == -1)
1748  {
1749  ps_chan->l_io_buf_size = 0;
1750  return(GETEVT__RDERR);
1751  }
1752  break;
1753  case GETEVT__STREAM :
1754  if(ps_chan->l_stream_bufs == 0)
1755  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1756  {
1757  return(GETEVT__FAILURE);
1758  }
1759 
1760  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1761  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1762  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1763  ps_chan->l_stream_bufs++;
1764  if(ps_chan->l_stream_bufs == ps_chan->l_bufs_in_stream)ps_chan->l_stream_bufs = 0;
1765  break;
1766  case GETEVT__TRANS :
1767  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1768  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1769  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1770  break;
1771  case GETEVT__REVSERV :
1772  case GETEVT__EVENT :
1773  default :
1774  return(GETEVT__FAILURE);
1775  } /* end of switch */
1776 
1777  /* swap */
1778  if( ((s_bufhe *)(ps_buffer))->l_free[0] !=1)
1779  f_evt_swap((CHARS *)ps_buffer, ps_chan->l_buf_size);
1780 
1781  return(GETEVT__SUCCESS);
1782 } /* end of f_evt_get_buffer */
1783 /*1+ C Main ****************+******************************************/
1784 /*+ Module : f_evt_skip_buffer */
1785 /*--------------------------------------------------------------------*/
1786 /*+ CALLING : f_evt_skip_buffer(s_evt_channel &s_chan, INTS4 l_buffer) */
1787 /*--------------------------------------------------------------------*/
1788 /* */
1789 /*+ PURPOSE : Skip buffers in file. */
1790 /*+ ARGUMENTS : */
1791 /*+ s_chan : structure s_evt_channel. */
1792 /*+ l_buffer : buffers to skip */
1793 /*+ Return type : int. */
1794 /*+ Status codes: */
1795 /*- GETEVT__SUCCESS : success. */
1796 /*- GETEVT__FAILURE : failure */
1797 /*- GETEVT__RDERR : read server or file error */
1798 /*- GETEVT__NOMORE : No more events. */
1799 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1800 /*+ Declaration : */
1801 /* INTS4 f_evt_skip_buffer(s_evt_channel *, INTS4); */
1802 /*1- C Main ****************+******************************************/
1804 {
1805  INTS4 l_temp;
1806  CHARS * pc_temp;
1807  INTS4 l_status,ii;
1808 
1809  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1810  switch(ps_chan->l_server_type)
1811  {
1812  case GETEVT__FILE :
1813  l_temp=lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1814  if(l_temp == -1)
1815  /* if end of file, then exit */
1816  {
1817  return(GETEVT__NOMORE);
1818  }
1819  break;
1820  case GETEVT__RFIO :
1821  l_temp=RFIO_lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1822  if(l_temp == -1)
1823  {
1824  return(GETEVT__NOMORE);
1825  }
1826  break;
1827  case GETEVT__STREAM :
1828  case GETEVT__TRANS :
1829  case GETEVT__REVSERV :
1830  case GETEVT__EVENT :
1831  default : return(GETEVT__FAILURE);
1832  } /* end of switch */
1833 
1834  ps_chan->l_first_get=1; /* so we will first call f_getevt_get */
1835  return(GETEVT__SUCCESS);
1836 } /* end of f_evt_skip_buffer */
1837 
1838 /*1+ C Main ****************+******************************************/
1839 /*+ Module : f_evt_timeout */
1840 /*--------------------------------------------------------------------*/
1841 /*+ CALLING : f_evt_timeout(s_evt_channel *ps_chan, seconds) */
1842 /*--------------------------------------------------------------------*/
1843 /* */
1844 /*+ PURPOSE : Set a timeout for TCP read operations */
1845 /*+ ARGUMENTS : */
1846 /*+ ps_chan : Address of channel structure. */
1847 /*+ seconds : -1: wait (default) */
1848 /* >0: if after n seconds no data arrived, */
1849 /* read functions return GETEVT__TIMEOUT. */
1850 /*+ Return type : INTS4 */
1851 /*+ Declaration : */
1852 /* INTS4 f_evt_timeout(s_evt_channel *, INTS4 ); */
1853 /*+ FUNCTION : Set a timeout for TCP read operations. */
1854 /* The calls of f_evt_get_event, f_evt_get_buffer */
1855 /* will return GETEVT__TIMEOUT when seconds have been */
1856 /* set to positive value. */
1857 /*1- C Main ****************+******************************************/
1859 {
1860  ps_chan->l_timeout = l_sec;
1861  return(GETEVT__SUCCESS);
1862 } /* end of f_evt_timeout */
1863 
1864 /*1- C Main ****************+******************************************/
1865 /*+ Module : f_evt_swap */
1866 /*--------------------------------------------------------------------*/
1867 /*+ CALLING : sts = f_evt_swap(char &c_source[], long l_length) */
1868 /*--------------------------------------------------------------------*/
1869 /* */
1870 /*+ PURPOSE : Long word byte swap. */
1871 /*+ ARGUMENTS : */
1872 /*+ c_source : source data array. */
1873 /*+ l_length : length (in bytes) */
1874 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1875 /*+ Return type : int */
1876 /*+ Status codes: bit 0: success */
1877 /*1- C Procedure ***********+******************************************/
1878 INTS4 f_evt_swap(CHARS * pc_source, INTS4 l_length)
1879 {
1880  CHARS * p_s, * p_d;
1881  INTS4 l_save;
1882  CHARS ch_temp;
1883 
1884  if(l_length%4 == 2){
1885  ch_temp=*(pc_source+l_length-2);
1886  *(pc_source+l_length-2)=*(pc_source+l_length-1);
1887  *(pc_source+l_length-1)=ch_temp;
1888  }
1889  l_length=(l_length/4)*4; /* aligned */
1890  for(p_d=pc_source,p_s=(CHARS *)&l_save; p_d<pc_source+l_length;)
1891  {
1892  l_save = *((INTS4 *)p_d);
1893  p_s += 4; /* increment source */
1894  *(p_d++) = *(--p_s);
1895  *(p_d++) = *(--p_s);
1896  *(p_d++) = *(--p_s);
1897  *(p_d++) = *(--p_s);
1898  }
1899  return(0);
1900 } /* end of f_evt_swap */
1901 /*1- C Main ****************+******************************************/
1902 /*+ Module : f_evt_swap */
1903 /*--------------------------------------------------------------------*/
1904 /*+ CALLING : sts = f_evt_swap_filhe(s_filhe *) */
1905 /*--------------------------------------------------------------------*/
1906 /* */
1907 /*+ PURPOSE : Swap file header. */
1908 /*+ ARGUMENTS : */
1909 /*+ c_source : source data array. */
1910 /*+ l_length : length (in bytes) */
1911 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1912 /*+ Return type : int */
1913 /*+ Status codes: bit 0: success */
1914 /*1- C Procedure ***********+******************************************/
1916 {
1917  CHARS * p_s, * p_d;
1918  INTS4 ii;
1919  INTS2 *pi;
1920  s_filhe *ps_filhe;
1921 
1922  f_evt_swap((CHARS *)ps_bufhe,48);
1923  if(ps_bufhe->i_type == 2000)
1924  {
1925  ps_filhe=(s_filhe *)ps_bufhe;
1926  f_evt_swap((CHARS *)&ps_filhe->filhe_lines,4);/* number of comment lines ps_filhe->filhe_lines*/
1927  ps_filhe->filhe_label_l=ps_filhe->filhe_label_l>>8;
1928  ps_filhe->filhe_file_l =ps_filhe->filhe_file_l >>8;
1929  ps_filhe->filhe_user_l =ps_filhe->filhe_user_l >>8;
1930  ps_filhe->filhe_run_l =ps_filhe->filhe_run_l >>8;
1931  ps_filhe->filhe_exp_l =ps_filhe->filhe_exp_l >>8;
1932  pi=(INTS2 *)&ps_filhe->s_strings;
1933  for(ii=0;ii<ps_filhe->filhe_lines;ii++)
1934  {
1935  *pi=*pi>>8;
1936  pi += 40;
1937  }
1938  }
1939 
1940  return(0);
1941  } /* end of f_evt_swap */
1942 
1943 /*1- C Main ****************+******************************************/
1944 /*+ Module : f_evt_get_buffer_ptr */
1945 /*--------------------------------------------------------------------*/
1946 /*+ CALLING : f_evt_get_buffer_ptr(s_evt_channel &s_chan) */
1947 /*--------------------------------------------------------------------*/
1948 /* */
1949 /*+ PURPOSE : f_evt_get_buffer_ptr returns buffer pointer */
1950 /*+ ARGUMENTS : */
1951 /*+ s_chan : structure s_evt_channel. */
1952 /*+ Return type : int. */
1953 /*+ Status codes: */
1954 /*1- C Main ****************+******************************************/
1956 {
1957  return(ps_chan->pc_io_buf);
1958 }
1959 /*1- C Main ****************+******************************************/
1960 /*+ Module : f_evt_get_newbuf */
1961 /*--------------------------------------------------------------------*/
1962 /*+ CALLING : f_evt_get_newbuf(s_evt_channel &s_chan) */
1963 /*--------------------------------------------------------------------*/
1964 /* */
1965 /*+ PURPOSE : f_evt_get_newbuf read a buffer from server */
1966 /*+ ARGUMENTS : */
1967 /*+ s_chan : structure s_evt_channel. */
1968 /*+ Return type : int. */
1969 /*+ Status codes: */
1970 /*- GETEVT__SUCCESS : success. */
1971 /*- GETEVT__FAILURE : failure */
1972 /*- GETEVT__RDERR : read server or file error */
1973 /*- GETEVT__NOMORE : No more events. */
1974 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1975 /*1- C Main ****************+******************************************/
1977 {
1978  INTS4 l_temp;
1979  CHARS * pc_temp;
1980  INTS4 l_status;
1981 
1982  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1983  switch(ps_chan->l_server_type)
1984  {
1985  case GETEVT__FILE :
1986  while(1){
1987  l_temp=read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
1988  if(l_temp == 0) return(GETEVT__NOMORE);
1989  if(l_temp == -1) return(GETEVT__RDERR);
1990  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
1991  break; /* skip out while(1) */
1992  } /* end of while(1) */
1993  break;
1994  case GETEVT__STREAM :
1995  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1996  {
1997  return(GETEVT__FAILURE);
1998  }
1999 
2000  for(l_temp=0; l_temp<ps_chan->l_bufs_in_stream; l_temp++)
2001  {
2002  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
2003  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
2004  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
2005  pc_temp+=ps_chan->l_buf_size;
2006  }
2007  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
2008  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
2009  f_evt_swap((CHARS *)&l_temp,4);
2010  if(l_temp < 0) {// server will shutdown
2011  printf("**** I-f_evt: Stream server request for disconnect!\n");
2012  f_evt_get_close(ps_chan);
2013  return(GETEVT__RDERR);
2014  }
2015  /* if first buffer is empty, all are empty */
2016  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_evt == 0) return(GETEVT__TIMEOUT);
2017  break;
2018  case GETEVT__TRANS :
2019  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
2020  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
2021  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
2022  f_evt_swap((CHARS *)&l_temp,4);
2023  if(l_temp < 0) {// server will shutdown
2024  printf("**** I-f_evt: Transport server request for disconnect!\n");
2025  f_evt_get_close(ps_chan);
2026  return(GETEVT__RDERR);
2027  }
2028  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
2029  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
2030  break;
2031  case GETEVT__RFIO :
2032  l_temp=RFIO_read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
2033  if(l_temp == 0) return(GETEVT__NOMORE);
2034  if(l_temp == -1) return(GETEVT__RDERR);
2035  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
2036  break;
2037  case GETEVT__REVSERV :
2038  case GETEVT__EVENT :
2039  default :
2040  return(GETEVT__FAILURE);
2041  } /* end of switch */
2042 
2043  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
2044  f_evt_swap(ps_chan->pc_io_buf, ps_chan->l_io_buf_size);
2045 
2046  return(GETEVT__SUCCESS);
2047 } /* end of f_evt_get_newbuf */
2048 
2049 /*1- C Main ****************+******************************************/
2050 /*+ Module : f_evt_check_buf */
2051 /*--------------------------------------------------------------------*/
2052 /*+ CALLING : f_evt_check_buf(CHARS *pc_head, INTS4 *pl_goosybuf, */
2053 /* INTS4 *pl_swap, INTS4 *pl_filehead) */
2054 /*--------------------------------------------------------------------*/
2055 /* */
2056 /*+ PURPOSE : check a buffer is a file header or GOOSY buffer, */
2057 /* and whether it's swaped. */
2058 /*+ ARGUMENTS : */
2059 /*+ pc_head : pointer to the buffer to be checked. */
2060 /*+ pl_goosybuf : 1 is goosy buffer, 0 is header */
2061 /*+ pl_swap : 1 means different endian, 0 means same endian. */
2062 /*+ pl_filehead : 1 means first buffer is header */
2063 /*+ Return type : void */
2064 /*+ Status codes: */
2065 /*+ FUNCTION : check a buffer is a file header or GOOSY buffer, */
2066 /* and whether it's swaped. */
2067 /*1- C Main ****************+******************************************/
2068 INTS4 f_evt_check_buf(CHARS *pc_head, INTS4 *pl_size, INTS4 *pl_is_goosybuf, INTS4 *pl_swap, INTS4 *pl_filehead)
2069 {
2070  INTU4 l_size;
2071 
2072  *pl_is_goosybuf=0;
2073  *pl_filehead=0;
2074  *pl_size=0;
2075  *pl_swap=0;
2076  /* first check if it's file header */
2077  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2078  (((s_filhe *)(pc_head))->filhe_type==2000) )
2079  {
2080  *pl_swap=0;
2081  *pl_is_goosybuf=0;
2082  *pl_filehead=1;
2083  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2084  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2085  if((l_size>>24) > 0) *pl_size=0;
2086  else *pl_size=l_size;
2087  return(PUTEVT__SUCCESS);
2088  }
2089  f_evt_swap(pc_head, sizeof(s_filhe));
2090  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2091  (((s_filhe *)(pc_head))->filhe_type==2000) )
2092  {
2093  *pl_swap=1;
2094  *pl_is_goosybuf=0;
2095  *pl_filehead=1;
2096  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2097  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2098  if((l_size>>24) > 0) *pl_size=0;
2099  else *pl_size=l_size;
2100  return(PUTEVT__SUCCESS);
2101  }
2102 
2103  /* if not file header, check if it's goosy buffer header */
2104  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2105  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2106  if( (((l_size>>24)== 0)&&(l_size > 0))&&
2107  (((s_bufhe *)(pc_head))->h_begin<2)&&
2108  (((s_bufhe *)(pc_head))->h_begin>=0)&&
2109  (((s_bufhe *)(pc_head))->h_end<2)&&
2110  (((s_bufhe *)(pc_head))->h_end>=0)&&
2111  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2112  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
2113  //(((s_bufhe *)(pc_head))->i_used>0)&&
2114  ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
2115  (((s_bufhe *)(pc_head))->l_free[0]==0)||
2116 /* above, because some old lsm file forgot to set this bit, so it's zero */
2117  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2118  {
2119  *pl_swap=1; /* !!!, because already swaped once */
2120  *pl_is_goosybuf=1;
2121  *pl_size=l_size;
2122  return(PUTEVT__SUCCESS);
2123  }
2124  f_evt_swap(pc_head, sizeof(s_filhe));
2125  l_size=((s_bufhe *)(pc_head))->l_dlen*2+sizeof(s_bufhe);
2126  if( (((l_size>>24)== 0)&&(l_size > 0))&&
2127  (((s_bufhe *)(pc_head))->l_dlen>0)&&
2128  (((s_bufhe *)(pc_head))->h_begin<2)&&
2129  (((s_bufhe *)(pc_head))->h_begin>=0)&&
2130  (((s_bufhe *)(pc_head))->h_end<2)&&
2131  (((s_bufhe *)(pc_head))->h_end>=0)&&
2132  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2133  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
2134  //(((s_bufhe *)(pc_head))->i_used>0)&&
2135  ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
2136  (((s_bufhe *)(pc_head))->l_free[0]==0)||
2137 /* above, because some old lsm file forgot to set this bit, so it's zero */
2138  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2139  {
2140  *pl_swap=0; /* !!!, because already swaped 2 times */
2141  *pl_is_goosybuf=1;
2142  *pl_size=l_size;
2143  return(PUTEVT__SUCCESS);
2144  }
2145  return(PUTEVT__SUCCESS);
2146 } /* end of f_evt_check_buf */
2147 
2148 /*1- C Main ****************+******************************************/
2149 /*+ Module : f_evt_ini_bufhe */
2150 /*--------------------------------------------------------------------*/
2151 /*+ CALLING : f_evt_ini_bufhe(s_evt_channel *ps_chan) */
2152 /*--------------------------------------------------------------------*/
2153 /* */
2154 /*+ PURPOSE : pre-fill each GOOSY buffer header in a stream */
2155 /*+ ARGUMENTS : */
2156 /*+ ps_chan : Address of channel structure. */
2157 /*+ Return type : void . */
2158 /*1- C Main ****************+******************************************/
2160 {
2161  INTS4 l_temp;
2162  struct timeb s_timeb;
2163 
2164  /* because "timeb" is not "typedef", so we must use "struct" */
2165 
2166  for(l_temp=0; l_temp<ps_chan->l_io_buf_size; l_temp += ps_chan->l_buf_size)
2167  {
2168  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
2169  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
2170  ps_chan->ps_bufhe->i_subtype = ps_chan->l_buf_subtype;
2171  ps_chan->ps_bufhe->i_type = ps_chan->l_buf_type;
2172  ps_chan->ps_bufhe->h_begin = 0;
2173  ps_chan->ps_bufhe->h_end = 0;
2174  ps_chan->ps_bufhe->i_used = 0;
2175  ps_chan->ps_bufhe->l_buf = ps_chan->l_buf_no; ps_chan->l_buf_no++;
2176  ps_chan->ps_bufhe->l_evt = 0;
2177  ps_chan->ps_bufhe->l_current_i = 0;
2178  ftime(&s_timeb);
2179  ps_chan->ps_bufhe->l_time[0]=(INTS4)s_timeb.time;
2180  ps_chan->ps_bufhe->l_time[1]=(INTS4)s_timeb.millitm;
2181  ps_chan->ps_bufhe->l_free[0] = 1; /* for swap flag */
2182  ps_chan->ps_bufhe->l_free[1] = 0;
2183  ps_chan->ps_bufhe->l_free[2] = 0;
2184  ps_chan->ps_bufhe->l_free[3] = 0;
2185  }
2186  return(PUTEVT__SUCCESS);
2187 } /* end of f_evt_ini_bufhe */
2188 
2189 /*1+ C Main ****************+******************************************/
2190 /*+ Module : f_evt_cre_tagfile */
2191 /*--------------------------------------------------------------------*/
2192 /*+ CALLING : f_evt_cre_tagfile(lmdfile,tagfile,filter) */
2193 /*--------------------------------------------------------------------*/
2194 /* */
2195 /*+ PURPOSE : Create a tag file from lmd file */
2196 /*+ ARGUMENTS : */
2197 /*+ lmdfile : LMD file name */
2198 /*+ tagfile : tag file name */
2199 /*+ filter : optional function for filter */
2200 /*+ Return type : INTS4 . */
2201 /*+ Status codes: */
2202 /*- GETEVT__SUCCESS : success. */
2203 /*- GETEVT__NOFILE : file does not exist. */
2204 /*- GETEVT__TAGWRERR : tag file write error. */
2205 /*- GETEVT__RDERR : lmd read error. */
2206 /*+ Declaration : */
2207 /* INTS4 f_evt_cre_tagfile(CHARS *,CHARS *, INTS4 (*)()); */
2208 /*+ FUNCTION : Create a tag file from lmd file */
2209 /*+ filter : The filter function is called at the beginning */
2210 /* with a NULL as argument, then for each event */
2211 /* with the event pointer. Returning 0 skips the event, */
2212 /* 1 takes the event into the tag file. */
2213 /* Different tag files can be created from one lmd file. */
2214 /*1- C Main ****************+******************************************/
2216 {
2217  /* take it */
2218 return(1);
2219 //if(ps_ve10_1 != NULL)
2220 //{
2221 // printf("Filter %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d\n",
2222 // ps_ve10_1->l_count,
2223 // ps_ve10_1->i_type,
2224 // ps_ve10_1->i_subtype,
2225 // ps_ve10_1->l_dlen,
2226 // ps_ve10_1->i_trigger);
2227 // if(ps_ve10_1->l_count%2) return(1); /* take it */
2228 // else return(0); /* skip it */
2229 //}
2230 //else printf("Initialized filter function\n");
2231 // return(0);
2232 }
2233 INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag,INTS4 (*e_filter)())
2234 {
2235  INTS4 ii,l_take_it,l_temp,l_chan,l_out,l_file_pos=0,l_bufnr=0,l_events=0;
2236  INTS4 l_firste,*pl,l_len,l_last=-1,l_lin=0,l_fragsize, la_head[2];
2237  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;
2238  INTS2 *pi;
2239  INTU4 *ps,*pd;
2240  CHARS c_lmd[128], c_tag[128], *pc_temp,*pc_evt_buf=NULL;
2241  s_ve10_1 *ps_ve10_1;
2242  s_bufhe *ps_bufhe;
2243  s_taghe s_taghe;
2244  s_tag s_tag;
2245 
2246  ps_bufhe = (s_bufhe *)c_temp;
2247  printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
2248  /* get file attributes */
2249  if((l_chan=open(pc_lmd,GET__OPEN_FLAG))== -1) return(GETEVT__NOFILE);
2250  /* read first 512 bytes */
2251  if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
2252  {
2253  close(l_chan);
2254  return(GETEVT__RDERR);
2255  }
2256  /* check for file header, return size and swap */
2257  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
2258  if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
2259  {
2260  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
2261  close(l_chan);
2262  return(GETEVT__NOLMDFILE);
2263  }
2264  /* read file header and first buffer and check for goosy header */
2265  if(l_filehead == 1)
2266  {
2267  lseek(l_chan, 0, SEEK_SET); /* rewind file */
2268  if(read(l_chan,c_temp,l_size_head)!=l_size_head)
2269  {
2270  close(l_chan);
2271  return(GETEVT__RDERR);
2272  }
2273  if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
2274  {
2275  close(l_chan);
2276  return(GETEVT__RDERR);
2277  }
2278  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
2279  if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
2280  {
2281  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
2282  close(l_chan);
2283  return(GETEVT__NOLMDFILE);
2284  }
2285  }/* check buffer behind header */
2286 
2287  lseek(l_chan, 0, SEEK_SET); /* rewind file */
2288 
2289  printf("Buffer swap %d, File header %d, LMD buffer %d, size %d[b]\n",l_swap,l_filehead,l_is_goosybuf,l_size);
2290 
2291  /* found file header, skip */
2292  if(l_filehead == 1)
2293  {
2294  if(read(l_chan,c_temp,l_size)!=l_size)
2295  {
2296  close(l_chan);
2297  return(GETEVT__RDERR);
2298  }
2299  l_file_pos += l_size;
2300  l_bufnr++;
2301  }
2302 
2303  /* Open and create tag file */
2304  if((l_out=open(pc_tag,PUT__CRT_FLAG,DEF_FILE_ACCE))== -1) return(GETEVT__NOFILE);
2305  write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe));
2306 
2307  /* Initialize filter function */
2308  if(e_filter != NULL) ii=(*e_filter)(NULL);
2309 
2310  while(read(l_chan,c_temp,l_size)==l_size)
2311  {
2312  l_file_pos=l_bufnr*l_size;
2313  if(l_swap) f_evt_swap(c_temp,l_size);
2314  if((ps_bufhe->h_end)&(ps_bufhe->h_begin)&(ps_bufhe->l_evt==1))
2315  {
2316  /* only fragment, next buffer */
2317  /* printf("Event fragment skipped Buffer %6d\n",l_bufnr);*/
2318  l_bufnr++;
2319  continue;
2320  }
2321  ps_ve10_1=(s_ve10_1 *)(ps_bufhe + 1);
2322  pl = (INTS4 *)ps_ve10_1;
2323  l_file_pos += sizeof(s_bufhe);
2324  /* skip fragment at begin */
2325  if(ps_bufhe->h_end)
2326  {
2327  l_len = (*pl>>1)+2;
2328  l_file_pos += (l_len<<2); /* bytes */
2329  ps_ve10_1=(s_ve10_1 *)(pl+l_len);
2330  pl = (INTS4 *)ps_ve10_1;
2331  ps_bufhe->l_evt--;
2332  /* printf("Event fragment end skipped Buffer %6d\n",l_bufnr);*/
2333  }
2334  for(ii=1;ii<ps_bufhe->l_evt;ii++) /* except last element */
2335  {
2336  /*printf("Event %10d pos %10d Buffer %6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2337  if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
2338  else l_take_it=1;
2339  l_len = (*pl>>1)+2;
2340  s_tag.l_event=ps_ve10_1->l_count;
2341  s_tag.l_offset=l_file_pos;
2342  if(l_take_it)
2343  {
2344  l_events++;
2345  if(ps_ve10_1->l_count != (l_last+1))
2346  {
2347  l_lin++;
2348  if(l_lin == 1)l_firste=ps_ve10_1->l_count;
2349  /* printf("New event number offset %d, index %d\n",ps_ve10_1->l_count,l_events);*/
2350  }
2351  l_last=ps_ve10_1->l_count;
2352  if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
2353  {
2354  close(l_chan);
2355  close(l_out);
2356  return(GETEVT__TAGWRERR);
2357  }
2358  }
2359  l_file_pos += (l_len<<2); /* bytes */
2360  ps_ve10_1=(s_ve10_1 *)(pl+l_len);
2361  pl = (INTS4 *)ps_ve10_1;
2362  }
2363 
2364  if(ps_bufhe->l_evt > 0)
2365  {
2366  if(ps_ve10_1->l_dlen < 4) printf("Buffer %d Event fragment %10d dlen %d ts %d %d trigger %d\n"
2367  ,l_bufnr,ps_ve10_1->l_count,ps_ve10_1->l_dlen,ps_ve10_1->i_type,
2368  ps_ve10_1->i_subtype,ps_ve10_1->i_trigger);
2369  s_tag.l_event=ps_ve10_1->l_count;
2370  if(ps_bufhe->h_begin)
2371  {
2372  /* copy event to event buffer for filter function */
2373  if(e_filter != NULL)
2374  {
2375  /* is event buffer big enough? */
2376  l_evsize=ps_bufhe->l_free[1]+4; /* total words */
2377  if(l_evt_buf_size < l_evsize*2)
2378  {
2379  if(pc_evt_buf != NULL)free(pc_evt_buf);
2380  l_evt_buf_size=l_evsize*2;
2381  pc_evt_buf=(CHARS *)malloc(l_evt_buf_size);
2382  }
2383  /* copy event fragment to buffer */
2384  ps=(INTU4 *)ps_ve10_1;
2385  pd=(INTU4 *)pc_evt_buf;
2386  l_fragsize = ps_ve10_1->l_dlen+4; /* fragment size + header [w] */
2387  for(ii=0;ii<l_fragsize/2;ii++) *pd++ = *ps++;
2388  /* loop over fragments */
2389  while(l_fragsize < l_evsize)
2390  {
2391  if(read(l_chan,c_temp,l_size) != l_size)break;
2392  l_bufnr++;
2393  if(l_swap) f_evt_swap(c_temp,l_size);
2394  ps = (INTU4 *) (ps_bufhe+1); /* behind buffer header, fragment header */
2395  l_temp=(INTS4)*ps; /* fragment size [w] */
2396  ps += 2; /* to data behind fragment header */
2397  for(ii=0;ii<l_temp/2;ii++) *pd++ = *ps++;
2398  l_fragsize += l_temp;
2399  }
2400  if(l_fragsize < l_evsize)break;
2401  ps_ve10_1 = (s_ve10_1 *)pc_evt_buf;
2402  ps_ve10_1->l_dlen=l_evsize-4;
2403  /* rewind last buffer, will be read again by while loop */
2404  l_bufnr--;
2405  lseek(l_chan, -l_size, SEEK_CUR);
2406  }
2407  s_tag.l_offset=-l_file_pos;
2408  /* printf("Event %10d pos %10d Buffer -%6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2409  }
2410  else
2411  {
2412  s_tag.l_offset=l_file_pos;
2413  /* printf("Event %10d pos %10d Buffer %6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2414  }
2415  if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
2416  else l_take_it=1;
2417  if(l_take_it)
2418  {
2419  l_events++;
2420  if(ps_ve10_1->l_count != (l_last+1))
2421  {
2422  l_lin++;
2423  if(l_lin == 1)l_firste=ps_ve10_1->l_count;
2424  /* printf("New event number offset %d, index %d\n",ps_ve10_1->l_count,l_events);*/
2425  }
2426  l_last=ps_ve10_1->l_count;
2427  if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
2428  {
2429  close(l_chan);
2430  close(l_out);
2431  return(GETEVT__TAGWRERR);
2432  }
2433  }
2434  }
2435  l_bufnr++;
2436  /* if(l_bufnr > 3) break; */
2437  }
2438  lseek(l_out, 0, SEEK_SET); /* rewind file */
2439  s_taghe.l_endian = 1;
2440  s_taghe.l_version = 1;
2441  s_taghe.l_bufsize = l_size;
2442  s_taghe.l_buffers = l_bufnr;
2443  s_taghe.l_events = l_events;
2444  s_taghe.l_filesize = sizeof(s_tag)*l_events;
2445  s_taghe.l_linear = (l_lin == 1);
2446  s_taghe.l_first = l_firste;
2447  s_taghe.l_last = s_tag.l_event;
2448  if(write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe)) != sizeof(s_taghe))
2449  {
2450  close(l_chan);
2451  close(l_out);
2452  return(GETEVT__TAGWRERR);
2453  }
2454  close(l_chan);
2455  close(l_out);
2456  printf("Buffers %6d, of size %d, Events %10d, first %d, last %d "
2457  ,s_taghe.l_buffers
2458  ,s_taghe.l_bufsize
2459  ,s_taghe.l_events
2460  ,s_taghe.l_first
2461  ,s_taghe.l_last);
2462  if(s_taghe.l_linear)printf("linear\n");
2463  else printf("not linear\n");
2464 
2465  return(GETEVT__SUCCESS);
2466 } /* end of f_evt_cre_tagfile */
2467 /*1+ C Main ****************+******************************************/
2468 /*+ Module : f_evt_get_tagopen */
2469 /*--------------------------------------------------------------------*/
2470 /*+ CALLING : f_evt_get_tagopen(channel,tagfile,lmdfile,header,print) */
2471 /*--------------------------------------------------------------------*/
2472 /* */
2473 /*+ PURPOSE : Open tag and lmd file */
2474 /*+ ARGUMENTS : */
2475 /*+ channel : s_evt_channel* , must be allocated. */
2476 /*+ tagfile : Name of tag file */
2477 /*+ filename : LMD file name */
2478 /*+ header : address of CHARS pointer. If it is not NULL, then */
2479 /* try to return file header or other information */
2480 /* about server. If it is NULL, then returns nothing. */
2481 /*+ print : Print flag: 1=verbose */
2482 /*+ Return type : INTS4 . */
2483 /*+ Status codes: */
2484 /*- GETEVT__SUCCESS : success. */
2485 /*- GETEVT__NOFILE : file does not exist. */
2486 /*- GETEVT__TAGRDERR : tag file read error. */
2487 /*- GETEVT__RDERR : read server error. */
2488 /*+ Declaration : */
2489 /* INTS4 f_evt_get_tagopen( */
2490 /* s_evt_channel *,CHARS *,CHARS *,CHARS **,INTS4); */
2491 /*+ FUNCTION : Open tag file and lmd file. If no tag file is found, */
2492 /* a standard f_evt_get_open is called. In this case */
2493 /* following tag functions call standard f_evt_get functions. */
2494 /*1- C Main ****************+******************************************/
2495 INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan,CHARS *pc_tag,CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
2496 {
2497  INTS4 l_temp,ii;
2498  s_bufhe *ps_bufhe;
2499 
2500  ps_chan->ps_tag = NULL; /* tagfile buffer */
2501  ps_chan->ps_taghe = NULL;
2502  if(l_prihe)printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
2503 
2504  /* if tag file name not specified, do not try to open it SL:11.11.09*/
2505  if ((pc_tag==0) || (*pc_tag==0))
2506  ps_chan->l_tagfile_no = -1;
2507  else
2508  ps_chan->l_tagfile_no = open(pc_tag, GET__OPEN_FLAG);
2509 
2510  /* open tag file and read header */
2511  if(ps_chan->l_tagfile_no == -1)
2512  {
2513  /* no tag file, use normal open */
2514  /*=============================================*/
2515  ii=f_evt_get_open(GETEVT__FILE, pc_lmd, ps_chan, (CHARS **) &ps_bufhe,0,0);
2516  *ps_head = (CHARS *) ps_bufhe;
2517  if(ii!=GETEVT__SUCCESS)
2518  {
2519  printf("Error opening input file %s\n",pc_lmd);
2520  return (ii);
2521  }
2522  /* printf("No tag file for %s\n",pc_lmd); */
2523  if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
2524  return(GETEVT__SUCCESS);
2525  }
2526  /*=============================================*/
2527  /* tag file found */
2528  ps_chan->ps_taghe = (s_taghe *)malloc(sizeof(s_taghe));
2529  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_taghe,sizeof(s_taghe))!=sizeof(s_taghe))
2530  {
2531  free(ps_chan->ps_taghe);
2532  ps_chan->ps_taghe = NULL;
2533  close(ps_chan->l_tagfile_no);
2534  return(GETEVT__TAGRDERR);
2535  }
2536  if(ps_chan->ps_taghe->l_endian != 1)ps_chan->l_tagswap=1;
2537  if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_chan->ps_taghe,sizeof(s_taghe));
2538  if(l_prihe)
2539  {
2540  printf("Buffers %6d, of size %d, Events %10d, first %d, last %d"
2541  ,ps_chan->ps_taghe->l_buffers
2542  ,ps_chan->ps_taghe->l_bufsize
2543  ,ps_chan->ps_taghe->l_events
2544  ,ps_chan->ps_taghe->l_first
2545  ,ps_chan->ps_taghe->l_last);
2546  if(ps_chan->ps_taghe->l_linear)printf(" linear\n");
2547  else printf(" not linear\n");
2548  }
2549  if((ps_chan->l_channel_no=open(pc_lmd,GET__OPEN_FLAG))== -1)
2550  {
2551  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2552  ps_chan->ps_taghe = NULL;
2553  close(ps_chan->l_tagfile_no);
2554  return(GETEVT__NOFILE);
2555  }
2556  /* read buffer header to check if we have to swap */
2557  ps_bufhe = (s_bufhe *)c_temp;
2558  if(read(ps_chan->l_channel_no,c_temp,ps_chan->ps_taghe->l_bufsize)!=ps_chan->ps_taghe->l_bufsize)
2559  {
2560  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2561  ps_chan->ps_taghe = NULL;
2562  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2563  ps_chan->ps_tag = NULL;
2564  close(ps_chan->l_tagfile_no);
2565  close(ps_chan->l_channel_no);
2566  return(GETEVT__RDERR);
2567  }
2568  if(ps_chan->ps_taghe->l_linear == 0)
2569  {
2570  ps_chan->ps_tag = (s_tag *)malloc(ps_chan->ps_taghe->l_filesize);
2571  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_tag,ps_chan->ps_taghe->l_filesize)!=ps_chan->ps_taghe->l_filesize)
2572  {
2573  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2574  ps_chan->ps_taghe = NULL;
2575  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2576  ps_chan->ps_tag = NULL;
2577  close(ps_chan->l_tagfile_no);
2578  close(ps_chan->l_channel_no);
2579  return(GETEVT__TAGRDERR);
2580  }
2581  }
2582  if(ps_bufhe->l_free[0] != 1)ps_chan->l_lmdswap=1;
2583  if(ps_chan->l_lmdswap)f_evt_swap_filhe(ps_bufhe);
2584  if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
2585  if(ps_head != NULL)
2586  {
2587  if(ps_bufhe->i_type == 2000) *ps_head = (CHARS *)ps_bufhe;
2588  }
2589  ps_chan->l_evt_buf_size=0;
2590  ps_chan->pc_evt_buf=NULL;
2591  ps_chan->l_io_buf_posi=0; /* keeps index of last event */
2592  return(GETEVT__SUCCESS);
2593 }
2594 
2595 /*1+ C Main ****************+******************************************/
2596 /*+ Module : f_evt_get_tagnext */
2597 /*--------------------------------------------------------------------*/
2598 /*+ CALLING : f_evt_get_tagnext(channel,skip,**event) */
2599 /*--------------------------------------------------------------------*/
2600 /* */
2601 /*+ PURPOSE : Get tagged event from lmd file */
2602 /*+ ARGUMENTS : */
2603 /*+ channel : s_evt_channel* , must be allocated. */
2604 /*+ event : address of pointer. If it is not NULL, then */
2605 /* return event pointer. */
2606 /*+ Return type : INTS4 . */
2607 /*+ Status codes: */
2608 /*- GETEVT__SUCCESS : success. */
2609 /*- GETEVT__NOFILE : file does not exist. */
2610 /*- GETEVT__TAGRDERR : tag file read error. */
2611 /*- GETEVT__RDERR : lmd read error. */
2612 /*- GETEVT__FRAGMENT : Event fragment found. */
2613 /*- GETEVT__NOMORE : No more events. */
2614 /*+ Declaration : */
2615 /* INTS4 f_evt_get_tagnext(s_evt_channel *,INTS4,INTS4 **); */
2616 /*+ FUNCTION : Get next event at current position, either in tag */
2617 /* file, or in lmd file. Optional <skip> events are skipped. */
2618 /*1- C Main ****************+******************************************/
2619 INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan,INTS4 l_skip, INTS4 **pl_event)
2620 {
2621  INTS4 ii,*pl,kk;
2622  /* no tagfile */
2623  /*=============================================*/
2624  if(ps_chan->ps_taghe == NULL)
2625  {
2626  for(kk=0;kk<=l_skip;kk++)
2627  {
2628  ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
2629  if(ii != GETEVT__SUCCESS) break;
2630  }
2631  }
2632  /*=============================================*/
2633  else
2634  {
2635  /* l_io_buf_posi is the index of last event */
2636  ii=f_evt_get_tagevent(ps_chan,ps_chan->l_io_buf_posi+l_skip+1,1,(INTS4 **)&pl);
2637  }
2638  if(pl_event != NULL) *pl_event=pl;
2639  return(ii);
2640 }
2641 /*1+ C Main ****************+******************************************/
2642 /*+ Module : f_evt_get_tagevent */
2643 /*--------------------------------------------------------------------*/
2644 /*+ CALLING : f_evt_get_tagevent(*channel, value, mode, **event) */
2645 /*--------------------------------------------------------------------*/
2646 /* */
2647 /*+ PURPOSE : Get tagged event from lmd file */
2648 /*+ ARGUMENTS : */
2649 /*+ channel : s_evt_channel* , must be allocated. */
2650 /*+ value : event number or index */
2651 /*+ mode : 0: value is number, 1: value is index */
2652 /*+ event : address of pointer. If it is not NULL, then */
2653 /* return event pointer. */
2654 /*+ Return type : INTS4 . */
2655 /*+ Status codes: */
2656 /*- GETEVT__SUCCESS : success. */
2657 /*- GETEVT__TAGRDERR : tag file read error. */
2658 /*- GETEVT__RDERR : lmd read error. */
2659 /*- GETEVT__FRAGMENT : Event fragment found. */
2660 /*- GETEVT__NOMORE : No more events. */
2661 /*- GETEVT__NOTAG : Specified event not in tag file. */
2662 /*+ Declaration : */
2663 /* INTS4 f_evt_get_tagevent( */
2664 /* s_evt_channel *,INTS4,INTS4,INTS4 **); */
2665 /*+ FUNCTION : Get tag event. If no tag file is there, skip <value> */
2666 /* events, or look for event number <value> */
2667 /*1- C Main ****************+******************************************/
2668 INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan,INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
2669 {
2670  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;
2671  INTS4 la_head[2],*pl;
2672  CHARS *pc;
2673  s_ve10_1 *ps_ve10_1;
2674  s_bufhe *ps_bufhe;
2675  s_tag *ps_tag;
2676  s_tag s_tag_l;
2677  s_filhe *ps_filhe;
2678  s_evt_channel s_chan_i;
2679 
2680  l_typ=l_type;
2681  l_val=l_value;
2682  /* no tagfile */
2683  /*=============================================*/
2684  if(ps_chan->ps_taghe == NULL)
2685  {
2686  /* search by index */
2687  if(l_type == 1)
2688  {
2689  if(l_val == 0) l_val=1;
2690  for(kk=0;kk<l_val;kk++)
2691  {
2692  ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
2693  if(ii != GETEVT__SUCCESS)return(ii);
2694  }
2695  *pl_event=pl;
2696  }
2697  else /* search by event number */
2698  {
2699  ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
2700  if(ii != GETEVT__SUCCESS)return(ii);
2701  while(ps_ve10_1->l_count != l_val)
2702  {
2703  ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
2704  if(ii != GETEVT__SUCCESS)return(ii);
2705  }
2706  *pl_event = (INTS4 *)ps_ve10_1;
2707  }
2708  return(GETEVT__SUCCESS);
2709  }
2710  /*=============================================*/
2711  ps_ve10_1 = (s_ve10_1 *)c_temp;
2712  ps_bufhe = (s_bufhe *)c_temp;
2713 
2714  /* linear==1 means that event numbers are subsequent. */
2715  /* in that case we can calculate index from number */
2716  if(ps_chan->ps_taghe->l_linear)
2717  {
2718  if(l_typ == 0)l_val=l_value-ps_chan->ps_taghe->l_first+1;
2719  l_typ=1;
2720  }
2721  /* search by index or by value */
2722  if(l_typ == 1)
2723  {
2724  if(l_val > ps_chan->ps_taghe->l_events)
2725  {
2726  printf("Event index %d not found\n",l_val);
2727  return(GETEVT__NOTAG);
2728  }
2729  if(l_val == 0) l_val=1;
2730  ps_tag=(s_tag *)&s_tag_l;
2731  lseek(ps_chan->l_tagfile_no, (l_val-1)*sizeof(s_tag)+sizeof(s_taghe), SEEK_SET); /* set file offset*/
2732  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_tag,sizeof(s_tag))!=sizeof(s_tag))
2733  {
2734  return(GETEVT__TAGRDERR);
2735  }
2736  if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_tag,sizeof(s_tag));
2737  ps_chan->l_io_buf_posi=l_val; /* keeps index */
2738  }
2739  else
2740  {
2741  ps_tag=ps_chan->ps_tag;
2742  for(ii=1;ii<=ps_chan->ps_taghe->l_events;ii++)
2743  {
2744  if(ps_tag->l_event == l_val) break;
2745  ps_tag++;
2746  }
2747  if(ps_tag->l_event != l_val)
2748  {
2749  printf("Event number %d not found\n",l_val);
2750  return(GETEVT__NOTAG);
2751  }
2752  ps_chan->l_io_buf_posi=ii; /* keeps index of last event */
2753  }
2754  /* now we have the requested event in ps_tag */
2755  l_off=ps_tag->l_offset;
2756  if(l_off < 0) l_off=((-l_off)/ps_chan->ps_taghe->l_bufsize)*ps_chan->ps_taghe->l_bufsize;
2757  l_evt=ps_tag->l_event;
2758  /* full event in buffer, read */
2759  if(ps_tag->l_offset > 0)
2760  {
2761  ps_ve10_1 = (s_ve10_1 *)c_temp;
2762  lseek(ps_chan->l_channel_no, l_off, SEEK_SET); /* set file offset*/
2763  if(read(ps_chan->l_channel_no,c_temp,8)!=8) return(GETEVT__RDERR);
2764  if(ps_chan->l_lmdswap)f_evt_swap(c_temp,8);
2765  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);
2766  if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2);
2767  /*ii=f_evt_type(NULL,(s_evhe *)ps_ve10_1,-1,0,1,1);*/
2768  }
2769  else
2770  /* spanning event begin, read to event buffer */
2771  {
2772  lseek(ps_chan->l_channel_no, l_off, SEEK_SET); /* set file offset to buffer begin */
2773  if(read(ps_chan->l_channel_no,c_temp,sizeof(s_bufhe))!=sizeof(s_bufhe)) return(GETEVT__RDERR);
2774  if(ps_chan->l_lmdswap)f_evt_swap(c_temp,sizeof(s_bufhe));
2775  /* is event buffer big enough? */
2776  l_evsize=ps_bufhe->l_free[1]+4; /* total words */
2777  if(ps_chan->l_evt_buf_size < l_evsize*2)
2778  {
2779  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
2780  ps_chan->l_evt_buf_size=l_evsize*2;
2781  ps_chan->pc_evt_buf=(CHARS *)malloc(ps_chan->l_evt_buf_size);
2782  }
2783  l_fragsize=0;
2784  ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
2785  lseek(ps_chan->l_channel_no, -ps_tag->l_offset, SEEK_SET); /* set file offset*/
2786  if(read(ps_chan->l_channel_no,ps_chan->pc_evt_buf,8)!=8) return(GETEVT__RDERR);
2787  if(ps_chan->l_lmdswap)f_evt_swap(ps_chan->pc_evt_buf,8);
2788  pc=ps_chan->pc_evt_buf+8;
2789  /* read fragment */
2790  if(read(ps_chan->l_channel_no,pc,ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
2791  l_fragsize += ps_ve10_1->l_dlen+4; /* fragment size + header [w] */
2792  pc += ps_ve10_1->l_dlen*2; /* next in event buffer */
2793  ps_ve10_1->l_dlen=l_evsize-4; /* set correct event size */
2794  /* loop over fragments */
2795  while(l_fragsize < l_evsize)
2796  {
2797  l_off += ps_chan->ps_taghe->l_bufsize; /* next buffer absolut address */
2798  lseek(ps_chan->l_channel_no,l_off+sizeof(s_bufhe), SEEK_SET); /* set file offset*/
2799  if(read(ps_chan->l_channel_no,(CHARS *)&la_head,8)!=8) return(GETEVT__RDERR);
2800  if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&la_head,8);
2801  if(read(ps_chan->l_channel_no,pc,la_head[0]*2)!=la_head[0]*2) return(GETEVT__RDERR);
2802  pc += la_head[0]*2;
2803  l_fragsize += la_head[0];
2804  }
2805  /* now swap whole event in buffer */
2806  pc=ps_chan->pc_evt_buf+8; /* header already swapped */
2807  ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
2808  if(ps_chan->l_lmdswap)f_evt_swap(pc,ps_ve10_1->l_dlen*2);
2809  }
2810  *pl_event = (INTS4 *)ps_ve10_1;
2811  return(GETEVT__SUCCESS);
2812 } /* end of f_evt_ini_bufhe */
2813 
2814 /*1+ C Main ****************+******************************************/
2815 /*+ Module : f_evt_get_tagclose */
2816 /*--------------------------------------------------------------------*/
2817 /*+ CALLING : f_evt_get_tagclose(s_evt_channel) */
2818 /*--------------------------------------------------------------------*/
2819 /* */
2820 /*+ PURPOSE : Close tag and lmd file, cleanup s_evt_channel */
2821 /*+ ARGUMENTS : */
2822 /*+ channel : s_evt_channel* , must be allocated. */
2823 /*+ Return type : INTS4 */
2824 /*+ Declaration : */
2825 /* INTS4 f_evt_get_tagclose(s_evt_channel *); */
2826 /*+ FUNCTION : Create a tag file from lmd file */
2827 /*1- C Main ****************+******************************************/
2829 {
2830  /*=============================================*/
2831  if(ps_chan->ps_taghe == NULL)
2832  {
2833  f_evt_get_close(ps_chan);
2834  return(GETEVT__SUCCESS);
2835  }
2836  /*=============================================*/
2837  free(ps_chan->ps_taghe);
2838  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2839  if(ps_chan->pc_evt_buf != NULL) free(ps_chan->pc_evt_buf);
2840  close(ps_chan->l_tagfile_no);
2841  close(ps_chan->l_channel_no);
2842  memset((void *)ps_chan, 0, sizeof(s_evt_channel)); /* clear memory */
2843  return(GETEVT__SUCCESS);
2844 }
2846  s_evt_channel *x;
2847  x=(s_evt_channel *)malloc(sizeof(s_evt_channel));
2848  memset(x,0,sizeof(s_evt_channel));
2849  return(x);
2850  }
INTS4 l_buf_type
Definition: f_evt.h:64
#define GETEVT__NOSERVER
Definition: f_evt.h:143
INTS2 filhe_file_l
Definition: s_filhe.h:69
INTS4 l_last
Definition: f_evt.h:48
INTS4 f_evt_rev_port(INTS4 l_port)
Definition: f_evt.c:518
int f_evcli_evt(s_evt_channel *ps_chan)
Definition: f_evcli.c:474
CHARS h_end
Definition: s_bufhe.h:48
#define PUTEVT__SUCCESS
Definition: f_evt.h:154
#define GETEVT__SUCCESS
Definition: f_evt.h:138
CHARS filhe_file[86]
Definition: s_filhe.h:70
INTS4 l_channel_no
Definition: f_evt.h:66
#define PUTEVT__CLOSE_ERR
Definition: f_evt.h:159
s_tag * ps_tag
Definition: f_evt.h:96
INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d, INTS4 *pl_lwords)
Definition: f_evt.c:243
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition: f_stccomm.c:1068
CHARS * pc_evt_buf
Definition: f_evt.h:87
INTS4 f_evt_type(s_bufhe *ps_bufhe, s_evhe *ps_evhe, INTS4 l_subid, INTS4 l_long, INTS4 l_hex, INTS4 l_data)
Definition: f_evt.c:306
INTS4 f_evt_tag_filter(s_ve10_1 *ps_ve10_1)
Definition: f_evt.c:2215
INTS4 l_first_buf
Definition: f_evt.h:84
#define GETLMD__EOFILE
Definition: fLmd.h:30
short INTS2
Definition: typedefs.h:26
#define LMD__INDEX
Definition: sMbs.h:26
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
Definition: f_stccomm.c:129
INTS4 l_buffers
Definition: f_evt.h:44
#define LMD__LARGE_FILE
Definition: sMbs.h:28
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1113
#define GETEVT__TIMEOUT
Definition: f_evt.h:147
INTS4 l_lmdswap
Definition: f_evt.h:94
CHARS h_subcrate
Definition: s_ves10_1.h:41
sLmdControl * pLmd
Definition: f_evt.h:97
CHARS filhe_run[66]
Definition: s_filhe.h:75
INTS4 l_evt
Definition: s_bufhe.h:51
#define GETLMD__NOMORE
Definition: fLmd.h:31
INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan, CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
Definition: f_evt.c:561
s_bufhe s_bufhe_1
Definition: f_evt.h:89
INTS4 f_evt_get_buffer(s_evt_channel *ps_chan, INTS4 *ps_buffer)
Definition: f_evt.c:1717
INTS2 filhe_used
Definition: s_filhe.h:60
#define LMD__NO_OVERWRITE
Definition: sMbs.h:35
CHARS string[78]
Definition: s_filhe.h:22
INTS4 l_free[4]
Definition: s_bufhe.h:54
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition: f_stccomm.c:315
#define LMD__NO_INDEX
Definition: sMbs.h:34
INTS4 l_first_get
Definition: f_evt.h:82
CHARS filhe_exp[66]
Definition: s_filhe.h:77
INTS4 f_evt_timeout(s_evt_channel *ps_chan, INTS4 l_sec)
Definition: f_evt.c:1858
#define MAX_BUF_LGTH
Definition: f_evt.h:34
#define GETEVT__NOCHANNEL
Definition: f_evt.h:146
s_bufhe * ps_bufhe
Definition: f_evt.h:88
#define GETEVT__NOFILE
Definition: f_evt.h:142
#define PORT__TRANSPORT
Definition: portnum_def.h:19
INTS4 l_buf_size
Definition: f_evt.h:67
INTS4 f_evt_put_event(s_evt_channel *ps_chan, INTS4 *pl_evt_buf)
Definition: f_evt.c:1327
Definition: s_evhe.h:32
#define PUTEVT__TOOBIG
Definition: f_evt.h:157
s_evt_channel * f_evt_control()
Definition: f_evt.c:2845
#define GETEVT__FAILURE
Definition: f_evt.h:139
INTS2 filhe_subtype
Definition: s_filhe.h:59
#define GETEVT__TAGWRERR
Definition: f_evt.h:151
INTS2 i_subtype
Definition: s_bufhe.h:46
INTS4 l_bufs_in_stream
Definition: f_evt.h:71
INTS2 i_type
Definition: s_ve10_1.h:38
#define GETEVT__NOLMDFILE
Definition: f_evt.h:152
uint32_t fLmdGetMbsEvent(sLmdControl *pLmdControl, sMbsHeader **event)
Definition: fLmd.c:422
INTS4 filhe_lines
Definition: s_filhe.h:78
INTS2 i_procid
Definition: s_ves10_1.h:40
int f_evcli_close(s_evt_channel *ps_chan)
Definition: f_evcli.c:493
#define RFIO_lseek
Definition: f_evt.c:162
INTS2 i_type
Definition: s_evhe.h:35
INTS4 f_evt_source_port(INTS4 l_port)
Definition: f_evt.c:495
INTS4 l_first_put
Definition: f_evt.h:83
#define RFIO_open
Definition: f_evt.c:159
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
Definition: f_evt.c:1610
#define GETEVT__EVENT
Definition: f_evt.h:130
uint32_t fLmdGetElement(sLmdControl *pLmdControl, uint32_t iEvent, sMbsHeader **event)
Definition: fLmd.c:710
int l
Definition: f_mbs_status.c:34
#define GETEVT__NOMORE
Definition: f_evt.h:141
#define MIN_BUF_LGTH
Definition: f_evt.h:35
INTS4 l_filesize
Definition: f_evt.h:46
#define PUTEVT__FAILURE
Definition: f_evt.h:156
INTS4 l_buf_no
Definition: f_evt.h:68
s_taghe * ps_taghe
Definition: f_evt.h:95
INTS2 filhe_type
Definition: s_filhe.h:58
CHARS * pc_io_buf
Definition: f_evt.h:86
#define STC__TIMEOUT
Definition: f_stccomm.h:369
INTS4 f_stc_discclient(INTS4 i_channel)
Definition: f_stccomm.c:1149
CHARS * f_evt_get_buffer_ptr(s_evt_channel *ps_chan)
Definition: f_evt.c:1955
#define GETEVT__NOTAGFILE
Definition: f_evt.h:148
uint32_t fLmdInitMbs(sLmdControl *pLmdControl, char *Nodename, uint32_t iMaxBytes, uint32_t iBuffers, uint32_t iStreams, uint32_t iPort, uint32_t iTimeout)
Definition: fLmd.c:382
uint32_t fLmdPutClose(sLmdControl *pLmdControl)
Definition: fLmd.c:297
static int l_gl_source_port
Definition: f_evt.c:184
uint32_t fLmdGetClose(sLmdControl *pLmdControl)
Definition: fLmd.c:789
INTS4 l_evt_buf_posi
Definition: f_evt.h:76
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
Definition: f_stccomm.c:470
INTS4 l_offset
Definition: f_evt.h:55
INTS2 i_type
Definition: s_bufhe.h:45
unsigned int INTU4
Definition: typedefs.h:29
int f_evcli_buf(s_evt_channel *ps_chan)
Definition: f_evcli.c:383
#define GETEVT__NOTAG
Definition: f_evt.h:149
#define STC__SUCCESS
Definition: f_stccomm.h:364
#define MAX_LONG
Definition: f_evt.h:37
struct cv_string s_strings[30]
Definition: s_filhe.h:79
INTS4 l_dlen
Definition: s_bufhe.h:44
INTS4 l_dlen
Definition: s_ve10_1.h:37
#define GETEVT__RDERR
Definition: f_evt.h:144
INTS2 filhe_user_l
Definition: s_filhe.h:71
#define GETEVT__TRANS
Definition: f_evt.h:129
INTS4 l_stream_bufs
Definition: f_evt.h:72
INTS4 l_first
Definition: f_evt.h:47
INTS4 f_evt_get_newbuf(s_evt_channel *)
Definition: f_evt.c:1976
int l_status
Definition: f_evcli.c:183
INTS4 l_tagswap
Definition: f_evt.h:93
INTS4 l_dlen
Definition: s_ves10_1.h:37
#define LMD__BUFFER
Definition: sMbs.h:30
#define LMD__TIMEOUT
Definition: fLmd.h:36
int INTS4
Definition: typedefs.h:28
CHARS h_begin
Definition: s_bufhe.h:49
INTS4 f_evt_check_buf(CHARS *, INTS4 *, INTS4 *, INTS4 *, INTS4 *)
Definition: f_evt.c:2068
INTS4 filhe_dlen
Definition: s_filhe.h:57
INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan, INTS4 l_skip, INTS4 **pl_event)
Definition: f_evt.c:2619
INTS4 l_tagfile_no
Definition: f_evt.h:92
INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan)
Definition: f_evt.c:2159
#define GETEVT__FRAGMENT
Definition: f_evt.h:140
INTS4 l_version
Definition: f_evt.h:42
#define PUTEVT__TOO_SMALLS
Definition: f_evt.h:158
INTS2 i_subtype
Definition: s_evhe.h:36
#define PUTEVT__WRERR
Definition: f_evt.h:160
CHARS filhe_label[30]
Definition: s_filhe.h:68
CHARS filhe_time[24]
Definition: s_filhe.h:73
CHARS filhe_user[30]
Definition: s_filhe.h:72
Definition: f_evt.h:39
#define RFIO_close
Definition: f_evt.c:160
static CHARS c_temp[MAX_BUF_LGTH]
Definition: f_evt.c:183
INTS4 l_endian
Definition: f_evt.h:41
#define GETEVT__REVSERV
Definition: f_evt.h:131
INTS4 l_evt_size
Definition: f_evt.h:77
uint32_t fLmdGetOpen(sLmdControl *pLmdControl, char *Filename, sMbsFileHeader *pBuffHead, uint32_t iBytes, uint32_t iUseOffset)
Definition: fLmd.c:505
INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag, INTS4(*e_filter)())
Definition: f_evt.c:2233
INTS2 i_trigger
Definition: s_ve10_1.h:41
#define PUTEVT__FILE_EXIST
Definition: f_evt.h:155
static int l_gl_evt_check
Definition: f_evt.c:185
INTS2 filhe_label_l
Definition: s_filhe.h:67
CHARS c_channel[128]
Definition: f_evt.h:91
INTS4 f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe)
Definition: f_evt.c:1470
#define PORT__EVENT_SERV
Definition: portnum_def.h:22
INTS4 l_events
Definition: f_evt.h:45
INTS4 l_frag_len
Definition: f_evt.h:85
INTS4 l_bufsize
Definition: f_evt.h:43
uint32_t fLmdCloseMbs(sLmdControl *pLmdControl)
Definition: fLmd.c:405
INTS4 f_evt_skip_buffer(s_evt_channel *ps_chan, INTS4 l_buffer)
Definition: f_evt.c:1803
#define PUTEVT__NOCHANNEL
Definition: f_evt.h:161
INTS4 l_timeout
Definition: f_evt.h:78
static struct s_tcpcomm s_tcpcomm_st_evt
Definition: f_evt.c:182
INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan, CHARS *pc_tag, CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
Definition: f_evt.c:2495
#define MAX__DLEN
Definition: s_bufhe.h:21
INTS4 f_ut_utime(INTS4, INTS4, CHARS *)
Definition: f_ut_utime.c:63
INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan, INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
Definition: f_evt.c:2668
sLmdControl * fLmdAllocateControl()
Definition: fLmd.c:872
INTS4 l_io_buf_size
Definition: f_evt.h:73
INTS2 filhe_run_l
Definition: s_filhe.h:74
INTS4 f_evt_put_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1516
INTS4 l_current_i
Definition: s_bufhe.h:52
INTS4 f_evt_swap(CHARS *pc_source, INTS4 l_length)
Definition: f_evt.c:1878
INTS4 l_buf_posi
Definition: f_evt.h:69
#define PORT__STREAM_SERV
Definition: portnum_def.h:21
uint32_t fLmdPutElement(sLmdControl *pLmdControl, sMbsHeader *pHeader)
Definition: fLmd.c:189
Definition: f_evt.h:52
#define LMD__TYPE_FILE_HEADER_101_1
Definition: sMbs.h:17
#define RFIO_read
Definition: f_evt.c:161
INTS2 filhe_exp_l
Definition: s_filhe.h:76
INTS4 filhe_stime[2]
Definition: s_filhe.h:65
INTS4 l_dlen
Definition: s_evhe.h:34
uint32_t fLmdPutOpen(sLmdControl *pLmdControl, char *Filename, sMbsFileHeader *pBuffHead, uint32_t iBytes, uint32_t iOver, uint32_t iUseOffset, uint32_t iLargeFile)
Definition: fLmd.c:119
INTS2 i_type
Definition: s_ves10_1.h:38
INTS4 l_buf
Definition: s_bufhe.h:50
struct s_tcpcomm * pTCP
Definition: fLmd.h:65
INTS4 l_time[2]
Definition: s_bufhe.h:53
#define GETLMD__NOBUFFER
Definition: fLmd.h:32
INTS4 l_linear
Definition: f_evt.h:49
#define GETEVT__TAGRDERR
Definition: f_evt.h:150
INTS4 l_event
Definition: f_evt.h:54
INTS2 i_subtype
Definition: s_ve10_1.h:39
INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream, INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
Definition: f_evt.c:1205
char CHARS
Definition: typedefs.h:21
INTS4 filhe_free[4]
Definition: s_filhe.h:66
INTS4 l_buf_subtype
Definition: f_evt.h:65
INTS4 f_evt_get_tagclose(s_evt_channel *ps_chan)
Definition: f_evt.c:2828
INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
Definition: f_evt.c:923
INTS2 i_used
Definition: s_bufhe.h:47
uint32_t fLmdPutBuffer(sLmdControl *pLmdControl, sMbsHeader *pHeader, uint32_t Items)
Definition: fLmd.c:248
#define GETEVT__FILE
Definition: f_evt.h:127
s_ve10_1 * ps_ve10_1
Definition: f_evt.h:90
#define GETEVT__RFIO
Definition: f_evt.h:132
int f_evcli_con(s_evt_channel *ps_chan, char *pc_node, int l_aport, int l_aevents, int l_asample)
Definition: f_evcli.c:199
INTS2 i_subtype
Definition: s_ves10_1.h:39
#define GETEVT__STREAM
Definition: f_evt.h:128
INTS4 f_evt_swap_filhe(s_bufhe *)
Definition: f_evt.c:1915
#define GETEVT__CLOSE_ERR
Definition: f_evt.h:145
INTS4 l_count
Definition: s_ve10_1.h:42
INTS4 l_io_buf_posi
Definition: f_evt.h:74
INTS4 l_evt_buf_size
Definition: f_evt.h:75
CHARS h_control
Definition: s_ves10_1.h:42
INTS4 l_server_type
Definition: f_evt.h:63
INTS4 l_buf_lmt
Definition: f_evt.h:70