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 SHOW_LAST_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++;
227 /* This probably won't work together very well with Middle
228 names and the like - thth */
229 if (msginfo->fromname) {
233 str = alloca(strlen(msginfo->fromname) + 1);
235 strcpy(str, msginfo->fromname);
237 while (*p && !isspace(*p)) p++;
239 /* We found a space. Get first none-space char and
240 insert rest of string from there. */
241 while (*p && isspace(*p)) p++;
245 /* If there is no none-space char, just insert
250 /* If there is no space, just insert whole fromname. */
256 | SHOW_SENDER_INITIAL
258 #define MAX_SENDER_INITIAL 20
259 if (msginfo->fromname) {
260 gchar tmp[MAX_SENDER_INITIAL];
265 p = msginfo->fromname;
268 if (*p && isalnum(*p)) {
272 if (len >= MAX_SENDER_INITIAL - 1)
276 while (*p && !isseparator(*p)) p++;
277 while (*p && isseparator(*p)) p++;
285 if (msginfo->subject)
286 INSERT(msginfo->subject);
296 INSERT(msginfo->msgid);
309 /* if (msginfo->references)
310 INSERT(msginfo->references); */
314 if (msginfo->folder) {
319 fp = str_open_as_stream(body);
321 fp = procmime_get_first_text_content(msginfo);
324 g_warning(_("Can't get text part\n"));
326 while (fgets(buf, sizeof(buf), fp) != NULL) {
334 | SHOW_QUOTED_MESSAGE
336 if (msginfo->folder) {
341 fp = str_open_as_stream(body);
343 fp = procmime_get_first_text_content(msginfo);
346 g_warning(_("Can't get text part\n"));
348 while (fgets(buf, sizeof(buf), fp) != NULL) {
358 | SHOW_MESSAGE_NO_SIGNATURE
360 if (msginfo->folder) {
365 fp = str_open_as_stream(body);
367 fp = procmime_get_first_text_content(msginfo);
370 g_warning(_("Can't get text part\n"));
372 while (fgets(buf, sizeof(buf), fp) != NULL) {
374 if (strncmp(buf, "-- ", 3) == 0)
382 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
384 if (msginfo->folder) {
389 fp = str_open_as_stream(body);
391 fp = procmime_get_first_text_content(msginfo);
394 g_warning(_("Can't get text part\n"));
396 while (fgets(buf, sizeof(buf), fp) != NULL) {
398 if (strncmp(buf, "-- ", 3) == 0)
440 add_visibility(msginfo->date != NULL);
442 OPARENT quote_fmt CPARENT
448 add_visibility(msginfo->from != NULL);
450 OPARENT quote_fmt CPARENT
456 add_visibility(msginfo->fromname != NULL);
458 OPARENT quote_fmt CPARENT
464 add_visibility(msginfo->subject != NULL);
466 OPARENT quote_fmt CPARENT
472 add_visibility(msginfo->to != NULL);
474 OPARENT quote_fmt CPARENT
480 add_visibility(msginfo->newsgroups != NULL);
482 OPARENT quote_fmt CPARENT
488 add_visibility(msginfo->msgid != NULL);
490 OPARENT quote_fmt CPARENT
496 add_visibility(msginfo->cc != NULL);
498 OPARENT quote_fmt CPARENT
504 /* add_visibility(msginfo->references != NULL); */
506 OPARENT quote_fmt CPARENT
512 INSERT_FILE OPARENT string CPARENT
518 if(file = fopen($3, "rb")) {
519 while(fgets(buffer, sizeof(buffer), file)) {
526 | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
532 if(file = popen($3, "r")) {
533 while(fgets(buffer, sizeof(buffer), file)) {