This patch is a.k.a. 8cdc6dd32bdc1c07c0207ba25099144ba25e4e57 in my
fork in git://repo.or.cz/geda-gaf/berndj.git
It teaches gsymcheck to divine the number of pins from the
package name only in whitelisted cases, specified by a regular
expression. I added only the pattern "^DIP([0-9]+)$"; add more
according to taste.
Dan, would you please try this and see if it makes you happier
than you were on #geda last night?
commit 8cdc6dd32bdc1c07c0207ba25099144ba25e4e57
Author: Bernd Jendrissek <[EMAIL PROTECTED]>
Date: Fri Jan 11 03:51:26 2008 +0200
Teach gsymcheck to extract the number of pins from some footprints.
Footprint attributes such as DIP8 or DIP40 have the total number of
pins encoded in their name, but SOT23 for example would confuse the
naive algorithm gsymcheck was using to just take the last number-like
substring. Regular expressions are good at this sort of work. Use
them if available.
diff --git a/gsymcheck/configure.ac b/gsymcheck/configure.ac
index 462b211..4aad887 100644
--- a/gsymcheck/configure.ac
+++ b/gsymcheck/configure.ac
@@ -190,7 +190,7 @@ fi
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
-AC_CHECK_HEADERS(unistd.h string.h stdlib.h \
+AC_CHECK_HEADERS(regex.h sys/types.h unistd.h string.h stdlib.h \
stdarg.h assert.h fcntl.h errno.h)
# Checks for typedefs, structures, and compiler characteristics.
@@ -198,7 +198,7 @@ AC_C_CONST
# Checks for library functions.
AC_TYPE_SIGNAL
-AC_CHECK_FUNCS(getcwd strstr vsnprintf snprintf)
+AC_CHECK_FUNCS(regcomp regexec getcwd strstr vsnprintf snprintf)
AC_MSG_CHECKING([for optarg in unistd.h])
AC_TRY_COMPILE(
diff --git a/gsymcheck/include/pincounts.h b/gsymcheck/include/pincounts.h
index 0ccb3f8..e5d14e3 100644
--- a/gsymcheck/include/pincounts.h
+++ b/gsymcheck/include/pincounts.h
@@ -1,5 +1,15 @@
/* pincounts.h */
+#include "config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_REGEX_H
+#include <regex.h>
+#endif
+#include <stdlib.h>
+
typedef struct st_pincount PINCOUNT;
struct st_pincount {
@@ -13,11 +23,19 @@ static PINCOUNT p_pincounts[] = {
{ NULL, 3 },
};
+static char const *pattern_pincounts[] = {
+ "^footprint=DIP([0-9]+)$",
+ NULL
+};
int s_get_footprint_size(char *footprint)
{
+#ifdef HAVE_REGCOMP
+ regmatch_t captures[2];
+ regex_t re;
+#endif
PINCOUNT *pcount = p_pincounts;
- char *tmp;
+ int i;
while(pcount->footprint != NULL) {
if (!strcasecmp(footprint, pcount->footprint))
@@ -25,19 +43,33 @@ int s_get_footprint_size(char *footprint)
pcount++;
}
- tmp = &footprint[strlen(footprint)-1];
+#ifdef HAVE_REGCOMP
+ for (i = 0; pattern_pincounts[i]; i++) {
+ if (regcomp(&re, pattern_pincounts[i], REG_EXTENDED)) {
+ continue;
+ }
+ if (regexec(&re, footprint, 2, captures, 0) == 0 &&
+ captures[1].rm_so != -1) {
+ char *number;
+ int count;
+
+ number = malloc(captures[1].rm_eo - captures[1].rm_so + 1);
+ if (number == NULL) {
+ return -1;
+ }
- while((*tmp >= '0') && (*tmp <= '9'))
- {
- if (tmp == footprint)
- return -1;
- tmp--;
+ sprintf(number, "%.*s",
+ captures[1].rm_eo - captures[1].rm_so,
+ footprint + captures[1].rm_so);
+
+ count = atoi(number);
+
+ free(number);
+
+ return count;
+ }
}
- tmp++;
+#endif
- if (*tmp == '\0')
- return -1;
-
- return atoi(tmp);
+ return -1;
}
-
_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev