From 5649b1d9910b8195a520987c91361ad20776d6e3 Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Sat, 22 Feb 2003 16:45:13 +0000 Subject: [PATCH] Add the ability to read a per-user config file located at $HOME/.avrduderc. Entries from .avrduderc take precedence over those from the system wide config file in ${PREFIX}/etc/avrdude.conf. Track and display the config file name and line number when we print out the available parts and programmers. This is useful in case someone has overridden a definition in their .avrduderc file and is wondering why the definition in the system wide config file is not being used. Remove the default programmer 'stk500' from the distributed config file. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@222 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/avr.c | 2 + avrdude/avrdude.conf.sample | 1 - avrdude/avrpart.h | 4 ++ avrdude/config_gram.y | 15 +++-- avrdude/main.c | 118 ++++++++++++++++++++++++++++-------- avrdude/par.c | 4 -- avrdude/pgm.c | 2 + avrdude/pgm.h | 2 + 8 files changed, 113 insertions(+), 35 deletions(-) diff --git a/avrdude/avr.c b/avrdude/avr.c index 4ef15439..77bbc96a 100644 --- a/avrdude/avr.c +++ b/avrdude/avr.c @@ -60,6 +60,8 @@ AVRPART * avr_new_part(void) p->reset_disposition = RESET_DEDICATED; p->retry_pulse = PIN_AVR_SCK; p->flags = AVRPART_SERIALOK | AVRPART_PARALLELOK; + p->config_file[0] = 0; + p->lineno = 0; p->mem = lcreat(NULL, 0); diff --git a/avrdude/avrdude.conf.sample b/avrdude/avrdude.conf.sample index f232bbe2..ceafe60f 100644 --- a/avrdude/avrdude.conf.sample +++ b/avrdude/avrdude.conf.sample @@ -174,7 +174,6 @@ # default_parallel = "/dev/ppi0"; default_serial = "/dev/cuaa0"; -default_programmer = "stk500"; # diff --git a/avrdude/avrpart.h b/avrdude/avrpart.h index 3bc452e8..b8c01c0b 100644 --- a/avrdude/avrpart.h +++ b/avrdude/avrpart.h @@ -22,6 +22,8 @@ #ifndef __avrpart_h__ #define __avrpart_h__ +#include + #include "lists.h" /* @@ -91,6 +93,8 @@ typedef struct avrpart { OPCODE * op[AVR_OP_MAX]; /* opcodes */ LISTID mem; /* avr memory definitions */ + char config_file[PATH_MAX]; /* config file where defined */ + int lineno; /* config file line number */ } AVRPART; #define AVR_MEMDESCLEN 64 diff --git a/avrdude/config_gram.y b/avrdude/config_gram.y index ef9471d6..6417892b 100644 --- a/avrdude/config_gram.y +++ b/avrdude/config_gram.y @@ -154,7 +154,10 @@ def : prog_def : K_PROGRAMMER - { current_prog = pgm_new(); } + { current_prog = pgm_new(); + strcpy(current_prog->config_file, infile); + current_prog->lineno = lineno; + } prog_parms { if (lsize(current_prog->id) == 0) { @@ -168,7 +171,7 @@ prog_def : progname, infile, lineno); exit(1); } - ladd(programmers, current_prog); + PUSH(programmers, current_prog); current_prog = NULL; } ; @@ -176,7 +179,11 @@ prog_def : part_def : K_PART - { current_part = avr_new_part(); } + { + current_part = avr_new_part(); + strcpy(current_part->config_file, infile); + current_part->lineno = lineno; + } part_parms { LNODEID ln; @@ -226,7 +233,7 @@ part_def : } } - ladd(part_list, current_part); + PUSH(part_list, current_part); current_part = NULL; } ; diff --git a/avrdude/main.c b/avrdude/main.c index 173c5ae7..29dea339 100644 --- a/avrdude/main.c +++ b/avrdude/main.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include "avr.h" #include "config.h" @@ -59,8 +61,6 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same PROGRAMMER * pgm = NULL; -PROGRAMMER * compiled_in_pgm; - /* * global options */ @@ -72,7 +72,7 @@ int do_cycles; /* track erase-rewrite cycles */ */ void usage(void) { - printf( + printf( "Usage: %s [options]\n" "Options:\n" " -p Required. Specify AVR device.\n" @@ -140,6 +140,7 @@ int read_config(char * file) return -1; } + lineno = 1; infile = file; yyin = f; @@ -155,7 +156,8 @@ int read_config(char * file) void programmer_display(char * p) { - fprintf(stderr, "%sProgrammer Type: %s\n", p, pgm->type); + fprintf(stderr, "%sProgrammer Type : %s\n", p, pgm->type); + fprintf(stderr, "%sDescription : %s\n", p, pgm->desc); pgm->display(pgm, p); } @@ -227,7 +229,23 @@ void list_parts(FILE * f, char * prefix, LISTID parts) for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) { p = ldata(ln1); - fprintf(f, "%s%-4s = %s\n", prefix, p->id, p->desc); + fprintf(f, "%s%-4s = %-15s [%s:%d]\n", + prefix, p->id, p->desc, p->config_file, p->lineno); + } + + return; +} + +void list_programmers(FILE * f, char * prefix, LISTID programmers) +{ + LNODEID ln1; + PROGRAMMER * p; + + for (ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) { + p = ldata(ln1); + fprintf(f, "%s%-8s = %-30s [%s:%d]\n", + prefix, (char *)ldata(lfirst(p->id)), p->desc, + p->config_file, p->lineno); } return; @@ -252,6 +270,7 @@ int main(int argc, char * argv []) int ppidata; /* cached value of the ppi data register */ int vsize=-1; /* number of bytes to verify */ AVRMEM * sig; /* signature data */ + struct stat sb; /* options / operating mode variables */ char * memtype; /* "flash", "eeprom", etc */ @@ -270,10 +289,12 @@ int main(int argc, char * argv []) char * exitspecs; /* exit specs string from command line */ char * programmer; /* programmer id */ char * partdesc; /* part id */ - char configfile[PATH_MAX]; /* pin configuration file */ + char sys_config[PATH_MAX]; /* system wide config file */ + char usr_config[PATH_MAX]; /* per-user config file */ int cycles; /* erase-rewrite cycles */ int set_cycles; /* value to set the erase-rewrite cycles to */ char * e; /* for strtol() error checking */ + char * homedir; progname = rindex(argv[0],'/'); if (progname) @@ -309,11 +330,21 @@ int main(int argc, char * argv []) do_cycles = 0; set_cycles = -1; - strcpy(configfile, CONFIG_DIR); - i = strlen(configfile); - if (i && (configfile[i-1] != '/')) - strcat(configfile, "/"); - strcat(configfile, "avrdude.conf"); + strcpy(sys_config, CONFIG_DIR); + i = strlen(sys_config); + if (i && (sys_config[i-1] != '/')) + strcat(sys_config, "/"); + strcat(sys_config, "avrdude.conf"); + + usr_config[0] = 0; + homedir = getenv("HOME"); + if (homedir != NULL) { + strcpy(usr_config, homedir); + i = strlen(usr_config); + if (i && (usr_config[i-1] != '/')) + strcat(usr_config, "/"); + strcat(usr_config, ".avrduderc"); + } len = strlen(progname) + 2; for (i=0; iid)), pgm->desc); - fprintf(stderr, "%s VCC = 0x%02x%s\n" "%s BUFF = 0x%02x%s\n" diff --git a/avrdude/pgm.c b/avrdude/pgm.c index 21ab9bb1..b65da69e 100644 --- a/avrdude/pgm.c +++ b/avrdude/pgm.c @@ -55,6 +55,8 @@ PROGRAMMER * pgm_new(void) pgm->id = lcreat(NULL, 0); pgm->desc[0] = 0; pgm->type[0] = 0; + pgm->config_file[0] = 0; + pgm->lineno = 0; for (i=0; ipinno[i] = 0; diff --git a/avrdude/pgm.h b/avrdude/pgm.h index ea47f5e3..5dcde7be 100644 --- a/avrdude/pgm.h +++ b/avrdude/pgm.h @@ -66,6 +66,8 @@ typedef struct programmer_t { int page_size, int n_bytes); int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, int page_size, int n_bytes); + char config_file[PATH_MAX]; /* config file where defined */ + int lineno; /* config file line number */ } PROGRAMMER;