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
00040 static gboolean version(void)
00041 {
00042 fprintf (stdout, "heraia, %s - %s - Version %s - License %s\n", HERAIA_AUTHORS, HERAIA_DATE, HERAIA_VERSION, HERAIA_LICENSE);
00043 return TRUE;
00044 }
00045
00046
00051 static gboolean usage(int status)
00052 {
00053 if (status == 0)
00054 {
00055 fprintf (stderr,
00056 "Try `heraia --help' for more information.\n");
00057 return FALSE;
00058 }
00059 else
00060 {
00061 version();
00062 fprintf(stdout, "\nheraia is a simple hexadecimal file editor and file analyser");
00063 fprintf(stdout, "\nUsage :\n heraia [options] filename\n");
00064 fprintf(stdout, "\nOptions :\n\
00065 -h, --help\tThis help.\n\
00066 -v, --version\tProgram version information.\n");
00067 return TRUE;
00068 }
00069 }
00070
00071
00075 static window_prop_t *init_window_properties(gint x, gint y, gboolean displayed)
00076 {
00077 window_prop_t *window_p;
00078
00079
00080 window_p = (window_prop_t *) g_malloc0(sizeof(window_prop_t));
00081
00082
00083 window_p->x = x;
00084 window_p->y = y;
00085 window_p->displayed = displayed;
00086
00087 return window_p;
00088 }
00089
00090
00094 static heraia_window_t *init_window_property_struct(heraia_window_t *main_window)
00095 {
00096 all_window_prop_t *win_prop = NULL;
00097 window_prop_t *about_box = NULL;
00098 window_prop_t *data_interpretor = NULL;
00099 window_prop_t *log_box = NULL;
00100 window_prop_t *main_dialog = NULL;
00101 window_prop_t *plugin_list = NULL;
00102 window_prop_t *ldt = NULL;
00103
00104
00105 win_prop = (all_window_prop_t *) g_malloc0(sizeof(all_window_prop_t));
00106
00107
00108 about_box = init_window_properties(0, 0, FALSE);
00109 data_interpretor = init_window_properties(0, 0, H_DI_DISPLAYED);
00110 log_box = init_window_properties(0, 0, FALSE);
00111 main_dialog = init_window_properties(0, 0, TRUE);
00112 plugin_list = init_window_properties(0, 0, FALSE);
00113 ldt = init_window_properties(0, 0, FALSE);
00114
00115
00116 win_prop->about_box = about_box;
00117 win_prop->data_interpretor = data_interpretor;
00118 win_prop->log_box = log_box;
00119 win_prop->main_dialog = main_dialog;
00120 win_prop->plugin_list = plugin_list;
00121 win_prop->ldt = ldt;
00122
00123
00124 main_window->win_prop = win_prop;
00125
00126 return main_window;
00127 }
00128
00129
00133 static heraia_window_t *heraia_init_main_struct(void)
00134 {
00135 heraia_window_t *herwin = NULL;
00136 xml_t *xmls = NULL;
00137
00138 herwin = (heraia_window_t *) g_malloc0(sizeof(heraia_window_t));
00139
00140 if (!herwin)
00141 {
00142 fprintf(stderr, "Main structure could not be initialiazed !");
00143 fprintf(stderr, "Do you have a memory problem ?\n");
00144 return NULL;
00145 }
00146
00151 herwin->debug = ENABLE_DEBUG;
00152 herwin->filename = NULL;
00153
00154 herwin->current_doc = NULL;
00155 herwin->plugins_list = NULL;
00156 herwin->location_list = init_heraia_location_list();
00157 herwin->data_type_list = NULL;
00158 herwin->current_data_type = NULL;
00159 herwin->available_treatment_list = init_treatments();
00160
00161
00162 xmls = (xml_t *) g_malloc0(sizeof(xml_t));
00163 xmls->main = NULL;
00164 herwin->xmls = xmls;
00165
00166
00167 herwin->current_DW = (data_window_t *) g_malloc0 (sizeof(data_window_t));
00168 herwin->current_DW->current_hexwidget = NULL;
00169 herwin->current_DW->diw = NULL;
00170
00171 herwin->current_DW->tab_displayed = 0;
00172
00173
00174 herwin = init_window_property_struct(herwin);
00175
00176 return herwin;
00177 }
00178
00184 static HERAIA_ERROR init_heraia_plugin_system(heraia_window_t *main_window)
00185 {
00186
00187
00188 if (plugin_capable() == TRUE)
00189 {
00190 log_message(main_window, G_LOG_LEVEL_INFO, "Enabling plugins");
00191 load_plugins(main_window);
00192
00193
00194 log_message(main_window, G_LOG_LEVEL_DEBUG, "Inits the plugin list window");
00195 plugin_list_window_init_interface(main_window);
00196
00197 return HERAIA_NOERR;
00198 }
00199 else
00200 {
00201 log_message(main_window, G_LOG_LEVEL_WARNING, "Plugins will be disabled");
00202 return HERAIA_NO_PLUGINS;
00203 }
00204 }
00205
00211 static GList *init_heraia_location_list(void)
00212 {
00213 gchar *path = NULL;
00214 const gchar* const *system_data_dirs;
00215 guint i = 0;
00216 GList *location_list = NULL;
00217
00218
00219 path = g_strdup_printf("%s", g_get_current_dir());
00220 location_list = g_list_prepend(location_list, path);
00221
00222
00223 system_data_dirs = g_get_system_data_dirs();
00224 i = 0;
00225 while(system_data_dirs[i] != NULL)
00226 {
00227 path = g_strdup_printf("%s%c%s", system_data_dirs[i], G_DIR_SEPARATOR, "heraia");
00228 location_list = g_list_prepend(location_list, path);
00229 i++;
00230 }
00231
00232
00233 system_data_dirs = g_get_system_config_dirs();
00234 i = 0;
00235 while(system_data_dirs[i] != NULL)
00236 {
00237 path = g_strdup_printf("%s%c%s", system_data_dirs[i], G_DIR_SEPARATOR, "heraia");
00238 location_list = g_list_prepend(location_list, path);
00239 i++;
00240 }
00241
00242
00243 path = g_strdup_printf("%s%c.%s", g_get_home_dir(), G_DIR_SEPARATOR, "heraia");
00244 location_list = g_list_prepend(location_list, path);
00245
00246
00247 path = g_strdup_printf("%s%c%s", g_get_user_data_dir(), G_DIR_SEPARATOR, "heraia");
00248 location_list = g_list_prepend(location_list, path);
00249
00250
00251 path = g_strdup_printf("%s%c%s", g_get_user_config_dir(), G_DIR_SEPARATOR, "heraia");
00252 location_list = g_list_prepend(location_list, path);
00253
00254 return location_list;
00255 }
00256
00261 static gboolean manage_command_line_options(Options *opt, int argc, char ** argv)
00262 {
00263 int exit_value = TRUE;
00264 int c = 0;
00265
00266 while ((c = getopt_long (argc, argv, "vh", long_options, NULL)) != -1)
00267 {
00268 switch (c)
00269 {
00270 case 0:
00271 break;
00272
00273 case 'v':
00274 exit_value = version();
00275 opt->usage = TRUE;
00276 break;
00277
00278 case 'h':
00279 exit_value = usage(1);
00280 opt->usage = TRUE;
00281 break;
00282
00283 default:
00284 exit_value = usage(0);
00285 opt->usage = TRUE;
00286 }
00287 }
00288
00289 if (optind < argc)
00290 {
00291 opt->filename = (char *) malloc (sizeof(char) * strlen(argv[optind]) + 1);
00292 strcpy(opt->filename, argv[optind]);
00293 }
00306 return exit_value;
00307 }
00308
00309
00316 int main (int argc, char ** argv)
00317 {
00318 Options *opt;
00319 gboolean exit_value = TRUE;
00320 heraia_window_t *main_window = NULL;
00321
00322 opt = (Options *) g_malloc0(sizeof(Options));
00323
00324 opt->filename = NULL;
00325 opt->usage = FALSE;
00326
00327 main_window = heraia_init_main_struct();
00328
00329 if (main_window->debug == TRUE)
00330 {
00331 fprintf(stdout, "Main struct initialized !\n");
00332 }
00333
00334
00335 exit_value = manage_command_line_options(opt, argc, argv);
00336
00337 if (opt->usage != TRUE)
00338 {
00339 if (main_window->debug == TRUE)
00340 {
00341 fprintf(stderr, "Beginning things\n");
00342 }
00343
00344
00345 exit_value = gtk_init_check(&argc, &argv);
00346
00347 if (load_heraia_ui(main_window) == TRUE)
00348 {
00349
00350 log_message(main_window, G_LOG_LEVEL_INFO, "Main interface loaded (%s)", main_window->xmls->main->filename);
00351
00352 init_heraia_plugin_system(main_window);
00353
00354 if (opt->filename != NULL)
00355 {
00356 load_file_to_analyse(main_window, opt->filename);
00357 }
00358
00359
00360 log_message(main_window, G_LOG_LEVEL_DEBUG, "Main_window : %p", main_window);
00361
00362 init_heraia_interface(main_window);
00363
00364
00365 gtk_main();
00366
00367 exit_value = TRUE;
00368 }
00369 else
00370 {
00371 fprintf(stderr, "File heraia.glade not found !\n");
00372 }
00373 }
00374
00375 return !exit_value;
00376 }