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
146 %token SHOW_DATE_EXPR
150 %token <chr> CHARACTER
151 %type <chr> character
157 character_or_special_or_insert_or_query_list;
159 character_or_special_or_insert_or_query_list:
160 character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
161 | character_or_special_or_insert_or_query ;
163 character_or_special_or_insert_or_query:
167 INSERT_CHARACTER($1);
185 $$[strlen($$) + 1] = '\0';
192 if (msginfo->newsgroups)
193 INSERT(msginfo->newsgroups);
195 | SHOW_DATE_EXPR OPARENT string CPARENT
197 if (msginfo->date_t) {
201 if (NULL != (lt = localtime(&msginfo->date_t))) {
202 strftime(timef, sizeof timef, $3, lt);
210 INSERT(msginfo->date);
215 INSERT(msginfo->from);
219 if (msginfo->fromname)
220 INSERT(msginfo->fromname);
224 if (msginfo->fromname) {
228 str = alloca(strlen(msginfo->fromname) + 1);
230 strcpy(str, msginfo->fromname);
232 while (*p && !isspace(*p)) p++;
240 /* This probably won't work together very well with Middle
241 names and the like - thth */
242 if (msginfo->fromname) {
246 str = alloca(strlen(msginfo->fromname) + 1);
248 strcpy(str, msginfo->fromname);
250 while (*p && !isspace(*p)) p++;
252 /* We found a space. Get first none-space char and
253 insert rest of string from there. */
254 while (*p && isspace(*p)) p++;
258 /* If there is no none-space char, just insert
263 /* If there is no space, just insert whole fromname. */
269 | SHOW_SENDER_INITIAL
271 #define MAX_SENDER_INITIAL 20
272 if (msginfo->fromname) {
273 gchar tmp[MAX_SENDER_INITIAL];
278 p = msginfo->fromname;
281 if (*p && isalnum(*p)) {
285 if (len >= MAX_SENDER_INITIAL - 1)
289 while (*p && !isseparator(*p)) p++;
290 while (*p && isseparator(*p)) p++;
298 if (msginfo->subject)
299 INSERT(msginfo->subject);
309 INSERT(msginfo->msgid);
322 /* if (msginfo->references)
323 INSERT(msginfo->references); */
327 if (msginfo->folder) {
332 fp = str_open_as_stream(body);
334 fp = procmime_get_first_text_content(msginfo);
337 g_warning(_("Can't get text part\n"));
339 while (fgets(buf, sizeof(buf), fp) != NULL) {
347 | SHOW_QUOTED_MESSAGE
349 if (msginfo->folder) {
354 fp = str_open_as_stream(body);
356 fp = procmime_get_first_text_content(msginfo);
359 g_warning(_("Can't get text part\n"));
361 while (fgets(buf, sizeof(buf), fp) != NULL) {
371 | SHOW_MESSAGE_NO_SIGNATURE
373 if (msginfo->folder) {
378 fp = str_open_as_stream(body);
380 fp = procmime_get_first_text_content(msginfo);
383 g_warning(_("Can't get text part\n"));
385 while (fgets(buf, sizeof(buf), fp) != NULL) {
387 if (strncmp(buf, "-- ", 3) == 0)
395 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
397 if (msginfo->folder) {
402 fp = str_open_as_stream(body);
404 fp = procmime_get_first_text_content(msginfo);
407 g_warning(_("Can't get text part\n"));
409 while (fgets(buf, sizeof(buf), fp) != NULL) {
411 if (strncmp(buf, "-- ", 3) == 0)
453 add_visibility(msginfo->date != NULL);
455 OPARENT quote_fmt CPARENT
461 add_visibility(msginfo->from != NULL);
463 OPARENT quote_fmt CPARENT
469 add_visibility(msginfo->fromname != NULL);
471 OPARENT quote_fmt CPARENT
477 add_visibility(msginfo->subject != NULL);
479 OPARENT quote_fmt CPARENT
485 add_visibility(msginfo->to != NULL);
487 OPARENT quote_fmt CPARENT
493 add_visibility(msginfo->newsgroups != NULL);
495 OPARENT quote_fmt CPARENT
501 add_visibility(msginfo->msgid != NULL);
503 OPARENT quote_fmt CPARENT
509 add_visibility(msginfo->cc != NULL);
511 OPARENT quote_fmt CPARENT
517 /* add_visibility(msginfo->references != NULL); */
519 OPARENT quote_fmt CPARENT
525 INSERT_FILE OPARENT string CPARENT
531 if(file = fopen($3, "rb")) {
532 while(fgets(buffer, sizeof(buffer), file)) {
539 | INSERT_PROGRAMOUTPUT OPARENT string CPARENT
545 if(file = popen($3, "r")) {
546 while(fgets(buffer, sizeof(buffer), file)) {