• R/O
  • SSH
  • HTTPS

avrdude: Commit


Commit MetaInfo

Revisión1469 (tree)
Tiempo2020-02-17 04:46:32
Autorgottfried

Log Message

AVRPART to std::vector

Cambiar Resumen

Diferencia

--- trunk/avrpart.cpp (revision 1468)
+++ trunk/avrpart.cpp (revision 1469)
@@ -25,6 +25,8 @@
2525 #include "avrdude.h"
2626 #include "libavrdude.h"
2727
28+#include <algorithm>
29+
2830 /***
2931 *** Elementary functions dealing with OPCODE structures
3032 ***/
@@ -490,49 +492,64 @@
490492
491493 void avr_free_part(AVRPART * d)
492494 {
493-int i;
494- ldestroy_cb(d->mem, (void(*)(void *))avr_free_mem);
495- d->mem = NULL;
496- for(i=0;i<sizeof(d->op)/sizeof(d->op[0]);i++)
495+ int i;
496+ ldestroy_cb(d->mem, (void(*)(void *))avr_free_mem);
497+ d->mem = NULL;
498+ for(i=0; i < sizeof(d->op) / sizeof(d->op[0]); i++)
499+ {
500+ if(d->op[i] != NULL)
497501 {
498- if (d->op[i] != NULL)
499- {
500- avr_free_opcode(d->op[i]);
501- d->op[i] = NULL;
502- }
502+ avr_free_opcode(d->op[i]);
503+ d->op[i] = NULL;
503504 }
504- free(d);
505+ }
505506 }
506507
507-AVRPART * locate_part(LISTID parts, char * partdesc)
508+void avr_free_parts()
508509 {
509- LNODEID ln1;
510- AVRPART * p = NULL;
511- int found;
510+ for(std::vector<AVRPART>::iterator it = part_list.begin(); it != part_list.end(); ++it)
511+ {
512+ avr_free_part(&(*it));
513+ }
514+ part_list.clear();
515+}
512516
513- found = 0;
517+// New std::vector lists
518+void remove_part(std::vector<AVRPART> &parts, AVRPART *data_ptr)
519+{
520+ for( std::vector<AVRPART>::iterator it = parts.begin(); it != parts.end(); ++it )
521+ {
522+ AVRPART *p = &(*it);
523+ if(p == data_ptr)
524+ {
525+ avr_free_part(p);
526+ parts.erase(it);
527+ return;
528+ }
529+ }
530+}
514531
515- for (ln1=lfirst(parts); ln1 && !found; ln1=lnext(ln1)) {
516- p = static_cast<AVRPART*>(ldata(ln1));
517- if ((strcasecmp(partdesc, p->id) == 0) ||
518- (strcasecmp(partdesc, p->desc) == 0))
519- found = 1;
532+AVRPART *locate_part(std::vector<AVRPART> &parts, char *partdesc)
533+{
534+ for(std::vector<AVRPART>::iterator it = parts.begin(); it != parts.end(); ++it)
535+ {
536+ AVRPART *p = &(*it);
537+ if((strcasecmp(partdesc, p->id) == 0) ||
538+ (strcasecmp(partdesc, p->desc) == 0))
539+ {
540+ return p; // found = 1;
541+ }
520542 }
521543
522- if (found)
523- return p;
524-
525544 return NULL;
526545 }
527546
528-AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode)
547+AVRPART *locate_part_by_avr910_devcode(std::vector<AVRPART> &parts, int devcode)
529548 {
530- LNODEID ln1;
531- AVRPART * p = NULL;
532-
533- for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
534- p = static_cast<AVRPART*>(ldata(ln1));
535- if (p->avr910_devcode == devcode)
549+ for(std::vector<AVRPART>::iterator it = parts.begin(); it != parts.end(); ++it)
550+ {
551+ AVRPART *p = &(*it);
552+ if(p->avr910_devcode == devcode)
536553 return p;
537554 }
538555
@@ -539,20 +556,20 @@
539556 return NULL;
540557 }
541558
542-AVRPART * locate_part_by_signature(LISTID parts, unsigned char * sig,
543- int sigsize)
559+AVRPART *locate_part_by_signature(std::vector<AVRPART> &parts, unsigned char * sig, int sigsize)
544560 {
545- LNODEID ln1;
546- AVRPART * p = NULL;
547- int i;
548-
549- if (sigsize == 3) {
550- for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
551- p = static_cast<AVRPART*>(ldata(ln1));
552- for (i=0; i<3; i++)
553- if (p->signature[i] != sig[i])
561+ if(sigsize == 3)
562+ {
563+ for(std::vector<AVRPART>::iterator it = parts.begin(); it != parts.end(); ++it)
564+ {
565+ AVRPART *p = &(*it);
566+ int i = 0;
567+ for(; i < 3; i++)
568+ {
569+ if(p->signature[i] != sig[i])
554570 break;
555- if (i == 3)
571+ }
572+ if(i == 3)
556573 return p;
557574 }
558575 }
@@ -570,13 +587,11 @@
570587 * . the line number of the config file this avrpart has been defined at
571588 * . the "cookie" passed into walk_avrparts() (opaque client data)
572589 */
573-void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie)
590+void walk_avrparts(const std::vector<AVRPART> &avrparts, walk_avrparts_cb cb, void *cookie)
574591 {
575- LNODEID ln1;
576- AVRPART * p;
577-
578- for (ln1 = lfirst(avrparts); ln1; ln1 = lnext(ln1)) {
579- p = static_cast<AVRPART*>(ldata(ln1));
592+ for(std::vector<AVRPART>::const_iterator it = avrparts.begin(); it != avrparts.end(); ++it)
593+ {
594+ const AVRPART *p = &(*it);
580595 cb(p->id, p->desc, p->config_file, p->lineno, cookie);
581596 }
582597 }
@@ -584,20 +599,17 @@
584599 /*
585600 * Compare function to sort the list of programmers
586601 */
587-static int sort_avrparts_compare(AVRPART * p1,AVRPART * p2)
602+bool sort_avrparts_compare(const AVRPART &p1, const AVRPART &p2)
588603 {
589- if(p1 == NULL || p2 == NULL) {
590- return 0;
591- }
592- return strncasecmp(p1->desc,p2->desc,AVR_DESCLEN);
604+ return strncasecmp(p1.desc, p2.desc, AVR_DESCLEN) < 0;
593605 }
594606
595607 /*
596608 * Sort the list of programmers given as "programmers"
597609 */
598-void sort_avrparts(LISTID avrparts)
610+void sort_avrparts(std::vector<AVRPART> &avrparts)
599611 {
600- lsort(avrparts,(int (*)(void*, void*)) sort_avrparts_compare);
612+ std::sort(avrparts.begin(), avrparts.end(), sort_avrparts_compare);
601613 }
602614
603615
--- trunk/config.cpp (revision 1468)
+++ trunk/config.cpp (revision 1469)
@@ -59,7 +59,7 @@
5959 PROGRAMMER * current_prog;
6060 AVRPART * current_part;
6161 AVRMEM * current_mem;
62-LISTID part_list;
62+std::vector<AVRPART> part_list;
6363 std::vector<PROGRAMMER> programmers;
6464
6565 int lineno;
@@ -71,7 +71,7 @@
7171
7272 void cleanup_config(void)
7373 {
74- ldestroy_cb(part_list, (void(*)(void*))avr_free_part);
74+ avr_free_parts();
7575 ldestroy_cb(string_list, (void(*)(void*))free_token);
7676 ldestroy_cb(number_list, (void(*)(void*))free_token);
7777 }
@@ -83,7 +83,6 @@
8383 current_prog = NULL;
8484 current_part = NULL;
8585 current_mem = NULL;
86- part_list = lcreat(NULL, 0);
8786
8887 lineno = 1;
8988 infile = NULL;
--- trunk/config_gram.y (revision 1468)
+++ trunk/config_gram.y (revision 1469)
@@ -384,10 +384,9 @@
384384 existing_part->config_file, existing_part->lineno);
385385 lineno = temp;
386386 }
387- lrmv_d(part_list, existing_part);
388- avr_free_part(existing_part);
387+ remove_part(part_list, existing_part);
389388 }
390- PUSH(part_list, current_part);
389+ part_list.push_back(*current_part);
391390 current_part = NULL;
392391 }
393392 ;
--- trunk/libavrdude.h (revision 1468)
+++ trunk/libavrdude.h (revision 1469)
@@ -46,16 +46,6 @@
4646 typedef void * LNODEID;
4747
4848
49-/*----------------------------------------------------------------------
50- several defines to access the LIST structure as as stack or a queue
51- --- use for program readability
52- ----------------------------------------------------------------------*/
53-#define STACKID LISTID
54-#define SNODEID LNODEID
55-#define QUEUEID LISTID
56-#define QNODEID LNODEID
57-
58-
5949 #define PUSH(s,d) lins_n(s,d,1) /* push 'd' onto the stack */
6050 #define POP(s) lrmv_n(s,1) /* pop the stack */
6151 #define LOOKSTACK(s) lget_n(s,1) /* look at the top of the stack,
@@ -323,9 +313,11 @@
323313 AVRPART * avr_new_part(void);
324314 AVRPART * avr_dup_part(AVRPART * d);
325315 void avr_free_part(AVRPART * d);
326-AVRPART * locate_part(LISTID parts, char * partdesc);
327-AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode);
328-AVRPART * locate_part_by_signature(LISTID parts, unsigned char * sig,
316+void avr_free_parts();
317+void remove_part(std::vector<AVRPART> &parts, AVRPART *data_ptr);
318+AVRPART * locate_part(std::vector<AVRPART> &parts, char *partdesc);
319+AVRPART * locate_part_by_avr910_devcode(std::vector<AVRPART> &parts, int devcode);
320+AVRPART * locate_part_by_signature(std::vector<AVRPART> &parts, unsigned char * sig,
329321 int sigsize);
330322 void avr_display(FILE * f, AVRPART * p, const char * prefix, int verbose);
331323
@@ -332,8 +324,8 @@
332324 typedef void (*walk_avrparts_cb)(const char *name, const char *desc,
333325 const char *cfgname, int cfglineno,
334326 void *cookie);
335-void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie);
336-void sort_avrparts(LISTID avrparts);
327+void walk_avrparts(const std::vector<AVRPART> &avrparts, walk_avrparts_cb cb, void *cookie);
328+void sort_avrparts(std::vector<AVRPART> &avrparts);
337329 //#ifdef __cplusplus
338330 //}
339331 //#endif
@@ -909,7 +901,7 @@
909901
910902 /* formerly config.h */
911903
912-extern LISTID part_list;
904+extern std::vector<AVRPART> part_list;
913905 extern std::vector<PROGRAMMER> programmers;
914906 extern char default_programmer[];
915907 extern char default_parallel[];
--- trunk/main.cpp (revision 1468)
+++ trunk/main.cpp (revision 1469)
@@ -269,7 +269,7 @@
269269 }
270270 }
271271
272-static void list_parts(FILE * f, const char *prefix, LISTID avrparts)
272+static void list_parts(FILE *f, const char *prefix, std::vector<AVRPART> &avrparts)
273273 {
274274 struct list_walk_cookie c;
275275
--- trunk/pgm.cpp (revision 1468)
+++ trunk/pgm.cpp (revision 1469)
@@ -185,7 +185,21 @@
185185 return pgm;
186186 }
187187
188+// New std::vector lists
189+void remove_programmer(std::vector<PROGRAMMER> &programmers, PROGRAMMER *data_ptr )
190+{
191+ for( std::vector<PROGRAMMER>::iterator it = programmers.begin(); it != programmers.end(); ++it )
192+ {
193+ PROGRAMMER *p = &(*it);
194+ if(p == data_ptr)
195+ {
196+ programmers.erase(it);
197+ return;
198+ }
199+ }
200+}
188201
202+
189203 static void pgm_default(void)
190204 {
191205 avrdude_message(MSG_INFO, "%s: programmer operation not supported\n", progname);
--- trunk/pgm_type.cpp (revision 1468)
+++ trunk/pgm_type.cpp (revision 1469)
@@ -144,18 +144,5 @@
144144 }
145145 }
146146
147-// New std::vector lists
148-void remove_programmer(std::vector<PROGRAMMER> &programmers, PROGRAMMER *data_ptr )
149-{
150- for( std::vector<PROGRAMMER>::iterator it = programmers.begin(); it != programmers.end(); ++it )
151- {
152- PROGRAMMER *p = &(*it);
153- if(p == data_ptr)
154- {
155- programmers.erase(it);
156- return;
157- }
158- }
159-}
160147
161148
Show on old repository browser