]> www.wagner.pp.ru Git - oss/fgis.git/blob - lib/epp_iter.c
First checked in version
[oss/fgis.git] / lib / epp_iter.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <epp.h>
4 #include "epp_private.h"
5 int (*EndLineProc)(int row,int seqno,int total);
6 int for_each_cell(EPP *epp, EPP_ITER_PROC action)
7 /* performs given operation for each non-offsite cell of existing EPP file
8    (terminated if action returns non-zero,
9    or performs operation for each cell of created EPP file, filling cell
10    by value, returned by action. value parameter in this case always containt
11    offsite of epp */
12 { int i,j,k,l,rowcount,offsite;
13   rowcount=epp->lr-epp->fr;
14   offsite=epp->offsite;
15   if (epp->mode&MAP_INPUT)
16   { reset_epp(epp);
17    for(i=epp->fr,l=1;i<epp->lr;i++,l++)
18    { epp->position(epp,i);
19      for(k=0,j=epp->fc;j<epp->lc;k++,j++)
20        if (epp->row[k]!=epp->offsite) if ((*action)(j,i,epp->row[k])) return -2;
21      if (EndLineProc!=NULL) 
22       {
23        if  ((*EndLineProc)(i,l,rowcount)) return -1;
24       }
25     }
26   }
27  else
28  {
29   if (epp->currentline>epp->fr) {map_error=ME_INVALID_PUT;}
30   for (i=epp->fr,l=1;i<epp->lr;i++,l++)
31   { for(k=0,j=epp->fc;j<epp->lc;k++,j++)
32       epp_put(epp,j,i,(*action)(j,i,offsite));
33      if (EndLineProc!=NULL) 
34       {
35        if  ((*EndLineProc)(i,l,rowcount)) return -1;
36       }
37   }
38  }   
39  return 0; 
40 }
41 long count_cells(EPP *epp, EPP_ITER_PROC condition)
42 /* calls condition for each non-offsite cell in existing epp file, returns
43    count of cells, for which condition was non-zero */
44 { int i,j,k,l,rowcount;
45   long count=0;
46   rowcount=epp->lr-epp->fr;
47   if (epp->mode&MAP_OUTPUT)
48     {map_error=ME_INVALID_MODE; return 0L;}
49    reset_epp(epp);
50    for(i=epp->fr,l=1;i<epp->lr;i++,l++)
51    { get_row(epp);
52      for(k=0,j=epp->fc;j<epp->lc;k++,j++)
53        if (epp->row[k]!=epp->offsite)
54         {
55          if ((*condition)(j,i,epp->row[k])) count++;
56         }
57      if (EndLineProc!=NULL) 
58       {
59        if  ((*EndLineProc)(i,l,rowcount)) return -1;
60       }
61     }
62   return count;
63 }
64