00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "heraia_types.h"
00037
00038 static gboolean version(void);
00039 static gboolean usage(int status);
00040 static window_prop_t *init_window_properties(gint x, gint y, guint height, guint width, gboolean displayed);
00041 static heraia_window_t *init_window_property_struct(heraia_window_t *main_window);
00042 static heraia_window_t *heraia_init_main_struct(void);
00043 static HERAIA_ERROR init_heraia_plugin_system(heraia_window_t *main_window);
00044 static GList *init_heraia_location_list(void);
00045 static gboolean manage_command_line_options(Options *opt, int argc, char **argv);
00046
00047
00048
00049
00050
00051
00052 static heraia_window_t *libheraia_main_struct = NULL;
00053
00054
00055
00056
00057
00058
00059
00060 heraia_window_t *get_main_struct(void)
00061 {
00062 return libheraia_main_struct;
00063 }
00064
00065
00066
00067
00068
00069 static gboolean version(void)
00070 {
00071 fprintf (stdout, "heraia, %s - %s - Version %s - License %s\n", HERAIA_AUTHORS, HERAIA_DATE, HERAIA_VERSION, HERAIA_LICENSE);
00072 return TRUE;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 static gboolean usage(int status)
00086 {
00087 if (status == 0)
00088 {
00089 fprintf (stderr,
00090 "Try `heraia --help' for more information.\n");
00091 return FALSE;
00092 }
00093 else
00094 {
00095 version();
00096 fprintf(stdout, "\nheraia is a simple hexadecimal file editor and file analyser");
00097 fprintf(stdout, "\nUsage :\n heraia [options] filename\n");
00098 fprintf(stdout, "\nOptions :\n\
00099 -h, --help\tThis help.\n\
00100 -v, --version\tProgram version information.\n");
00101 return TRUE;
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 static window_prop_t *init_window_properties(gint x, gint y, guint height, guint width, gboolean displayed)
00116 {
00117 window_prop_t *window_p;
00118
00119
00120 window_p = (window_prop_t *) g_malloc0(sizeof(window_prop_t));
00121
00122
00123 window_p->x = x;
00124 window_p->y = y;
00125 window_p->height = height;
00126 window_p->width = width;
00127 window_p->displayed = displayed;
00128
00129 return window_p;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 static heraia_window_t *init_window_property_struct(heraia_window_t *main_window)
00139 {
00140 all_window_prop_t *win_prop = NULL;
00141 window_prop_t *about_box = NULL;
00142 window_prop_t *data_interpretor = NULL;
00143 window_prop_t *log_box = NULL;
00144 window_prop_t *main_dialog = NULL;
00145 window_prop_t *plugin_list = NULL;
00146 window_prop_t *ldt = NULL;
00147 window_prop_t *main_pref_window = NULL;
00148
00149
00150 win_prop = (all_window_prop_t *) g_malloc0(sizeof(all_window_prop_t));
00151
00152
00153 about_box = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, FALSE);
00154 data_interpretor = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, H_DI_DISPLAYED);
00155 log_box = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, FALSE);
00156 main_dialog = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, TRUE);
00157 plugin_list = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, FALSE);
00158 ldt = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, FALSE);
00159 main_pref_window = init_window_properties(0, 0, WPT_DEFAULT_HEIGHT, WPT_DEFAULT_WIDTH, FALSE);
00160
00161
00162 win_prop->about_box = about_box;
00163 win_prop->data_interpretor = data_interpretor;
00164 win_prop->log_box = log_box;
00165 win_prop->main_dialog = main_dialog;
00166 win_prop->plugin_list = plugin_list;
00167 win_prop->ldt = ldt;
00168 win_prop->main_pref_window = main_pref_window;
00169
00170
00171 main_window->win_prop = win_prop;
00172
00173 return main_window;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 static heraia_window_t *heraia_init_main_struct(void)
00183 {
00184 heraia_window_t *herwin = NULL;
00185 xml_t *xmls = NULL;
00186
00187 herwin = (heraia_window_t *) g_malloc0(sizeof(heraia_window_t));
00188
00189 if (!herwin)
00190 {
00191 fprintf(stderr, "Main structure could not be initialiazed !");
00192 fprintf(stderr, "Do you have a memory problem ?\n");
00193 return NULL;
00194 }
00195
00196
00197 herwin->prefs = NULL;
00198 init_preference_struct(herwin);
00199 verify_preference_file(herwin->prefs->pathname, herwin->prefs->filename);
00200
00201
00202
00203
00204
00205 herwin->debug = ENABLE_DEBUG;
00206 herwin->filename = NULL;
00207
00208 herwin->current_doc = NULL;
00209 herwin->plugins_list = NULL;
00210 herwin->location_list = init_heraia_location_list();
00211 herwin->data_type_list = NULL;
00212 herwin->current_data_type = NULL;
00213 herwin->available_treatment_list = init_treatments();
00214
00215
00216
00217 xmls = (xml_t *) g_malloc0(sizeof(xml_t));
00218 xmls->main = NULL;
00219 herwin->xmls = xmls;
00220
00221
00222 herwin->current_DW = (data_window_t *) g_malloc0 (sizeof(data_window_t));
00223 herwin->current_DW->current_hexwidget = NULL;
00224 herwin->current_DW->diw = NULL;
00225
00226 herwin->current_DW->tab_displayed = 0;
00227
00228
00229 herwin = init_window_property_struct(herwin);
00230
00231
00232 libheraia_main_struct = herwin;
00233
00234 return herwin;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 static HERAIA_ERROR init_heraia_plugin_system(heraia_window_t *main_window)
00248 {
00249
00250
00251 if (plugin_capable() == TRUE)
00252 {
00253 log_message(main_window, G_LOG_LEVEL_INFO, "Enabling plugins");
00254 load_plugins(main_window);
00255
00256
00257 log_message(main_window, G_LOG_LEVEL_DEBUG, "Inits the plugin list window");
00258 plugin_list_window_init_interface(main_window);
00259
00260 return HERAIA_NOERR;
00261 }
00262 else
00263 {
00264 log_message(main_window, G_LOG_LEVEL_WARNING, "Plugins will be disabled");
00265 return HERAIA_NO_PLUGINS;
00266 }
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276 static GList *init_heraia_location_list(void)
00277 {
00278 gchar *path = NULL;
00279 const gchar* const *system_data_dirs;
00280 guint i = 0;
00281 GList *location_list = NULL;
00282
00283
00284 path = g_strdup_printf("%s", g_get_current_dir());
00285 location_list = g_list_prepend(location_list, path);
00286
00287
00288 system_data_dirs = g_get_system_data_dirs();
00289 i = 0;
00290 while(system_data_dirs[i] != NULL)
00291 {
00292 path = g_strdup_printf("%s%c%s", system_data_dirs[i], G_DIR_SEPARATOR, "heraia");
00293 location_list = g_list_prepend(location_list, path);
00294 i++;
00295 }
00296
00297
00298 system_data_dirs = g_get_system_config_dirs();
00299 i = 0;
00300 while(system_data_dirs[i] != NULL)
00301 {
00302 path = g_strdup_printf("%s%c%s", system_data_dirs[i], G_DIR_SEPARATOR, "heraia");
00303 location_list = g_list_prepend(location_list, path);
00304 i++;
00305 }
00306
00307
00308 path = g_strdup_printf("%s%c.%s", g_get_home_dir(), G_DIR_SEPARATOR, "heraia");
00309 location_list = g_list_prepend(location_list, path);
00310
00311
00312 path = g_strdup_printf("%s%c%s", g_get_user_data_dir(), G_DIR_SEPARATOR, "heraia");
00313 location_list = g_list_prepend(location_list, path);
00314
00315
00316 path = g_strdup_printf("%s%c%s", g_get_user_config_dir(), G_DIR_SEPARATOR, "heraia");
00317 location_list = g_list_prepend(location_list, path);
00318
00319 return location_list;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 static gboolean manage_command_line_options(Options *opt, int argc, char **argv)
00331 {
00332 int exit_value = TRUE;
00333 int c = 0;
00334
00335 while ((c = getopt_long (argc, argv, "vh", long_options, NULL)) != -1)
00336 {
00337 switch (c)
00338 {
00339 case 0:
00340 break;
00341
00342 case 'v':
00343 exit_value = version();
00344 opt->usage = TRUE;
00345 break;
00346
00347 case 'h':
00348 exit_value = usage(1);
00349 opt->usage = TRUE;
00350 break;
00351
00352 default:
00353 exit_value = usage(0);
00354 opt->usage = TRUE;
00355 }
00356 }
00357
00358 if (optind < argc)
00359 {
00360 opt->filename = (char *) malloc (sizeof(char) * strlen(argv[optind]) + 1);
00361 strcpy(opt->filename, argv[optind]);
00362 }
00363
00364 return exit_value;
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374 int main (int argc, char ** argv)
00375 {
00376 Options *opt;
00377 gboolean exit_value = TRUE;
00378 heraia_window_t *main_window = NULL;
00379
00380 opt = (Options *) g_malloc0(sizeof(Options));
00381
00382 opt->filename = NULL;
00383 opt->usage = FALSE;
00384
00385 main_window = heraia_init_main_struct();
00386
00387 libheraia_initialize();
00388
00389 if (main_window->debug == TRUE)
00390 {
00391 fprintf(stdout, "Main struct initialized !\n");
00392 }
00393
00394
00395 exit_value = manage_command_line_options(opt, argc, argv);
00396
00397 if (opt->usage != TRUE)
00398 {
00399 if (main_window->debug == TRUE)
00400 {
00401 fprintf(stderr, "Beginning things\n");
00402 libheraia_test();
00403 }
00404
00405
00406 exit_value = gtk_init_check(&argc, &argv);
00407
00408 if (load_heraia_ui(main_window) == TRUE)
00409 {
00410
00411 log_message(main_window, G_LOG_LEVEL_INFO, "Main interface loaded (%s)", main_window->xmls->main->filename);
00412 log_message(main_window, G_LOG_LEVEL_DEBUG, "Preference file is %s", main_window->prefs->filename);
00413 log_message(main_window, G_LOG_LEVEL_DEBUG, "data interpretor's tab is %d", main_window->current_DW->tab_displayed);
00414
00415 init_heraia_plugin_system(main_window);
00416
00417 if (opt->filename != NULL)
00418 {
00419 load_file_to_analyse(main_window, opt->filename);
00420 }
00421
00422 log_message(main_window, G_LOG_LEVEL_DEBUG, "Main_window : %p", main_window);
00423
00424 init_heraia_interface(main_window);
00425
00426
00427 gtk_main();
00428
00429 exit_value = TRUE;
00430 }
00431 else
00432 {
00433 fprintf(stderr, "File heraia.glade not found !\n");
00434 }
00435 }
00436
00437 libheraia_finalize();
00438
00439 return !exit_value;
00440 }