- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# lib/header_internal.c

Go to the documentation of this file.

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