rem: fprintf ( stderr, "%s: writing eeprom memory:\n", progname );
add: fprintf(stderr, "%s: writing %d bytes into eeprom memory:\n", progname, size);
context: int main ( int argc, char * argv [] ){  int fd;  int rc;  unsigned char buf[2048];  int ch;  int iofd;  int flash, eeprom, doread, erase;  int size;  char * outputf;  char * inputf;  iofd    = -1;  outputf = NULL;  inputf  = NULL;  doread  = 1;  eeprom  = 0;  flash   = 0;  erase   = 0;  progname = rindex(argv[0],'/');  if (progname)    progname++;  else    progname = argv[0];  if (argc == 1) {    usage();    return 0;  }  while ((ch = getopt(argc,argv,"?efo:ru:")) != -1) {    switch (ch) {      case 'e':        if (flash) {          fprintf(stderr,"%s: -e and -f are incompatible\n", progname);          return 1;        }        eeprom = 1;        break;      case 'r':        erase = 1;        break;      case 'f':        if (eeprom) {          fprintf(stderr,"%s: -e and -f are incompatible\n", progname);          return 1;        }        flash = 1;        break;      case 'o':        if (inputf) {          fprintf(stderr,"%s: -o and -u are incompatible\n", progname);          return 1;        }        doread = 1;        outputf = optarg;        if (strcmp(outputf,"-")==0) {          iofd = fileno(stdout);        }        else {          iofd = open ( outputf, O_WRONLY|O_CREAT|O_TRUNC,                        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);          if (iofd < 0) {            fprintf(stderr, "%s: can't open output file \"%s\": %s\n",                    progname, outputf, strerror(errno));            return 1;          }        }        break;      case 'u':        if (outputf) {          fprintf(stderr,"%s: -o and -u are incompatible\n", progname);          return 1;        }        doread = 0;        inputf = optarg;        iofd = open ( inputf, O_RDONLY, 0);        if (iofd < 0) {          fprintf(stderr, "%s: can't open input file \"%s\": %s\n",                  progname, inputf, strerror(errno));          return 1;        }        break;      case '?':        usage();        return 1;        break;      default:        fprintf(stderr, "%s: invalid option -%c\n", progname, ch);        usage();        return 1;        break;    }  }  fd = open ( PARALLEL, O_RDWR );  if (fd < 0) {    fprintf ( stderr, "%s: can't open device \"%s\": %s\n",              progname, PARALLEL, strerror(errno) );    return 1;  }  fprintf ( stderr, "%s: initializing\n", progname );  rc = avr_initialize(fd);  if (rc < 0) {    fprintf ( stderr, "%s: initialization failed, rc=%d\n", progname, rc );    return 1;  }  fprintf ( stderr, "%s: AVR device initialized and ready to accept instructions\n",            progname );  if (erase) {    fprintf(stderr, "%s: erasing chip\n", progname );    avr_chip_erase(fd);    avr_initialize(fd);    fprintf(stderr, "%s: done.\n", progname );  }  if (iofd < 0) {    fprintf(stderr, "%s: you must specify an input or an output file\n",            progname);    return 1;  }  if (!(eeprom||flash)) {    fprintf(stderr,             "%s: please specify either the eeprom (-e) or the flash (-f) memory\n",            progname);    return 1;  }  if (doread) {    /*     * read device memory      */    if (flash) {      size = 2048;      fprintf ( stderr, "%s: reading flash memory:\n", progname );      rc = avr_read ( fd, AVR_FLASH, 0, size/2, buf, size );      if (rc) {        fprintf ( stderr, "%s: failed to read all of flash memory, rc=%d\n",                   progname, rc );        return 1;      }    }    else if (eeprom) {      size = 128;      fprintf ( stderr, "%s: reading eeprom memory:\n", progname );      rc = avr_read ( fd, AVR_EEPROM, 0, size, buf, size );      if (rc) {        fprintf ( stderr, "%s: failed to read all of eeprom memory, rc=%d\n",                   progname, rc );        return 1;      }    }    rc = write ( iofd, buf, size );    if (rc < 0) {      fprintf(stderr, "%s: write error: %s\n", progname, strerror(errno));      return 1;    }    else if (rc != size) {      fprintf(stderr, "%s: wrote only %d bytes of the expected %d\n",               progname, rc, size);      return 1;    }  }  else {    /*     * write device memory      */    if (flash) {      size = 2048;    }    else if (eeprom) {      size = 128;    }    /* read in the data file */    rc = read(iofd, buf, size);    if (rc < 0) {      fprintf(stderr, "%s: read error from \"%s\": %s\n",               progname, inputf, strerror(errno));      return 1;    }    else if (rc != size) {      fprintf(stderr, "%s: read only %d bytes of the expected %d from \"%s\"\n",               progname, rc, size, inputf);      return 1;    }    if (flash) {      fprintf ( stderr, "%s: writing flash memory:\n", progname );      rc = avr_write ( fd, AVR_FLASH, 0, buf, size );      if (rc) {        fprintf ( stderr, "%s: failed to write flash memory, rc=%d\n",                   progname, rc );        return 1;      }    }    else if (eeprom) {      fprintf ( stderr, "%s: writing eeprom memory:\n", progname );      rc = avr_write ( fd, AVR_EEPROM, 0, buf, size );      if (rc) {        fprintf ( stderr, "%s: failed to write eeprom memory, rc=%d\n",                   progname, rc );        return 1;      }    }  }  close(fd);  close(iofd);  return 0;}