00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 00002 /* 00003 libheraia.h 00004 Heraia's library header 00005 00006 (C) Copyright 2008 - 2009 Sébastien Tricaud, Olivier Delhomme 00007 e-mail : heraia@delhomme.org 00008 URL : http://heraia.tuxfamily.org 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2, or (at your option) 00013 any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00023 /** 00024 * @file libheraia.h 00025 * 00026 * This file contains all the definitions and includes all other .h 00027 * files. This is not very friendly, but ease compilation on exotic 00028 * systems. 00029 */ 00030 #ifndef _LIBHERAIA_H_ 00031 #define _LIBHERAIA_H_ 00032 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 #include <string.h> 00036 #include <time.h> 00037 #include <unistd.h> 00038 #include <sys/types.h> 00039 #include <sys/stat.h> 00040 #include <getopt.h> 00041 00042 #include <glib.h> 00043 #include <glib/gstdio.h> 00044 #include <glade/glade.h> 00045 #include <gmodule.h> 00046 00047 #include <gtkhex/gtkhex.h> 00048 00049 /** 00050 * @typedef HexDocument Heraia_Document 00051 * Abstract layer this may be usefull if we decide to leave GtkHex 00052 * and use something else ! 00053 * 00054 * @typedef GtkHex Heraia_Hex 00055 * Abstract layer this may be usefull if we decide to leave GtkHex 00056 * and use something else ! 00057 */ 00058 /** 00059 * @typedef gint HERAIA_ERROR 00060 * Defines heraia error type (this should be used !) 00061 */ 00062 typedef HexDocument Heraia_Document; 00063 typedef GtkHex Heraia_Hex; 00064 typedef gint HERAIA_ERROR; 00065 00066 /** 00067 * @typedef gint RefreshType 00068 * Refresh type (may be used to decide what to do 00069 * in a particular case) 00070 * @warning This is not thread safe !! 00071 */ 00072 /** 00073 * @def HERAIA_REFRESH_NOTHING 00074 * When nothing is refreshed 00075 * 00076 * @def HERAIA_REFRESH_NEW_FILE 00077 * When a new file has been loaded 00078 * 00079 * @def HERAIA_REFRESH_CURSOR_MOVE 00080 * When the cursor is moving 00081 * 00082 * @def HERAIA_REFRESH_TAB_CHANGED 00083 * When user selects another tab in main notebook 00084 */ 00085 typedef gint RefreshType; 00086 #define HERAIA_REFRESH_NOTHING 0 00087 #define HERAIA_REFRESH_NEW_FILE 1 00088 #define HERAIA_REFRESH_CURSOR_MOVE 2 00089 #define HERAIA_REFRESH_TAB_CHANGED 3 00090 00091 /** 00092 * @struct date_and_time_t 00093 * A human struct to store a date with a time. 00094 * @todo add an UTC info field 00095 */ 00096 typedef struct 00097 { 00098 guint32 year; 00099 guint32 month; 00100 guint32 day; 00101 00102 guint32 hour; 00103 guint32 minutes; 00104 guint32 seconds; 00105 } date_and_time_t; 00106 00107 00108 /** Templates for the decoding functions */ 00109 typedef gchar *(* DecodeFunc) (guchar *, gpointer); /**< Decode function template */ 00110 00111 /** 00112 * @struct decode_parameters_t 00113 * Used to pass decoding options to the functions. Those options are evaluated 00114 * from data_interpretor's window 00115 */ 00116 typedef struct 00117 { 00118 guint endianness; /**< endianness */ 00119 guint stream_size; /**< stream_size */ 00120 } decode_parameters_t; 00121 00122 /** 00123 * @struct decode_t 00124 * Basic way to associate a decode function and an entry that will receive the 00125 * result 00126 * @warning this structure is subject to changes 00127 */ 00128 typedef struct 00129 { 00130 DecodeFunc func; /**< a function to decode into something */ 00131 GtkWidget *entry; /**< the widget that will receive the result */ 00132 gchar *err_msg; /**< error message if something went wrong when decoding 00133 expects a %d somewhere in the message to represents 00134 the stream lenght to be decoded */ 00135 } decode_t; 00136 00137 00138 /** 00139 * @struct decode_generic_t 00140 * Basic way to have as many as we want decoding functions corresponding to one 00141 * label. This Structure is basicaly one row in the data intrepretor window 00142 * @warning this structure is subject to changes 00143 */ 00144 typedef struct 00145 { 00146 GPtrArray *decode_array; /**< Pointer Array of decode_t functions and corresponding entries */ 00147 GtkWidget *label; /**< label for these decoding functions */ 00148 guint data_size; /**< size of what we may decode */ 00149 gboolean fixed_size; /**< says whether we can modify data_size or not */ 00150 } decode_generic_t; 00151 00152 00153 /** 00154 * @struct tab_t 00155 * Tabulation structure to be used in the GtkNoteBook of 00156 * data_interpretor's window 00157 */ 00158 typedef struct 00159 { 00160 guint index; /**< number for this tab */ 00161 guint nb_cols; /**< number of columns in this tab - this MUST NOT change in any way */ 00162 guint nb_rows; /**< number of rows in this tab - this is automatically updated */ 00163 GtkWidget *label; /**< label for this tab */ 00164 GPtrArray *col_labels; /**< array of GtkWidgets of columns labels */ 00165 GPtrArray *vboxes; /**< array of vboxes where we will pack label and entry widgets */ 00166 GPtrArray *rows; /**< array of pointers to decode_generic_t variables. */ 00167 } tab_t; 00168 00169 /** 00170 * @struct data_window_t 00171 * Data interpretor window structure 00172 */ 00173 typedef struct 00174 { 00175 GtkWidget *diw; /**< data interpretor window */ 00176 gint tab_displayed; /**< keeps the last displayed tab's number before closing */ 00177 guint nb_tabs; /**< keeps Number of tabs in the GPtrArray */ 00178 GPtrArray *tabs; /**< an array of tabs displayed in data interpretor's notebook */ 00179 } data_window_t; 00180 00181 /* Treatment Stuff (if one wants to add new data types) */ 00182 typedef GList *(* TreatmentDoFunc) (GList *); /**< Treatment function called while operating the treatment */ 00183 typedef void (* TreatmentInitFunc) (gpointer); /**< Treatment init function */ 00184 typedef void (* TreatmentDelFunc) (gpointer); /**< Treatment delete function */ 00185 typedef gpointer (*TreatmentCopyFunc) (gpointer); /**< Treatment copy function that have to copy internal 00186 structures (widgets and all stuff in it) */ 00187 /** 00188 * @struct treatment_t 00189 * Treatment structure 00190 * @warning I'm not happy with this struct and all data_type.c file. I plan 00191 * to replace thoses ugly things with an embedded scripting language 00192 * such as python. 00193 */ 00194 typedef struct 00195 { 00196 gchar *name; /**< Treatment name */ 00197 TreatmentDoFunc do_it; /**< Treatment function that manages the whole treatment (interface + treatment itself) */ 00198 TreatmentInitFunc init; /**< inits the interface */ 00199 TreatmentDelFunc kill; /**< kills the treatment itself */ 00200 TreatmentCopyFunc copy; /**< Copy the gpointer data sub structure of the treatment itself */ 00201 gpointer data; /**< Generic treatment data. Each instantiated treatment may have it's own */ 00202 } treatment_t; 00203 00204 /** 00205 * @struct treatment_container_t 00206 * Structure in order to contain one treatment 00207 * @warning I'm not happy with this struct and all data_type.c file. I plan 00208 * to replace thoses ugly things with an embedded scripting language 00209 * such as python. 00210 */ 00211 typedef struct 00212 { 00213 GtkWidget *container_box; /**< Upper box containing the whole stuff */ 00214 GtkWidget *button_box; /**< Right part of the hbox. Contains "-", GtkEntry, "+" */ 00215 GtkWidget *combo_box; /**< Left box where we have the combobox */ 00216 GtkWidget *tment_list; /**< Combobox containning the treatment list */ 00217 GtkWidget *result; /**< The GtkEntry in the vbox */ 00218 GtkWidget *moins; /**< "-" button */ 00219 GtkWidget *plus; /**< "+" button */ 00220 treatment_t *treatment; /**< Selected treatment */ 00221 } treatment_container_t; 00222 00223 /** 00224 * @struct data_type_t 00225 * Data type structure entry that contains user defined data types 00226 * This is integrated within a GList. 00227 * !! Do not forget to update the functions related to this such as 00228 * - new_data_type 00229 * - free_data_type 00230 * - copy_data_type 00231 * See data_type.c for thoses functions 00232 * @warning I'm not happy with this struct and all data_type.c file. I plan 00233 * to replace thoses ugly things with an embedded scripting language 00234 * such as python. 00235 */ 00236 typedef struct 00237 { 00238 gchar *name; /**< Name of the data type */ 00239 guint size; /**< size of the data type (here we may limit size entry, eg <= 16 for example) */ 00240 GList *treatment_c_list; /**< Treatments containers to be applied (in the list order) to the data 00241 (treatment_container_t *) */ 00242 GtkWidget *di_label; /**< label for the data_interpretor window */ 00243 GtkWidget *di_entry; /**< entry for the data interpretor window */ 00244 } data_type_t; 00245 00246 00247 /** 00248 * @struct xml_t 00249 * Structure that contains all the xml definitions loaded at 00250 * running time using libglade 00251 */ 00252 typedef struct 00253 { 00254 GladeXML *main; /**< the main interface xml description */ 00255 } xml_t; 00256 00257 00258 /** 00259 * @def WPT_DEFAULT_HEIGHT 00260 * Defines the default height for a window (set in window_prop_t) 00261 * 00262 * @def WPT_DEFAULT_WIDTH 00263 * Defines the default width for a window (set in window_prop_t) 00264 */ 00265 #define WPT_DEFAULT_HEIGHT 200 00266 #define WPT_DEFAULT_WIDTH 200 00267 00268 /** 00269 * @struct window_prop_t 00270 * Window properties 00271 * - position (x,y) record window's position 00272 * - displayed (boolean) say whether the window is displayed or not 00273 */ 00274 typedef struct 00275 { 00276 gint x; /**< x position (upper left corner) */ 00277 gint y; /**< y position (upper left corner) */ 00278 guint height; /**< y+height (bottom right corner) */ 00279 guint width; /**< x+width (bottom right corner) */ 00280 gboolean displayed; /**< TRUE if displayed, FALSE otherwise */ 00281 } window_prop_t; 00282 00283 /** 00284 * @struct all_window_prop_t 00285 * Structure to keep window properties for each window 00286 */ 00287 typedef struct 00288 { 00289 window_prop_t *about_box; 00290 window_prop_t *data_interpretor; /**< data interpretor window */ 00291 window_prop_t *log_box; /**< log window */ 00292 window_prop_t *main_dialog; /**< heraia's main window */ 00293 window_prop_t *plugin_list; /**< plugin description window */ 00294 window_prop_t *ldt; /**< list data types window */ 00295 window_prop_t *main_pref_window; /**< main preference window */ 00296 } all_window_prop_t; 00297 00298 /** 00299 * @struct prefs_t 00300 * Data type related to preferences 00301 */ 00302 typedef struct 00303 { 00304 gchar *filename; /**< user preference file file name */ 00305 gchar *pathname; /**< user preference file path name */ 00306 GKeyFile *file; /**< preference file contents */ 00307 } prefs_t; 00308 00309 00310 /** 00311 * @struct doc_t 00312 * Proposal for a structure that will group all informations about 00313 * a single document. This structure is managed in heraia_io.c 00314 */ 00315 typedef struct 00316 { 00317 Heraia_Document *hex_doc; /**< Document definition related to libgtkhex */ 00318 GtkWidget *hex_widget; /**< hexwidget corresponding to the document */ 00319 } doc_t; 00320 00321 00322 /** 00323 * @struct heraia_window_t 00324 * This is the main structure (mainly named main_window due to historycal reasons) 00325 * It contains all things that the program needs 00326 */ 00327 typedef struct 00328 { 00329 gboolean debug; /**< Used to tell the program wether we want to display debug messages or not */ 00330 doc_t *current_doc; /**< This is a pointer to the current edited document */ 00331 GPtrArray *documents; /**< An array of doc_t in order to be able to open more than one doc */ 00332 xml_t *xmls; /**< All the xmls used in the program, loaded at running time */ 00333 data_window_t *current_DW; /**< data_interpretor pointer */ 00334 GList *location_list; /**< this is the location list where we store some paths */ 00335 GList *plugins_list; /**< A list of plugins */ 00336 GList *data_type_list; /**< A list of data types */ 00337 data_type_t *current_data_type; /**< data type that is being edited */ 00338 GList *available_treatment_list;/**< Available treatments that can be used by the user in the data type window */ 00339 RefreshType event; /**< Tells what is happening */ 00340 all_window_prop_t *win_prop; /**< Keeps window properties */ 00341 prefs_t *prefs; /**< All datas related to main preferences */ 00342 } heraia_window_t; 00343 00344 #include "config.h" 00345 #include "data_interpretor.h" 00346 #include "data_type.h" 00347 #include "decode.h" 00348 #include "ghex_heraia_interface.h" 00349 #include "heraia_errors.h" 00350 #include "heraia_io.h" 00351 #include "heraia_ui.h" 00352 #include "list_data_types.h" 00353 #include "log.h" 00354 #include "main_pref_window.h" 00355 #include "plugin.h" 00356 #include "plugin_list.h" 00357 #include "treatments.h" 00358 #include "user_prefs.h" 00359 00360 extern int libheraia_test(void); 00361 00362 /** 00363 * Python specific 00364 */ 00365 extern void libheraia_initialize(void); 00366 extern void libheraia_finalize(void); 00367 00368 #endif /* _LIBHERAIA_H_ */