Changeset 5209

Show
Ignore:
Timestamp:
04/24/08 14:43:10 (7 months ago)
Author:
khali
Message:

Move the confirmation to a separate function, as is done in i2cget
already.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • i2c-tools/trunk/CHANGES

    r5203 r5209  
    1414          Shorten the usage message 
    1515          Restrict the chip address to 0x03-0x77 
     16          Split the code into several functions for clarity 
    1617 
    17183.0.1 (2008-04-04) 
  • i2c-tools/trunk/tools/i2cset.c

    r5208 r5209  
    8282 
    8383        return 0; 
     84} 
     85 
     86static int confirm(const char *filename, int address, int size, int daddress, 
     87                   int value, int vmask, int pec) 
     88{ 
     89        int dont = 0; 
     90 
     91        fprintf(stderr, "WARNING! This program can confuse your I2C " 
     92                "bus, cause data loss and worse!\n"); 
     93 
     94        if (address >= 0x50 && address <= 0x57) { 
     95                fprintf(stderr, "DANGEROUS! Writing to a serial " 
     96                        "EEPROM on a memory DIMM\nmay render your " 
     97                        "memory USELESS and make your system " 
     98                        "UNBOOTABLE!\n"); 
     99                dont++; 
     100        } 
     101 
     102        fprintf(stderr, "I will write to device file %s, chip address " 
     103                "0x%02x, data address\n0x%02x, data 0x%02x%s, mode " 
     104                "%s.\n", filename, address, daddress, value, 
     105                vmask ? " (masked)" : "", 
     106                size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 
     107        if (pec) 
     108                fprintf(stderr, "PEC checking enabled.\n"); 
     109 
     110        fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n"); 
     111        fflush(stderr); 
     112        if (!user_ack(!dont)) { 
     113                fprintf(stderr, "Aborting on user request.\n"); 
     114                return 0; 
     115        } 
     116 
     117        return 1; 
    84118} 
    85119 
     
    171205                exit(1); 
    172206 
    173         if (!yes) { 
    174                 int dont = 0; 
    175  
    176                 fprintf(stderr, "WARNING! This program can confuse your I2C " 
    177                         "bus, cause data loss and worse!\n"); 
    178  
    179                 if (address >= 0x50 && address <= 0x57) { 
    180                         fprintf(stderr, "DANGEROUS! Writing to a serial " 
    181                                 "EEPROM on a memory DIMM\nmay render your " 
    182                                 "memory USELESS and make your system " 
    183                                 "UNBOOTABLE!\n"); 
    184                         dont = 1; 
    185                 } 
    186  
    187                 fprintf(stderr, "I will write to device file %s, chip address " 
    188                         "0x%02x, data address\n0x%02x, data 0x%02x%s, mode " 
    189                         "%s.\n", filename, address, daddress, value, 
    190                         vmask ? " (masked)" : "", 
    191                         size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 
    192                 if (pec) 
    193                         fprintf(stderr, "PEC checking enabled.\n"); 
    194  
    195                 fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n"); 
    196                 fflush(stderr); 
    197                 if (!user_ack(!dont)) { 
    198                         fprintf(stderr, "Aborting on user request.\n"); 
    199                         exit(0); 
    200                 } 
    201         } 
     207        if (!yes && !confirm(filename, address, size, daddress, 
     208                             value, vmask, pec)) 
     209                exit(0); 
    202210 
    203211        if (vmask) {