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
12 { int i,j,k,l,rowcount,offsite;
13 rowcount=epp->lr-epp->fr;
15 if (epp->mode&MAP_INPUT)
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)
23 if ((*EndLineProc)(i,l,rowcount)) return -1;
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)
35 if ((*EndLineProc)(i,l,rowcount)) return -1;
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;
46 rowcount=epp->lr-epp->fr;
47 if (epp->mode&MAP_OUTPUT)
48 {map_error=ME_INVALID_MODE; return 0L;}
50 for(i=epp->fr,l=1;i<epp->lr;i++,l++)
52 for(k=0,j=epp->fc;j<epp->lc;k++,j++)
53 if (epp->row[k]!=epp->offsite)
55 if ((*condition)(j,i,epp->row[k])) count++;
57 if (EndLineProc!=NULL)
59 if ((*EndLineProc)(i,l,rowcount)) return -1;