SURFEX v8.1
General documentation of Surfex
lfi_alts.c
Go to the documentation of this file.
1 /**** *lfi_alts.c* - LFI library
2  *
3  * Author.
4  * -------
5  * Philippe Marguinaud *METEO-FRANCE*
6  * Original : 12-08-2013
7  * Modified : 08-12-2014 Portability on Mac OSX
8  *
9  * Description :
10  * This LFI library can handle native LFI files
11  */
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <time.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #if defined(DARWIN)
21 #include <limits.h>
22 #define MAXINT INT_MAX
23 #define MAXLONG LONG_MAX
24 #elif defined(MACOSX)
25 #include <limits.h>
26 #define MAXLONG LONG_MAX
27 #else
28 #include <values.h>
29 #endif
30 
31 #include "lfi_type.h"
32 #include "lfi_alts.h"
33 #include "lfi_dumm.h"
34 #include "lfi_miss.h"
35 #include "lfi_abor.h"
36 #include "lfi_misc.h"
37 #include "lfi_verb.h"
38 #include "lfi_fmul.h"
39 #include "lfi_altm.h"
40 #include "lfi_util.h"
41 #include "lfi_grok.h"
42 
43 #include "drhook.h"
44 
45 /* Ancillary macros */
46 
47 #define ARTNLEN 16
48 #define minARTN(x) ((x) > ARTNLEN ? ARTNLEN : (x))
49 
50 #define eqan(a,b) (strncmp ((a), (b), ARTNLEN) == 0)
51 #define neqan(a,b) (!eqan(a,b))
52 
53 
54 /* Reserved article names */
55 static const char
56  * fin_d_index = "**FIN D'INDEX** ", /* End of article index */
57  * trou__index = " ", /* Hole in the index */
58  * page__index = "****************" /* Placeholder for extra index sections */
59  ;
60 
61 /* File header */
62 typedef struct lfi_alts_fh_hdr_t
63 {
64  integer64 size; /* Size in bytes of a physical article */
65  integer64 ilpar; /* Taille d'un article physique en mots de 8 octets */
66  integer64 ilmna; /* Taille maximale des noms d'articles */
67  integer64 ifeam; /* Flag de fermeture correcte de fichier */
68  integer64 illdo; /* Taille de l'entete */
69  integer64 inaph; /* Nombre d'articles physiques */
70  integer64 inalo; /* Nombre d'articles logiques */
71  integer64 ilnal; /* Taille minimale d'un article logique */
72  integer64 ilxal; /* Taille maximale d'un article logique */
73  integer64 iltal; /* Taille totale des donnees */
74  integer64 inres; /* Nombre de reecritures avec la meme taille */
75  integer64 inrec; /* Nombre de reecritures avec des donnees plus courtes */
76  integer64 inrel; /* Nombre de reecritures avec des donnees plus longues */
77  integer64 ixapi; /* */
78  integer64 idcre; /* Date de creation */
79  integer64 ihcre; /* Heure de creation */
80  integer64 iddmg; /* Date de derniere modification */
81  integer64 ihdmg; /* Heure de derniere modification */
82  integer64 idmng; /* Date de premiere modification */
83  integer64 ihmng; /* Heure de premiere modification */
84  integer64 inpir; /* ? */
85  integer64 intru; /* Nombre de trous */
86  integer64 iaxpd; /* Nombre maximum d'articles physiques */
87  integer64 ioffi[1]; /* Extra index position */
88 }
90 
91 /* Article descriptor */
92 typedef struct lfi_alts_fh_idx_t
93 {
94  integer64 len; /* Article length; length is reckoned in 8b words */
95  integer64 pos; /* Article position in the LFI file; position is reckoned */
96  /* in 8b words, starting from one */
97  character name[ARTNLEN]; /* Article name */
99 
100 typedef enum lfi_alts_fh_kind_t
101 {
106 
107 /* Open file descriptor */
108 typedef struct lfi_alts_fh_t
109 {
110  lfi_alts_fh_kind_t kind;
111  FILE * fp; /* stdio file descriptor for this file */
112  int fd; /* file descriptor */
113  long offset; /* current offset */
114  char * buf;
115  integer64 inumer; /* Unit number */
116  char * cnomf; /* File name */
117  char * cstto; /* Fortran status */
118  integer64 inimes; /* Message level */
119  logical llerfa; /* All errors are fatal */
120  int lswap; /* File requires byte-swap */
121  integer64 fmult; /* Facteur multiplicatif */
122  integer64 nart; /* Maximum number of articles */
123  integer64 iart; /* Current article */
124  int modified; /* File was modified */
125  lfi_alts_fh_hdr_t * hdr; /* File header */
126  lfi_alts_fh_idx_t * idx; /* File article index */
127  struct lfi_alts_fh_t * next; /* Next file */
128 }
130 
131 /* LFI library data */
132 typedef struct lfi_alts_t
133 {
134  char cmagic[8];
135  lfi_alts_fh_t * fh; /* File descriptor list */
136  int fmult; /* Default for the "facteur multiplicatif" */
137  lfi_fmul_t * fmult_list; /* Predefined units and "facteurs multiplicatifs" */
138  int nerfag; /* Erreurs fatales */
139  int inivau; /* Niveau global des messages */
140  int iulout; /* Unite Fortran pour impression des messages */
141 }
142 lfi_alts_t;
143 
144 
145 static const int use_fd = 0;
146 static const int buf_sz = 0;
147 
148 /* Open file; try various modes depending on Fortran status */
149 static void fh_open (lfi_alts_fh_t * fh, char * cnomf, char * cstto, lfi_alts_fh_kind_t kind, integer64 * KREP)
150 {
151  FILE * fp = NULL;
152 
153  errno = 0;
154 
155  *KREP = 0;
156 
157  if (kind == FH_KIND_RECORD)
158  {
159  fp = NULL;
160  }
161  else if (kind == FH_KIND_STREAM)
162  {
163  if ((cnomf[0] == '-') && (cnomf[1] == '\0'))
164  fp = stdout;
165  else
166  fp = fopen (cnomf, "w");
167  }
168  else if (strcmp (cstto, "NEW") == 0)
169  {
170  fp = fopen (cnomf, "r");
171  if (fp != NULL)
172  {
173  fclose (fp);
174  fp = NULL;
175  goto end;
176  }
177  fp = fopen (cnomf, "w+");
178  }
179  else if (strcmp (cstto, "OLD") == 0)
180  {
181  fp = fopen (cnomf, "r+");
182  if (fp == NULL)
183  fp = fopen (cnomf, "r");
184  }
185  else
186  {
187  fp = fopen (cnomf, "r+");
188  if (fp == NULL)
189  fp = fopen (cnomf, "w+");
190  if (fp == NULL)
191  fp = fopen (cnomf, "r");
192  }
193 
194 
195 end:
196 
197  fh->fp = fp;
198  fh->kind = kind;
199 
200  if (kind == FH_KIND_RECORD)
201  {
202  fh->fd = -1;
203  }
204  else if (fp == NULL)
205  {
206  *KREP = -9;
207  fh->fd = -1;
208  }
209  else
210  {
211  fh->fd = fileno (fp);
212  fh->buf = NULL;
213  if (buf_sz > 0)
214  {
215  fh->buf = (char *)malloc (buf_sz);
216  setvbuf (fh->fp, fh->buf, _IOFBF, buf_sz);
217  }
218  }
219 
220  return;
221 }
222 
223 static void fh_close (lfi_alts_fh_t * fh, integer64 * KREP)
224 {
225  if (fh->kind != FH_KIND_RECORD)
226  {
227  errno = 0;
228  *KREP = fclose (fh->fp);
229  if (fh->buf != NULL)
230  free ((void *)fh->buf);
231  fh->fp = NULL;
232  }
233 }
234 
235 static integer64 fh_seek (lfi_alts_fh_t * fh, integer64 pos, int whence)
236 {
237  if (fh->kind != FH_KIND_REGULAR)
238  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
239 
240  if (use_fd)
241  {
242  fh->offset = lseek (fh->fd, pos, whence);
243  }
244  else
245  {
246  if (fseek (fh->fp, pos, whence) == 0)
247  fh->offset = ftell (fh->fp);
248  else
249  return -1;
250  }
251  return fh->offset;
252 }
253 
254 static void fh_flush (lfi_alts_fh_t * fh)
255 {
256  if (fh->kind == FH_KIND_RECORD)
257  return;
258  if (! use_fd)
259  fflush (fh->fp);
260 }
261 
262 static void fh_fstat (lfi_alts_fh_t * fh, struct stat * st)
263 {
264  if (fh->kind == FH_KIND_RECORD)
265  memset (st, 0, sizeof (struct stat));
266  fstat (fh->fd, st);
267 }
268 
269 /* Read a chunk of data; pos and len are in bytes, starting from zero */
270 static void fh_read (lfi_alts_fh_t * fh, void * ptr, integer64 pos, integer64 len, int lswap)
271 {
272  integer64 lenr = len;
273  char * _ptr = (char *)ptr;
274 
275  if (fh->kind != FH_KIND_REGULAR)
276  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
277 
278  errno = 0;
279 
280  if (fh->offset != pos)
281  if (fh_seek (fh, pos, SEEK_SET) < 0)
282  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
283 
284  while (lenr > 0)
285  {
286  integer64 nr = use_fd
287  ? read (fh->fd, &_ptr[len-lenr], lenr)
288  : fread (&_ptr[len-lenr], 1, lenr, fh->fp);
289  if (nr == 0)
290  break;
291  lenr -= nr;
292  }
293 
294  if (lenr > 0)
295  lfi_abor ("Reading %lld bytes at offset %lld, from unit %lld failed",
296  len, pos, fh->inumer);
297 
298  fh->offset += len;
299 
300  if (fh->lswap && lswap)
301  {
302  int t = 8, n = len / 8;
303  jswap_ (ptr, ptr, &t, &n);
304  }
305 }
306 
307 /* Write a chunk of data; pos and len are in bytes, starting from zero */
308 static void fh_write (lfi_alts_fh_t * fh, void * ptr, integer64 pos, integer64 len, int lswap)
309 {
310  char * _ptr;
311  integer64 lenw = len;
312 
313  if (fh->kind == FH_KIND_RECORD)
314  {
315  if (fh->offset != pos)
316  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
317  fh->offset += len;
318  return;
319  }
320 
321  errno = 0;
322 
323  if (fh->lswap && lswap)
324  {
325  int t = 8, n = len / 8;
326  _ptr = (char *)malloc (len);
327  jswap_ (_ptr, ptr, &t, &n);
328  }
329  else
330  {
331  _ptr = (char *)ptr;
332  }
333 
334  if (fh->offset != pos)
335  if (fh_seek (fh, pos, SEEK_SET) < 0)
336  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
337 
338  while (lenw > 0)
339  {
340  integer64 nw = use_fd
341  ? write (fh->fd, &_ptr[len-lenw], lenw)
342  : fwrite (&_ptr[len-lenw], 1, lenw, fh->fp);
343  if (nw == 0)
344  break;
345  lenw -= nw;
346  }
347 
348  if (lenw > 0)
349  lfi_abor ("Writing %lld bytes at offset %lld, in unit %lld failed",
350  len, pos, fh->inumer);
351 
352  fh->offset += len;
353 
354  if (fh->lswap && lswap)
355  free ((void *)_ptr);
356 }
357 
358 /* Retrieve current date */
359 static void xgetdate (integer64 * YYYYMMDD, integer64 * HHmmss)
360 {
361  time_t T = time (NULL);
362  struct tm TM;
363 
364  gmtime_r (&T, &TM);
365 
366  *YYYYMMDD = (1900 + TM.tm_year) * 10000 + (1 + TM.tm_mon) * 100 + TM.tm_mday;
367  *HHmmss = TM.tm_hour * 10000 + TM.tm_min * 100 + TM.tm_sec;
368 
369 }
370 
371 /* Write file header; a side effect is that some statistics are updated.
372  * if kind is true, then it is assumed that these statistics are correct,
373  * and the file header is written without doing any fseeks */
375 {
376  int isize = fh->hdr->size;
377  int ioffib = isize / 8 - fh->hdr->illdo;
378  character csect2[isize];
379  integer64 isect3[isize/8];
380  int iart, iartx;
381  int iidx;
382 
383  *KREP = 0;
384 
385  integer64 YYYYMMDD, HHmmss;
386  xgetdate (&YYYYMMDD, &HHmmss);
387 
388  fh->hdr->iddmg = YYYYMMDD;
389  fh->hdr->ihdmg = HHmmss;
390 
391  if (fh->kind == FH_KIND_STREAM || fh->kind == FH_KIND_RECORD)
392  {
393  fh_write (fh, &fh->hdr->ilpar, 0*isize, isize, 1);
394  }
395  else
396  {
397  fh->hdr->ilnal = +MAXLONG;
398  fh->hdr->ilxal = 0;
399  }
400 
401 
402  for (iartx = 0, iidx = 0; ; iidx++)
403  {
404  integer64 offsetx = iidx ? (fh->hdr->ioffi[ioffib-iidx]-1) * isize : isize;
405 
406  if (offsetx < 0)
407  break;
408 
409  for (iart = 0; iart < isize / ARTNLEN; iart++, iartx++)
410  {
411  while (eqan (fh->idx[iartx].name, page__index))
412  iartx++;
413  isect3[iart*2] = fh->idx[iartx].len;
414  isect3[iart*2+1] = fh->idx[iartx].pos;
415  memcpy (&csect2[iart*ARTNLEN], fh->idx[iartx].name, ARTNLEN);
416 
417  if ((fh->kind == FH_KIND_REGULAR) && neqan (fh->idx[iartx].name, trou__index) && neqan (fh->idx[iartx].name, fin_d_index))
418  {
419  if (fh->idx[iartx].len < fh->hdr->ilnal)
420  fh->hdr->ilnal = fh->idx[iartx].len;
421  if (fh->idx[iartx].len > fh->hdr->ilxal)
422  fh->hdr->ilxal = fh->idx[iartx].len;
423  }
424  }
425 
426  fh_write (fh, csect2, offsetx, isize, 0);
427  fh_write (fh, isect3, offsetx + isize, isize, 1);
428  }
429 
430  if (fh->kind == FH_KIND_REGULAR)
431  fh_write (fh, &fh->hdr->ilpar, 0*isize, isize, 1);
432 
433  return;
434 }
435 
436 /* If file size is not a multiple of physical article size,
437  * then pad file with zeroes */
439 {
440  integer64 nr;
441  integer64 sz;
442 
443  *KREP = 0;
444 
445  if (fh->kind == FH_KIND_STREAM || fh->kind == FH_KIND_RECORD)
446  /* Assume we are already at EOF
447  * we need this option in case we are writing to a fifo
448  */
449  {
450  sz = fh->offset;
451  }
452  else
453  {
454  if ((sz = fh_seek (fh, 0, SEEK_END)) < 0)
455  lfi_abor ("Cannot fseek unit %lld, `%s'", fh->inumer, fh->cnomf);
456  }
457 
458  if ((nr = sz % fh->hdr->size) != 0)
459  {
460  integer64 nw = fh->hdr->size - nr;
461  char * buf = (char *)malloc (nw);
462  memset (buf, 0, nw);
463  fh_write (fh, buf, sz, nw, 0);
464  free (buf);
465  }
466 
467  return;
468 }
469 
470 
471 /* Set modified status */
472 static void fh_modified (lfi_alts_fh_t * fh)
473 {
474  integer64 flag = 1;
475  integer64 IREP = 0;
476 
477 
478  if (fh->kind != FH_KIND_REGULAR)
479  return;
480 
481  if (fh->modified)
482  return;
483 
484  fh_write_hdr (fh, &IREP);
485  fh_write (fh, &flag, 16, 8, 1);
486  fh_flush (fh);
487 
488  fh->modified = 1;
489 }
490 
491 /* Cast void * to a lfi_alts_t pointer and make a check */
492 static lfi_alts_t * lookup_als (void * LFI)
493 {
494  lfi_alts_t * als = LFI;
495  if (strncmp (als->cmagic, "lfi_alts", 8))
496  lfi_abor ("Corrupted descriptor");
497  return als;
498 }
499 
500 /* Search for open file by unit number (KNUMER) */
501 static lfi_alts_fh_t * lookup_fh (lfi_alts_t * als, integer64 * KNUMER, int fatal)
502 {
503  lfi_alts_fh_t * fh;
504  for (fh = als->fh; fh; fh = fh->next)
505  if (fh->inumer == *KNUMER)
506  return fh;
507  if (fatal)
508  lfi_abor ("File number `%lld' is not opened", *KNUMER);
509  return NULL;
510 }
511 
512 /* Check article name length */
513 static int check_an_len (const char * CDNOMA, const character_len CDNOMA_len)
514 {
515  int len = lfi_fstrlen (CDNOMA, CDNOMA_len);
516  return len > ARTNLEN ? 0 : 1;
517 }
518 
519 /* Check article name */
520 static int check_an (const char * CDNOMA, const character_len CDNOMA_len)
521 {
522  int len;
523  if (! check_an_len (CDNOMA, CDNOMA_len))
524  return 0;
525  len = minARTN (CDNOMA_len);
526  return strncmp (CDNOMA, fin_d_index, len)
527  && strncmp (CDNOMA, trou__index, len)
528  && strncmp (CDNOMA, page__index, len);
529 }
530 
531 /* Search for an article given its name */
532 static int lookup_rc (lfi_alts_fh_t * fh, character * name, character_len name_len)
533 {
534  char _name[ARTNLEN];
535  int iart;
536 
537  if (! check_an_len (name, name_len))
538  return -15;
539 
540  memset (_name, ' ', ARTNLEN);
541  memcpy (_name, name, minARTN (name_len));
542 
543  /* Look around current article */
544  if (fh->iart >= 0)
545  {
546  const int da = 1;
547  int iart1 = fh->iart-da > 0 ? fh->iart-da : 0;
548  int iart2 = fh->iart+da < fh->nart ? fh->iart+da : fh->nart;
549  for (iart = iart1; iart < iart2; iart++)
550  if (eqan (_name, fh->idx[iart].name))
551  return iart;
552  }
553 
554  for (iart = 0; iart < fh->nart; iart++)
555  if (eqan (_name, fh->idx[iart].name))
556  return iart;
557 
558  return -20;
559 }
560 
561 /* Search for next/previous article */
562 static int seek_rc (lfi_alts_fh_t * fh, int d)
563 {
564  int iart = fh->iart;
565 
566  d = d >= 0 ? +1 : -1;
567 
568  if ((d < 0) && (iart < 0))
569  iart = fh->nart;
570 
571  while (1)
572  {
573  iart = iart + d;
574  if ((iart >= fh->nart) || (iart < 0))
575  goto ko;
576  if (eqan (fh->idx[iart].name, fin_d_index) && (d > 0))
577  goto ko;
578  if (neqan (fh->idx[iart].name, trou__index) && neqan (fh->idx[iart].name, page__index))
579  goto ok;
580  }
581 
582  return 0;
583 ko:
584  return -1;
585 ok:
586  return iart;
587 }
588 
589 /* Assuming index is full, grow index and return a pointer on first empty slot */
590 static void fh_grow_idx (lfi_alts_fh_t * fh, integer64 alen, int * iartx)
591 {
592  int ioffib = fh->hdr->size / 8 - fh->hdr->illdo;
593  int nart = fh->nart + fh->hdr->size / ARTNLEN + 1; /* The 1 is here to store the new index section position */
594  int iart;
595  int iidx;
596  int iart_idx;
597  int iart_art;
598  integer64 pos, pose;
599 
600  /* Look for an empty index slot in header; we need that to mark the extra index section position in the article index */
601  for (iidx = 0; fh->hdr->ioffi[ioffib-1-iidx]; iidx++);
602  if (ioffib-1-iidx == fh->hdr->illdo)
603  {
604  *iartx = -1;
605  return;
606  }
607 
608  fh->idx = (lfi_alts_fh_idx_t *)realloc (fh->idx, sizeof (lfi_alts_fh_idx_t) * nart);
609 
610  /* Fill new entries with empty slot values */
611 
612  for (iart = fh->nart; iart < nart; iart++)
613  {
614  fh->idx[iart].len = 0;
615  fh->idx[iart].pos = 0;
616  memcpy (fh->idx[iart].name, fin_d_index, ARTNLEN);
617  }
618 
619  /* For some reason, the legacy LFI prefers that the article to be written be
620  * inserted before the new index entry
621  */
622 
623  iart_art = fh->nart;
624  iart_idx = fh->nart + 1;
625 
626  /* Compute len and pos of index section and add it in the index */
627 
628  fh->idx[iart_idx].len = 2 * fh->hdr->size / 8;
629  pos = fh->idx[iart_idx-2].pos + fh->idx[iart_idx-2].len + alen;
630 
631  pose = (pos-1) % (fh->hdr->size / 8);
632 
633  if (pose > 0)
634  pos += (fh->hdr->size / 8) - pose;
635 
636  fh->idx[iart_idx].pos = pos;
637 
638  memcpy (fh->idx[iart_idx].name, page__index, ARTNLEN);
639 
640  /* Update header */
641 
642  if (ioffib-1-iidx < 0)
643  lfi_abor ("Internal error: index is full");
644 
645  fh->hdr->ioffi[ioffib-1-iidx] = 1 + ((pos-1) * 8) / fh->hdr->size;
646 
647  *iartx = iart_art;
648  fh->nart = nart;
649 
650 }
651 
652 #define ALS_DECL \
653  lfi_alts_t * als = lookup_als (LFI);
654 #define FH_DECL(fatal) \
655  lfi_alts_fh_t * fh = lookup_fh (als, KNUMER, fatal);
656 #define ART_DECL \
657  int iart = lookup_rc (fh, CDNOMA, CDNOMA_len);
658 
659 /* Extended lfiouv; the extra kind argument tells that we are writing to a fifo or a socket */
660 static void lfiouv_alts_ext (LFIOUV_ARGS_DECL, lfi_alts_fh_kind_t kind)
661 {
662  ALS_DECL;
663  FH_DECL (0);
664  char * clendi;
665  char * cnomf, * cstto;
666  int iislen, llrqle;
667  struct stat st;
668  int old;
669  int isize;
670  character CLNOMF[32];
671 
672  DRHOOK_START ("lfiouv_alts_ext");
673 
674  if (fh != NULL)
675  {
676  *KREP = -13;
677  goto end;
678  }
679 
680  if (! istrue (*LDNOMM))
681  {
682  if (*KNUMER <= 0)
683  lfi_abor ("LDNOMM=T is not compatible with KNUMER<=0");
684  CDNOMF_len = sprintf (CLNOMF, "fort.%lld", *KNUMER);
685  CDNOMF = CLNOMF;
686  }
687 
688  cnomf = lfi_fstrdup (CDNOMF, CDNOMF_len, NULL);
689  cstto = lfi_fstrdup (CDSTTO, CDSTTO_len, NULL);
690 
691  fh = (lfi_alts_fh_t *)malloc (sizeof (lfi_alts_fh_t));
692  memset (fh, 0, sizeof (*fh));
693 
694  fh_open (fh, cnomf, cstto, kind, KREP);
695 
696  if (*KREP != 0)
697  {
698  free (cnomf);
699  free (cstto);
700  free (fh);
701  goto end;
702  }
703 
704  if (*KNUMER == 0)
705  {
706  /* Allocate a unit number for this file */
707  integer64 inumer = -1000000;
708  lfi_alts_fh_t * fh;
709 again:
710  for (fh = als->fh; fh; fh = fh->next)
711  if (fh->inumer == inumer)
712  {
713  inumer--;
714  goto again;
715  }
716  *KNUMER = inumer;
717  }
718 
719  fh->cnomf = cnomf;
720  fh->cstto = cstto;
721  fh->inumer = *KNUMER;
722  fh->inimes = *KNIMES;
723  fh->llerfa = *LDERFA;
724  fh->offset = 0;
725  fh->iart = -1;
726  fh->modified = 0;
727 
728  /* Facteur multiplicatif */
729 
730  fh->fmult = als->fmult;
731  lfi_fmul_get (als->fmult_list, KNUMER, &fh->fmult);
732 
733  /* Choose endian mode */
734 
735  clendi = getenv ("LFI_BYTE_ORDER");
736  iswap_isle_ (&iislen);
737 
738  if (clendi && strcmp (clendi, "LITTLE_ENDIAN") == 0)
739  llrqle = 1;
740  else if (clendi && strcmp (clendi, "BIG_ENDIAN") == 0)
741  llrqle = 0;
742  else if (clendi && strcmp (clendi, "NATIVE_ENDIAN") == 0)
743  llrqle = iislen;
744  else
745  llrqle = 0;
746 
747  fh->lswap = iislen != llrqle;
748 
749  fh_fstat (fh, &st);
750 
751  old = st.st_size > 0;
752 
753  /* File already exists; grok its endianess */
754  if (old)
755  {
756  integer64 i_lfi_s1_2[2], i_lfi_s1_1;
757  DRHOOK_START ("lfiouv_alts_ext:read1");
758  fh_read (fh, i_lfi_s1_2, 0, 16, 0);
759  DRHOOK_END (0);
760  i_lfi_s1_1 = i_lfi_s1_2[0];
761  fh->lswap = i_lfi_s1_2[1] > 128;
762  if (fh->lswap)
763  {
764  int t = 8, n = 1;
765  jswap_ (&i_lfi_s1_1, &i_lfi_s1_1, &t, &n);
766  }
767  fh->fmult = i_lfi_s1_1 / 512;
768  }
769 
770  isize = sizeof (integer64) * 512 * fh->fmult;
771 
772  fh->nart = isize / ARTNLEN;
773  fh->hdr = (lfi_alts_fh_hdr_t *)malloc (sizeof (lfi_alts_fh_hdr_t) + sizeof (integer64) * isize);
774  fh->hdr->size = isize;
775 
776  /* File already exists; read header and index */
777 
778  if (old)
779  {
780  character csect2[isize];
781  integer64 isect3[isize/8];
782  int iidx, iidy, nidx;
783  int iart;
784  int ioffib;
785 
786  DRHOOK_START ("lfiouv_alts_ext:read");
787 
788  fh_read (fh, &fh->hdr->ilpar, 0*isize, isize, 1);
789 
790  /* Count indexes that may be scattered inside the file */
791 
792  ioffib = isize / 8 - fh->hdr->illdo;
793 
794  for (nidx = 0; fh->hdr->ioffi[ioffib-1-nidx]; nidx++);
795 
796  /* Update maximum number of articles */
797 
798  fh->nart = (isize / ARTNLEN) * (nidx + 1) + nidx;
799 
800  /* Allocate index struct; up to maximum number of articles */
801 
802  fh->idx = (lfi_alts_fh_idx_t *)malloc (sizeof (lfi_alts_fh_idx_t) * fh->nart);
803 
804  /* Read all index data */
805  for (iart = 0, iidx = 0, iidy = 1; iidx < nidx + 1; iidx++)
806  {
807  integer64 offsetx = iidx ? (fh->hdr->ioffi[ioffib-iidx]-1) * isize : isize;
808  int iartx;
809 
810  fh_read (fh, csect2, offsetx + 0, isize, 0);
811  fh_read (fh, isect3, offsetx + isize, isize, 1);
812 
813  for (iartx = 0; iartx < isize / ARTNLEN; iartx++, iart++)
814  {
815  integer64 len = isect3[iartx*2],
816  pos = isect3[iartx*2+1];
817 
818  /* Add a dummy article for each index that is embedded within data */
819 
820  if (fh->hdr->ioffi[ioffib-iidy])
821  {
822  int ioffi;
823  while ((ioffi = fh->hdr->ioffi[ioffib-iidy]))
824  {
825  integer64 offsety = (ioffi-1) * isize;
826  if ((pos-1)*8 < offsety)
827  break;
828  fh->idx[iart].len = 2 * isize / 8;
829  fh->idx[iart].pos = 1 + offsety / 8;
830  memcpy (fh->idx[iart].name, page__index, ARTNLEN);
831  iart++;
832  iidy++;
833  }
834  }
835 
836  fh->idx[iart].len = len;
837  fh->idx[iart].pos = pos;
838  memcpy (fh->idx[iart].name, &csect2[iartx*ARTNLEN], ARTNLEN);
839  }
840 
841  }
842 
843  /* End of index */
844  for (iart = fh->nart-1; iart >= 0; iart--)
845  if (eqan (fh->idx[iart].name, trou__index))
846  memcpy (fh->idx[iart].name, fin_d_index, ARTNLEN);
847  else
848  break;
849 
850  DRHOOK_END (0);
851  }
852  else
853  {
854  /* New file; create a header and an index */
855 
856  int iart;
857  integer64 YYYYMMDD, HHmmss;
858 
859  fh->idx = (lfi_alts_fh_idx_t *)malloc (sizeof (lfi_alts_fh_idx_t) * fh->nart);
860 
861  xgetdate (&YYYYMMDD, &HHmmss);
862  memset (&fh->hdr->ilpar, 0, fh->hdr->size);
863  for (iart = 0; iart < fh->nart; iart++)
864  {
865  fh->idx[iart].len = 0;
866  fh->idx[iart].pos = 0;
867  memcpy (fh->idx[iart].name, fin_d_index, ARTNLEN);
868  }
869  fh->hdr->inaph = 3;
870  fh->hdr->ilpar = isize / 8;
871  fh->hdr->ixapi = isize / 16;
872  fh->hdr->ilmna = ARTNLEN;
873  fh->hdr->ifeam = 0;
874  fh->hdr->illdo = 22;
875  fh->hdr->idcre = YYYYMMDD;
876  fh->hdr->iddmg = YYYYMMDD;
877  fh->hdr->idmng = YYYYMMDD;
878  fh->hdr->ihcre = HHmmss;
879  fh->hdr->ihdmg = HHmmss;
880  fh->hdr->ihmng = HHmmss;
881  fh->hdr->inpir = 1;
882 
883  fh_modified (fh);
884  }
885 
886 
887  fh->next = als->fh;
888  als->fh = fh;
889 
890 
891  *KNBARI = fh->hdr->inalo - fh->hdr->intru;
892 
893  if (fh->hdr->ifeam != 0)
894  *KREP = -11;
895  else
896  *KREP = 0;
897 
898 end:
899  DRHOOK_END (0);
900  return;
901 }
902 
903 static void lfiouv_alts (LFIOUV_ARGS_DECL)
904 {
905  DRHOOK_START ("lfiouv_alts");
906  lfiouv_alts_ext (LFIOUV_ARGS_LIST, FH_KIND_REGULAR);
907  DRHOOK_END (0);
908 }
909 
910 static void lfifer_alts (LFIFER_ARGS_DECL)
911 {
912  ALS_DECL;
913  lfi_alts_fh_t * fh, * fg;
914  DRHOOK_START ("lfifer_alts");
915 
916  *KREP = 0;
917 
918  /* We search the file handle by hand, because we need to update the list of opened file handles */
919 
920  for (fh = als->fh, fg = NULL; fh; fg = fh, fh = fh->next)
921  if (fh->inumer == *KNUMER)
922  break;
923 
924  if (fh == als->fh)
925  als->fh = fh->next;
926  else
927  fg->next = fh->next;
928 
929  if (fh->modified)
930  {
931  fh_write_hdr (fh, KREP);
932  if (*KREP != 0)
933  goto end;
934  fh_write_pad (fh, KREP);
935  if (*KREP != 0)
936  goto end;
937  }
938 
939  if (*KREP == 0)
940  fh_close (fh, KREP);
941 
942 end:
943 
944  free (fh->cnomf);
945  free (fh->cstto);
946  free (fh->idx);
947  free (fh->hdr);
948 
949  free (fh);
950 
951  DRHOOK_END (0);
952 
953 }
954 
955 static void lfinum_alts (LFINUM_ARGS_DECL)
956 {
957  ALS_DECL;
958  FH_DECL (0);
959 
960  DRHOOK_START ("lfinum_alts");
961 
962  *KRANG = fh == NULL ? 0 : 1;
963 
964  DRHOOK_END (0);
965 }
966 
967 static void lfinfo_alts (LFINFO_ARGS_DECL)
968 {
969  ALS_DECL;
970  FH_DECL (1);
971  ART_DECL;
972  DRHOOK_START ("lfinfo_alts");
973 
974  if (iart < 0)
975  {
976  *KREP = 0;
977  *KLONG = 0;
978  *KPOSEX = 0;
979  }
980  else
981  {
982  fh->iart = iart;
983  *KLONG = fh->idx[iart].len;
984  *KPOSEX = fh->idx[iart].pos;
985  *KREP = 0;
986  }
987 
988  DRHOOK_END (0);
989 }
990 
991 static void lfilec_alts (LFILEC_ARGS_DECL)
992 {
993  ALS_DECL;
994  FH_DECL (1);
995  ART_DECL;
996  DRHOOK_START ("lfilec_alts");
997 
998  *KREP = 0;
999 
1000  if (*KLONG < 0)
1001  {
1002  *KREP = -14;
1003  goto end;
1004  }
1005 
1006  if (iart < 0)
1007  {
1008  *KREP = iart;
1009  goto end;
1010  }
1011  else
1012  {
1013  integer64 len = fh->idx[iart].len > *KLONG ? *KLONG : fh->idx[iart].len;
1014  integer64 pos = fh->idx[iart].pos;
1015 
1016  fh_read (fh, KTAB, (pos-1) * 8, len * 8, 1);
1017 
1018  if (*KLONG < fh->idx[iart].len)
1019  {
1020  *KREP = -21;
1021  goto end;
1022  }
1023 
1024  fh->iart = iart;
1025 
1026  }
1027 
1028 end:
1029  DRHOOK_END (0);
1030 }
1031 
1032 static void lfilas_alts (LFILAS_ARGS_DECL)
1033 {
1034  ALS_DECL;
1035  FH_DECL (1);
1036  int iart = seek_rc (fh, +1);
1037  DRHOOK_START ("lfilas_alts");
1038 
1039  if (iart < 0)
1040  {
1041  *KREP = -23;
1042  goto end;
1043  }
1044  else
1045  {
1046  integer64 len = fh->idx[iart].len > *KLONG ? *KLONG : fh->idx[iart].len;
1047  integer64 pos = fh->idx[iart].pos;
1048 
1049  fh_read (fh, KTAB, (pos-1) * 8, len * 8, 1);
1050 
1051  *KREP = 0;
1052 
1053  if (*KLONG < fh->idx[iart].len)
1054  {
1055  *KREP = -21;
1056  goto end;
1057  }
1058 
1059  memset (CDNOMA, ' ', CDNOMA_len);
1060  memcpy (CDNOMA, fh->idx[iart].name, minARTN (CDNOMA_len));
1061 
1062  if (CDNOMA_len < lfi_fstrlen (fh->idx[iart].name, ARTNLEN))
1063  {
1064  *KREP = -24;
1065  goto end;
1066  }
1067 
1068  fh->iart = iart;
1069  }
1070 
1071 end:
1072  DRHOOK_END (0);
1073 }
1074 
1075 static void lfilap_alts (LFILAP_ARGS_DECL)
1076 {
1077  ALS_DECL;
1078  FH_DECL (1);
1079  int iart = seek_rc (fh, -1);
1080  DRHOOK_START ("lfilap_alts");
1081 
1082  if (iart < 0)
1083  {
1084  *KREP = -26;
1085  goto end;
1086  }
1087  else
1088  {
1089  integer64 len = fh->idx[iart].len > *KLONG ? *KLONG : fh->idx[iart].len;
1090  integer64 pos = fh->idx[iart].pos;
1091 
1092  fh_read (fh, KTAB, (pos-1) * 8, len * 8, 1);
1093 
1094  *KREP = 0;
1095 
1096  if (*KLONG < fh->idx[iart].len)
1097  {
1098  *KREP = -21;
1099  goto end;
1100  }
1101 
1102  memset (CDNOMA, ' ', CDNOMA_len);
1103  memcpy (CDNOMA, fh->idx[iart].name, minARTN (CDNOMA_len));
1104 
1105  if (CDNOMA_len < lfi_fstrlen (fh->idx[iart].name, ARTNLEN))
1106  {
1107  *KREP = -24;
1108  goto end;
1109  }
1110 
1111  fh->iart = iart;
1112  }
1113 
1114 end:
1115  DRHOOK_END (0);
1116 }
1117 
1118 static void lficas_alts (LFICAS_ARGS_DECL)
1119 {
1120  ALS_DECL;
1121  FH_DECL (1);
1122  int iart = seek_rc (fh, +1);
1123  DRHOOK_START ("lficas_alts");
1124 
1125  *KREP = 0;
1126  memset (CDNOMA, ' ', CDNOMA_len);
1127 
1128  if (iart < 0)
1129  {
1130  *KLONG = 0;
1131  *KPOSEX = 0;
1132  goto end;
1133  }
1134 
1135  *KLONG = fh->idx[iart].len;
1136  *KPOSEX = fh->idx[iart].pos;
1137 
1138  memcpy (CDNOMA, fh->idx[iart].name, minARTN (CDNOMA_len));
1139 
1140  if (CDNOMA_len < lfi_fstrlen (fh->idx[iart].name, ARTNLEN))
1141  {
1142  *KREP = -24;
1143  goto end;
1144  }
1145 
1146  if (istrue (*LDAVAN))
1147  fh->iart = iart;
1148 
1149 end:
1150  DRHOOK_END (0);
1151 }
1152 
1153 static void lfipos_alts (LFIPOS_ARGS_DECL)
1154 {
1155  ALS_DECL;
1156  FH_DECL (1);
1157  DRHOOK_START ("lfipos_alts");
1158 
1159  fh->iart = -1;
1160 
1161  *KREP = 0;
1162 
1163  DRHOOK_END (0);
1164 }
1165 
1166 static void lficap_alts (LFICAP_ARGS_DECL)
1167 {
1168  ALS_DECL;
1169  FH_DECL (1);
1170  int iart = seek_rc (fh, -1);
1171  DRHOOK_START ("lficap_alts");
1172 
1173  *KREP = 0;
1174  memset (CDNOMA, ' ', CDNOMA_len);
1175 
1176  if (iart < 0)
1177  {
1178  *KLONG = 0;
1179  *KPOSEX = 0;
1180  goto end;
1181  }
1182 
1183  *KLONG = fh->idx[iart].len;
1184  *KPOSEX = fh->idx[iart].pos;
1185 
1186  if (CDNOMA_len < lfi_fstrlen (fh->idx[iart].name, ARTNLEN))
1187  {
1188  *KREP = -24;
1189  goto end;
1190  }
1191 
1192  if (istrue (*LDRECU))
1193  fh->iart = iart;
1194 
1195 end:
1196  DRHOOK_END (0);
1197 }
1198 
1199 static void lfilaf_alts (LFILAF_ARGS_DECL)
1200 {
1201  ALS_DECL;
1202  FH_DECL (1);
1203  int iart;
1204  integer64 itrou = 1;
1205  integer64 idonn = 1;
1206  DRHOOK_START ("lfilaf_alts");
1207 
1208  *KREP = 0;
1209 
1210  for (iart = 0; iart < fh->nart; iart++)
1211  {
1212  if (eqan (fin_d_index, fh->idx[iart].name))
1213  break;
1214  else if (eqan (page__index, fh->idx[iart].name))
1215  continue;
1216  else if (eqan (trou__index, fh->idx[iart].name))
1217  {
1218  printf (
1219 " =====> %7lld-eme TROU repertorie dans l'index, longueur reutilisable: %6lld mots, position %8lld a %8lld",
1220 itrou++, fh->idx[iart].len, fh->idx[iart].pos, fh->idx[iart].pos + fh->idx[iart].len-1);
1221  }
1222  else
1223  {
1224  printf (
1225 "%7lld-eme article de donnees: \"%16.16s\", %6lld mots, position %8lld a %8lld",
1226 idonn++, fh->idx[iart].name, fh->idx[iart].len, fh->idx[iart].pos, fh->idx[iart].pos + fh->idx[iart].len-1);
1227  }
1228  if (iart < fh->nart-1)
1229  if (neqan (fin_d_index, fh->idx[iart+1].name))
1230  {
1231  integer64 d = fh->idx[iart+1].pos - (fh->idx[iart].pos + fh->idx[iart].len);
1232  if (d > 0)
1233  printf (" < %+7lld >", d);
1234  }
1235 
1236  printf ("\n");
1237  }
1238 
1239  DRHOOK_END (0);
1240 }
1241 
1242 static void lfisup_alts (LFISUP_ARGS_DECL)
1243 {
1244  ALS_DECL;
1245  FH_DECL (1);
1246  ART_DECL;
1247 
1248  DRHOOK_START ("lfisup_alts");
1249 
1250  if (iart < 0)
1251  {
1252  *KREP = iart;
1253  goto end;
1254  }
1255 
1256  memcpy (fh->idx[iart].name, trou__index, ARTNLEN);
1257  *KLONUT = fh->idx[iart].len;
1258  *KREP = 0;
1259 
1260  fh_modified (fh);
1261  fh->hdr->intru++;
1262  fh->hdr->iltal -= fh->idx[iart].len;
1263 
1264  if (iart < fh->nart-1)
1265  if (neqan (fin_d_index, fh->idx[iart+1].name))
1266  fh->idx[iart].len = fh->idx[iart+1].pos - fh->idx[iart].pos;
1267 
1268  /* If the hole is at eof, then round its end limit on a physical page boundary */
1269  {
1270  integer64 pose = fh->idx[iart].pos - 1 + fh->idx[iart].len;
1271  int t = iart == fh->nart-1;
1272  if (! t)
1273  t = eqan (fin_d_index, fh->idx[iart+1].name);
1274  if (t)
1275  {
1276  integer64 pags = fh->hdr->size / 8;
1277  integer64 post = pose % pags;
1278  if (post > 0)
1279  pose = pose + pags - post;
1280  }
1281  fh->idx[iart].len = 1 + pose - fh->idx[iart].pos;
1282  }
1283 
1284  fh->iart = -1;
1285 
1286 end:
1287  DRHOOK_END (0);
1288 }
1289 
1290 static void lfiren_alts (LFIREN_ARGS_DECL)
1291 {
1292  ALS_DECL;
1293  FH_DECL (1);
1294  int iart1 = lookup_rc (fh, CDNOM1, CDNOM1_len);
1295  int iart2 = lookup_rc (fh, CDNOM2, CDNOM2_len);
1296  integer64 ILONUT;
1297  DRHOOK_START ("lfiren_alts");
1298 
1299  if (iart1 < 0)
1300  {
1301  *KREP = iart1;
1302  goto end;
1303  }
1304 
1305  if (! check_an (CDNOM2, CDNOM2_len))
1306  {
1307  *KREP = -15;
1308  goto end;
1309  }
1310 
1311  if (iart2 >= 0)
1312  {
1313  *KREP = -25;
1314  goto end;
1315  }
1316 
1317  fh_modified (fh);
1318 
1319  lfisup_alts (LFI, KREP, KNUMER, CDNOM2, &ILONUT, CDNOM2_len);
1320 
1321  memcpy (fh->idx[iart1].name, trou__index, ARTNLEN);
1322  memcpy (fh->idx[iart1].name, CDNOM2, minARTN (CDNOM2_len));
1323 
1324  *KREP = 0;
1325 
1326 end:
1327  DRHOOK_END (0);
1328 }
1329 
1330 static void lfiecr_alts (LFIECR_ARGS_DECL)
1331 {
1332  ALS_DECL;
1333  FH_DECL (1);
1334  int iart = lookup_rc (fh, CDNOMA, CDNOMA_len);
1335  int iartx = -1; /* Index of article with the most appropriate size */
1336  int append;
1337  DRHOOK_START ("lfiecr_alts");
1338 
1339  if (*KLONG < 0)
1340  {
1341  *KREP = -14;
1342  goto end;
1343  }
1344 
1345  if (iart >= 0)
1346  {
1347  integer64 ILONUT;
1348  lfisup_alts (LFI, KREP, KNUMER, CDNOMA, &ILONUT, CDNOMA_len);
1349  }
1350  /* Check article name validity */
1351  else if (! check_an (CDNOMA, CDNOMA_len))
1352  {
1353  *KREP = -15;
1354  goto end;
1355  }
1356 
1357  /*
1358  * Try original slot
1359  */
1360 
1361  if (iart >= 0)
1362  {
1363  if (fh->idx[iart].len >= *KLONG)
1364  {
1365  iartx = iart;
1366  }
1367  else if (iart < fh->nart-1)
1368  {
1369  if (eqan (trou__index, fh->idx[iart+1].name) && ((fh->idx[iart].len + fh->idx[iart+1].len) >= *KLONG))
1370  {
1371  integer64 d = *KLONG - fh->idx[iart].len;
1372  fh->idx[iart+1].pos = fh->idx[iart+1].pos + d;
1373  fh->idx[iart+1].len = fh->idx[iart+1].len - d;
1374  fh->idx[iart].len = *KLONG;
1375  iartx = iart;
1376  }
1377  else if (eqan (fin_d_index, fh->idx[iart+1].name))
1378  {
1379  fh->idx[iart].len = *KLONG;
1380  iartx = iart;
1381  }
1382  }
1383  }
1384 
1385  /*
1386  * Look for a large enough empty slot;
1387  * try to select the most appropriate slot :
1388  * the hole with the smallest size if possible
1389  */
1390 
1391  if (iartx < 0)
1392  for (iart = 0; iart < fh->nart; iart++)
1393  {
1394  if (eqan (page__index, fh->idx[iart].name))
1395  continue;
1396  else if (eqan (fin_d_index, fh->idx[iart].name))
1397  {
1398  if (iartx < 0)
1399  iartx = iart;
1400  break;
1401  }
1402  /* Hole is big enough */
1403  else if (eqan (trou__index, fh->idx[iart].name) && (fh->idx[iart].len >= *KLONG))
1404  {
1405  if (iartx < 0)
1406  iartx = iart;
1407  else if (fh->idx[iart].len < fh->idx[iartx].len)
1408  iartx = iart;
1409  }
1410  /* If last hole is at EOF, we can enlarge it */
1411  else if (0 && eqan (trou__index, fh->idx[iart].name) && (iart < fh->nart-1) && (iartx < 0))
1412  {
1413  if (eqan (fin_d_index, fh->idx[iart+1].name))
1414  {
1415  iartx = iart;
1416  /* Make this look like we appended data at EOF */
1417  memcpy (fh->idx[iart].name, fin_d_index, ARTNLEN);
1418  fh->hdr->intru--;
1419  fh->hdr->inalo--;
1420  break;
1421  }
1422  }
1423  }
1424 
1425  /* Index is full; try to grow index */
1426 
1427  if (iartx < 0)
1428  {
1429  fh_grow_idx (fh, *KLONG, &iartx);
1430  if (iartx < 0)
1431  {
1432  *KREP = -1;
1433  goto end;
1434  }
1435  }
1436 
1437  /* Everything is OK; mark file as modified */
1438 
1439  fh_modified (fh);
1440 
1441  append = eqan (fh->idx[iartx].name, fin_d_index);
1442 
1443  /* If article is appended, then compute its position */
1444  if (append)
1445  {
1446  if (iartx > 0)
1447  fh->idx[iartx].pos = fh->idx[iartx-1].pos + fh->idx[iartx-1].len;
1448  else
1449  fh->idx[iartx].pos = fh->hdr->inaph * fh->hdr->ilpar + 1;
1450  }
1451 
1452  /* Finish to setup index */
1453  fh->idx[iartx].len = *KLONG;
1454  memcpy (fh->idx[iartx].name, trou__index, ARTNLEN);
1455  memcpy (fh->idx[iartx].name, CDNOMA, minARTN (CDNOMA_len));
1456 
1457  /* Write data */
1458  fh_write (fh, KTAB, (fh->idx[iartx].pos - 1) * 8, fh->idx[iartx].len * 8, 1);
1459 
1460  /* Update header parameters */
1461 
1462  fh->hdr->iltal += fh->idx[iartx].len;
1463 
1464  if (append)
1465  {
1466  fh->hdr->inalo++;
1467 
1468  /* Update number of physical articles */
1469  {
1470  integer64 size = fh->idx[iartx].pos + fh->idx[iartx].len - 8;
1471  fh->hdr->inaph = size / fh->hdr->ilpar;
1472  if (size % (fh->hdr->inaph * fh->hdr->ilpar))
1473  fh->hdr->inaph++;
1474  }
1475 
1476  fh->hdr->iaxpd = fh->hdr->inaph;
1477  }
1478  else
1479  {
1480  /* We reused a hole; decrement hole count */
1481  fh->hdr->intru--;
1482  }
1483 
1484  fh->iart = iartx;
1485 
1486  *KREP = 0;
1487 
1488 end:
1489 
1490  DRHOOK_END (0);
1491 
1492 }
1493 
1494 static void lfiopt_alts (LFIOPT_ARGS_DECL)
1495 {
1496  ALS_DECL;
1497  FH_DECL (0);
1498  DRHOOK_START ("lfiopt_alts");
1499 
1500  if (fh == NULL)
1501  {
1502  *KREP = -1;
1503  goto end;
1504  }
1505 
1506  memset (CDNOMF, ' ', CDNOMF_len);
1507  memset (CDSTTO, ' ', CDSTTO_len);
1508 
1509  memcpy (CDNOMF, fh->cnomf, CDNOMF_len > strlen (fh->cnomf) ? strlen (fh->cnomf) : CDNOMF_len);
1510  memcpy (CDSTTO, fh->cstto, CDSTTO_len > strlen (fh->cstto) ? strlen (fh->cstto) : CDSTTO_len);
1511 
1512  *LDNOMM = fort_TRUE;
1513  *LDIMST = fort_FALSE;
1514  *LDERFA = fh->llerfa;
1515  *KNIMES = fh->inimes;
1516  *KREP = 0;
1517 
1518 end:
1519  DRHOOK_END (0);
1520 
1521 }
1522 
1523 static void lfinaf_alts (LFINAF_ARGS_DECL)
1524 {
1525  ALS_DECL;
1526  FH_DECL (1);
1527  DRHOOK_START ("lfinaf_alts");
1528 
1529  *KNTROU = fh->hdr->intru;
1530  *KNALDO = fh->hdr->inalo - fh->hdr->intru;
1531  *KNARES = 0;
1532  *KNAMAX = 0;
1533  *KREP = 0;
1534 
1535  DRHOOK_END (0);
1536 
1537 }
1538 
1539 static void lfinim_alts (LFINIM_ARGS_DECL)
1540 {
1541  ALS_DECL;
1542  FH_DECL (1);
1543 
1544  DRHOOK_START ("lfinim_alts");
1545 
1546  *KREP = 0;
1547 
1548  if ((*KNIMES > 2) || (*KNIMES < 0))
1549  {
1550  *KREP = -2;
1551  goto end;
1552  }
1553 
1554  fh->inimes = *KNIMES;
1555 
1556 end:
1557 
1558  DRHOOK_END (0);
1559 }
1560 
1561 static void lfierf_alts (LFIERF_ARGS_DECL)
1562 {
1563  ALS_DECL;
1564  FH_DECL (1);
1565  DRHOOK_START ("lfierf_alts");
1566 
1567  fh->llerfa = *LDERFA;
1568  *KREP = 0;
1569 
1570  DRHOOK_END (0);
1571 }
1572 
1573 static void lfioef_alts (LFIOEF_ARGS_DECL)
1574 {
1575  ALS_DECL;
1576  FH_DECL (1);
1577 
1578  DRHOOK_START ("lfioef_alts");
1579 
1580  *LDERFA = fh->llerfa;
1581  *KREP = 0;
1582 
1583  DRHOOK_END (0);
1584 }
1585 
1586 static void lfifmd_alts (LFIFMD_ARGS_DECL)
1587 {
1588  ALS_DECL;
1589 
1590  DRHOOK_START ("lfifmd_alts");
1591 
1592  if (*KFACMD > 0)
1593  als->fmult = *KFACMD;
1594 
1595  DRHOOK_END (0);
1596 }
1597 
1598 static void lfiofd_alts (LFIOFD_ARGS_DECL)
1599 {
1600  ALS_DECL;
1601  DRHOOK_START ("lfiofd_alts");
1602  *KFACMD = als->fmult;
1603  DRHOOK_END (0);
1604 }
1605 
1606 static void lfiofm_alts (LFIOFM_ARGS_DECL)
1607 {
1608  ALS_DECL;
1609  FH_DECL (0);
1610  DRHOOK_START ("lfiofm_alts");
1611 
1612  if (fh)
1613  {
1614  *KFACTM = fh->fmult;
1615  *LDOUVR = fort_TRUE;
1616  *KREP = 0;
1617  }
1618  else
1619  {
1620  *KFACTM = als->fmult;
1621  lfi_fmul_get (als->fmult_list, KNUMER, KFACTM);
1622  *LDOUVR = fort_FALSE;
1623  *KREP = 0;
1624  }
1625 
1626  DRHOOK_END (0);
1627 }
1628 
1629 static void lfiafm_alts (LFIAFM_ARGS_DECL)
1630 {
1631  ALS_DECL;
1632  FH_DECL (0);
1633  DRHOOK_START ("lfiafm_alts");
1634 
1635  if (fh)
1636  {
1637  *KREP = -5;
1638  }
1639  else if (*KFACTM < 0)
1640  {
1641  *KREP = -14;
1642  }
1643  else
1644  {
1645  lfi_fmul_set (&als->fmult_list, KNUMER, KFACTM);
1646  *KREP = 0;
1647  }
1648 
1649  DRHOOK_END (0);
1650 }
1651 
1652 static void lfisfm_alts (LFISFM_ARGS_DECL)
1653 {
1654 
1655  ALS_DECL;
1656  FH_DECL (0);
1657  DRHOOK_START ("lfisfm_alts");
1658 
1659  *KREP = 0;
1660  if (fh)
1661  {
1662  *KREP = -5;
1663  }
1664  else
1665  {
1666  if (lfi_fmul_del (&als->fmult_list, KNUMER) < 0)
1667  *KREP = -31;
1668  }
1669 
1670  DRHOOK_END (0);
1671 }
1672 
1673 static void lfineg_alts (LFINEG_ARGS_DECL)
1674 {
1675  ALS_DECL;
1676  DRHOOK_START ("lfineg_alts");
1677  if ((*KNIVAU >= 0) && (*KNIVAU <= 2))
1678  als->nerfag = *KNIVAU;
1679  DRHOOK_END (0);
1680 }
1681 
1682 static void lfioeg_alts (LFIOEG_ARGS_DECL)
1683 {
1684  ALS_DECL;
1685  DRHOOK_START ("lfioeg_alts");
1686  *KNIVAU = als->nerfag;
1687  DRHOOK_END (0);
1688 }
1689 
1690 static void lfiomg_alts (LFIOMG_ARGS_DECL)
1691 {
1692  ALS_DECL;
1693  DRHOOK_START ("lfiomg_alts");
1694  *KNIVAU = als->inivau;
1695  *KULOUT = als->iulout;
1696  DRHOOK_END (0);
1697 }
1698 
1699 static void lfinmg_alts (LFINMG_ARGS_DECL)
1700 {
1701  ALS_DECL;
1702  DRHOOK_START ("lfinmg_alts");
1703  als->inivau = *KNIVAU;
1704  als->iulout = *KULOUT;
1705  DRHOOK_END (0);
1706 }
1707 
1708 #undef ALS_DECL
1709 
1711  lfiouv_alts, /* Ouverture fichier */
1712  lficas_alts, /* KNUMER Caracteristiques de l'article suivant */
1713  lfiecr_alts, /* KNUMER Ecriture */
1714  lfifer_alts, /* KNUMER Fermeture */
1715  lfilec_alts, /* KNUMER Lecture */
1716  lfinfo_alts, /* KNUMER Caracteristiques d'un article nomme */
1717  lfipos_alts, /* KNUMER Remise a zero du pointeur de fichier */
1718  lfiver_dumm, /* KNUMER Verrouillage d'un fichier */
1719  lfiofm_alts, /* KNUMER Obtention du facteur multiplicatif */
1720  lfineg_alts, /* Niveau global d'erreur */
1721  lfilaf_alts, /* KNUMER Liste des articles */
1722  lfiosg_dumm, /* Obtention du niveau d'impression des statistiques */
1723  lfinum_alts, /* KNUMER Rang de l'unite logique KNUMER */
1724  lfisup_alts, /* KNUMER Suppression d'un article */
1725  lfiopt_alts, /* KNUMER Obtention des options d'ouverture d'un fichier */
1726  lfinmg_alts, /* Niveau global d'erreur */
1727  lficap_alts, /* KNUMER Caracteristiques de l'article precedent */
1728  lfifra_dumm, /* Messages en Francais */
1729  lficfg_dumm, /* Impression des parametres de base de LFI */
1730  lfierf_alts, /* KNUMER Erreur fatale */
1731  lfilas_alts, /* KNUMER Lecture de l'article de donnees suivant */
1732  lfiren_alts, /* KNUMER Renommer un article */
1733  lfiini_dumm, /* Initialisation de LFI */
1734  lfipxf_miss, /* KNUMER Export d'un fichier LFI */
1735  lfioeg_alts, /* Obtention du niveau global de traitement des erreurs */
1736  lfinaf_alts, /* KNUMER Nombre d'articles divers */
1737  lfiofd_alts, /* Facteur multiplicatif courant */
1738  lfiomf_dumm, /* KNUMER Obtention du niveau de messagerie */
1739  lfiafm_alts, /* KNUMER Attribution d'un facteur multiplicatif a une unite */
1740  lfista_dumm, /* KNUMER Impression des statistiques d'utilisation */
1741  lfiosf_miss, /* KNUMER Obtention de l'option d'impression des statistiques */
1742  lfilap_alts, /* KNUMER Lecture de l'article precedent */
1743  lfioef_alts, /* KNUMER Obtention de l'option courante de traitement des erreurs */
1744  lfimst_dumm, /* KNUMER Activation de l'option d'impression de statistiques */
1745  lfinim_alts, /* KNUMER Ajustement du niveau de messagerie */
1746  lfisfm_alts, /* KNUMER Suppression d'un facteur multiplicatif */
1747  lfinsg_dumm, /* Niveau global d'impression de statistiques */
1748  lfideb_dumm, /* Mode mise au point (debug) */
1749  lfiomg_alts, /* Obtention du niveau global des messages LFI */
1750  lfifmd_alts, /* Facteur multiplicatif par defaut */
1751 };
1752 
1753 #define ALS_DECL \
1754  lfi_alts_t * als = lookup_als (lfi->data);
1755 
1756 static void lfi_del_alts_hndl (lfi_hndl_t * lfi)
1757 {
1758  ALS_DECL;
1759 
1760  if (als->fh)
1761  lfi_abor ("Attempt to release lfi handler with opened files");
1762 
1763  lfi_fmul_free (&als->fmult_list);
1764 
1765  free (als);
1766  free (lfi);
1767 }
1768 
1770 {
1771  ALS_DECL;
1772  FH_DECL (0);
1773  return fh == NULL ? 0 : 1;
1774 }
1775 
1777 {
1778  ALS_DECL;
1779  FH_DECL (1);
1780  return fh->inimes == 2 ? 1 : 0;
1781 }
1782 
1784 {
1785  ALS_DECL;
1786  FH_DECL (1);
1787  return (als->nerfag == 0) || ((als->nerfag == 1) && istrue (fh->llerfa));
1788 }
1789 
1790 #undef ALS_DECL
1791 
1793 {
1794  lfi_hndl_t * lfi = (lfi_hndl_t *)malloc (sizeof (lfi_hndl_t));
1795  lfi_alts_t * als = (lfi_alts_t *)malloc (sizeof (lfi_alts_t));
1796 
1797  memset (als, 0, sizeof (lfi_alts_t));
1798  memcpy (als->cmagic, "lfi_alts", 8);
1799  als->fmult = 6;
1800  als->fmult_list = NULL;
1801  als->nerfag = 1;
1802  als->inivau = 0;
1803  als->iulout = 0;
1804 
1805  lfi->cb = &lficb_alts;
1806  lfi->cb_verb = &lficb_verb;
1807  lfi->data = als;
1808  lfi->destroy = lfi_del_alts_hndl;
1809  lfi->is_open = lfi_opn_alts_hndl;
1810  lfi->is_verb = lfi_vrb_alts_hndl;
1811  lfi->is_fatl = lfi_fat_alts_hndl;
1812  lfi->next = NULL;
1813  return lfi;
1814 }
1815 
1816 static void lfi_alts_pack (integer64 * KREP, character * CDNOMF1, character * CDNOMF2,
1817  character_len CDNOMF1_len, character_len CDNOMF2_len,
1818  lfi_alts_fh_kind_t kind, long * offset)
1819 {
1820  lfi_grok_t islfi = lfi_grok (CDNOMF1, CDNOMF1_len);
1821  /* Multi-file is opened with lfi_altm */
1822  lfi_hndl_t * lfm;
1823  /* Target file is opened with lfi_alts */
1824  lfi_hndl_t * lfs;
1825  integer64 INUMER = 1;
1826  integer64 INALDO;
1827 
1828  *KREP = 0;
1829  *offset = 0;
1830 
1831  if (islfi != LFI_ALTM)
1832  {
1833  struct stat st;
1834  char path[CDNOMF1_len+1];
1835 
1836  if (kind != FH_KIND_RECORD)
1837  if ((*KREP = lfi_fsmartcopy (CDNOMF1, CDNOMF2, 1, CDNOMF1_len, CDNOMF2_len)) != 0)
1838  goto error;
1839 
1840  lfi_fstrdup (CDNOMF1, CDNOMF1_len, path);
1841 
1842  if (stat (path, &st) == 0)
1843  *offset = st.st_size;
1844 
1845  goto end;
1846  }
1847 
1848 
1849  lfm = lfi_get_altm_hndl (NULL);
1850  lfs = lfi_get_alts_hndl (NULL);
1851 
1852 
1853 
1854  {
1855  integer64 INTROU, INARES, INAMAX;
1856  integer64 INIMES = 2, INBARP = 0, INBARI = 0;
1857  logical LLNOMM = fort_TRUE, LLERFA = fort_TRUE, LLIMST = fort_TRUE;
1858  character * CLSTTO = (character *)"OLD";
1859  character * CLSTTN = (character *)"NEW";
1860  character_len CLSTTO_len = 3;
1861  character_len CLSTTN_len = 3;
1862  integer64 IFACMD;
1863 
1864  lfm->cb->lfiouv (lfm->data, KREP, &INUMER, &LLNOMM, CDNOMF1, CLSTTO, &LLERFA,
1865  &LLIMST, &INIMES, &INBARP, &INBARI, CDNOMF1_len, CLSTTO_len);
1866 
1867  if (*KREP != 0)
1868  goto error;
1869 
1870  /* Count articles */
1871  lfm->cb->lfinaf (lfm->data, KREP, &INUMER, &INALDO, &INTROU, &INARES, &INAMAX);
1872 
1873  if (*KREP != 0)
1874  goto error;
1875 
1876  /*
1877  * Choose a "facteur multiplicatif" so that all articles will fit
1878  * in a single header section
1879  */
1880  {
1881  integer64 isize1 = 512 * 8,
1882  isize2 = ARTNLEN * INALDO,
1883  isized = isize2 % isize1;
1884  if (isized > 0)
1885  isize2 = isize2 + isize1 - isized;
1886  IFACMD = isize2 / isize1;
1887  if (IFACMD < 6)
1888  IFACMD = 6;
1889  lfs->cb->lfifmd (lfs->data, &IFACMD);
1890  }
1891 
1892  /* Open new file */
1893  lfiouv_alts_ext (lfs->data, KREP, &INUMER, &LLNOMM, CDNOMF2, CLSTTN, &LLERFA,
1894  &LLIMST, &INIMES, &INBARP, &INBARI, CDNOMF2_len, CLSTTN_len,
1895  kind);
1896 
1897  if (*KREP != 0)
1898  goto error;
1899 
1900  }
1901 
1902 
1903  {
1904  int iart;
1905  lfi_alts_fh_t * fh = lookup_fh (lfs->data, &INUMER, 0);
1906  integer64 pos = 1 + (fh->hdr->size * 3) / 8;
1907  integer64 len = 0;
1908 
1909  /* Build index */
1910  lfm->cb->lfipos (lfm->data, KREP, &INUMER);
1911 
1912  if (*KREP != 0)
1913  goto error;
1914 
1915  /* Min & max article size */
1916  fh->hdr->ilnal = +MAXLONG;
1917  fh->hdr->ilxal = 0;
1918 
1919  for (iart = 0; iart < INALDO; iart++)
1920  {
1921  logical LLAVAN = fort_TRUE;
1922  integer64 IPOSEX;
1923 
1924  lfm->cb->lficas (lfm->data, KREP, &INUMER, fh->idx[iart].name, &fh->idx[iart].len, &IPOSEX, &LLAVAN, ARTNLEN);
1925 
1926  if (*KREP != 0)
1927  goto error;
1928 
1929  fh->idx[iart].pos = pos;
1930  pos += fh->idx[iart].len;
1931  len += fh->idx[iart].len;
1932 
1933  if (fh->hdr->ilnal > fh->idx[iart].len)
1934  fh->hdr->ilnal = fh->idx[iart].len;
1935  if (fh->hdr->ilxal < fh->idx[iart].len)
1936  fh->hdr->ilxal = fh->idx[iart].len;
1937 
1938  }
1939 
1940  /* Update header */
1941 
1942  {
1943  integer64 size = len * 8 + fh->hdr->size * 3; /* File size in bytes */
1944  if (size % fh->hdr->size) /* Make size a multiple of fh->hdr->size */
1945  size += (fh->hdr->size - (size % fh->hdr->size));
1946  fh->hdr->inaph = size / fh->hdr->size;
1947  fh->hdr->inalo = INALDO;
1948  fh->hdr->iltal = len;
1949  fh->hdr->iaxpd = fh->hdr->inaph;
1950  }
1951 
1952  /* Write header */
1953 
1954  fh_write_hdr (fh, KREP);
1955  if (*KREP != 0)
1956  goto error;
1957 
1958  /* Read and write articles */
1959 
1960  for (iart = 0; iart < INALDO; iart++)
1961  {
1962  integer64 KTAB[fh->idx[iart].len];
1963 
1964  if (kind != FH_KIND_RECORD)
1965  {
1966  lfm->cb->lfilec (lfm->data, KREP, &INUMER, fh->idx[iart].name, KTAB, &fh->idx[iart].len, ARTNLEN);
1967 
1968  if (*KREP != 0)
1969  goto error;
1970  }
1971 
1972  fh_write (fh, KTAB, (fh->idx[iart].pos-1) * 8, fh->idx[iart].len * 8, 1);
1973 
1974  }
1975 
1976  /* Pad file */
1977 
1978  fh_write_pad (fh, KREP);
1979 
1980  if (*KREP != 0)
1981  goto error;
1982 
1983  *offset = fh->offset;
1984  }
1985 
1986  /* Close files */
1987  {
1988  character * CLSTTK = (character *)"KEEP";
1989  character_len CLSTTK_len = 4;
1990 
1991  lfm->cb->lfifer (lfm->data, KREP, &INUMER, CLSTTK, CLSTTK_len);
1992 
1993  if (*KREP != 0)
1994  goto error;
1995 
1996  lfs->cb->lfifer (lfs->data, KREP, &INUMER, CLSTTK, CLSTTK_len);
1997 
1998  if (*KREP != 0)
1999  goto error;
2000 
2001  }
2002 
2003 
2004 
2005  lfm->destroy (lfm);
2006  lfs->destroy (lfs);
2007 
2008 end:
2009 
2010  return;
2011 
2012 error:
2013 
2014  lfi_verb (NULL, "lfi_altm_pack", "KREP", KREP, NULL);
2015  lfi_abor ("lfi_altm_pack");
2016 
2017  return;
2018 
2019 }
2020 
2021 /* Pack a multi-file into a single regular LFI file */
2022 void lfi_alts_pack_ (integer64 * KREP, character * CDNOMF1, character * CDNOMF2,
2023  character_len CDNOMF1_len, character_len CDNOMF2_len)
2024 {
2025  long offset = 0;
2026  lfi_alts_pack (KREP, CDNOMF1, CDNOMF2, CDNOMF1_len, CDNOMF2_len, FH_KIND_STREAM, &offset);
2027 
2028 }
2029 
2030 void lfi_alts_size_ (integer64 * KREP, character * CDNOMF1, integer64 * KSIZE, character_len CDNOMF1_len)
2031 {
2032  long offset = 0;
2033  character * CDNOMF2 = "";
2034  character_len CDNOMF2_len = 0;
2035  lfi_alts_pack (KREP, CDNOMF1, CDNOMF2, CDNOMF1_len, CDNOMF2_len, FH_KIND_RECORD, &offset);
2036  *KSIZE = offset;
2037 }
static int lfi_vrb_alts_hndl(lfi_hndl_t *lfi, integer64 *KNUMER)
Definition: lfi_alts.c:1776
static int check_an(const char *CDNOMA, const character_len CDNOMA_len)
Definition: lfi_alts.c:520
static long size
Definition: bytes_io.c:262
lfi_fmul_t * lfi_fmul_get(lfi_fmul_t *fmul, const integer64 *KNUMER, integer64 *KFACTM)
Definition: lfi_fmul.c:36
static void lfinfo_alts(LFINFO_ARGS_DECL)
Definition: lfi_alts.c:967
int(* is_fatl)(struct lfi_hndl_t *, integer64 *)
Definition: lfi_hndl.h:26
void(* lfinaf)(LFINAF_ARGS_DECL)
Definition: lfi_call.h:46
static void lfinaf_alts(LFINAF_ARGS_DECL)
Definition: lfi_alts.c:1523
static lfi_alts_fh_t * lookup_fh(lfi_alts_t *als, integer64 *KNUMER, int fatal)
Definition: lfi_alts.c:501
void lfifra_dumm(LFIFRA_ARGS_DECL)
void lfiosf_miss(LFIOSF_ARGS_DECL)
void iswap_isle_(int *)
Definition: iswap8.c:7
lfi_hndl_t * lfi_get_altm_hndl(void *data)
Definition: lfi_altm.c:1965
static void lfioeg_alts(LFIOEG_ARGS_DECL)
Definition: lfi_alts.c:1682
static void lfiomg_alts(LFIOMG_ARGS_DECL)
Definition: lfi_alts.c:1690
void lfiosg_dumm(LFIOSG_ARGS_DECL)
lfi_fmul_t * lfi_fmul_set(lfi_fmul_t **fmul, const integer64 *KNUMER, const integer64 *KFACTM)
Definition: lfi_fmul.c:15
static void lfioef_alts(LFIOEF_ARGS_DECL)
Definition: lfi_alts.c:1573
void lfiver_dumm(LFIVER_ARGS_DECL)
struct lfi_alts_fh_idx_t lfi_alts_fh_idx_t
lfi_hndl_t * lfi_get_alts_hndl(void *data)
Definition: lfi_alts.c:1792
struct lfi_alts_fh_hdr_t lfi_alts_fh_hdr_t
static void lfilas_alts(LFILAS_ARGS_DECL)
Definition: lfi_alts.c:1032
void lfi_alts_size_(integer64 *KREP, character *CDNOMF1, integer64 *KSIZE, character_len CDNOMF1_len)
Definition: lfi_alts.c:2030
INTERFACE SUBROUTINE FACILO KNIVAU
Definition: facilo.h:4
INTERFACE SUBROUTINE FACILO && KREP
Definition: facilo.h:4
void(* lficas)(LFICAS_ARGS_DECL)
Definition: lfi_call.h:22
static const char * fin_d_index
Definition: lfi_alts.c:56
static void lfiafm_alts(LFIAFM_ARGS_DECL)
Definition: lfi_alts.c:1629
static void fh_write_pad(lfi_alts_fh_t *fh, integer64 *KREP)
Definition: lfi_alts.c:438
void lfimst_dumm(LFIMST_ARGS_DECL)
static const char * T
Definition: iswap8.c:3
quick &counting sorts only inumt inumt name
void lficfg_dumm(LFICFG_ARGS_DECL)
static void fh_flush(lfi_alts_fh_t *fh)
Definition: lfi_alts.c:254
int(* is_verb)(struct lfi_hndl_t *, integer64 *)
Definition: lfi_hndl.h:24
static void fh_fstat(lfi_alts_fh_t *fh, struct stat *st)
Definition: lfi_alts.c:262
static void lfineg_alts(LFINEG_ARGS_DECL)
Definition: lfi_alts.c:1673
void(* destroy)(struct lfi_hndl_t *)
Definition: lfi_hndl.h:23
static void lfi_del_alts_hndl(lfi_hndl_t *lfi)
Definition: lfi_alts.c:1756
struct lfi_hndl_t * next
Definition: lfi_hndl.h:22
void(* lfilec)(LFILEC_ARGS_DECL)
Definition: lfi_call.h:25
static void lfisup_alts(LFISUP_ARGS_DECL)
Definition: lfi_alts.c:1242
static void lficap_alts(LFICAP_ARGS_DECL)
Definition: lfi_alts.c:1166
FILE * fp
Definition: opfla_perfmon.c:24
void lfista_dumm(LFISTA_ARGS_DECL)
static void fh_write(lfi_alts_fh_t *fh, void *ptr, integer64 pos, integer64 len, int lswap)
Definition: lfi_alts.c:308
long long int integer64
Definition: lfi_type.h:15
static int lookup_rc(lfi_alts_fh_t *fh, character *name, character_len name_len)
Definition: lfi_alts.c:532
static void lfiouv_alts(LFIOUV_ARGS_DECL)
Definition: lfi_alts.c:903
char * lfi_fstrdup(const character *fstr, const character_len len, char *cstr)
Definition: lfi_util.c:30
static int check_an_len(const char *CDNOMA, const character_len CDNOMA_len)
Definition: lfi_alts.c:513
struct lfi_alts_fh_t lfi_alts_fh_t
static void lfiecr_alts(LFIECR_ARGS_DECL)
Definition: lfi_alts.c:1330
struct lfi_alts_t lfi_alts_t
int character_len
Definition: lfi_type.h:17
void lfipxf_miss(LFIPXF_ARGS_DECL)
void(* lfiouv)(LFIOUV_ARGS_DECL)
Definition: lfi_call.h:21
static const char * trou__index
Definition: lfi_alts.c:57
static void lfi_alts_pack(integer64 *KREP, character *CDNOMF1, character *CDNOMF2, character_len CDNOMF1_len, character_len CDNOMF2_len, lfi_alts_fh_kind_t kind, long *offset)
Definition: lfi_alts.c:1816
static void lfisfm_alts(LFISFM_ARGS_DECL)
Definition: lfi_alts.c:1652
static void lfinim_alts(LFINIM_ARGS_DECL)
Definition: lfi_alts.c:1539
lfi_grok_t lfi_grok(const character *file, character_len file_len)
Definition: lfi_grok.c:36
void lfideb_dumm(LFIDEB_ARGS_DECL)
lfi_alts_fh_kind_t
Definition: lfi_alts.c:100
lficb_t * cb
Definition: lfi_hndl.h:19
static int lfi_fat_alts_hndl(lfi_hndl_t *lfi, integer64 *KNUMER)
Definition: lfi_alts.c:1783
char character
Definition: lfi_type.h:18
static void lfinum_alts(LFINUM_ARGS_DECL)
Definition: lfi_alts.c:955
void lfi_abor(const char *fmt,...)
Definition: lfi_abor.c:21
void lfiini_dumm(LFIINI_ARGS_DECL)
static void lficas_alts(LFICAS_ARGS_DECL)
Definition: lfi_alts.c:1118
integer(kind=kindofint) nidx
static void fh_close(lfi_alts_fh_t *fh, integer64 *KREP)
Definition: lfi_alts.c:223
static const int buf_sz
Definition: lfi_alts.c:146
ERROR in n
Definition: ecsort_shared.h:90
static void lfiren_alts(LFIREN_ARGS_DECL)
Definition: lfi_alts.c:1290
void lfiomf_dumm(LFIOMF_ARGS_DECL)
static int lfi_opn_alts_hndl(lfi_hndl_t *lfi, integer64 *KNUMER)
Definition: lfi_alts.c:1769
character_len lfi_fstrlen(const character *fstr, const character_len len)
Definition: lfi_util.c:20
static void fh_modified(lfi_alts_fh_t *fh)
Definition: lfi_alts.c:472
static void fh_grow_idx(lfi_alts_fh_t *fh, integer64 alen, int *iartx)
Definition: lfi_alts.c:590
void(* lfifer)(LFIFER_ARGS_DECL)
Definition: lfi_call.h:24
void * data
Definition: lfi_hndl.h:21
static void fh_read(lfi_alts_fh_t *fh, void *ptr, integer64 pos, integer64 len, int lswap)
Definition: lfi_alts.c:270
static void lfiofd_alts(LFIOFD_ARGS_DECL)
Definition: lfi_alts.c:1598
static const int use_fd
Definition: lfi_alts.c:145
lficb_verb_t * cb_verb
Definition: lfi_hndl.h:20
void(* lfipos)(LFIPOS_ARGS_DECL)
Definition: lfi_call.h:27
int lfi_fsmartcopy(const character *cnomf1, const character *cnomf2, int copy, character_len cnomf1_len, character_len cnomf2_len)
Definition: lfi_util.c:132
integer64 lfi_fmul_del(lfi_fmul_t **fmul, const integer64 *KNUMER)
Definition: lfi_fmul.c:49
lficb_t lficb_alts
Definition: lfi_alts.c:1710
static void fh_open(lfi_alts_fh_t *fh, char *cnomf, char *cstto, lfi_alts_fh_kind_t kind, integer64 *KREP)
Definition: lfi_alts.c:149
static void lfilaf_alts(LFILAF_ARGS_DECL)
Definition: lfi_alts.c:1199
static void lfilec_alts(LFILEC_ARGS_DECL)
Definition: lfi_alts.c:991
static void lfilap_alts(LFILAP_ARGS_DECL)
Definition: lfi_alts.c:1075
void lfinsg_dumm(LFINSG_ARGS_DECL)
static void lfierf_alts(LFIERF_ARGS_DECL)
Definition: lfi_alts.c:1561
static void lfinmg_alts(LFINMG_ARGS_DECL)
Definition: lfi_alts.c:1699
static void lfipos_alts(LFIPOS_ARGS_DECL)
Definition: lfi_alts.c:1153
void lfi_fmul_free(lfi_fmul_t **fmul)
Definition: lfi_fmul.c:68
void lfi_alts_pack_(integer64 *KREP, character *CDNOMF1, character *CDNOMF2, character_len CDNOMF1_len, character_len CDNOMF2_len)
Definition: lfi_alts.c:2022
static const char * page__index
Definition: lfi_alts.c:58
static void lfiouv_alts_ext(LFIOUV_ARGS_DECL, lfi_alts_fh_kind_t kind)
Definition: lfi_alts.c:660
static integer64 fh_seek(lfi_alts_fh_t *fh, integer64 pos, int whence)
Definition: lfi_alts.c:235
static void lfiopt_alts(LFIOPT_ARGS_DECL)
Definition: lfi_alts.c:1494
INTERFACE SUBROUTINE FACILO KNUMER
Definition: facilo.h:4
static lfi_alts_t * lookup_als(void *LFI)
Definition: lfi_alts.c:492
static integer64 iulout(lfi_hndl_t *lfi)
Definition: lfi_verb.c:65
INTERFACE SUBROUTINE FACONO CDNOMA
Definition: facono.h:4
void(* lfifmd)(LFIFMD_ARGS_DECL)
Definition: lfi_call.h:60
int(* is_open)(struct lfi_hndl_t *, integer64 *)
Definition: lfi_hndl.h:25
void jswap_(void *, const void *, const int *, const int *)
static void xgetdate(integer64 *YYYYMMDD, integer64 *HHmmss)
Definition: lfi_alts.c:359
static void lfifer_alts(LFIFER_ARGS_DECL)
Definition: lfi_alts.c:910
static int seek_rc(lfi_alts_fh_t *fh, int d)
Definition: lfi_alts.c:562
static void lfiofm_alts(LFIOFM_ARGS_DECL)
Definition: lfi_alts.c:1606
int logical
Definition: lfi_type.h:16
lficb_verb_t lficb_verb
Definition: lfi_verb.c:534
void lfi_verb(lfi_hndl_t *lfi, const char *func,...)
Definition: lfi_verb.c:76
subroutine t(CDPREF, CDSUFF, KCODPA, LDNIVA, PMULTI)
Definition: faicor.F90:567
lfi_grok_t
Definition: lfi_grok.h:14
static void lfifmd_alts(LFIFMD_ARGS_DECL)
Definition: lfi_alts.c:1586
static void fh_write_hdr(lfi_alts_fh_t *fh, integer64 *KREP)
Definition: lfi_alts.c:374