示例#1
0
/* Returns a pointer to the first character past the list. */
static const char *
parse_layer_list (const char *bp, int (*error) (const char *))
{
  const char *orig_bp = bp;
  int l = 0, range = -1;
  int value = 1;

  grow_layer_list (0);
  while (*bp)
    {
      if (*bp == '+')
        value = 2;
      else if (*bp == 'S')
        value = 3;
      else if (*bp == 'X')
        value = 4;
      else if (*bp == 't')
        value = 5;
      else if (*bp == ')' || *bp == ',' || *bp == '-')
	{
	  if (range == -1)
	    range = l;
	  while (range <= l)
	    set_layer_list (range++, value);
	  if (*bp == '-')
	    range = l;
	  else
	    range = -1;
	  value = 1;
	  l = 0;
	}

      else if (isdigit ((int) *bp))
	l = l * 10 + (*bp - '0');

      else if (error)
	{
	  char *fmt = "Syntax error parsing layer list \"%.*s\" at %c";
	  char *msg = alloc_buf (strlen (fmt) + strlen (orig_bp));
	  sprintf (msg, fmt, bp - orig_bp + 5, orig_bp, *bp);
	  error (msg);
	  error = NULL;
	}

      if (*bp == ')')
	return bp + 1;

      bp++;
    }
  return bp;
}
示例#2
0
int
main ()
{
  time_t now;
  int i;
  int errors = 0, count = 0;

  time (&now);
  srandom ((unsigned int) now + getpid ());

  grow_layer_list (0);
  for (i = 0; i < 16; i++)
    {
      int j;
      char *p;
      if (i != 1 && i != 4 && i != 5 && i != 9)
	set_layer_list (i, 1);
      else
	set_layer_list (i, 0);
      p = print_layer_list ();
      printf ("%2d : %20s =", i, p);
      parse_layer_list (p + 1, 0);
      for (j = 0; j < num_layers; j++)
	printf (" %d", layers[j]);
      printf ("\n");
    }

  while (count < 1000000)
    {
      FlagHolder fh;
      char *str;
      FlagType new_flags;
      int i;
      int otype;

      otype = ALL_TYPES;
      fh.Flags = empty_flags;
      for (i = 0; i < ENTRIES (object_flagbits); i++)
	{
	  if (TEST_FLAG (object_flagbits[i].mask, &fh))
	    continue;
	  if ((otype & object_flagbits[i].object_types) == 0)
	    continue;
	  if ((random () & 4) == 0)
	    continue;

	  otype &= object_flagbits[i].object_types;
	  SET_FLAG (object_flagbits[i].mask, &fh);
	}

      if (otype & PIN_TYPES)
	for (i = 0; i < MAX_LAYER; i++)
	  if (random () & 4)
	    ASSIGN_THERM (i, 3, &fh);

      str = flags_to_string (fh.Flags, otype);
      new_flags = string_to_flags (str, 0);

      count++;
      if (FLAGS_EQUAL (fh.Flags, new_flags))
	continue;

      dump_flag (&fh.Flags);
      printf (" ");
      dump_flag (&new_flags);
      printf ("\n");
      if (++errors == 5)
	exit (1);
    }

  while (count < 1000000)
    {
      FlagHolder fh;
      char *str;
      FlagType new_flags;
      int i;
      int otype;

      otype = ALL_TYPES;
      fh.Flags = empty_flags;
      for (i = 0; i < ENTRIES (pcb_flagbits); i++)
	{
	  if (TEST_FLAG (pcb_flagbits[i].mask, &fh))
	    continue;
	  if ((random () & 4) == 0)
	    continue;

	  otype &= pcb_flagbits[i].object_types;
	  SET_FLAG (pcb_flagbits[i].mask, &fh);
	}

      str = pcbflags_to_string (fh.Flags);
      new_flags = string_to_pcbflags (str, 0);

      count++;
      if (FLAGS_EQUAL (fh.Flags, new_flags))
	continue;

      dump_flag (&fh.Flags);
      printf (" ");
      dump_flag (&new_flags);
      printf ("\n");
      if (++errors == 5)
	exit (1);
    }
  printf ("%d out of %d failed\n", errors, count);
  return errors;
}
示例#3
0
static char *
common_flags_to_string (FlagType flags,
			int object_type,
			FlagBitsType *flagbits,
			int n_flagbits)
{
  int len;
  int i;
  FlagHolder fh, savef;
  char *buf, *bp;

  fh.Flags = flags;

#ifndef FLAG_TEST
  switch (object_type)
    {
    case VIA_TYPE:
      CLEAR_FLAG (VIAFLAG, &fh);
      break;
    case RATLINE_TYPE:
      CLEAR_FLAG (RATFLAG, &fh);
      break;
    case PIN_TYPE:
      CLEAR_FLAG (PINFLAG, &fh);
      break;
    }
#endif

  savef = fh;

  len = 3;			/* for "()\0" */
  for (i = 0; i < n_flagbits; i++)
    if ((flagbits[i].object_types & object_type)
	&& (TEST_FLAG (flagbits[i].mask, &fh)))
      {
	len += flagbits[i].nlen + 1;
	CLEAR_FLAG (flagbits[i].mask, &fh);
      }

  if (TEST_ANY_THERMS (&fh))
    {
      len += sizeof ("thermal()");
      for (i = 0; i < MAX_LAYER; i++)
	if (TEST_THERM (i, &fh))
	  len += printed_int_length (i, GET_THERM (i, &fh)) + 1;
    }

  bp = buf = alloc_buf (len + 2);

  *bp++ = '"';

  fh = savef;
  for (i = 0; i < n_flagbits; i++)
    if (flagbits[i].object_types & object_type
	&& (TEST_FLAG (flagbits[i].mask, &fh)))
      {
	if (bp != buf + 1)
	  *bp++ = ',';
	strcpy (bp, flagbits[i].name);
	bp += flagbits[i].nlen;
	CLEAR_FLAG (flagbits[i].mask, &fh);
      }

  if (TEST_ANY_THERMS (&fh))
    {
      if (bp != buf + 1)
	*bp++ = ',';
      strcpy (bp, "thermal");
      bp += strlen ("thermal");
      grow_layer_list (0);
      for (i = 0; i < MAX_LAYER; i++)
	if (TEST_THERM (i, &fh))
	  set_layer_list (i, GET_THERM (i, &fh));
      strcpy (bp, print_layer_list ());
      bp += strlen (bp);
    }

  *bp++ = '"';
  *bp = 0;
  return buf;
}
示例#4
0
文件: strflags.c 项目: bert/pcb-rnd
static char *
common_flags_to_string (FlagType flags,
			int object_type,
			FlagBitsType *flagbits,
			int n_flagbits)
{
  int len;
  int i;
  FlagHolder fh, savef;
  char *buf, *bp;
  unknown_flag_t *u;

  fh.Flags = flags;

#ifndef FLAG_TEST
  switch (object_type)
    {
    case VIA_TYPE:
      CLEAR_FLAG (VIAFLAG, &fh);
      break;
    case RATLINE_TYPE:
      CLEAR_FLAG (RATFLAG, &fh);
      break;
    case PIN_TYPE:
      CLEAR_FLAG (PINFLAG, &fh);
      break;
    }
#endif

  savef = fh;

  len = 3;			/* for "()\0" */

  for (i = 0; i < n_flagbits; i++)

    if ((flagbits[i].object_types & object_type)
	&& (TEST_FLAG (flagbits[i].mask, &fh)))
      {

	len += flagbits[i].nlen + 1;
	CLEAR_FLAG (flagbits[i].mask, &fh);
      }

  if (TEST_ANY_THERMS (&fh))
    {
      len += sizeof ("thermal()");
      for (i = 0; i < MAX_LAYER; i++)
	if (TEST_THERM (i, &fh))
	  len += printed_int_length (i, GET_THERM (i, &fh)) + 1;
    }

  if (flags.q > 0)
    {
      len += sizeof ("shape(.)");
			if (flags.q > 9)
				len+=2;
    }

  if (flags.int_conn_grp > 0)
    {
      len += sizeof ("intconn(.)");
			if (flags.q > 9)
				len++;
			if (flags.q > 99)
				len++;
    }

	for(u = flags.unknowns; u != NULL; u = u->next)
		len += strlen(u->str)+1;

  bp = buf = alloc_buf (len + 2);

  *bp++ = '"';

  fh = savef;
  for (i = 0; i < n_flagbits; i++)
    if (flagbits[i].object_types & object_type
	&& (TEST_FLAG (flagbits[i].mask, &fh)))
      {
	if (bp != buf + 1)
	  *bp++ = ',';
	strcpy (bp, flagbits[i].name);
	bp += flagbits[i].nlen;
	CLEAR_FLAG (flagbits[i].mask, &fh);
      }

  if (TEST_ANY_THERMS (&fh))
    {
      if (bp != buf + 1)
	*bp++ = ',';
      strcpy (bp, "thermal");
      bp += strlen ("thermal");
      grow_layer_list (0);
      for (i = 0; i < MAX_LAYER; i++)
	if (TEST_THERM (i, &fh))
	  set_layer_list (i, GET_THERM (i, &fh));
      strcpy (bp, print_layer_list ());
      bp += strlen (bp);
    }

  if (flags.q > 0)
    {
			if (bp != buf + 1)
				*bp++ = ',';
			bp += sprintf(bp, "shape(%d)", flags.q);
    }

  if (flags.int_conn_grp > 0)
    {
			if (bp != buf + 1)
				*bp++ = ',';
			bp += sprintf(bp, "intconn(%d)", flags.int_conn_grp);
    }

	for(u = flags.unknowns; u != NULL; u = u->next) {
		int len;
		len = strlen(u->str);
		if (bp != buf + 1)
			*bp++ = ',';
		memcpy(bp, u->str, len);
		bp += len;
	}

  *bp++ = '"';
  *bp = 0;
  return buf;
}