2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include <sys/types.h>
33 #define eprintf(...) fprintf ( stderr, __VA_ARGS__ )
35 /** Command-line options */
39 /** Error usage information */
41 /** Size of error information record */
45 /** Offset to error description (NUL-terminated) */
47 /** Offset to file name (NUL-terminated) */
51 } __attribute__ (( packed ));
57 * @v opts Command-line options
59 static void einfo ( const char *infile,
60 struct options *opts __attribute__ (( unused )) ) {
68 if ( ( fd = open ( infile, O_RDONLY ) ) < 0 ) {
69 eprintf ( "Cannot open \"%s\": %s\n",
70 infile, strerror ( errno ) );
75 if ( fstat ( fd, &stat ) < 0 ) {
76 eprintf ( "Cannot stat \"%s\": %s\n",
77 infile, strerror ( errno ) );
85 if ( ( start = mmap ( NULL, len, PROT_READ, MAP_SHARED,
86 fd, 0 ) ) == MAP_FAILED ) {
87 eprintf ( "Cannot mmap \"%s\": %s\n",
88 infile, strerror ( errno ) );
92 /* Iterate over einfo records */
93 for ( einfo = start ; ( ( void * ) einfo ) < ( start + len ) ;
94 einfo = ( ( ( void * ) einfo ) + einfo->size ) ) {
95 printf ( "%08x\t%s\t%d\t%s\n", einfo->error,
96 ( ( ( char * ) einfo ) + einfo->file ),
98 ( ( ( char * ) einfo ) + einfo->desc ) );
102 munmap ( start, len );
112 * @v program_name Program name
114 static void print_help ( const char *program_name ) {
115 eprintf ( "Syntax: %s file1.einfo [file2.einfo...]\n",
120 * Parse command-line options
122 * @v argc Argument count
123 * @v argv Argument list
124 * @v opts Options structure to populate
126 static int parse_options ( const int argc, char **argv,
127 struct options *opts __attribute__ (( unused )) ) {
131 int option_index = 0;
132 static struct option long_options[] = {
133 { "help", 0, NULL, 'h' },
137 if ( ( c = getopt_long ( argc, argv, "s:h",
139 &option_index ) ) == -1 ) {
145 print_help ( argv[0] );
155 int main ( int argc, char **argv ) {
156 struct options opts = {
161 /* Parse command-line arguments */
162 infile_index = parse_options ( argc, argv, &opts );
163 if ( argc <= infile_index ) {
164 print_help ( argv[0] );
168 /* Process each einfo file */
169 for ( ; infile_index < argc ; infile_index++ ) {
170 infile = argv[infile_index];
171 einfo ( infile, &opts );