12 #include "procheader.h"
14 #include "quote_fmt.h"
15 #include "quote_fmt_lex.h"
20 bison -p quote_fmt quote_fmt.y
25 static MsgInfo *msginfo = NULL;
26 static gboolean *visible = NULL;
27 static gint maxsize = 0;
28 static gint stacksize = 0;
30 static gchar *buffer = NULL;
31 static gint bufmax = 0;
32 static gint bufsize = 0;
33 static const gchar *quote_str = NULL;
34 static const gchar *body = NULL;
35 static gint error = 0;
37 static void add_visibility(gboolean val)
40 if (maxsize < stacksize) {
42 visible = g_realloc(visible, maxsize * sizeof(gboolean));
47 visible[stacksize - 1] = val;
50 static void remove_visibility(void)
55 static void add_buffer(const gchar *s)
60 if (bufsize + len + 1 > bufmax) {
63 while (bufsize + len + 1 > bufmax)
65 buffer = g_realloc(buffer, bufmax);
67 strcpy(buffer + bufsize, s);
71 static void flush_buffer(void)
78 gchar *quote_fmt_get_buffer(void)
87 if (stacksize != 0 && visible[stacksize - 1]) \
90 #define INSERT_CHARACTER(chr) \
91 if (stacksize != 0 && visible[stacksize - 1]) { \
98 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
101 quote_str = my_quote_str;
105 add_visibility(TRUE);
112 void quote_fmterror(char *str)
114 g_warning(_("Error: %s\n"), str);
118 int quote_fmtwrap(void)
123 static int isseparator(char ch)
125 return isspace(ch) || ch == '.' || ch == '-';
134 %token SHOW_NEWSGROUPS
135 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME SHOW_LAST_NAME
136 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
137 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
138 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
139 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
140 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
141 %token QUERY_DATE QUERY_FROM
142 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
143 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
144 %token INSERT_FILE INSERT_PROGRAMOUTPUT
145 %token OPARENT CPARENT
147 %token SHOW_DATE_EXPR
151 %token <chr> CHARACTER
152 %type <chr> character
158 character_or_special_or_insert_or_query_list;
160 character_or_special_or_insert_or_query_list:
161 character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
162 | character_or_special_or_insert_or_query ;
164 character_or_special_or_insert_or_query:
168 INSERT_CHARACTER($1);
186 $$[strlen($$) + 1] = '\0';
193 if (msginfo->newsgroups)
194 INSERT(msginfo->newsgroups);
196 | SHOW_DATE_EXPR OPARENT string CPARENT
199 * ALF - GNU C's strftime() has a nice format specifier
200 * for time zone offset (%z). Non-standard however, so
211 #define RLEFT (sizeof result) - (rptr - result)
212 #define STR_SIZE(x) (sizeof (x) - 1)
216 if (procheader_date_parse_to_tm(msginfo->date, <, zone)) {
218 * break up format string in tiny bits delimited by valid %z's and
219 * feed it to strftime(). don't forget that '%%z' mean literal '%z'.
221 for (rptr = result, fptr = $3; fptr && *fptr && rptr < &result[sizeof result - 1];) {
226 if (NULL != (zptr = strstr(fptr, "%z"))) {
228 * count nr. of prepended percent chars
230 for (perc = 0, p = zptr; p && p >= $3 && *p == '%'; p--, perc++)
235 tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z")));
237 rptr += strftime(rptr, RLEFT, tmp, <);
241 * append time zone offset
243 if (zone[0] && perc % 2)
244 rptr += g_snprintf(rptr, RLEFT, "%s", zone);
245 fptr = zptr + STR_SIZE("%z");
247 rptr += strftime(rptr, RLEFT, fptr, <);
261 INSERT(msginfo->date);
266 INSERT(msginfo->from);
270 if (msginfo->fromname)
271 INSERT(msginfo->fromname);
275 if (msginfo->fromname) {
279 str = alloca(strlen(msginfo->fromname) + 1);
281 strcpy(str, msginfo->fromname);
283 while (*p && !isspace(*p)) p++;
291 /* This probably won't work together very well with Middle
292 names and the like - thth */
293 if (msginfo->fromname) {
297 str = alloca(strlen(msginfo->fromname) + 1);
299 strcpy(str, msginfo->fromname);
301 while (*p && !isspace(*p)) p++;
303 /* We found a space. Get first none-space char and
304 insert rest of string from there. */
305 while (*p && isspace(*p)) p++;
309 /* If there is no none-space char, just insert
314 /* If there is no space, just insert whole fromname. */
320 | SHOW_SENDER_INITIAL
322 #define MAX_SENDER_INITIAL 20
323 if (msginfo->fromname) {
324 gchar tmp[MAX_SENDER_INITIAL];
329 p = msginfo->fromname;
332 if (*p && isalnum(*p)) {
336 if (len >= MAX_SENDER_INITIAL - 1)
340 while (*p && !isseparator(*p)) p++;
341 while (*p && isseparator(*p)) p++;
349 if (msginfo->subject)
350 INSERT(msginfo->subject);
360 INSERT(msginfo->msgid);
373 /* if (msginfo->references)
374 INSERT(msginfo->references); */
378 if (msginfo->folder) {
383 fp = str_open_as_stream(body);
385 fp = procmime_get_first_text_content(msginfo);
388 g_warning(_("Can't get text part\n"));
390 while (fgets(buf, sizeof(buf), fp) != NULL) {
398 | SHOW_QUOTED_MESSAGE
400 if (msginfo->folder) {
405 fp = str_open_as_stream(body);
407 fp = procmime_get_first_text_content(msginfo);
410 g_warning(_("Can't get text part\n"));
412 while (fgets(buf, sizeof(buf), fp) != NULL) {
422 | SHOW_MESSAGE_NO_SIGNATURE
424 if (msginfo->folder) {
429 fp = str_open_as_stream(body);
431 fp = procmime_get_first_text_content(msginfo);
434 g_warning(_("Can't get text part\n"));
436 while (fgets(buf, sizeof(buf), fp) != NULL) {
438 if (strncmp(buf, "-- ", 3) == 0)
446 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
448 if (msginfo->folder) {
453 fp = str_open_as_stream(body);
455 fp = procmime_get_first_text_content(msginfo);
458 g_warning(_("Can't get text part\n"));
460 while (fgets(buf, sizeof(buf), fp) != NULL) {
462 if (strncmp(buf, "-- ", 3) == 0)
504 add_visibility(msginfo->date != NULL);
506 OPARENT quote_fmt CPARENT
512 add_visibility(msginfo->from != NULL);
514 OPARENT quote_fmt CPARENT
520 add_visibility(msginfo->fromname != NULL);
522 OPARENT quote_fmt CPARENT
528 add_visibility(msginfo->subject != NULL);
530 OPARENT quote_fmt CPARENT
536 add_visibility(msginfo->to != NULL);
538 OPARENT quote_fmt CPARENT
544 add_visibility(msginfo->newsgroups != NULL);
546 OPARENT quote_fmt CPARENT
552 add_visibility(msginfo->msgid != NULL);
554 OPARENT quote_fmt CPARENT
560 add_visibility(msginfo->cc != NULL);
562 OPARENT quote_fmt CPARENT
568 /* add_visibility(msginfo->references != NULL); */
570 OPARENT quote_fmt CPARENT
576 INSERT_FILE OPARENT string CPARENT
582 if(file = fopen($3, "rb")) {
583 while(fgets(buffer, sizeof(buffer), file)) {
590 | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
596 if(file = popen($3, "r")) {
597 while(fgets(buffer, sizeof(buffer), file)) {