예제 #1
0
파일: o_attrib.c 프로젝트: dmay31/geda-gaf
/*! \brief Search inherited attribute by name.
 *  \par Function Description
 *  Search for attribute by name.
 *
 *  Counter is the n'th occurance of the attribute, and starts searching
 *  from zero.  Zero is the first occurance of an attribute.
 *
 *  \param [in] object   The OBJECT whos inherited attributes to search.
 *  \param [in] name     Character string with attribute name to search for.
 *  \param [in] counter  Which occurance to return.
 *  \return Character string with attribute value, NULL otherwise.
 *
 *  \warning
 *  Caller must g_free returned character string.
 */
char *o_attrib_search_inherited_attribs_by_name (OBJECT *object, char *name, int counter)
{
  g_return_val_if_fail (object->type == OBJ_COMPLEX ||
                        object->type == OBJ_PLACEHOLDER, NULL);

  return o_attrib_search_floating_attribs_by_name (object->complex->prim_objs, name, counter);
}
예제 #2
0
void
s_check_graphical (const GList *obj_list, SYMCHECK *s_current)
{
  char *temp;
  
  /* look for special graphical tag */
  temp = o_attrib_search_floating_attribs_by_name (obj_list, "graphical", 0);

  if (temp) {
    s_current->graphical_symbol=TRUE;
    g_free(temp);
  }
}
예제 #3
0
void
s_check_device (const GList *obj_list, SYMCHECK *s_current)
{
  char *temp;
  char *message;
  
  /* search for device attribute */
  temp = o_attrib_search_floating_attribs_by_name (obj_list, "device", 0);
  if (!temp) {
    /* did not find device= attribute */
    message = g_strdup ("Missing device= attribute\n");
    s_current->error_messages = g_list_append(s_current->error_messages,
		                              message);
    s_current->missing_device_attrib=TRUE;
    s_current->error_count++;
  } else {
    /* found device= attribute */
    s_current->missing_device_attrib=FALSE;
    s_current->device_attribute = g_strdup (temp);
    message = g_strdup_printf ("Found device=%s\n", temp);
    s_current->info_messages = g_list_append(s_current->info_messages,
		                             message);
  }

  /* check for device = none for graphical symbols */
  if (temp && s_current->graphical_symbol && (strcmp(temp, "none") == 0)) {
    s_current->device_attribute_incorrect=FALSE;
    message = g_strdup ("Found graphical symbol, device=none\n");
    s_current->info_messages = g_list_append(s_current->info_messages,
                                             message);
  } else if (s_current->graphical_symbol) {
    s_current->device_attribute_incorrect=TRUE;
    message = g_strdup ("Found graphical symbol, device= should be set to none\n");
    s_current->warning_messages = g_list_append(s_current->warning_messages,
                                                message);
    s_current->warning_count++;
  } 

  g_free(temp);
}
예제 #4
0
/* still highly temp and doesn't work right */
SCM g_get_toplevel_attribute(SCM scm_wanted_attrib)
{
  const GList *p_iter;
  PAGE *p_current;
  char *wanted_attrib;
  char *attrib_value = NULL;
  SCM scm_return_value;
  TOPLEVEL *toplevel = edascm_c_current_toplevel ();

  SCM_ASSERT(scm_is_string (scm_wanted_attrib),
             scm_wanted_attrib, SCM_ARG1, "gnetlist:get-toplevel-attribute");

  wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);

  for (p_iter = geda_list_get_glist (toplevel->pages); p_iter != NULL;
       p_iter = g_list_next (p_iter)) {
    p_current = p_iter->data;

    /* only look for first occurrance of the attribute on each page */
    attrib_value =
      o_attrib_search_floating_attribs_by_name (s_page_objects (p_current),
                                                wanted_attrib, 0);

    /* Stop when we find the first one */
    if (attrib_value != NULL)
      break;
  }

  free (wanted_attrib);

  if (attrib_value != NULL) {
    scm_return_value = scm_from_utf8_string (attrib_value);
    g_free (attrib_value);
  } else {
    scm_return_value = scm_from_utf8_string ("not found");
  }

  return (scm_return_value);
}
예제 #5
0
void
s_check_slotdef (const GList *obj_list, SYMCHECK *s_current)
{
  char* value = NULL;
  char* slotdef = NULL;
  char* slotnum = NULL;
  char* pins = NULL;
  char* temp = NULL;
  char numslots_str[10];
  int slot;
  int i,j;
  char *message;
  char tempstr1[10];
  /*  pinlist will store the pin definitions for each slot */
  /* example: pinlist[0] = 3,2,8,4,1 ; pinlist[1] = 5,6,8,4,7 */
  char** pinlist = NULL;
  int n,m;
  char* pin;
  char* cmp;
  int match;
  gboolean error_parsing = FALSE;
  int errors_found = 0;

  /* look for numslots to see if this symbol has slotting info */
  value = o_attrib_search_floating_attribs_by_name (obj_list, "numslots", 0);

  if (!value) {
    message = g_strdup ("Did not find numslots= attribute, not checking slotting\n");
    s_current->warning_messages = g_list_append(s_current->warning_messages,
                                                message);
    s_current->warning_count++;
    message = g_strdup ("If this symbol does not need slotting, set numslots to zero (numslots=0)\n");
    s_current->info_messages = g_list_append(s_current->info_messages,
                                             message);
    return;
  }

  s_current->numslots=atoi(value);
  sprintf(numslots_str, "%d", s_current->numslots);
  g_free(value);

  message = g_strdup_printf ("Found numslots=%s attribute\n", numslots_str);
  s_current->info_messages = g_list_append(s_current->info_messages,
	 	    			   message);

  if (s_current->numslots == 0) {
    message = g_strdup ("numslots set to zero, symbol does not have slots\n");
    s_current->info_messages = g_list_append(s_current->info_messages,
                                             message);
    return;
  }
  

  pinlist = (char**)g_malloc0(sizeof(*pinlist) * s_current->numslots);

  i = 0;
  /* get the slotdef attribute */
  slotdef = o_attrib_search_floating_attribs_by_name (obj_list, "slotdef", 0);
  while ((slotdef != NULL) && (!error_parsing))
  {

    if (i > s_current->numslots-1) {

      sprintf(tempstr1, "%d", i+1); /* i starts at zero */
      message = g_strdup_printf (
        "Found %s slotdef= attributes.  Expecting %s slotdef= attributes\n",
        tempstr1, numslots_str); 
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);

      s_current->error_count++;
      s_current->slotting_errors++;
    }
    
    message = g_strdup_printf ("Found slotdef=%s attribute\n", slotdef);
    s_current->info_messages = g_list_append(s_current->info_messages,
	 	    			     message);

    slotnum = u_basic_breakup_string(slotdef, ':', 0);
    if (!slotnum)
    {
      message = g_strdup_printf (
        "Invalid slotdef=%s attributes, not continuing\n",
        slotdef);
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
      s_current->slotting_errors++;
      error_parsing = TRUE;
      continue;
    }

    if (strcmp(slotnum, "0") == 0) {
      message = g_strdup_printf (
        "Found a zero slot in slotdef=%s\n",
        slotdef);
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
    }
  
    slot = atoi(slotnum);
    g_free(slotnum);

    /* make sure that the slot # is less than the number of slots */
    if (slot > s_current->numslots) {
      sprintf(tempstr1, "%d", slot);
      message = g_strdup_printf (
        "Slot %s is larger then the maximum number (%s) of slots\n",
        tempstr1, numslots_str);
      s_current->error_messages = g_list_append(s_current->error_messages,
		      			        message);

      s_current->error_count++;
      s_current->slotting_errors++;
    }

    /* skip over the : */
    pins = strchr(slotdef, ':');
    if (!pins) {
      message = g_strdup_printf (
        "Invalid slotdef=%s attributes, not continuing\n",
        slotdef);
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
      s_current->slotting_errors++;
      error_parsing = TRUE;
      continue;
    }
    pins++;  /* get past that : */
    if (!pins) {
      message = g_strdup_printf (
        "Invalid slotdef=%s attributes, not continuing\n",
        slotdef);
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
      s_current->slotting_errors++;
      error_parsing = TRUE;
      continue;
    }

    if (*pins == '\0') {
      message = g_strdup_printf (
        "Invalid slotdef=%s attributes, not continuing\n",
        slotdef);
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
      s_current->slotting_errors++;
      error_parsing = TRUE;
      continue;
    }

    if ((slot > 0) && (slot <= s_current->numslots)) {
      if (pinlist[slot-1]) {
        message = g_strdup_printf ("Duplicate slot number in slotdef=%s\n",
				   slotdef);
        s_current->error_messages = g_list_append(s_current->error_messages,
	    			                  message);
        s_current->error_count++;
        s_current->slotting_errors++;
      } else {
	pinlist[slot-1] = g_strdup_printf(",%s,", pins);
      }
    }
    
    j = 0;
    do {
      if (temp) {
        g_free(temp);
        temp = NULL;
      }
        
      temp = u_basic_breakup_string(pins, ',', j);

      if (!temp && j < s_current->numpins) {
        message = g_strdup_printf (
          "Not enough pins in slotdef=%s\n",
          slotdef);
        s_current->error_messages = g_list_append(s_current->error_messages,
	    			                  message);
        s_current->error_count++;
        s_current->slotting_errors++;
        break;
      }

      if (j > s_current->numpins) {
        message = g_strdup_printf (
          "Too many pins in slotdef=%s\n",
          slotdef);
        s_current->error_messages = g_list_append(s_current->error_messages,
	    			                  message);
        s_current->error_count++;
        s_current->slotting_errors++;
        g_free(temp);
        temp = NULL;
        break;
      }
      
      if (temp && strcmp(temp, "0") == 0) {
        message = g_strdup_printf (
          "Found a zero pin in slotdef=%s\n",
          slotdef);
        s_current->error_messages = g_list_append(s_current->error_messages,
                                                  message);
        s_current->error_count++;
      }
     
      j++;
    } while (temp);

    g_free(temp);

    g_free(slotdef);
    slotdef = NULL;
   
    i++;
    slotdef = o_attrib_search_floating_attribs_by_name (obj_list, "slotdef", i);
  }

  if (!slotdef && i < s_current->numslots) {
    message = g_strdup_printf (
      "Missing slotdef= (there should be %s slotdef= attributes)\n",
      numslots_str);
    s_current->error_messages = g_list_append(s_current->error_messages,
			                      message);
    s_current->error_count++;
    s_current->slotting_errors++;
  } else {

    /* Validate that pinslist does not contain a null entry.  If any entry */
    /* is null, that means the slotdef= attribute was malformed to start */
    /* with. */
    for (i = 0; i < s_current->numslots; i++) { 
      if (pinlist[i] == NULL) {
        errors_found++;
      }
    }

    if (errors_found) {
      message = g_strdup_printf(
               "Malformed slotdef= (the format is #:#,#,#,...)\n");
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
      s_current->slotting_errors++;
    } else { 
      /* Now compare each pin with the rest */
      s_current->numslotpins = 0;
      for (i = 0; i < s_current->numslots; i++) {
        for (n = 1; n <= s_current->numpins; n++) {
          /* Get the number of one pin */
          pin = u_basic_breakup_string(pinlist[i], ',', n);
          if (pin && *pin) {
            match = FALSE;
            for (j = i - 1; j >= 0 && !match; j--) {
              for (m = 1; m <= s_current->numpins && !match; m++) {
                /* Get the number of the other pin */
                cmp = u_basic_breakup_string(pinlist[j], ',', m);
                if (cmp && *cmp) {
                  match = (0 == strcmp (pin, cmp));
                  g_free(cmp);
                }
              }
            }
            if (!match) {
              /* If they don't match, then increase the number of pins */
              s_current->numslotpins++;
            }
            g_free(pin);
          }
        }
      }
      message = g_strdup_printf ("Found %d distinct pins in slots\n", 
                                 s_current->numslotpins);
      s_current->info_messages = g_list_append(s_current->info_messages,
                                               message);
    }
  }
  
  g_free(slotdef);
  if (pinlist) {
    /* Free the pinlist */
    for (i = 0; i < s_current->numslots; i++) {
      g_free(pinlist[i]);
    }
    g_free(pinlist);
  }
 
  return;
}
예제 #6
0
void
s_check_pinnumber (const GList *obj_list, SYMCHECK *s_current)
{
  char *string;
  int missing_pinnumber_attrib_sum=0;
  int multiple_pinnumber_attrib_sum=0;
  int counter=0;
  int i;

  gchar **net_tokens;
  gchar **pin_tokens;
  GList *net_numbers = NULL;
  GList *pin_numbers = NULL;
  GList *cur = NULL;
  GList *cur2 = NULL;
  const GList *iter;
  char *message;
  char *net = NULL;
    
  /* collect all net pins */
  for (counter = 0;
       (net = o_attrib_search_floating_attribs_by_name (obj_list, "net", counter)) != NULL;
       counter++) {
    message = g_strdup_printf ("Found net=%s attribute\n", net);
    s_current->info_messages = g_list_append(s_current->info_messages,
					     message);

    net_tokens = g_strsplit(net,":", -1);
    /* length of net tokens have to be 2 */
    if (net_tokens[1] == NULL) {
      message = g_strdup_printf ("Bad net= attribute [net=%s]\n", net);
      s_current->error_messages = g_list_append(s_current->error_messages,
						message);
      s_current->error_count++;
      g_strfreev(net_tokens);
      continue;
    } else if (net_tokens[2] != NULL) { /* more than 2 tokens */
      message = g_strdup_printf ("Bad net= attribute [net=%s]\n", net);
      s_current->error_messages = g_list_append(s_current->error_messages,
						message);
      s_current->error_count++;
      g_strfreev(net_tokens);
      continue;
    }

    pin_tokens = g_strsplit(net_tokens[1],",",-1);
    
    for (i = 0; pin_tokens[i] != NULL; i++) {
      net_numbers = g_list_append(net_numbers, g_strdup(pin_tokens[i]));
      message = g_strdup_printf ("Found pin number %s in net attribute\n",
                                 pin_tokens[i]);
      s_current->info_messages = g_list_append(s_current->info_messages,
					       message);
      s_current->numnetpins++;
    }
    g_free(net);
    g_strfreev(net_tokens);
    g_strfreev(pin_tokens);
  }
  
  /* check for duplicate net pin numbers */
  net_numbers = g_list_sort(net_numbers, (GCompareFunc)strcmp);

  for (cur = net_numbers;
       cur != NULL && g_list_next(cur) != NULL;
       cur = g_list_next(cur)) {
    if (strcmp((gchar*)cur->data, (gchar*) cur->next->data) == 0) {
      message = g_strdup_printf ("Found duplicate pin in net= "
				 "attributes [%s]\n", (gchar*) cur->data);
      s_current->error_messages = g_list_append(s_current->error_messages,
						message);
      s_current->error_count++;
    }
    if (strcmp((gchar*) cur->data, "0") == 0) {
      message = g_strdup ("Found pinnumber 0 in net= attribute\n");
      s_current->error_messages = g_list_append(s_current->error_messages,
                                                message);
      s_current->error_count++;
    }
  }

  /* collect all pin numbers */
  for (iter = obj_list; iter != NULL; iter = g_list_next (iter)) {
    OBJECT *o_current = iter->data;
    
    if (o_current->type == OBJ_PIN) {
      s_current->numpins++;
      
      missing_pinnumber_attrib_sum = 0;
      multiple_pinnumber_attrib_sum = 0;
      
      for (counter = 0; 
	   (string = o_attrib_search_object_attribs_by_name (o_current, "pinnumber",
	                                                     counter)) != NULL;
	   counter++) {
	
        message = g_strdup_printf ("Found pinnumber=%s attribute\n", string);
        s_current->info_messages = g_list_append(s_current->info_messages,
	 	    			         message);

	if (counter == 0) { /* collect the first appearance */
	  pin_numbers = g_list_append(pin_numbers, string);
	}
        if (counter >= 1) {
          message = g_strdup_printf ("Found multiple pinnumber=%s attributes"
				     " on one pin\n", string);
          s_current->error_messages = g_list_append(s_current->error_messages,
	 	    			            message);
          multiple_pinnumber_attrib_sum++;
          s_current->error_count++;
	  g_free(string); 
        }
      }
	   
      if (counter == 0) {
        message = g_strdup ("Missing pinnumber= attribute\n");
        s_current->error_messages = g_list_append(s_current->error_messages,
                                                  message);
        missing_pinnumber_attrib_sum++;
        s_current->error_count++;
      }

      s_current->missing_pinnumber_attrib += missing_pinnumber_attrib_sum;
      s_current->multiple_pinnumber_attrib += multiple_pinnumber_attrib_sum;
    }
  }

  /* check for duplicate pinlabel numbers */
  pin_numbers = g_list_sort(pin_numbers, (GCompareFunc)strcmp);
  for (cur = pin_numbers;
       cur != NULL && g_list_next(cur) != NULL;
       cur = g_list_next(cur)) { 
    if (strcmp((gchar*)cur->data, (gchar*) cur->next->data) == 0) {
      message = g_strdup_printf ("Found duplicate pinnumber=%s attribute "
				 "in the symbol\n", (gchar*) cur->data);
      s_current->error_messages = g_list_append(s_current->error_messages,
						message);
      s_current->error_count++;
      s_current->duplicate_pinnumber_attrib++;
    }
    if (strcmp((gchar*) cur->data, "0") == 0) {
      message = g_strdup ("Found pinnumber=0 attribute\n");
      s_current->error_messages = g_list_append(s_current->error_messages,
						message);
      s_current->error_count++;
    }
  }

  /* Check for all pins that are in both lists and print a warning.
     Sometimes this is useful and sometimes it's an error. */

  cur = net_numbers;
  cur2 = pin_numbers;

  while (cur != NULL && cur2 != NULL) {
    
    i = strcmp((gchar*)cur->data, (gchar*)cur2->data);

    if (i == 0) {
      message = g_strdup_printf ("Found the same number in a pinnumber "
				 "attribute and in a net attribute [%s]\n",
				 (gchar*) cur->data);
      s_current->warning_messages = g_list_append(s_current->warning_messages,
						  message);
      s_current->warning_count++;
      cur = g_list_next(cur);

    } else if ( i > 0 ) {
      cur2 = g_list_next(cur2);

    } else { /* i < 0 */
      cur = g_list_next(cur);
    }
  }

  /* FIXME: this is not correct if a pinnumber is defined as pinnumber and
     inside a net. We have to calculate the union set */
  message = g_strdup_printf ("Found %d pins inside symbol\n", 
			     s_current->numpins + s_current->numnetpins);
  s_current->info_messages = g_list_append(s_current->info_messages,
                                           message);

  g_list_foreach(pin_numbers, (GFunc) g_free, NULL);
  g_list_free(pin_numbers);
  g_list_foreach(net_numbers, (GFunc) g_free, NULL);
  g_list_free(net_numbers);
}