diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 61 |
1 files changed, 9 insertions, 52 deletions
@@ -16,79 +16,36 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "interface.h" -#include "subtitle.h" +#include "main.h" +#include "mainwin.h" #include "dict.h" -#define PROGNAME "wordextract" -#define OPT_FOLDER "/.wordextract" -#define PATH_LENGTH 50 - +char optpath[PATH_LENGTH] = {0}; +char dictfile[PATH_LENGTH] = {0}; Language lang; -static void create_dict_file(char *); -static void open_and_load_dict(); +static void fill_vars(); int main(int argc, char *argv[]) { - gtk_init(&argc, &argv); - open_and_load_dict(); + fill_vars(); + dict = load_dict(); lang = ENG; create_main_window(); gtk_widget_show(main_window); gtk_main(); - - free_words(dict); + free_words(dict); /*Where to put?*/ return 0; } -void create_dict_file(char *path) -{ - mode_t mode_0755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - struct stat st; - FILE *fdict; - char file[PATH_LENGTH] = {0}; - - if (stat(path, &st)) { - fprintf(stderr, "%s: Creating directory\n", path); - if (mkdir(path, mode_0755)) { - perror(path); - exit(1); - } - } - strcat(file, path); - strcat(file, DICT_FILE); - fprintf(stderr, "%s: Creating blank dictionary file\n", file); - if (!(fdict = fopen(file, "w"))) { - perror(file); - exit(1); - } - fclose(fdict); -} - -void open_and_load_dict() +void fill_vars() { - 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); } |