Changeset 585


Ignore:
Timestamp:
May 6, 2011, 7:47:13 PM (12 years ago)
Author:
Sam Hocevar
Message:

tool: compute and display SPEC item CRCs.

Location:
abuse/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/Makefile.am

    r574 r585  
    7070
    7171abuse_tool_SOURCES = \
    72     tool/abuse-tool.cpp
     72    tool/abuse-tool.cpp \
     73    crc.cpp crc.h
    7374abuse_tool_LDADD = imlib/libimlib.a
    7475abuse_tool_DEPENDENCIES = $(abuse_tool_LDADD)
  • abuse/trunk/src/crc.cpp

    r555 r585  
    1515#include "crc.h"
    1616
    17 uint16_t calc_crc(uint8_t *buf, int len)
     17uint16_t calc_crc(void *buf, size_t len)
    1818{
    19   uint8_t c1=0,c2=0;
    20   while (len)
    21   {
    22     len--;
    23     c1+=*buf;
    24     c2+=c1;
    25     buf++;
    26   }
    27   return (c2<<8)|c1;
     19    uint8_t *data = (uint8_t *)buf;
     20    uint8_t c1 = 0, c2 = 0;
     21
     22    while (len--)
     23        c2 += (c1 += *data++);
     24
     25    return (c2 << 8) | c1;
    2826}
    2927
  • abuse/trunk/src/crc.h

    r555 r585  
    1111#ifndef _CRC_HPP_
    1212#define _CRC_HPP_
     13
    1314#include "specs.h"
    1415
    15 uint16_t calc_crc(uint8_t *buf, int len);
     16uint16_t calc_crc(void *buf, size_t len);
    1617uint32_t crc_file(bFILE *fp);
    1718
     19#endif
    1820
    19 #endif
  • abuse/trunk/src/tool/abuse-tool.cpp

    r564 r585  
    2020#include "image.h"
    2121#include "pcxread.h"
     22#include "crc.h"
    2223
    2324static void Usage();
     
    123124    if (cmd == CMD_LIST)
    124125    {
    125         printf("   id  type     size  name & information\n");
    126         printf(" ----  ----  -------  ----------------------------\n");
     126        printf("   id  type    bytes   crc  name & information\n");
     127        printf(" ----  ----  -------  ----  ----------------------------\n");
     128
     129        dir.FullyLoad(&fp);
    127130
    128131        for (int i = 0; i < dir.total; i++)
     
    131134
    132135            /* Print basic information */
    133             printf("% 5i   % 3i % 8i  %s",
    134                    i, se->type, (int)se->size, se->name);
     136            printf("% 5i   % 3i % 8i  %04x  %s", i, se->type, (int)se->size,
     137                   calc_crc(se->data, se->size), se->name);
    135138
    136139            /* Is there anything special to say? */
     
    144147              {
    145148                image *im = new image(&fp, se);
    146                 printf(" (%i x %i pixels)", im->Size().x, im->Size().y);
     149                printf(" \t# %i x %i pixels", im->Size().x, im->Size().y);
    147150                delete im;
    148151                break;
     
    151154              {
    152155                palette *pal = new palette(se, &fp);
    153                 printf(" (%i colors)", pal->pal_size());
     156                printf(" \t# %i colors", pal->pal_size());
    154157                delete pal;
    155158                break;
    156159              }
     160#if 0
     161            default:
     162              {
     163                /* Try to print a representation of the item */
     164                int has_binary = 0;
     165                for (int i = 0; i < Min(20, (int)se->size); i++)
     166                {
     167                    uint8_t ch = ((uint8_t *)se->data)[i];
     168                    if (ch < 0x20 || ch >= 0x7f)
     169                        has_binary++;
     170                }
     171                if (has_binary <= 2 && se->size > 5)
     172                    has_binary = 0;
     173
     174                printf(" \t# ");
     175                if (!has_binary)
     176                    putchar('\"');
     177
     178                size_t max = Min(has_binary ? 15 : 30, (int)se->size);
     179                for (size_t i = 0; i < max; i++)
     180                {
     181                    uint8_t ch = ((uint8_t *)se->data)[i];
     182                    if (has_binary)
     183                        printf("%02x ", ch);
     184                    else if (ch && (ch < 0x20 || ch >= 0x7f))
     185                        printf("\\x%02x", ch);
     186                    else if (ch)
     187                        putchar(ch);
     188                    else
     189                        printf("\\0");
     190                }
     191                if (se->size > max)
     192                    printf("...");
     193                else if (!has_binary)
     194                    printf("\"");
     195                break;
     196              }
     197#endif
    157198            }
    158199
Note: See TracChangeset for help on using the changeset viewer.