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 == '-';
132 %token SHOW_NEWSGROUPS
133 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME
134 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
135 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
136 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
137 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
138 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_OPARENT SHOW_CPARENT
139 %token QUERY_DATE QUERY_FROM
140 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
141 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
142 %token OPARENT CPARENT
147 %token <chr> CHARACTER
148 %type <chr> character
153 character_or_special_or_query_list;
155 character_or_special_or_query_list:
156 character_or_special_or_query character_or_special_or_query_list
157 | character_or_special_or_query ;
159 character_or_special_or_query:
163 INSERT_CHARACTER($1);
175 if (msginfo->newsgroups)
176 INSERT(msginfo->newsgroups);
181 INSERT(msginfo->date);
186 INSERT(msginfo->from);
190 if (msginfo->fromname)
191 INSERT(msginfo->fromname);
195 if (msginfo->fromname) {
199 str = alloca(strlen(msginfo->fromname) + 1);
201 strcpy(str, msginfo->fromname);
203 while (*p && !isspace(*p)) p++;
209 | SHOW_SENDER_INITIAL
211 #define MAX_SENDER_INITIAL 20
212 if (msginfo->fromname) {
213 gchar tmp[MAX_SENDER_INITIAL];
218 p = msginfo->fromname;
221 if (*p && isalnum(*p)) {
225 if (len >= MAX_SENDER_INITIAL - 1)
229 while (*p && !isseparator(*p)) p++;
230 while (*p && isseparator(*p)) p++;
238 if (msginfo->subject)
239 INSERT(msginfo->subject);
249 INSERT(msginfo->msgid);
262 /* if (msginfo->references)
263 INSERT(msginfo->references); */
267 if (msginfo->folder) {
272 fp = str_open_as_stream(body);
274 fp = procmime_get_first_text_content(msginfo);
277 g_warning(_("Can't get text part\n"));
279 while (fgets(buf, sizeof(buf), fp) != NULL) {
287 | SHOW_QUOTED_MESSAGE
289 if (msginfo->folder) {
294 fp = str_open_as_stream(body);
296 fp = procmime_get_first_text_content(msginfo);
299 g_warning(_("Can't get text part\n"));
301 while (fgets(buf, sizeof(buf), fp) != NULL) {
311 | SHOW_MESSAGE_NO_SIGNATURE
313 if (msginfo->folder) {
318 fp = str_open_as_stream(body);
320 fp = procmime_get_first_text_content(msginfo);
323 g_warning(_("Can't get text part\n"));
325 while (fgets(buf, sizeof(buf), fp) != NULL) {
327 if (strncmp(buf, "-- ", 3) == 0)
335 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
337 if (msginfo->folder) {
342 fp = str_open_as_stream(body);
344 fp = procmime_get_first_text_content(msginfo);
347 g_warning(_("Can't get text part\n"));
349 while (fgets(buf, sizeof(buf), fp) != NULL) {
351 if (strncmp(buf, "-- ", 3) == 0)
389 add_visibility(msginfo->date != NULL);
391 OPARENT quote_fmt CPARENT
397 add_visibility(msginfo->from != NULL);
399 OPARENT quote_fmt CPARENT
405 add_visibility(msginfo->fromname != NULL);
407 OPARENT quote_fmt CPARENT
413 add_visibility(msginfo->subject != NULL);
415 OPARENT quote_fmt CPARENT
421 add_visibility(msginfo->to != NULL);
423 OPARENT quote_fmt CPARENT
429 add_visibility(msginfo->newsgroups != NULL);
431 OPARENT quote_fmt CPARENT
437 add_visibility(msginfo->msgid != NULL);
439 OPARENT quote_fmt CPARENT
445 add_visibility(msginfo->cc != NULL);
447 OPARENT quote_fmt CPARENT
453 /* add_visibility(msginfo->references != NULL); */
455 OPARENT quote_fmt CPARENT