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