Ignore:
Timestamp:
Jun 22, 2009 12:38:49 PM (15 years ago)
Author:
dkearney
Message:

various code cleanups, mainly tabs. adding units ohms and amps, adding appendf interface to the simple buffer so we can append formatted strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpBuffer.cc

    r1384 r1527  
    120120    if (f == NULL) {
    121121        status.addError("can't open \"%s\": %s", filePath, strerror(errno));
    122         return false;
     122        return false;
    123123    }
    124124    struct stat stat;
    125125    if (fstat(fileno(f), &stat) < 0) {
    126126        status.addError("can't stat \"%s\": %s", filePath, strerror(errno));
    127         return false;
    128     }   
     127        return false;
     128    }
    129129    off_t size;
    130130    size = stat.st_size;
     
    133133    if (memblock == NULL) {
    134134        status.addError("can't allocate %d bytes for file \"%s\": %s",
    135                         size, filePath, strerror(errno));
     135                        size, filePath, strerror(errno));
    136136        fclose(f);
    137137        return false;
     
    139139
    140140    // FIXME: better yet, create an "extend" method in the buffer and returns
    141     //       the address of the char buffer so I can read the data directly
    142     //       into the buffer.  This eliminates memory new/copy/delete ops.
     141    //             the address of the char buffer so I can read the data directly
     142    //             into the buffer.  This eliminates memory new/copy/delete ops.
    143143
    144144    size_t nRead;
    145145    nRead = fread(memblock, sizeof(char), size, f);
    146     fclose(f);                  // Close the file.
     146    fclose(f);                        // Close the file.
    147147
    148148    if (nRead != (size_t)size) {
    149149        status.addError("can't read %d bytes from \"%s\": %s", size, filePath,
    150                         strerror(errno));
    151         return false;
    152     }   
     150                        strerror(errno));
     151        return false;
     152    }
    153153
    154154    int nBytes;
     
    158158    if (nBytes != size) {
    159159        status.addError("can't append %d bytes from \"%s\" to buffer: %s",
    160                 size, filePath, strerror(errno));
    161         return false;
    162     }   
     160                size, filePath, strerror(errno));
     161        return false;
     162    }
    163163    return true;
    164164}
     
    174174    if (f != NULL) {
    175175        status.addError("can't open \"%s\": %s\n", filePath, strerror(errno));
    176         return false;
     176        return false;
    177177    }
    178178    ssize_t nWritten;
    179179    nWritten = fwrite(bytes(), size(), sizeof(char), f);
    180     fclose(f);                  // Close the file.
    181    
     180    fclose(f);                        // Close the file.
     181
    182182    if (nWritten != (ssize_t)size()) {
    183183        status.addError("can't write %d bytes to \"%s\": %s\n", size(),
    184                         filePath, strerror(errno));
    185         return false;
     184                        filePath, strerror(errno));
     185        return false;
    186186    }
    187187    return true;
     
    198198    switch (flags & (RPENC_Z | RPENC_B64)) {
    199199    case 0:
    200         break;
    201 
    202     case RPENC_Z:               // Compress only
    203         if (!do_compress(status, *this, bout)) {
    204             return false;
    205         }
    206         move(bout);
    207         break;
    208 
    209     case RPENC_B64:             // Encode only
     200        break;
     201
     202    case RPENC_Z:                // Compress only
     203        if (!do_compress(status, *this, bout)) {
     204            return false;
     205        }
     206        move(bout);
     207        break;
     208
     209    case RPENC_B64:                // Encode only
    210210        if (!do_base64_enc(status, *this, bout)) {
    211211            return false;
    212212        }
    213         move(bout);
    214         break;
     213        move(bout);
     214        break;
    215215
    216216    case (RPENC_B64 | RPENC_Z):
    217        
    218         // It's always compress then encode
    219         if (!do_compress(status, *this, bout)) {
    220             return false;
    221         }
     217
     218        // It's always compress then encode
     219        if (!do_compress(status, *this, bout)) {
     220            return false;
     221        }
    222222        if (!do_base64_enc(status, bout, *this)) {
    223223            return false;
    224224        }
    225         break;
     225        break;
    226226    }
    227227    return true;
     
    238238    switch (flags & (RPENC_Z | RPENC_B64)) {
    239239    case 0:
    240         if (encoding::isBase64(bytes(), size())) {
    241             if (!do_base64_dec(status, *this, bout)) {
    242                 return false;
    243             }
    244             move(bout);
    245         }
    246         bout.clear();
    247         if (encoding::isBinary(bytes(), size())) {
    248             if (!do_decompress(status, *this, bout)) {
    249                 return false;
    250             }
    251             move(bout);
    252         }
    253         break;
    254 
    255     case RPENC_Z:               // Decompress only
    256         if (!do_decompress(status, *this, bout)) {
    257             return false;
    258         }
    259         move(bout);
    260         break;
    261 
    262     case RPENC_B64:             // Decode only
     240        if (encoding::isBase64(bytes(), size())) {
     241            if (!do_base64_dec(status, *this, bout)) {
     242                return false;
     243            }
     244            move(bout);
     245        }
     246        bout.clear();
     247        if (encoding::isBinary(bytes(), size())) {
     248            if (!do_decompress(status, *this, bout)) {
     249                return false;
     250            }
     251            move(bout);
     252        }
     253        break;
     254
     255    case RPENC_Z:                // Decompress only
     256        if (!do_decompress(status, *this, bout)) {
     257            return false;
     258        }
     259        move(bout);
     260        break;
     261
     262    case RPENC_B64:                // Decode only
    263263        if (!do_base64_dec(status, *this, bout)) {
    264264            return false;
    265265        }
    266         move(bout);
    267         break;
     266        move(bout);
     267        break;
    268268
    269269    case (RPENC_B64 | RPENC_Z):
    270        
    271         // It's always decode then decompress
     270
     271        // It's always decode then decompress
    272272        if (!do_base64_dec(status, *this, bout)) {
    273273            return false;
    274274        }
    275         clear();
    276         if (!do_decompress(status, bout, *this)) {
    277             return false;
    278         }
    279         break;
     275        clear();
     276        if (!do_decompress(status, bout, *this)) {
     277            return false;
     278        }
     279        break;
    280280    }
    281281    return true;
     
    285285bool
    286286Buffer::do_compress(Outcome& status, SimpleCharBuffer& bin,
    287                     SimpleCharBuffer& bout)
     287                    SimpleCharBuffer& bout)
    288288{
    289289    int ret=0, flush=0;
     
    357357bool
    358358Buffer::do_decompress(Outcome& status, SimpleCharBuffer& bin,
    359                       SimpleCharBuffer& bout)
     359                      SimpleCharBuffer& bout)
    360360{
    361361    int ret;
     
    433433bool
    434434Buffer::do_base64_enc(Outcome& status, const SimpleCharBuffer& bin,
    435                       SimpleCharBuffer& bout )
     435                      SimpleCharBuffer& bout )
    436436{
    437437    int tBufSize = 0;
     
    453453bool
    454454Buffer::do_base64_dec(Outcome& status, const SimpleCharBuffer& bin,
    455                       SimpleCharBuffer& bout )
     455                      SimpleCharBuffer& bout )
    456456{
    457457    int tBufSize = 0;
Note: See TracChangeset for help on using the changeset viewer.