main.c: Remove unused variables
[memprof.git] / src / binparser.h
blobebedf405ab95d6ac387f1666b891709043b83d8b
1 /* Sysprof -- Sampling, systemwide CPU profiler
2 * Copyright 2006, 2007, Soeren Sandmann
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <glib.h>
20 typedef struct BinParser BinParser;
21 typedef struct BinRecord BinRecord;
22 typedef struct BinField BinField;
24 /* The model is:
26 * BinParser has an offset associated with it. This offset can be
27 * manipulated with methods
29 * goto - go to absolute position from file start
30 * goto_rel - go to relative positio
31 * goto_record_rel - skip the given number of records
32 * align - move forward until aligned to given width
33 * save/restore - save/restore the current offset (stack)
35 * and queried with
37 * get_offset - return current offset in bytes from start
39 * data can be retrieved with
41 * get_uint - return a uint of given width, and skip
42 * get_string - return a null terminated stringm, and skip
43 * get_pstring - return a 'pascal' string with given length
45 * get_uint_field - return the named field
47 * formats should probably be definable as static data.
49 * A bin parser also has an associated "status" with it. This can be
50 * OK, or error. It is ok to use a parser with an error status, but
51 * the data returned will not be meaningfull.
56 #define BIN_MAX_NAME 52
58 typedef enum
60 BIN_LITTLE_ENDIAN,
61 BIN_BIG_ENDIAN,
62 BIN_NATIVE_ENDIAN
63 } BinEndian;
65 typedef enum
67 /* More types can (and probably will) be added in the future */
68 BIN_UINT,
69 BIN_UNINTERPRETED
70 } BinType;
72 struct BinField {
73 const char name[BIN_MAX_NAME];
74 char type;
75 char n_bytes; /* number of bytes in the type */
78 BinParser * bin_parser_new (const guchar *data,
79 gsize length);
80 void bin_parser_free (BinParser *parser);
81 const guchar *bin_parser_get_data (BinParser *parser);
82 gsize bin_parser_get_length (BinParser *parser);
83 void bin_parser_set_endian (BinParser *parser,
84 BinEndian endian);
85 gboolean bin_parser_error (BinParser *parser);
86 void bin_parser_clear_error (BinParser *parser);
87 const gchar * bin_parser_get_error_msg (BinParser *parser);
88 BinRecord * bin_parser_create_record (BinParser *parser,
89 const BinField *fields);
90 gsize bin_record_get_size (BinRecord *record);
91 guint64 bin_parser_get_uint_field (BinParser *parser,
92 BinRecord *record,
93 const char *field);
95 /* Move current offset */
96 gsize bin_parser_get_offset (BinParser *parser);
97 void bin_parser_set_offset (BinParser *parser,
98 gsize offset);
99 void bin_parser_align (BinParser *parser,
100 gsize byte_width);
101 void bin_parser_seek_record (BinParser *parser,
102 BinRecord *record,
103 int n_records);
104 void bin_parser_save (BinParser *parser);
105 void bin_parser_restore (BinParser *parser);
107 /* retrieve data */
108 guint64 bin_parser_get_uint (BinParser *parser,
109 int width);
110 const char * bin_parser_get_string (BinParser *parser);