rpmdb/header_internal.c

Go to the documentation of this file.
00001 /*@-sizeoftype@*/
00006 #include "system.h"
00007 
00008 #include <header_internal.h>
00009 
00010 #include "debug.h"
00011 
00012 /*@-boundswrite@*/
00013 char ** headerGetLangs(Header h)
00014 {
00015     char **s, *e, **table;
00016     int i, type, count;
00017 
00018     if (!headerGetRawEntry(h, HEADER_I18NTABLE, &type, (const void **)&s, &count))
00019         return NULL;
00020 
00021     /* XXX xcalloc never returns NULL. */
00022     if ((table = (char **)xcalloc((count+1), sizeof(char *))) == NULL)
00023         return NULL;
00024 
00025     for (i = 0, e = *s; i < count; i++, e += strlen(e)+1)
00026         table[i] = e;
00027     table[count] = NULL;
00028 
00029     /*@-nullret@*/ return table; /*@=nullret@*/ /* LCL: double indirection? */
00030 }
00031 /*@=boundswrite@*/
00032 
00033 /*@-boundsread@*/
00034 /*@-type@*/ /* FIX: shrug */
00035 void headerDump(Header h, FILE *f, int flags,
00036         const struct headerTagTableEntry_s * tags)
00037 {
00038     int i;
00039     indexEntry p;
00040     const struct headerTagTableEntry_s * tage;
00041     const char * tag;
00042     char * type;
00043 
00044     /* First write out the length of the index (count of index entries) */
00045     fprintf(f, "Entry count: %d\n", h->indexUsed);
00046 
00047     /* Now write the index */
00048     p = h->index;
00049     fprintf(f, "\n             CT  TAG                  TYPE         "
00050                 "      OFSET      COUNT\n");
00051     for (i = 0; i < h->indexUsed; i++) {
00052         switch (p->info.type) {
00053         case RPM_NULL_TYPE:
00054             type = "NULL";
00055             /*@switchbreak@*/ break;
00056         case RPM_CHAR_TYPE:
00057             type = "CHAR";
00058             /*@switchbreak@*/ break;
00059         case RPM_BIN_TYPE:
00060             type = "BIN";
00061             /*@switchbreak@*/ break;
00062         case RPM_INT8_TYPE:
00063             type = "INT8";
00064             /*@switchbreak@*/ break;
00065         case RPM_INT16_TYPE:
00066             type = "INT16";
00067             /*@switchbreak@*/ break;
00068         case RPM_INT32_TYPE:
00069             type = "INT32";
00070             /*@switchbreak@*/ break;
00071         /*case RPM_INT64_TYPE:          type = "INT64";         break;*/
00072         case RPM_STRING_TYPE:
00073             type = "STRING";
00074             /*@switchbreak@*/ break;
00075         case RPM_STRING_ARRAY_TYPE:
00076             type = "STRING_ARRAY";
00077             /*@switchbreak@*/ break;
00078         case RPM_I18NSTRING_TYPE:
00079             type = "I18N_STRING";
00080             /*@switchbreak@*/ break;
00081         default:
00082             type = "(unknown)";
00083             /*@switchbreak@*/ break;
00084         }
00085 
00086         tage = tags;
00087         while (tage->name && tage->val != p->info.tag) tage++;
00088 
00089         if (!tage->name)
00090             tag = "(unknown)";
00091         else
00092             tag = tage->name;
00093 
00094         fprintf(f, "Entry      : %3.3d (%d)%-14s %-18s 0x%.8x %.8d\n", i,
00095                 p->info.tag, tag, type, (unsigned) p->info.offset,
00096                 (int) p->info.count);
00097 
00098         if (flags & HEADER_DUMP_INLINE) {
00099             char *dp = p->data;
00100             int c = p->info.count;
00101             int ct = 0;
00102 
00103             /* Print the data inline */
00104             switch (p->info.type) {
00105             case RPM_INT32_TYPE:
00106                 while (c--) {
00107                     fprintf(f, "       Data: %.3d 0x%08x (%d)\n", ct++,
00108                             (unsigned) *((int_32 *) dp),
00109                             (int) *((int_32 *) dp));
00110                     dp += sizeof(int_32);
00111                 }
00112                 /*@switchbreak@*/ break;
00113 
00114             case RPM_INT16_TYPE:
00115                 while (c--) {
00116                     fprintf(f, "       Data: %.3d 0x%04x (%d)\n", ct++,
00117                             (unsigned) (*((int_16 *) dp) & 0xffff),
00118                             (int) *((int_16 *) dp));
00119                     dp += sizeof(int_16);
00120                 }
00121                 /*@switchbreak@*/ break;
00122             case RPM_INT8_TYPE:
00123                 while (c--) {
00124                     fprintf(f, "       Data: %.3d 0x%02x (%d)\n", ct++,
00125                             (unsigned) (*((int_8 *) dp) & 0xff),
00126                             (int) *((int_8 *) dp));
00127                     dp += sizeof(int_8);
00128                 }
00129                 /*@switchbreak@*/ break;
00130             case RPM_BIN_TYPE:
00131                 while (c > 0) {
00132                     fprintf(f, "       Data: %.3d ", ct);
00133                     while (c--) {
00134                         fprintf(f, "%02x ", (unsigned) (*(int_8 *)dp & 0xff));
00135                         ct++;
00136                         dp += sizeof(int_8);
00137                         if (! (ct % 8)) {
00138                             /*@loopbreak@*/ break;
00139                         }
00140                     }
00141                     fprintf(f, "\n");
00142                 }
00143                 /*@switchbreak@*/ break;
00144             case RPM_CHAR_TYPE:
00145                 while (c--) {
00146                     char ch = (char) *((char *) dp);
00147                     fprintf(f, "       Data: %.3d 0x%2x %c (%d)\n", ct++,
00148                             (unsigned)(ch & 0xff),
00149                             (isprint(ch) ? ch : ' '),
00150                             (int) *((char *) dp));
00151                     dp += sizeof(char);
00152                 }
00153                 /*@switchbreak@*/ break;
00154             case RPM_STRING_TYPE:
00155             case RPM_STRING_ARRAY_TYPE:
00156             case RPM_I18NSTRING_TYPE:
00157                 while (c--) {
00158                     fprintf(f, "       Data: %.3d %s\n", ct++, (char *) dp);
00159                     dp = strchr(dp, 0);
00160                     dp++;
00161                 }
00162                 /*@switchbreak@*/ break;
00163             default:
00164                 fprintf(stderr, _("Data type %d not supported\n"), 
00165                         (int) p->info.type);
00166                 /*@switchbreak@*/ break;
00167             }
00168         }
00169         p++;
00170     }
00171 }
00172 /*@=type@*/
00173 /*@=sizeoftype@*/
00174 /*@=boundsread@*/
00175 
00176 char * bin2hex(const char *data, size_t size)
00177 {
00178     static char hex[] = "0123456789abcdef";
00179     const char * s = data;
00180     char * t, * val;
00181     val = t = xmalloc(size * 2 + 1);
00182     while (size-- > 0) {
00183         unsigned int i;
00184         i = *s++;
00185         *t++ = hex[ (i >> 4) & 0xf ];
00186         *t++ = hex[ (i     ) & 0xf ];
00187     }
00188     *t = '\0';
00189 
00190     return val;
00191 }
00192     
00193     

Generated on Fri Oct 12 08:44:54 2007 for rpm by  doxygen 1.5.2