14 #include "quote_fmt.h"
15 #include "quote_fmt_lex.h"
20 bison -p quote_fmt quote_fmt.y
23 static MsgInfo * msginfo = NULL;
24 static gboolean * visible = NULL;
25 static gint maxsize = 0;
26 static gint stacksize = 0;
28 static gchar * buffer = NULL;
29 static gint bufmax = 0;
30 static gint bufsize = 0;
31 static gchar * quote_str = NULL;
32 static gint error = 0;
34 static void add_visibility(gboolean val)
37 if (maxsize < stacksize) {
39 visible = g_realloc(visible, maxsize * sizeof(gboolean));
44 visible[stacksize - 1] = val;
47 static void remove_visibility()
53 static void add_buffer(gchar * s)
57 if (bufsize + len + 1 > bufmax) {
60 while (bufsize + len + 1 > bufmax)
62 buffer = g_realloc(buffer, bufmax);
64 strcpy(buffer + bufsize, s);
68 static void flush_buffer()
75 gchar * quote_fmt_get_buffer()
84 if (stacksize != 0 && visible[stacksize - 1]) \
87 #define INSERT_CHARACTER(chr) \
88 if (stacksize != 0 && visible[stacksize - 1]) { \
95 void quote_fmt_init(MsgInfo * info, gchar * my_quote_str)
97 quote_str = my_quote_str;
100 add_visibility(TRUE);
107 void quote_fmterror(char * str)
109 g_warning(_("Error %s\n"), str);
113 int quote_fmtwrap(void)
118 static int isseparator(char ch)
120 return isspace(ch) || ch == '.' || ch == '-';
128 %token SHOW_NEWSGROUPS
129 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME
130 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
131 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
132 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
133 %token SHOW_EOL SHOW_QUESTION_MARK 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 OPARENT CPARENT
142 %token <chr> CHARACTER
143 %type <chr> character
148 character_or_special_or_query_list;
150 character_or_special_or_query_list:
151 character_or_special_or_query character_or_special_or_query_list
152 | character_or_special_or_query ;
154 character_or_special_or_query:
158 INSERT_CHARACTER($1);
170 if (msginfo->newsgroups)
171 INSERT(msginfo->newsgroups);
176 INSERT(msginfo->date);
181 INSERT(msginfo->from);
185 if (msginfo->fromname)
186 INSERT(msginfo->fromname);
190 if (msginfo->fromname) {
194 str = alloca(strlen(msginfo->fromname) + 1);
196 strcpy(str, msginfo->fromname);
198 while (*p && !isspace(*p)) p++;
204 | SHOW_SENDER_INITIAL
206 #define MAX_SENDER_INITIAL 20
207 if (msginfo->fromname) {
208 gchar tmp[MAX_SENDER_INITIAL];
213 p = msginfo->fromname;
216 if (*p && isalnum(*p)) {
220 if (len >= MAX_SENDER_INITIAL - 1)
225 while (*p && !isseparator(*p)) p++;
226 while (*p && isseparator(*p)) p++;
234 if (msginfo->subject)
235 INSERT(msginfo->subject);
245 INSERT(msginfo->msgid);
258 if (msginfo->references)
259 INSERT(msginfo->references);
266 if ((fp = procmime_get_text_part(msginfo)) == NULL)
267 g_warning(_("Can't get text part\n"));
268 while (fgets(buf, sizeof(buf), fp) != NULL) {
273 | SHOW_QUOTED_MESSAGE
278 if ((fp = procmime_get_text_part(msginfo)) == NULL)
279 g_warning(_("Can't get text part\n"));
280 while (fgets(buf, sizeof(buf), fp) != NULL) {
315 add_visibility(msginfo->date != NULL);
317 OPARENT quote_fmt CPARENT
323 add_visibility(msginfo->from != NULL);
325 OPARENT quote_fmt CPARENT
331 add_visibility(msginfo->fromname != NULL);
333 OPARENT quote_fmt CPARENT
339 add_visibility(msginfo->subject != NULL);
341 OPARENT quote_fmt CPARENT
347 add_visibility(msginfo->to != NULL);
349 OPARENT quote_fmt CPARENT
355 add_visibility(msginfo->newsgroups != NULL);
357 OPARENT quote_fmt CPARENT
363 add_visibility(msginfo->msgid != NULL);
365 OPARENT quote_fmt CPARENT
371 add_visibility(msginfo->cc != NULL);
373 OPARENT quote_fmt CPARENT
379 add_visibility(msginfo->references != NULL);
381 OPARENT quote_fmt CPARENT