Uwe Hermann | 7eb845e | 2008-11-02 17:01:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the bayou project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Uwe Hermann | 7eb845e | 2008-11-02 17:01:06 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include "liblar.h" |
| 22 | #include "pbuilder.h" |
| 23 | |
| 24 | void show_subchain(struct bpt_config *cfg, char *fptr, int index) |
| 25 | { |
| 26 | int i; |
| 27 | char *ptr = fptr + sizeof(struct bpt_config); |
| 28 | |
| 29 | for (i = 0; i < cfg->entries; i++) { |
| 30 | struct bpt_pentry *entry = (struct bpt_pentry *)ptr; |
| 31 | |
| 32 | if (entry->parent == index) |
| 33 | printf(" + %.64s\n", |
| 34 | ptr + sizeof(struct bpt_pentry)); |
| 35 | |
| 36 | ptr += (sizeof(struct bpt_pentry) + entry->nlen); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | int show_payloads(struct bpt_config *cfg, char *fptr) |
| 41 | { |
| 42 | int i; |
| 43 | char *ptr = fptr + sizeof(struct bpt_config); |
| 44 | |
| 45 | for (i = 0; i < cfg->entries; i++) { |
| 46 | struct bpt_pentry *entry = (struct bpt_pentry *)ptr; |
| 47 | |
| 48 | if (entry->parent != 0) { |
| 49 | ptr += (sizeof(struct bpt_pentry) + entry->nlen); |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | printf(" "); |
| 54 | |
| 55 | if (entry->flags & BPT_FLAG_DEFAULT) |
| 56 | printf("D"); |
| 57 | else |
| 58 | printf(" "); |
| 59 | |
| 60 | if (entry->flags & BPT_FLAG_NOSHOW) |
| 61 | printf("N"); |
| 62 | else |
| 63 | printf(" "); |
| 64 | |
| 65 | switch (entry->type) { |
| 66 | case BPT_TYPE_CHOOSER: |
| 67 | printf(" MENU "); |
| 68 | break; |
| 69 | case BPT_TYPE_CHAIN: |
| 70 | printf(" CHAIN"); |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | if (entry->title[0] != 0) |
| 75 | printf(" %.64s\n", entry->title); |
| 76 | else |
| 77 | printf(" - no title -\n"); |
| 78 | |
| 79 | if (entry->type == BPT_TYPE_CHOOSER) |
| 80 | printf(" %.60s\n", |
| 81 | ptr + sizeof(struct bpt_pentry)); |
| 82 | else |
| 83 | show_subchain(cfg, fptr, entry->index); |
| 84 | |
| 85 | ptr += (sizeof(struct bpt_pentry) + entry->nlen); |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | int pbuilder_show_lar(const char *input) |
| 92 | { |
| 93 | int ret = -1; |
| 94 | struct LAR *lar; |
| 95 | struct bpt_config *cfg; |
| 96 | struct LARFile *lfile; |
| 97 | |
| 98 | lar = LAR_Open(input); |
| 99 | |
| 100 | if (lar == NULL) { |
| 101 | warn("E: Couldn't open LAR %s\n", input); |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | lfile = LAR_MapFile(lar, "bayou_payload_table"); |
| 106 | |
| 107 | if (lfile == NULL) { |
| 108 | warn("E: Couldn't find the bayou payload table. Nothing to do.\n"); |
| 109 | goto err; |
| 110 | } |
| 111 | |
| 112 | cfg = (struct bpt_config *)lfile->buffer; |
| 113 | |
| 114 | if (cfg->id != BPT_ID) { |
| 115 | warn("E: BPT ID does not match\n"); |
| 116 | goto err; |
| 117 | } |
| 118 | |
| 119 | printf("Bayou Payload Configuration\n"); |
| 120 | printf("Timeout = %d seconds\n", cfg->timeout); |
| 121 | |
| 122 | printf("Payload List:\n"); |
| 123 | show_payloads(cfg, lfile->buffer); |
| 124 | ret = 0; |
| 125 | |
| 126 | err: |
| 127 | LAR_CloseFile(lfile); |
| 128 | LAR_Close(lar); |
| 129 | |
| 130 | return ret; |
| 131 | } |