regions.c
/* make the string containing region initialization calls */
make the string containing region initialization calls
make the string containing region initialization calls
char *_RegionsInitString(Regions reg){
  char *ibuf, *iptr, *fptr;
  char *s, *t;
  char tbuf[SZ_LINE];
  int paren=0;
  ibuf = xcalloc(strlen(reg->filter)*10+1, sizeof(char));
  if( !reg->nshape ){
    return ibuf;
  }
  iptr = ibuf;
  fptr = reg->filter;
  if( reg->reg_prefix ){
    snprintf(tbuf, SZ_LINE-1, "%sim", reg->reg_prefix);
  } else {
    strcpy(tbuf, "im");
  }
  while( *fptr ){
    if( !(s=strstr(fptr, tbuf)) ){
      break;
    }
    t = s + strlen(tbuf);
    if( !*t ){
      break;
    }
    if( strncmp(t, "annulus(", 8)    &&
	strncmp(t, "box(", 4)        &&
	strncmp(t, "circle(", 7)     &&
	strncmp(t, "ellipse(", 8)    &&
	strncmp(t, "line(", 5)       &&
	strncmp(t, "panda(", 6)      &&
	strncmp(t, "bpanda(", 7)     &&
	strncmp(t, "cpanda(", 7)     &&
	strncmp(t, "epanda(", 7)     &&
	strncmp(t, "pie(", 4)        &&
	strncmp(t, "qtpie(", 6)      &&
	strncmp(t, "point(", 6)      &&
	strncmp(t, "nannulus(", 9)   &&
	strncmp(t, "nbox(", 5)       &&
	strncmp(t, "ncircle(", 8)    &&
	strncmp(t, "nellipse(", 9)   &&
	strncmp(t, "npie(", 5)       &&
	strncmp(t, "vannulus(", 9)   &&
	strncmp(t, "vbox(", 5)       &&
	strncmp(t, "vcircle(", 8)    &&
	strncmp(t, "vellipse(", 9)   &&
	strncmp(t, "vpie(", 5)       &&
	strncmp(t, "vpoint(", 7)     &&
	strncmp(t, "polygon(", 8)    &&
	strncmp(t, "field(", 6)      &&
	strncmp(t, "imagemask(", 10) ){
      fptr = t;
      continue;
    }
    for(fptr=s; *fptr && *fptr!='('; fptr++){
      *iptr++ = *fptr;
    }
    *iptr++ = 'i';
    if( *fptr == '(' ){
      *iptr++ = *fptr++;
      paren++;
    }
    while( *fptr && paren ){
      if( *fptr == '(' ){
	paren++;
      }
      if( *fptr == ')' ){
	paren--;
      }
      *iptr++ = *fptr++;
    }
    *iptr++ = ';';
  }
  return ibuf;
}
char * _RegionsInitString ( Regions reg ) { char * ibuf , * iptr , * fptr ; char * s , * t ; char tbuf [ SZ_LINE ] ; int paren = 0 ; ibuf = xcalloc ( strlen ( reg -> filter ) * 10 + 1 , sizeof ( char ) ) ; if ( ! reg -> nshape ) { return ibuf ; } iptr = ibuf ; fptr = reg -> filter ; if ( reg -> reg_prefix ) { snprintf ( tbuf , SZ_LINE - 1 , " " , reg -> reg_prefix ) ; } else { strcpy ( tbuf , " " ) ; } while ( * fptr ) { if ( ! ( s = strstr ( fptr , tbuf ) ) ) { break ; } t = s + strlen ( tbuf ) ; if ( ! * t ) { break ; } if ( strncmp ( t , " " , 8 ) && strncmp ( t , " " , 4 ) && strncmp ( t , " " , 7 ) && strncmp ( t , " " , 8 ) && strncmp ( t , " " , 5 ) && strncmp ( t , " " , 6 ) && strncmp ( t , " " , 7 ) && strncmp ( t , " " , 7 ) && strncmp ( t , " " , 7 ) && strncmp ( t , " " , 4 ) && strncmp ( t , " " , 6 ) && strncmp ( t , " " , 6 ) && strncmp ( t , " " , 9 ) && strncmp ( t , " " , 5 ) && strncmp ( t , " " , 8 ) && strncmp ( t , " " , 9 ) && strncmp ( t , " " , 5 ) && strncmp ( t , " " , 9 ) && strncmp ( t , " " , 5 ) && strncmp ( t , " " , 8 ) && strncmp ( t , " " , 9 ) && strncmp ( t , " " , 5 ) && strncmp ( t , " " , 7 ) && strncmp ( t , " " , 8 ) && strncmp ( t , " " , 6 ) && strncmp ( t , " " , 10 ) ) { fptr = t ; continue ; } for ( fptr = s ; * fptr && * fptr != ' ' ; fptr ++ ) { * iptr ++ = * fptr ; } * iptr ++ = ' ' ; if ( * fptr == ' ' ) { * iptr ++ = * fptr ++ ; paren ++ ; } while ( * fptr && paren ) { if ( * fptr == ' ' ) { paren ++ ; } if ( * fptr == ' ' ) { paren -- ; } * iptr ++ = * fptr ++ ; } * iptr ++ = ' ' ; } return ibuf ; }
make the string containing region initialization calls
make the string containing region initialization calls
/* make sure we have at least one shape */ /* look for beginning of region routine */ /* which is followed by a region and open paren */ /* copy region name up to open paren */ /* append init suffix */ /* copy the paren */ /* copy til end of region, i.e., when paren goes to 0 */ /* copy ';' */