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