rem: pgm->pinno[PIN_AVR_BUFF]  =  0;
add: pgm->pinno[PPI_AVR_BUFF]  =  0;
context: int main(int argc, char * argv []){  int              fd;          /* file descriptor for parallel port */  int              rc;          /* general return code checking */  int              exitrc;      /* exit code for main() */  int              i;           /* general loop counter */  int              ch;          /* options flag */  int              size;        /* size of memory region */  int              len;         /* length for various strings */  struct avrpart * p;           /* which avr part we are programming */  struct avrpart * v;           /* used for verify */  int              readorwrite; /* true if a chip read/write op was selected */  int              ppidata;	/* cached value of the ppi data register */  int              vsize=-1;    /* number of bytes to verify */  char             timestamp[64];  AVRMEM         * sig;         /* signature data */  /* options / operating mode variables */  char *  memtype;     /* "flash", "eeprom", etc */  int     doread;      /* 1=reading AVR, 0=writing AVR */  int     erase;       /* 1=erase chip, 0=don't */  char  * outputf;     /* output file name */  char  * inputf;      /* input file name */  int     ovsigck;     /* 1=override sig check, 0=don't */  char  * parallel;    /* parallel port device */  int     terminal;    /* 1=enter terminal mode, 0=don't */  FILEFMT filefmt;     /* FMT_AUTO, FMT_IHEX, FMT_SREC, FMT_RBIN */  int     nowrite;     /* don't actually write anything to the chip */  int     verify;      /* perform a verify operation */  int     ppisetbits;  /* bits to set in ppi data register at exit */  int     ppiclrbits;  /* bits to clear in ppi data register at exit */  char  * exitspecs;   /* exit specs string from command line */  int     verbose;     /* verbose output */  char  * pinconfig;   /* programmer id */  char  * partdesc;    /* part id */  char    configfile[PATH_MAX]; /* pin configuration file */  progname = rindex(argv[0],'/');  if (progname)    progname++;  else    progname = argv[0];  init_config();  partdesc      = NULL;  readorwrite   = 0;  parallel      = DEFAULT_PARALLEL;  outputf       = NULL;  inputf        = NULL;  doread        = 1;  memtype       = "flash";  erase         = 0;  p             = NULL;  ovsigck       = 0;  terminal      = 0;  filefmt       = FMT_AUTO;  nowrite       = 0;  verify        = 1;        /* on by default; XXX can't turn it off */  ppisetbits    = 0;  ppiclrbits    = 0;  exitspecs     = NULL;  pgm           = NULL;  pinconfig     = "avrprog"; /* compiled-in default */  verbose       = 0;  strcpy(configfile, CONFIG_DIR);  i = strlen(configfile);  if (i && (configfile[i-1] != '/'))    strcat(configfile, "/");  strcat(configfile, "avrprog.conf");  /*   * initialize compiled-in default programmer    */  pgm = &compiled_in_pgm;  pgm->id = lcreat(NULL, 0);  ladd(pgm->id, dup_string("avrprog"));  strcpy(pgm->desc, "avrprog compiled-in default");  for (i=0; i<N_PINS; i++)    pgm->pinno[i] = 0;  pgm->pinno[PPI_AVR_VCC]   = 0x0f;  /* ppi pins 2-5, data reg bits 0-3 */  pgm->pinno[PIN_AVR_BUFF]  =  0;  pgm->pinno[PIN_AVR_RESET] =  7;  pgm->pinno[PIN_AVR_SCK]   =  8;  pgm->pinno[PIN_AVR_MOSI]  =  9;  pgm->pinno[PIN_AVR_MISO]  = 10;  pgm->pinno[PIN_LED_ERR]   =  0;  pgm->pinno[PIN_LED_RDY]   =  0;  pgm->pinno[PIN_LED_PGM]   =  0;  pgm->pinno[PIN_LED_VFY]   =  0;  len = strlen(progname) + 2;  for (i=0; i<len; i++)    progbuf[i] = ' ';  progbuf[i] = 0;  print_module_versions(NULL, timestamp);  /*   * check for no arguments   */  if (argc == 1) {    usage();    return 0;  }  /*   * process command line arguments   */  while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:m:no:p:P:tv")) != -1) {    switch (ch) {      case 'c': /* pin configuration */        pinconfig = optarg;        break;      case 'C': /* pin configuration file */        strncpy(configfile, optarg, PATH_MAX);        configfile[PATH_MAX-1] = 0;        break;      case 'm': /* select memory type to operate on */        if ((strcasecmp(optarg,"e")==0)||(strcasecmp(optarg,"eeprom")==0)) {          memtype = "eeprom";        }        else if ((strcasecmp(optarg,"f")==0)||                 (strcasecmp(optarg,"flash")==0)) {          memtype = "flash";        }        else {          memtype = optarg;        }        readorwrite = 1;        break;      case 'F': /* override invalid signature check */        ovsigck = 1;        break;      case 'n':        nowrite = 1;        break;      case 'o': /* specify output file */        if (inputf || terminal) {          fprintf(stderr,"%s: -i, -o, and -t are incompatible\n\n", progname);          return 1;        }        doread = 1;        outputf = optarg;        if (filefmt == FMT_AUTO)          filefmt = FMT_RBIN;        break;      case 'p' : /* specify AVR part */        partdesc = optarg;        break;      case 'e': /* perform a chip erase */        erase = 1;        break;      case 'E':        exitspecs = optarg;	break;      case 'i': /* specify input file */        if (outputf || terminal) {          fprintf(stderr,"%s: -o, -i, and -t are incompatible\n\n", progname);          return 1;        }        doread = 0;        inputf = optarg;        break;      case 'f':   /* specify file format */        if (strlen(optarg) != 1) {          fprintf(stderr, "%s: invalid file format \"%s\"\n",                  progname, optarg);          usage();          exit(1);        }        switch (optarg[0]) {          case 'a' : filefmt = FMT_AUTO; break;          case 'i' : filefmt = FMT_IHEX; break;          case 'r' : filefmt = FMT_RBIN; break;          case 's' :            fprintf(stderr,                     "%s: Motorola S-Record format not yet supported\n\n",                    progname);            exit(1);            break;          default :            fprintf(stderr, "%s: invalid file format \"%s\"\n\n",                    progname, optarg);            usage();            exit(1);        }        break;      case 't': /* enter terminal mode */        if (!((inputf == NULL)||(outputf == NULL))) {          fprintf(stderr,                   "%s: terminal mode is not compatible with -i or -o\n\n",                  progname);          usage();          exit(1);        }        terminal = 1;        break;      case 'P':        parallel = optarg;        break;      case 'v':        verbose++;        break;      case '?': /* help */        usage();        exit(0);        break;      default:        fprintf(stderr, "%s: invalid option -%c\n\n", progname, ch);        usage();        exit(1);        break;    }  }  if (verbose) {    /*     * Print out an identifying string so folks can tell what version     * they are running     */    fprintf(stderr, "\n%s: Copyright 2001 Brian Dean, bsd@bsdhome.com\n"            "%sVersion %s  Revision Timestamp %s\n\n",             progname, progbuf, version, timestamp);        if (verbose > 1) {      print_module_versions(stderr, NULL);    }  }  rc = read_config(configfile);  if (rc) {    fprintf(stderr, "%s: error reading \"%s\" configuration from \"%s\"\n",            progname, pinconfig, configfile);    exit(1);  }  if (strcmp(pinconfig, "avrprog") == 0) {    pgm = locate_pinconfig(programmers, "default");    if (pgm == NULL) {      /* no default config listed, use the compile-in default */      pgm = &compiled_in_pgm;    }  }  else {    pgm = locate_pinconfig(programmers, pinconfig);    if (pgm == NULL) {      fprintf(stderr,               "%s: Can't find pin config id \"%s\"\n",              progname, pinconfig);      fprintf(stderr,"\n");      exit(1);    }  }  if (partdesc == NULL) {    fprintf(stderr,             "%s: No AVR part has been specified, use \"-p Part\"\n\n"            "  Valid Parts are:\n\n",            progname);    list_parts(stderr, "    ", part_list);    fprintf(stderr,"\n");    exit(1);  }  p = locate_part(part_list, partdesc);  if (p == NULL) {    fprintf(stderr,             "%s: AVR Part \"%s\" not found.  Valid parts are:\n\n",            progname, partdesc);    list_parts(stderr, "    ", part_list);    fprintf(stderr, "\n");    exit(1);  }  if (exitspecs != NULL) {    if (getexitspecs(exitspecs, &ppisetbits, &ppiclrbits) < 0) {      usage();      exit(1);    }  }  /*    * set up seperate instances of the avr part, one for use in   * programming, one for use in verifying.  These are separate   * because they need separate flash and eeprom buffer space    */  p = avr_dup_part(p);  v = avr_dup_part(p);  if (verbose) {    avr_display(stderr, p, progbuf);    fprintf(stderr, "\n");    pinconfig_display(progbuf);  }  fprintf(stderr, "\n");  verify_pin_assigned(PIN_AVR_RESET, "AVR RESET");  verify_pin_assigned(PIN_AVR_SCK,   "AVR SCK");  verify_pin_assigned(PIN_AVR_MISO,  "AVR MISO");  verify_pin_assigned(PIN_AVR_MOSI,  "AVR MOSI");  /*   * open the parallel port   */  fd = open(parallel, O_RDWR);  if (fd < 0) {    fprintf(stderr, "%s: can't open device \"%s\": %s\n\n",              progname, parallel, strerror(errno));    return 1;  }  exitrc = 0;#if 0  ppi_sense(fd);#endif  ppidata = ppi_getall(fd, PPIDATA);  if (ppidata < 0) {    fprintf(stderr, "%s: error reading status of ppi data port\n", progname);    exitrc = 1;    ppidata = 0; /* clear all bits at exit */    goto main_exit;  }  ppidata &= ~ppiclrbits;  ppidata |= ppisetbits;  /*    * turn off all the status leds   */  LED_OFF(fd, pgm->pinno[PIN_LED_RDY]);  LED_OFF(fd, pgm->pinno[PIN_LED_ERR]);  LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);  LED_OFF(fd, pgm->pinno[PIN_LED_VFY]);  /*   * enable the 74367 buffer, if connected; this signal is active low   */  ppi_setpin(fd, pgm->pinno[PIN_AVR_BUFF], 0);  /*   * initialize the chip in preperation for accepting commands   */  rc = avr_initialize(fd,p);  if (rc < 0) {    fprintf(stderr, "%s: initialization failed, rc=%d\n", progname, rc);    exitrc = 1;    goto main_exit;  }  /* indicate ready */  LED_ON(fd, pgm->pinno[PIN_LED_RDY]);  fprintf(stderr,             "%s: AVR device initialized and ready to accept instructions\n",            progname);  /*   * Let's read the signature bytes to make sure there is at least a   * chip on the other end that is responding correctly.  A check   * against 0xffffffff should ensure that the signature bytes are   * valid.     */  rc = avr_signature(fd, p);  if (rc != 0) {    fprintf(stderr, "%s: error reading signature data, rc=%d\n",            progname, rc);    exit(1);  }  sig = avr_locate_mem(p, "signature");  if (sig == NULL) {    fprintf(stderr,            "%s: WARNING: signature data not defined for device \"%s\"\n",            progname, p->desc);  }     if (sig != NULL) {    int ff;    fprintf(stderr, "%s: Device signature = 0x", progname);    ff = 1;    for (i=0; i<sig->size; i++) {      fprintf(stderr, "%02x", sig->buf[i]);      if (sig->buf[i] != 0xff)        ff = 0;    }    fprintf(stderr, "\n");    if (ff) {      fprintf(stderr,               "%s: Yikes!  Invalid device signature.\n", progname);      if (!ovsigck) {        fprintf(stderr, "%sDouble check connections and try again, "                "or use -F to override\n"                "%sthis check.\n\n",                progbuf, progbuf);        exitrc = 1;        goto main_exit;      }    }  }  fprintf(stderr, "\n");  if (erase) {    /*     * erase the chip's flash and eeprom memories, this is required     * before the chip can accept new programming     */    fprintf(stderr, "%s: erasing chip\n", progname);    avr_chip_erase(fd,p);    fprintf(stderr, "%s: done.\n", progname);  }  if (!terminal && ((inputf==NULL) && (outputf==NULL))) {    /*     * Check here to see if any other operations were selected and     * generate an error message because if they were, we need either     * an input or an output file, but one was not selected.     * Otherwise, we just shut down.       */    if (readorwrite) {      fprintf(stderr, "%s: you must specify an input or an output file\n",              progname);      exitrc = 1;    }    goto main_exit;  }  if (terminal) {    /*     * terminal mode     */    exitrc = terminal_mode(fd, p);  }  else if (doread) {    /*     * read out the specified device memory and write it to a file      */    fprintf(stderr, "%s: reading %s memory:\n",             progname, memtype);    rc = avr_read(fd, p, memtype, 0, 1);    if (rc < 0) {      fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",               progname, memtype, rc);      exitrc = 1;      goto main_exit;    }    size = rc;    fprintf(stderr, "%s: writing output file \"%s\"\n",            progname, outputf);    rc = fileio(FIO_WRITE, outputf, filefmt, p, memtype, size);    if (rc < 0) {      fprintf(stderr, "%s: terminating\n", progname);      exitrc = 1;      goto main_exit;    }  }  else {    /*     * write the selected device memory using data from a file; first     * read the data from the specified file     */    fprintf(stderr, "%s: reading input file \"%s\"\n",            progname, inputf);    rc = fileio(FIO_READ, inputf, filefmt, p, memtype, -1);    if (rc < 0) {      fprintf(stderr, "%s: terminating\n", progname);      exitrc = 1;      goto main_exit;    }    size = rc;    /*     * write the buffer contents to the selected memory type     */    fprintf(stderr, "%s: writing %s:\n",             progname, memtype);    if (!nowrite) {      rc = avr_write(fd, p, memtype, size, 1);    }    else {      /*        * test mode, don't actually write to the chip, output the buffer       * to stdout in intel hex instead        */      rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, memtype, size);    }    if (rc < 0) {      fprintf(stderr, "%s: failed to write flash memory, rc=%d\n",                 progname, rc);      exitrc = 1;      goto main_exit;    }    vsize = rc;    fprintf(stderr, "%s: %d bytes of %s written\n", progname,             vsize, memtype);  }  if (!doread && verify) {    /*      * verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM])     * is the same as what is on the chip      */    LED_ON(fd, pgm->pinno[PIN_LED_VFY]);    fprintf(stderr, "%s: verifying %s memory against %s:\n",             progname, memtype, inputf);    fprintf(stderr, "%s: reading on-chip %s data:\n",             progname, memtype);    rc = avr_read(fd, v, memtype, vsize, 1);    if (rc < 0) {      fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",               progname, memtype, rc);      LED_ON(fd, pgm->pinno[PIN_LED_ERR]);      exitrc = 1;      goto main_exit;    }    fprintf(stderr, "%s: verifying ...\n", progname);    rc = avr_verify(p, v, memtype, vsize);    if (rc < 0) {      fprintf(stderr, "%s: verification error; content mismatch\n",               progname);      LED_ON(fd, pgm->pinno[PIN_LED_ERR]);      exitrc = 1;      goto main_exit;    }        fprintf(stderr, "%s: %d bytes of %s verified\n",             progname, rc, memtype);    LED_OFF(fd, pgm->pinno[PIN_LED_VFY]);  } main_exit:  /*   * program complete   */  avr_powerdown(fd);  ppi_setall(fd, PPIDATA, ppidata);  /*   * disable the 74367 buffer, if connected; this signal is active low    */  ppi_setpin(fd, pgm->pinno[PIN_AVR_BUFF], 1);  LED_OFF(fd, pgm->pinno[PIN_LED_RDY]);  close(fd);  fprintf(stderr, "\n%s done.  Thank you.\n\n", progname);  return exitrc;}