summaryrefslogtreecommitdiff
path: root/main.c
blob: 349942dfbc9a897d3b698bad84a7becfe122f8c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* This file is a part of WordExtract project
 *
 * Copyright (C) 2009 Borisov Alexandr
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#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"

#define PROGNAME "wordextract"
#define OPT_FOLDER "/.wordextract"
#define PATH_LENGTH 50

Language lang;

void create_dict_file(char *path);

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); 
 lang = ENG;

 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;
}

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);
}