| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: printhex.c |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | #include "stdio.h" |
| 24 | |
| 25 | void usage() { |
| 26 | fprintf(stderr, "Usage: printhex file\n"); |
| 27 | } |
| 28 | |
| 29 | int main(int argc, char* argv[]) { |
| 30 | FILE* infp; |
| 31 | int c, bytes; |
| 32 | |
| 33 | infp = fopen(argv[1], "r"); |
| 34 | if (infp == NULL) { |
| 35 | usage(); |
| 36 | fprintf(stderr, "\nError: unable to open input file: %s\n", argv[1]); |
| 37 | exit(1); |
| 38 | } |
| 39 | |
| 40 | fprintf(stdout, "\n"); |
| 41 | |
| 42 | for (bytes = 0; (c = fgetc(infp)) != EOF; bytes++) { |
| 43 | if (bytes % 40 == 0) { |
| 44 | fprintf(stdout, "\n"); |
| 45 | } |
| 46 | |
| 47 | fprintf(stdout, "%02x", c); |
| 48 | } |
| 49 | |
| 50 | fprintf(stdout, "\n\n%d bytes read\n\n", bytes); |
| 51 | |
| 52 | return 0; |
| 53 | } |