diff options
author | b0ric <b0risov.alexandr@rambler.ru> | 2009-08-16 01:17:55 +0300 |
---|---|---|
committer | b0ric <b0risov.alexandr@rambler.ru> | 2009-08-16 01:17:55 +0300 |
commit | 3d4738a09d55010fa0d58f606f397ee09883b4c2 (patch) | |
tree | c061149db2c5de7b0151197d5a7377d498c5ad49 | |
parent | 9d2cc46e50218768b43d4f8b80647828bca74576 (diff) |
Fully working version
but i18n, automake and autoconf support is needed
-rw-r--r-- | confwin.c | 33 | ||||
-rw-r--r-- | engparser.h | 2 | ||||
-rw-r--r-- | main.c | 111 | ||||
-rw-r--r-- | main.h | 7 |
4 files changed, 145 insertions, 8 deletions
@@ -23,6 +23,13 @@ #include "main.h" static GtkWidget *conf_win; + +/*saving controls*/ +static GtkWidget *col_counter; +static GtkWidget *field_counter; +/*general parsing controls*/ +static GtkWidget *wcap_btn; +static GtkWidget *lower_first_cap; /*quote controls*/ static GtkWidget *wquot_btn; /*==excl_with_quoted_btn (here and below*/ static GtkWidget *quoted_btn; /*'excl_' part of vatiable name is omitted)*/ @@ -87,7 +94,7 @@ void create_conf_win() gtk_widget_show(col_label); GtkObject *col_adjust = gtk_adjustment_new(save_user_words.columns, 1, 10, 1, 2, 0); - GtkWidget *col_counter = gtk_spin_button_new(GTK_ADJUSTMENT(col_adjust), 0.5, 0); + col_counter = gtk_spin_button_new(GTK_ADJUSTMENT(col_adjust), 0.5, 0); gtk_widget_set_tooltip_text(col_counter, "Specify how many columns will be in the saved list of the words"); gtk_table_attach_defaults(GTK_TABLE(gen_table), col_counter, 5, 7, 1, 2); gtk_widget_show(col_counter); @@ -100,7 +107,7 @@ void create_conf_win() gtk_widget_show(field_label); GtkObject *field_adjust = gtk_adjustment_new(save_user_words.col_width, 10, 100, 1, 10, 0); - GtkWidget *field_counter = gtk_spin_button_new(GTK_ADJUSTMENT(field_adjust), 0.5, 0); + field_counter = gtk_spin_button_new(GTK_ADJUSTMENT(field_adjust), 0.5, 0); gtk_widget_set_tooltip_text(field_counter, "Specify length of one field (in symbols) in the saved list of the words"); gtk_widget_set_sensitive(field_counter, field_sens); gtk_table_attach_defaults(GTK_TABLE(gen_table), field_counter, 5, 7, 2, 3); @@ -136,12 +143,12 @@ void create_conf_win() gtk_widget_set_tooltip_text(lang_box, "Language of the text you want to analyse"); gtk_widget_show(lang_box); - GtkWidget *wcap_btn = gtk_check_button_new_with_label("Exclude words with capital letters"); + wcap_btn = gtk_check_button_new_with_label("Exclude words with capital letters"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wcap_btn), (gboolean) excl_w_capital); gtk_table_attach_defaults(GTK_TABLE(analys_table), wcap_btn, 0, 12, 1, 2); gtk_widget_show(wcap_btn); - GtkWidget *lower_first_cap = gtk_check_button_new_with_label("Lower first capital in each sentence"); + lower_first_cap = gtk_check_button_new_with_label("Lower first capital in each sentence"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lower_first_cap), (gboolean) lower_first_capital); gtk_table_attach_defaults(GTK_TABLE(analys_table), lower_first_cap, 0, 12, 2, 3); gtk_widget_show(lower_first_cap); @@ -271,7 +278,23 @@ void create_conf_win() static void ok_btn_click(GtkWidget *widget, gpointer data) { - + save_user_words.columns = (int) gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(col_counter)); + save_user_words.col_width = (int) gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(field_counter)); + /*lang = */ + excl_w_capital = (int) GTK_TOGGLE_BUTTON(wcap_btn)->active; + lower_first_capital = (int) GTK_TOGGLE_BUTTON(lower_first_cap)->active; + quote.excl_symbolled = (int) GTK_TOGGLE_BUTTON(quoted_btn)->active; + quote.excl_w_starting = (int) GTK_TOGGLE_BUTTON(st_quote_btn)->active; + quote.excl_w_middle = (int) GTK_TOGGLE_BUTTON(mid_quote_btn)->active; + quote.excl_word_after_symb = (int) GTK_TOGGLE_BUTTON(after_quote_btn)->active; + quote.excl_w_ending = (int) GTK_TOGGLE_BUTTON(end_quote_btn)->active; + hyphen.excl_symbolled = (int) GTK_TOGGLE_BUTTON(hyphened_btn)->active; + hyphen.excl_w_starting = (int) GTK_TOGGLE_BUTTON(st_hyphen_btn)->active; + hyphen.excl_w_middle = (int) GTK_TOGGLE_BUTTON(mid_hyphen_btn)->active; + hyphen.excl_word_after_symb = (int) GTK_TOGGLE_BUTTON(after_hyphen_btn)->active; + hyphen.excl_w_ending = (int) GTK_TOGGLE_BUTTON(end_hyphen_btn)->active; + + write_config(); gtk_widget_destroy(conf_win); } diff --git a/engparser.h b/engparser.h index ac0c4b0..ca0a1b5 100644 --- a/engparser.h +++ b/engparser.h @@ -33,8 +33,8 @@ typedef struct { } Parseoptions; /* Parsing options */ -extern int lower_first_capital; extern int excl_w_capital; +extern int lower_first_capital; extern Parseoptions hyphen; extern Parseoptions quote; @@ -17,17 +17,20 @@ * along with WordExtract. If not, see <http://www.gnu.org/licenses/>. */ +#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "main.h" #include "mainwin.h" #include "dict.h" +#include "engparser.h" Language lang; SaveOpt save_user_words = {2, 40}; char optpath[PATH_LENGTH] = {0}; char dictfile[PATH_LENGTH] = {0}; +char conffile[PATH_LENGTH] = {0}; static void fill_vars(); @@ -64,10 +67,116 @@ int main(int argc, char *argv[]) return 0; } -void fill_vars() +static void fill_vars() { strcpy(optpath, getenv("HOME")); strcat(optpath, OPT_FOLDER); strcat(dictfile, optpath); strcat(dictfile, DICT_FILE); + strcat(conffile, optpath); + strcat(conffile, CONF_FILE); + read_config(); } + +void create_config(char *path) +{ + mode_t mode_0755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; + struct stat st; + FILE *conf; + 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, CONF_FILE); + fprintf(stderr, "%s: Creating configuration file\n", file); + if (!(conf = fopen(file, "w"))) { + perror(file); + exit(1); + } + fclose(conf); +} + +void read_config() +{ + FILE *conf; + + if (!(conf = fopen(conffile, "r"))) { + perror(conffile); + create_config(optpath); + write_config(); + if (!(conf = fopen(dictfile, "r"))) { + perror(conffile); + exit(1); + } + } else { + char option[OPTION_LENGTH] = {0}; + char svalue[OPTION_LENGTH] = {0}; + while (fscanf(conf, "%s\t\t%s\n", option, svalue) != EOF) { + if (!strcmp(option, "columns")) { + save_user_words.columns = atoi(svalue); + } else if (!strcmp(option, "field")) { + save_user_words.col_width = atoi(svalue); + } else if (!strcmp(option, "language")) { + lang = atoi(svalue); + } else if (!strcmp(option, "exclude_with_capital")) { + excl_w_capital = atoi(svalue); + } else if (!strcmp(option, "lower_first_capital")) { + lower_first_capital = atoi(svalue); + } else if (!strcmp(option, "exclude_quoted")) { + quote.excl_symbolled = atoi(svalue); + } else if (!strcmp(option, "exclude_with_first_quote")) { + quote.excl_w_starting = atoi(svalue); + } else if (!strcmp(option, "exclude_with_middle_quote")) { + quote.excl_w_middle = atoi(svalue); + } else if (!strcmp(option, "exclude_part_after_quote")) { + quote.excl_word_after_symb = atoi(svalue); + } else if (!strcmp(option, "exclude_with_end_quote")) { + quote.excl_w_ending = atoi(svalue); + } else if (!strcmp(option, "exclude_hyphened")) { + hyphen.excl_symbolled = atoi(svalue); + } else if (!strcmp(option, "exclude_with_first_hyphen")) { + hyphen.excl_w_starting = atoi(svalue); + } else if (!strcmp(option, "exclude_with_middle_hyphen")) { + hyphen.excl_w_middle = atoi(svalue); + } else if (!strcmp(option, "exclude_part_after_hyphen")) { + hyphen.excl_word_after_symb = atoi(svalue); + } else if (!strcmp(option, "exclude_with_end_hyphen")) { + hyphen.excl_w_ending = atoi(svalue); + } + } + fclose(conf); + } +} + +void write_config() +{ + FILE *conf; + + if (!(conf = fopen(conffile, "w"))) + perror(conffile); + else { + fprintf(conf, "%s\t\t%d\n", "columns", save_user_words.columns); + fprintf(conf, "%s\t\t%d\n", "field", save_user_words.col_width); + fprintf(conf, "%s\t\t%d\n", "language", lang); + fprintf(conf, "%s\t\t%d\n", "exclude_with_capital", excl_w_capital); + fprintf(conf, "%s\t\t%d\n", "lower_first_capital", lower_first_capital); + fprintf(conf, "%s\t\t%d\n", "exclude_quoted", quote.excl_symbolled); + fprintf(conf, "%s\t\t%d\n", "exclude_with_first_quote", quote.excl_w_starting); + fprintf(conf, "%s\t\t%d\n", "exclude_with_middle_quote", quote.excl_w_middle); + fprintf(conf, "%s\t\t%d\n", "exclude_part_after_quote", quote.excl_word_after_symb); + fprintf(conf, "%s\t\t%d\n", "exclude_with_end_quote", quote.excl_w_ending); + fprintf(conf, "%s\t\t%d\n", "exclude_hyphened", hyphen.excl_symbolled); + fprintf(conf, "%s\t\t%d\n", "exclude_with_first_hyphen", hyphen.excl_w_starting); + fprintf(conf, "%s\t\t%d\n", "exclude_with_middle_hyphen", hyphen.excl_w_middle); + fprintf(conf, "%s\t\t%d\n", "exclude_part_after_hyphen", hyphen.excl_word_after_symb); + fprintf(conf, "%s\t\t%d\n", "exclude_with_end_hyphen", hyphen.excl_w_ending); + fclose(conf); + } +} + @@ -23,6 +23,8 @@ #define PATH_LENGTH 50 #define PROGNAME "wordextract" #define OPT_FOLDER "/.wordextract" +#define CONF_FILE "/config" +#define OPTION_LENGTH 30 /* maximum subtitle line and phrase length * it's not allocated dinamically 'cause it costs a lot of resources and * it can't be more than mean human reading speed in a half of a minute @@ -31,7 +33,7 @@ #define MAXLINE 300 #define MAXPHRASE 100 -typedef enum {ENG} Language; +typedef enum {ENG = 0} Language; typedef struct { unsigned int columns; unsigned int col_width; @@ -44,4 +46,7 @@ extern SaveOpt save_user_words; extern char optpath[PATH_LENGTH]; extern char dictfile[PATH_LENGTH]; +void read_config(); +void write_config(); + #endif /*MAIN_H*/ |