#include "defs.h"
-#include <ctype.h>
-#include <gtk/gtk.h>
#include <glib.h>
+#include <ctype.h>
#include "procmsg.h"
#include "procmime.h"
#include "utils.h"
#include "intl.h"
+#include "quote_fmt.h"
#include "quote_fmt_lex.h"
/* decl */
bison -p quote_fmt quote_fmt.y
*/
-static MsgInfo * msginfo = NULL;
-static gboolean * visible = NULL;
+int yylex(void);
+
+static MsgInfo *msginfo = NULL;
+static gboolean *visible = NULL;
static gint maxsize = 0;
static gint stacksize = 0;
-static gchar * buffer = NULL;
+static gchar *buffer = NULL;
static gint bufmax = 0;
static gint bufsize = 0;
-static gchar * quote_str = NULL;
+static const gchar *quote_str = NULL;
+static const gchar *body = NULL;
static gint error = 0;
static void add_visibility(gboolean val)
{
- stacksize ++;
+ stacksize++;
if (maxsize < stacksize) {
maxsize += 128;
visible = g_realloc(visible, maxsize * sizeof(gboolean));
visible[stacksize - 1] = val;
}
-static void remove_visibility()
+static void remove_visibility(void)
{
- stacksize --;
+ stacksize--;
}
-
-static void add_buffer(gchar * s)
+static void add_buffer(const gchar *s)
{
- gint len = strlen(s);
-
+ gint len;
+
+ len = strlen(s);
if (bufsize + len + 1 > bufmax) {
if (bufmax == 0)
bufmax = 128;
bufsize += len;
}
-static void flush_buffer()
+static void flush_buffer(void)
{
if (buffer != NULL)
- *buffer = 0;
+ *buffer = '\0';
bufsize = 0;
}
-gchar * quote_fmt_get_buffer()
+gchar *quote_fmt_get_buffer(void)
{
if (error != 0)
return NULL;
add_buffer(tmp); \
}
-void quote_fmt_init(MsgInfo * info, gchar * my_quote_str)
+void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
+ const gchar *my_body)
{
quote_str = my_quote_str;
+ body = my_body;
msginfo = info;
stacksize = 0;
add_visibility(TRUE);
error = 0;
}
-void quote_fmterror(char * str)
+void quote_fmterror(char *str)
{
- g_warning(_("Error %s\n"), str);
+ g_warning(_("Error: %s\n"), str);
error = 1;
}
%union {
char chr;
+ char str[256];
}
%token SHOW_NEWSGROUPS
%token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
%token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
%token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
-%token SHOW_EOL SHOW_QUESTION_MARK SHOW_OPARENT SHOW_CPARENT
+%token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
+%token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
%token QUERY_DATE QUERY_FROM
%token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
%token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
+%token INSERT_FILE INSERT_PROGRAMOUTPUT
%token OPARENT CPARENT
%token CHARACTER
%token <chr> CHARACTER
%type <chr> character
+%type <str> string
%%
quote_fmt:
- character_or_special_or_query_list;
+ character_or_special_or_insert_or_query_list;
-character_or_special_or_query_list:
- character_or_special_or_query character_or_special_or_query_list
- | character_or_special_or_query ;
+character_or_special_or_insert_or_query_list:
+ character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
+ | character_or_special_or_insert_or_query ;
-character_or_special_or_query:
- special ;
+character_or_special_or_insert_or_query:
+ special
| character
{
INSERT_CHARACTER($1);
}
| query ;
-
+ | insert ;
character:
CHARACTER
;
+string:
+ CHARACTER
+ {
+ $$[0] = $1;
+ $$[1] = '\0';
+ }
+ | string CHARACTER
+ {
+ strcpy($$, $1);
+ $$[strlen($$) + 1] = '\0';
+ $$[strlen($$)] = $2;
+ };
+
special:
SHOW_NEWSGROUPS
{
| SHOW_FIRST_NAME
{
if (msginfo->fromname) {
- gchar * p;
- gchar * str;
+ gchar *p;
+ gchar *str;
str = alloca(strlen(msginfo->fromname) + 1);
if (str != NULL) {
#define MAX_SENDER_INITIAL 20
if (msginfo->fromname) {
gchar tmp[MAX_SENDER_INITIAL];
- gchar * p;
- gchar * cur;
+ gchar *p;
+ gchar *cur;
gint len = 0;
p = msginfo->fromname;
while (*p) {
if (*p && isalnum(*p)) {
*cur = toupper(*p);
- cur ++;
- len ++;
+ cur++;
+ len++;
if (len >= MAX_SENDER_INITIAL - 1)
break;
- }
- else
+ } else
break;
while (*p && !isseparator(*p)) p++;
while (*p && isseparator(*p)) p++;
}
| SHOW_REFERENCES
{
- if (msginfo->references)
- INSERT(msginfo->references);
+ /* if (msginfo->references)
+ INSERT(msginfo->references); */
}
| SHOW_MESSAGE
{
- gchar buf[BUFFSIZE];
- FILE * fp;
-
- if ((fp = procmime_get_text_part(msginfo)) == NULL)
- g_warning(_("Can't get text part\n"));
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- INSERT(buf);
+ if (msginfo->folder) {
+ gchar buf[BUFFSIZE];
+ FILE *fp;
+
+ if (body)
+ fp = str_open_as_stream(body);
+ else
+ fp = procmime_get_first_text_content(msginfo);
+
+ if (fp == NULL)
+ g_warning(_("Can't get text part\n"));
+ else {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ strcrchomp(buf);
+ INSERT(buf);
+ }
+ fclose(fp);
+ }
}
- fclose(fp);
}
| SHOW_QUOTED_MESSAGE
{
- gchar buf[BUFFSIZE];
- FILE * fp;
+ if (msginfo->folder) {
+ gchar buf[BUFFSIZE];
+ FILE *fp;
+
+ if (body)
+ fp = str_open_as_stream(body);
+ else
+ fp = procmime_get_first_text_content(msginfo);
+
+ if (fp == NULL)
+ g_warning(_("Can't get text part\n"));
+ else {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ strcrchomp(buf);
+ if (quote_str)
+ INSERT(quote_str);
+ INSERT(buf);
+ }
+ fclose(fp);
+ }
+ }
+ }
+ | SHOW_MESSAGE_NO_SIGNATURE
+ {
+ if (msginfo->folder) {
+ gchar buf[BUFFSIZE];
+ FILE *fp;
+
+ if (body)
+ fp = str_open_as_stream(body);
+ else
+ fp = procmime_get_first_text_content(msginfo);
+
+ if (fp == NULL)
+ g_warning(_("Can't get text part\n"));
+ else {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ strcrchomp(buf);
+ if (strncmp(buf, "-- ", 3) == 0)
+ break;
+ INSERT(buf);
+ }
+ fclose(fp);
+ }
+ }
+ }
+ | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
+ {
+ if (msginfo->folder) {
+ gchar buf[BUFFSIZE];
+ FILE *fp;
- if ((fp = procmime_get_text_part(msginfo)) == NULL)
- g_warning(_("Can't get text part\n"));
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (quote_str)
- INSERT(quote_str);
- INSERT(buf);
+ if (body)
+ fp = str_open_as_stream(body);
+ else
+ fp = procmime_get_first_text_content(msginfo);
+
+ if (fp == NULL)
+ g_warning(_("Can't get text part\n"));
+ else {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ strcrchomp(buf);
+ if (strncmp(buf, "-- ", 3) == 0)
+ break;
+ if (quote_str)
+ INSERT(quote_str);
+ INSERT(buf);
+ }
+ fclose(fp);
+ }
}
- fclose(fp);
}
| SHOW_BACKSLASH
{
{
INSERT("?");
}
+ | SHOW_PIPE
+ {
+ INSERT("|");
+ }
| SHOW_OPARENT
{
- INSERT("(");
+ INSERT("{");
}
| SHOW_CPARENT
{
- INSERT(")");
+ INSERT("}");
};
query:
}
| QUERY_REFERENCES
{
- add_visibility(msginfo->references != NULL);
+ /* add_visibility(msginfo->references != NULL); */
}
OPARENT quote_fmt CPARENT
{
remove_visibility();
};
+
+insert:
+ INSERT_FILE OPARENT string CPARENT
+ {
+ {
+ FILE *file;
+ char buffer[256];
+
+ if(file = fopen($3, "r")) {
+ while(fgets(buffer, sizeof(buffer), file)) {
+ INSERT(buffer);
+ }
+ fclose(file);
+ }
+ }
+ }
+ | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
+ {
+ {
+ FILE *file;
+ char buffer[256];
+
+ if(file = popen($3, "r")) {
+ while(fgets(buffer, sizeof(buffer), file)) {
+ INSERT(buffer);
+ }
+ fclose(file);
+ }
+ }
+ };