13 #include "quote_fmt.h"
14 #include "quote_fmt_lex.h"
19 bison -p quote_fmt quote_fmt.y
24 static MsgInfo *msginfo = NULL;
25 static gboolean *visible = NULL;
26 static gint maxsize = 0;
27 static gint stacksize = 0;
29 static gchar *buffer = NULL;
30 static gint bufmax = 0;
31 static gint bufsize = 0;
32 static const gchar *quote_str = NULL;
33 static const gchar *body = NULL;
34 static gint error = 0;
36 static void add_visibility(gboolean val)
39 if (maxsize < stacksize) {
41 visible = g_realloc(visible, maxsize * sizeof(gboolean));
46 visible[stacksize - 1] = val;
49 static void remove_visibility(void)
54 static void add_buffer(const gchar *s)
59 if (bufsize + len + 1 > bufmax) {
62 while (bufsize + len + 1 > bufmax)
64 buffer = g_realloc(buffer, bufmax);
66 strcpy(buffer + bufsize, s);
70 static void flush_buffer(void)
77 gchar *quote_fmt_get_buffer(void)
86 if (stacksize != 0 && visible[stacksize - 1]) \
89 #define INSERT_CHARACTER(chr) \
90 if (stacksize != 0 && visible[stacksize - 1]) { \
97 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
100 quote_str = my_quote_str;
104 add_visibility(TRUE);
111 void quote_fmterror(char *str)
113 g_warning(_("Error: %s\n"), str);
117 int quote_fmtwrap(void)
122 static int isseparator(char ch)
124 return isspace(ch) || ch == '.' || ch == '-';
133 %token SHOW_NEWSGROUPS
134 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME
135 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
136 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
137 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
138 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
139 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
140 %token QUERY_DATE QUERY_FROM
141 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
142 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
143 %token INSERT_FILE INSERT_PROGRAMOUTPUT
144 %token OPARENT CPARENT
149 %token <chr> CHARACTER
150 %type <chr> character
156 character_or_special_or_insert_or_query_list;
158 character_or_special_or_insert_or_query_list:
159 character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
160 | character_or_special_or_insert_or_query ;
162 character_or_special_or_insert_or_query:
166 INSERT_CHARACTER($1);
184 $$[strlen($$) + 1] = '\0';
191 if (msginfo->newsgroups)
192 INSERT(msginfo->newsgroups);
197 INSERT(msginfo->date);
202 INSERT(msginfo->from);
206 if (msginfo->fromname)
207 INSERT(msginfo->fromname);
211 if (msginfo->fromname) {
215 str = alloca(strlen(msginfo->fromname) + 1);
217 strcpy(str, msginfo->fromname);
219 while (*p && !isspace(*p)) p++;
225 | SHOW_SENDER_INITIAL
227 #define MAX_SENDER_INITIAL 20
228 if (msginfo->fromname) {
229 gchar tmp[MAX_SENDER_INITIAL];
234 p = msginfo->fromname;
237 if (*p && isalnum(*p)) {
241 if (len >= MAX_SENDER_INITIAL - 1)
245 while (*p && !isseparator(*p)) p++;
246 while (*p && isseparator(*p)) p++;
254 if (msginfo->subject)
255 INSERT(msginfo->subject);
265 INSERT(msginfo->msgid);
278 /* if (msginfo->references)
279 INSERT(msginfo->references); */
283 if (msginfo->folder) {
288 fp = str_open_as_stream(body);
290 fp = procmime_get_first_text_content(msginfo);
293 g_warning(_("Can't get text part\n"));
295 while (fgets(buf, sizeof(buf), fp) != NULL) {
303 | SHOW_QUOTED_MESSAGE
305 if (msginfo->folder) {
310 fp = str_open_as_stream(body);
312 fp = procmime_get_first_text_content(msginfo);
315 g_warning(_("Can't get text part\n"));
317 while (fgets(buf, sizeof(buf), fp) != NULL) {
327 | SHOW_MESSAGE_NO_SIGNATURE
329 if (msginfo->folder) {
334 fp = str_open_as_stream(body);
336 fp = procmime_get_first_text_content(msginfo);
339 g_warning(_("Can't get text part\n"));
341 while (fgets(buf, sizeof(buf), fp) != NULL) {
343 if (strncmp(buf, "-- ", 3) == 0)
351 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
353 if (msginfo->folder) {
358 fp = str_open_as_stream(body);
360 fp = procmime_get_first_text_content(msginfo);
363 g_warning(_("Can't get text part\n"));
365 while (fgets(buf, sizeof(buf), fp) != NULL) {
367 if (strncmp(buf, "-- ", 3) == 0)
409 add_visibility(msginfo->date != NULL);
411 OPARENT quote_fmt CPARENT
417 add_visibility(msginfo->from != NULL);
419 OPARENT quote_fmt CPARENT
425 add_visibility(msginfo->fromname != NULL);
427 OPARENT quote_fmt CPARENT
433 add_visibility(msginfo->subject != NULL);
435 OPARENT quote_fmt CPARENT
441 add_visibility(msginfo->to != NULL);
443 OPARENT quote_fmt CPARENT
449 add_visibility(msginfo->newsgroups != NULL);
451 OPARENT quote_fmt CPARENT
457 add_visibility(msginfo->msgid != NULL);
459 OPARENT quote_fmt CPARENT
465 add_visibility(msginfo->cc != NULL);
467 OPARENT quote_fmt CPARENT
473 /* add_visibility(msginfo->references != NULL); */
475 OPARENT quote_fmt CPARENT
481 INSERT_FILE OPARENT string CPARENT
487 if(file = fopen($3, "r")) {
488 while(fgets(buffer, sizeof(buffer), file)) {
494 | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
500 if(file = popen($3, "r")) {
501 while(fgets(buffer, sizeof(buffer), file)) {