2008-09-12 [colin] 3.5.0cvs103
[claws.git] / src / quote_fmt_parse.y
index 6e29c2725e1cdacb33f9090fce579ab03f422982..762120c23ed0a5add218ea81ac3775a09041d50a 100644 (file)
@@ -47,7 +47,7 @@ int yylex(void);
 
 static MsgInfo *msginfo = NULL;
 static PrefsAccount *account = NULL;
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
 static gchar default_dictionary[BUFFSIZE];
 #endif
 static gboolean *visible = NULL;
@@ -55,6 +55,7 @@ static gboolean dry_run = FALSE;
 static gint maxsize = 0;
 static gint stacksize = 0;
 static GHashTable *var_table = NULL;
+static GList *attachments = NULL;
 
 typedef struct st_buffer
 {
@@ -75,6 +76,7 @@ static gint cursor_pos = -1;
 
 extern int quote_fmt_firsttime;
 extern int line;
+extern int escaped_string;
 
 static void add_visibility(gboolean val)
 {
@@ -138,6 +140,11 @@ gchar *quote_fmt_get_buffer(void)
                return current->buffer;
 }
 
+GList *quote_fmt_get_attachments_list(void)
+{
+       return attachments;
+}
+
 gint quote_fmt_get_line(void)
 {
        return line;
@@ -166,24 +173,35 @@ void quote_fmt_reset_vartable(void)
                g_hash_table_destroy(var_table);
                var_table = NULL;
        }
+       if (attachments) {
+               GList *cur = attachments;
+               while (cur) {
+                       g_free(cur->data);
+                       cur = g_list_next(cur);
+               }
+               g_list_free(attachments);
+               attachments = NULL;
+       }
 }
 
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
                    const gchar *my_body, gboolean my_dry_run,
                        PrefsAccount *compose_account,
+                       gboolean string_is_escaped,
                        GtkAspell *compose_gtkaspell)
 #else
 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
                    const gchar *my_body, gboolean my_dry_run,
-                       PrefsAccount *compose_account)
+                       PrefsAccount *compose_account,
+                       gboolean string_is_escaped)
 #endif
 {
        quote_str = my_quote_str;
        body = my_body;
        msginfo = info;
        account = compose_account;
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
        gchar *dict = gtkaspell_get_default_dictionary(compose_gtkaspell);
        if (dict)
                strncpy2(default_dictionary, dict, sizeof(default_dictionary));
@@ -199,6 +217,7 @@ void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
        clear_buffer();
        error = 0;
        line = 1;
+       escaped_string = string_is_escaped;
 
        if (!var_table)
                var_table = g_hash_table_new_full(g_str_hash, g_str_equal, 
@@ -503,6 +522,11 @@ static void quote_fmt_insert_user_input(const gchar *varname)
        g_free(text);
 }
 
+static void quote_fmt_attach_file(const gchar *filename)
+{
+       attachments = g_list_append(attachments, g_strdup(filename));
+}
+
 static gchar *quote_fmt_complete_address(const gchar *addr)
 {
        gint count;
@@ -582,6 +606,7 @@ static gchar *quote_fmt_complete_address(const gchar *addr)
 %token QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
 /* other tokens */
 %token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
+%token ATTACH_FILE
 %token OPARENT CPARENT
 %token CHARACTER
 %token SHOW_DATE_EXPR
@@ -613,7 +638,8 @@ character_or_special_or_insert_or_query:
        character_or_special
        | query
        | query_not
-       | insert ;
+       | insert
+       | attach ;
 
 character_or_special:
        special
@@ -634,7 +660,7 @@ string:
        }
        | string CHARACTER
        {
-               int len;
+               size_t len;
                
                strncpy($$, $1, sizeof($$));
                $$[sizeof($$) - 1] = '\0';
@@ -762,7 +788,7 @@ special:
        }
        | SHOW_ACCOUNT_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                if (account && account->enable_default_dictionary) {
                        gchar *dictname = g_path_get_basename(account->default_dictionary);
                        INSERT(dictname);
@@ -772,7 +798,7 @@ special:
        }
        | SHOW_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                INSERT(default_dictionary);
 #endif
        }
@@ -946,7 +972,7 @@ query:
        }
        | QUERY_ACCOUNT_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                add_visibility(account != NULL && account->enable_default_dictionary == TRUE &&
                                account->default_dictionary != NULL && *account->default_dictionary != '\0');
 #else
@@ -959,7 +985,7 @@ query:
        }
        | QUERY_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                add_visibility(*default_dictionary != '\0');
 #else
                add_visibility(FALSE);
@@ -1098,7 +1124,7 @@ query_not:
        }
        | QUERY_NOT_ACCOUNT_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                add_visibility(account == NULL || account->enable_default_dictionary == FALSE
                                || *account->default_dictionary == '\0');
 #else
@@ -1111,7 +1137,7 @@ query_not:
        }
        | QUERY_NOT_DICT
        {
-#ifdef USE_ASPELL
+#ifdef USE_ENCHANT
                add_visibility(*default_dictionary == '\0');
 #else
                add_visibility(FALSE);
@@ -1189,3 +1215,17 @@ insert:
                        quote_fmt_insert_user_input(sub_expr.buffer);
                }
        };
+
+attach:
+       ATTACH_FILE
+       {
+               current = &sub_expr;
+               clear_buffer();
+       }
+       OPARENT sub_expr CPARENT
+       {
+               current = &main_expr;
+               if (!dry_run) {
+                       quote_fmt_attach_file(sub_expr.buffer);
+               }
+       };