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_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
134 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_OPARENT SHOW_CPARENT
135 %token QUERY_DATE QUERY_FROM
136 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
137 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
138 %token OPARENT CPARENT
143 %token <chr> CHARACTER
144 %type <chr> character
149 character_or_special_or_query_list;
151 character_or_special_or_query_list:
152 character_or_special_or_query character_or_special_or_query_list
153 | character_or_special_or_query ;
155 character_or_special_or_query:
159 INSERT_CHARACTER($1);
171 if (msginfo->newsgroups)
172 INSERT(msginfo->newsgroups);
177 INSERT(msginfo->date);
182 INSERT(msginfo->from);
186 if (msginfo->fromname)
187 INSERT(msginfo->fromname);
191 if (msginfo->fromname) {
195 str = alloca(strlen(msginfo->fromname) + 1);
197 strcpy(str, msginfo->fromname);
199 while (*p && !isspace(*p)) p++;
205 | SHOW_SENDER_INITIAL
207 #define MAX_SENDER_INITIAL 20
208 if (msginfo->fromname) {
209 gchar tmp[MAX_SENDER_INITIAL];
214 p = msginfo->fromname;
217 if (*p && isalnum(*p)) {
221 if (len >= MAX_SENDER_INITIAL - 1)
226 while (*p && !isseparator(*p)) p++;
227 while (*p && isseparator(*p)) p++;
235 if (msginfo->subject)
236 INSERT(msginfo->subject);
246 INSERT(msginfo->msgid);
259 if (msginfo->references)
260 INSERT(msginfo->references);
267 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
268 g_warning(_("Can't get text part\n"));
269 while (fgets(buf, sizeof(buf), fp) != NULL) {
274 | SHOW_QUOTED_MESSAGE
279 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
280 g_warning(_("Can't get text part\n"));
281 while (fgets(buf, sizeof(buf), fp) != NULL) {
288 | SHOW_MESSAGE_NO_SIGNATURE
293 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
294 g_warning(_("Can't get text part\n"));
295 while (fgets(buf, sizeof(buf), fp) != NULL) {
296 if (strncmp(buf, "-- ", 3) == 0)
302 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
307 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
308 g_warning(_("Can't get text part\n"));
309 while (fgets(buf, sizeof(buf), fp) != NULL) {
310 if (strncmp(buf, "-- ", 3) == 0)
346 add_visibility(msginfo->date != NULL);
348 OPARENT quote_fmt CPARENT
354 add_visibility(msginfo->from != NULL);
356 OPARENT quote_fmt CPARENT
362 add_visibility(msginfo->fromname != NULL);
364 OPARENT quote_fmt CPARENT
370 add_visibility(msginfo->subject != NULL);
372 OPARENT quote_fmt CPARENT
378 add_visibility(msginfo->to != NULL);
380 OPARENT quote_fmt CPARENT
386 add_visibility(msginfo->newsgroups != NULL);
388 OPARENT quote_fmt CPARENT
394 add_visibility(msginfo->msgid != NULL);
396 OPARENT quote_fmt CPARENT
402 add_visibility(msginfo->cc != NULL);
404 OPARENT quote_fmt CPARENT
410 add_visibility(msginfo->references != NULL);
412 OPARENT quote_fmt CPARENT