regprog_c.c
/*
 *
 * RegionsProgWrite_C -- write the symbols for filtering
 *
 */
- write the symbols for filtering
- write the symbols for filtering
static int RegionsProgWrite_C(Regions reg){
  char *ibuf;
  char *contents=NULL;
  FILE *fd;
  if( !reg ){
    return 0;
  }
  if( reg->fp == NULL ){
    xerror(stderr, "no output file for parser\n");
    return 0;
  }
  if( !reg->filter || !strcmp(reg->filter, "()") ){
    return 0;
  }
  fd= reg->fp;
  switch(reg->ptype){
  case PTYPE_CONTAINED:
    if( reg->debug < 2 ){
      contents = IMREGIONS_C;
      if( (contents != NULL) && (*contents != '\0') ){
	fprintf(fd, "%s\n", contents);
      } else {
	xerror(stderr, "could not write filter subroutines\n");
	return 0;
      }
    }
    break;
  }
  fprintf(fd, "#define IMFILTRTN %s\n", reg->pname);
  fprintf(fd, "#define NSHAPE %d\n", reg->nshape);
  fprintf(fd, "#define FILTER %s\n", reg->filter);
  fprintf(fd, "#define FILTSTR \"%s\"\n", reg->filter);
  ibuf = _RegionsInitString(reg);
  fprintf(fd, "#define FINIT %s\n", ibuf);
  xfree(ibuf);
  fflush(fd);
  return 1;
}
static int RegionsProgWrite_C ( Regions reg ) { char * ibuf ; char * contents = NULL ; FILE * fd ; if ( ! reg ) { return 0 ; } if ( reg -> fp == NULL ) { xerror ( stderr , " \n " ) ; return 0 ; } if ( ! reg -> filter || ! strcmp ( reg -> filter , " " ) ) { return 0 ; } fd = reg -> fp ; switch ( reg -> ptype ) { case PTYPE_CONTAINED : if ( reg -> debug < 2 ) { contents = IMREGIONS_C ; if ( ( contents != NULL ) && ( * contents != ' \0 ' ) ) { fprintf ( fd , " \n " , contents ) ; } else { xerror ( stderr , " \n " ) ; return 0 ; } } break ; } fprintf ( fd , " \n " , reg -> pname ) ; fprintf ( fd , " \n " , reg -> nshape ) ; fprintf ( fd , " \n " , reg -> filter ) ; fprintf ( fd , " \" \" \n " , reg -> filter ) ; ibuf = _RegionsInitString ( reg ) ; fprintf ( fd , " \n " , ibuf ) ; xfree ( ibuf ) ; fflush ( fd ) ; return 1 ; }
RegionsProgWrite_C -- write the symbols for filtering
RegionsProgWrite_C -- write the symbols for filtering
/* make sure we have something to work with */ /* make sure we are init'ed */ /* get the filter string */ /* init temps */ /* ptype-specific processing */ /* Write code to output file -- must be done BEFORE we write the
       region symbols, to avoid unintentional redefinitions */ /* region routines if not linking against previously compiled code */ /* image are filtered by image pixels */ /* use fprintf so that we handle \n correctly in TEMPLATE */ /* always need the swap routines (they're part of the filter) */ /* name of routine to call */ /* output counts of shapes */ /* output the filter itself */ /* string version of the filter -- used to check for FIELD optimization */ /* output the initialization string */ /* write it now */