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 gchar *quote_fmt_get_buffer(void)
80 if (stacksize != 0 && visible[stacksize - 1]) \
83 #define INSERT_CHARACTER(chr) \
84 if (stacksize != 0 && visible[stacksize - 1]) { \
91 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
94 quote_str = my_quote_str;
105 void quote_fmterror(char *str)
107 g_warning(_("Error: %s\n"), str);
111 int quote_fmtwrap(void)
116 static int isseparator(char ch)
118 return isspace(ch) || ch == '.' || ch == '-';
127 %token SHOW_NEWSGROUPS
128 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME SHOW_LAST_NAME
129 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
130 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
131 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
132 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
133 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
134 %token QUERY_DATE QUERY_FROM
135 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
136 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
137 %token INSERT_FILE INSERT_PROGRAMOUTPUT
138 %token OPARENT CPARENT
140 %token SHOW_DATE_EXPR
144 %token <chr> CHARACTER
145 %type <chr> character
151 character_or_special_or_insert_or_query_list;
153 character_or_special_or_insert_or_query_list:
154 character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
155 | character_or_special_or_insert_or_query ;
157 character_or_special_or_insert_or_query:
161 INSERT_CHARACTER($1);
179 $$[strlen($$) + 1] = '\0';
186 if (msginfo->newsgroups)
187 INSERT(msginfo->newsgroups);
189 | SHOW_DATE_EXPR OPARENT string CPARENT
192 * ALF - GNU C's strftime() has a nice format specifier
193 * for time zone offset (%z). Non-standard however, so
204 #define RLEFT (sizeof result) - (rptr - result)
205 #define STR_SIZE(x) (sizeof (x) - 1)
209 if (procheader_date_parse_to_tm(msginfo->date, <, zone)) {
211 * break up format string in tiny bits delimited by valid %z's and
212 * feed it to strftime(). don't forget that '%%z' mean literal '%z'.
214 for (rptr = result, fptr = $3; fptr && *fptr && rptr < &result[sizeof result - 1];) {
219 if (NULL != (zptr = strstr(fptr, "%z"))) {
221 * count nr. of prepended percent chars
223 for (perc = 0, p = zptr; p && p >= $3 && *p == '%'; p--, perc++)
228 tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z")));
230 rptr += strftime(rptr, RLEFT, tmp, <);
234 * append time zone offset
236 if (zone[0] && perc % 2)
237 rptr += g_snprintf(rptr, RLEFT, "%s", zone);
238 fptr = zptr + STR_SIZE("%z");
240 rptr += strftime(rptr, RLEFT, fptr, <);
254 INSERT(msginfo->date);
259 INSERT(msginfo->from);
263 if (msginfo->fromname)
264 INSERT(msginfo->fromname);
268 if (msginfo->fromname) {
272 str = alloca(strlen(msginfo->fromname) + 1);
274 strcpy(str, msginfo->fromname);
276 while (*p && !isspace(*p)) p++;
284 /* This probably won't work together very well with Middle
285 names and the like - thth */
286 if (msginfo->fromname) {
290 str = alloca(strlen(msginfo->fromname) + 1);
292 strcpy(str, msginfo->fromname);
294 while (*p && !isspace(*p)) p++;
296 /* We found a space. Get first none-space char and
297 insert rest of string from there. */
298 while (*p && isspace(*p)) p++;
302 /* If there is no none-space char, just insert
307 /* If there is no space, just insert whole fromname. */
313 | SHOW_SENDER_INITIAL
315 #define MAX_SENDER_INITIAL 20
316 if (msginfo->fromname) {
317 gchar tmp[MAX_SENDER_INITIAL];
322 p = msginfo->fromname;
325 if (*p && isalnum(*p)) {
329 if (len >= MAX_SENDER_INITIAL - 1)
333 while (*p && !isseparator(*p)) p++;
334 while (*p && isseparator(*p)) p++;
342 if (msginfo->subject)
343 INSERT(msginfo->subject);
353 INSERT(msginfo->msgid);
366 /* if (msginfo->references)
367 INSERT(msginfo->references); */
371 if (msginfo->folder || body) {
376 fp = str_open_as_stream(body);
378 fp = procmime_get_first_text_content(msginfo);
381 g_warning(_("Can't get text part\n"));
383 while (fgets(buf, sizeof(buf), fp) != NULL) {
391 | SHOW_QUOTED_MESSAGE
393 if (msginfo->folder || body) {
398 fp = str_open_as_stream(body);
400 fp = procmime_get_first_text_content(msginfo);
403 g_warning(_("Can't get text part\n"));
405 while (fgets(buf, sizeof(buf), fp) != NULL) {
415 | SHOW_MESSAGE_NO_SIGNATURE
417 if (msginfo->folder || body) {
422 fp = str_open_as_stream(body);
424 fp = procmime_get_first_text_content(msginfo);
427 g_warning(_("Can't get text part\n"));
429 while (fgets(buf, sizeof(buf), fp) != NULL) {
431 if (strncmp(buf, "-- ", 3) == 0)
439 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
441 if (msginfo->folder || body) {
446 fp = str_open_as_stream(body);
448 fp = procmime_get_first_text_content(msginfo);
451 g_warning(_("Can't get text part\n"));
453 while (fgets(buf, sizeof(buf), fp) != NULL) {
455 if (strncmp(buf, "-- ", 3) == 0)
497 add_visibility(msginfo->date != NULL);
499 OPARENT quote_fmt CPARENT
505 add_visibility(msginfo->from != NULL);
507 OPARENT quote_fmt CPARENT
513 add_visibility(msginfo->fromname != NULL);
515 OPARENT quote_fmt CPARENT
521 add_visibility(msginfo->subject != NULL);
523 OPARENT quote_fmt CPARENT
529 add_visibility(msginfo->to != NULL);
531 OPARENT quote_fmt CPARENT
537 add_visibility(msginfo->newsgroups != NULL);
539 OPARENT quote_fmt CPARENT
545 add_visibility(msginfo->msgid != NULL);
547 OPARENT quote_fmt CPARENT
553 add_visibility(msginfo->cc != NULL);
555 OPARENT quote_fmt CPARENT
561 /* add_visibility(msginfo->references != NULL); */
563 OPARENT quote_fmt CPARENT
569 INSERT_FILE OPARENT string CPARENT
575 if((file = fopen($3, "rb")) != NULL) {
576 while(fgets(buffer, sizeof(buffer), file)) {
583 | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
589 if((file = popen($3, "r")) != NULL) {
590 while(fgets(buffer, sizeof(buffer), file)) {