From ec173a7e86a89ecfdf917c4c2f8f8329a9e717e0 Mon Sep 17 00:00:00 2001
From: rliebscher <rliebscher@81a1dc3b-b13d-400b-aceb-764788c761c2>
Date: Mon, 18 Aug 2014 21:43:08 +0000
Subject: [PATCH] patch #8440 Print part id after signature When printing the
 part signature also print the part id. * avrpart.c
 (locate_part_by_signature): New function. * libavrdude.h
 (locate_part_by_signature): New function. * main.c (main): Use the new
 function to find the part and print its id.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1332 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog    |  8 ++++++++
 avrpart.c    | 21 +++++++++++++++++++++
 libavrdude.h |  2 ++
 main.c       |  8 ++++++++
 4 files changed, 39 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 0457be4f..4caee166 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-08-18  Rene Liebscher <R.Liebscher@gmx.de>
+
+	patch #8440 Print part id after signature
+	When printing the part signature also print the part id.
+	* avrpart.c (locate_part_by_signature): New function.
+	* libavrdude.h (locate_part_by_signature): New function.
+	* main.c (main): Use the new function to find the part and print its id.
+
 2014-08-18  Rene Liebscher <R.Liebscher@gmx.de>
 
 	patch #8511 Fix reset on FT245R
diff --git a/avrpart.c b/avrpart.c
index 06762d6f..621a85b9 100644
--- a/avrpart.c
+++ b/avrpart.c
@@ -540,6 +540,27 @@ AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode)
   return NULL;
 }
 
+AVRPART * locate_part_by_signature(LISTID parts, unsigned char * sig,
+                                   int sigsize)
+{
+  LNODEID ln1;
+  AVRPART * p = NULL;
+  int i;
+
+  if (sigsize == 3) {
+    for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
+      p = ldata(ln1);
+      for (i=0; i<3; i++)
+        if (p->signature[i] != sig[i])
+          break;
+      if (i == 3)
+        return p;
+    }
+  }
+
+  return NULL;
+}
+
 /*
  * Iterate over the list of avrparts given as "avrparts", and
  * call the callback function cb for each entry found.  cb is being
diff --git a/libavrdude.h b/libavrdude.h
index b7ab381b..ac79640c 100644
--- a/libavrdude.h
+++ b/libavrdude.h
@@ -328,6 +328,8 @@ AVRPART * avr_dup_part(AVRPART * d);
 void      avr_free_part(AVRPART * d);
 AVRPART * locate_part(LISTID parts, char * partdesc);
 AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode);
+AVRPART * locate_part_by_signature(LISTID parts, unsigned char * sig,
+                                   int sigsize);
 void avr_display(FILE * f, AVRPART * p, const char * prefix, int verbose);
 
 typedef void (*walk_avrparts_cb)(const char *name, const char *desc,
diff --git a/main.c b/main.c
index 44d1869b..bfe2b596 100644
--- a/main.c
+++ b/main.c
@@ -1033,6 +1033,14 @@ int main(int argc, char * argv [])
         if (sig->buf[i] != 0x00)
           zz = 0;
       }
+      if (quell_progress < 2) {
+        AVRPART * part;
+
+        part = locate_part_by_signature(part_list, sig->buf, sig->size);
+        if (part) {
+          avrdude_message(MSG_INFO, " (probably %s)", part->id);
+        }
+      }
       if (ff || zz) {
         if (++attempt < 3) {
           waittime *= 5;