diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 64 |
1 files changed, 26 insertions, 38 deletions
@@ -17,15 +17,12 @@ */ #include <sys/stat.h> -#include <gtk/gtk.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "interface.h" -#include "dict.h" -#include "word.h" #include "subtitle.h" -#include "srt.h" +#include "dict.h" #define PROGNAME "wordextract" #define OPT_FOLDER "/.wordextract" @@ -33,50 +30,20 @@ Language lang; -void create_dict_file(char *path); +static void create_dict_file(char *); +static void open_and_load_dict(); int main(int argc, char *argv[]) { - GtkWidget *main_window; - FILE *subtitle; - FILE *fdict; - char optpath[PATH_LENGTH] = {0}; - char dictfile[PATH_LENGTH] = {0}; gtk_init(&argc, &argv); - - strcpy(optpath, getenv("HOME")); - strcat(optpath, OPT_FOLDER); - strcat(dictfile, optpath); - strcat(dictfile, DICT_FILE); - if (!(fdict = fopen(dictfile, "r"))) { - perror(dictfile); - create_dict_file(optpath); - if (!(fdict = fopen(dictfile, "r"))) { - perror(dictfile); - exit(1); - } - } - dict = load_dict(fdict); + open_and_load_dict(); lang = ENG; - - main_window = create_main_window(); + create_main_window(); gtk_widget_show(main_window); - - /*main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(main_window), "WordExtract"); - gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600); - gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER); - gtk_widget_show(main_window);*/ - gtk_main(); - //TODO: process subtitle extension to detect format - //process_srt(subtitle); - //print_words(words); - //fclose(subtitle); free_words(dict); - fclose(fdict); return 0; } @@ -104,3 +71,24 @@ void create_dict_file(char *path) fclose(fdict); } +void open_and_load_dict() +{ + FILE *fdict; + char optpath[PATH_LENGTH] = {0}; + char dictfile[PATH_LENGTH] = {0}; + + strcpy(optpath, getenv("HOME")); + strcat(optpath, OPT_FOLDER); + strcat(dictfile, optpath); + strcat(dictfile, DICT_FILE); + if (!(fdict = fopen(dictfile, "r"))) { + perror(dictfile); + create_dict_file(optpath); + if (!(fdict = fopen(dictfile, "r"))) { + perror(dictfile); + exit(1); + } + } + dict = load_dict(fdict); + fclose(fdict); +} |