summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorb0ric <b0risov.alexandr@rambler.ru>2009-08-03 00:49:26 +0300
committerb0ric <b0risov.alexandr@rambler.ru>2009-08-03 00:49:26 +0300
commite8349635329344f2c152d68c5dcaf65a7d385f9c (patch)
treefe28e7e2ba2c57571a959a4a2fa5708b68a63cd1 /main.c
parenteda41ef53d2f2633d6319e6f31d0052308d66513 (diff)
Basic console version of wordextract project
Diffstat (limited to 'main.c')
-rw-r--r--main.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/main.c b/main.c
index e69de29..e944736 100644
--- a/main.c
+++ b/main.c
@@ -0,0 +1,100 @@
+/* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.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[])
+{
+ FILE *subtitle;
+ FILE *fdict;
+ char optpath[PATH_LENGTH] = {0};
+ char dictfile[PATH_LENGTH] = {0};
+
+ if (argc == 2) {
+ if (!(subtitle = fopen(argv[1], "r"))) {
+ perror(argv[1]);
+ exit(1);
+ }
+ }
+ else {
+ printf("Usage: %s <subtitle filename>\n", argv[0]);
+ exit(1);
+ }
+ 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);
+
+ //TODO: process subtitle extension to detect format
+ lang = ENG;
+ 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(stdout, "%s: Creating directory\n", path);
+ if (mkdir(path, mode_0755)) {
+ perror(path);
+ exit(1);
+ }
+ }
+ strcat(file, path);
+ strcat(file, DICT_FILE);
+ fprintf(stdout, "%s: Creating blank dictionary file\n", file);
+ if (!(fdict = fopen(file, "w"))) {
+ perror(file);
+ exit(1);
+ }
+ fclose(fdict);
+}
+