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 gchar
*quote_str
= NULL
;
33 static gint
error = 0;
35 static void add_visibility
(gboolean val
)
38 if
(maxsize
< stacksize
) {
40 visible
= g_realloc
(visible
, maxsize
* sizeof
(gboolean
));
45 visible
[stacksize
- 1] = val
;
48 static void remove_visibility
(void)
53 static void add_buffer
(gchar
*s
)
58 if
(bufsize
+ len
+ 1 > bufmax
) {
61 while
(bufsize
+ len
+ 1 > bufmax
)
63 buffer
= g_realloc
(buffer
, bufmax
);
65 strcpy
(buffer
+ bufsize
, s
);
69 static void flush_buffer
(void)
76 gchar
*quote_fmt_get_buffer
(void)
85 if
(stacksize
!= 0 && visible
[stacksize
- 1]) \
88 #define INSERT_CHARACTER(chr) \
89 if
(stacksize
!= 0 && visible
[stacksize
- 1]) { \
96 void quote_fmt_init
(MsgInfo
*info
, gchar
*my_quote_str
)
98 quote_str
= my_quote_str
;
101 add_visibility
(TRUE
);
108 void quote_fmterror
(char *str
)
110 g_warning
(_
("Error: %s\n"), str
);
114 int quote_fmtwrap
(void)
119 static int isseparator
(char ch
)
121 return isspace
(ch
) || ch
== '.' || ch
== '-';
129 %token SHOW_NEWSGROUPS
130 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME
131 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
132 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
133 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
134 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
135 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_OPARENT SHOW_CPARENT
136 %token QUERY_DATE QUERY_FROM
137 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
138 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
139 %token OPARENT CPARENT
144 %token
<chr
> CHARACTER
145 %type
<chr
> character
150 character_or_special_or_query_list
;
152 character_or_special_or_query_list:
153 character_or_special_or_query character_or_special_or_query_list
154 | character_or_special_or_query
;
156 character_or_special_or_query:
160 INSERT_CHARACTER
($1);
172 if
(msginfo
->newsgroups
)
173 INSERT
(msginfo
->newsgroups
);
178 INSERT
(msginfo
->date
);
183 INSERT
(msginfo
->from
);
187 if
(msginfo
->fromname
)
188 INSERT
(msginfo
->fromname
);
192 if
(msginfo
->fromname
) {
196 str
= alloca
(strlen
(msginfo
->fromname
) + 1);
198 strcpy
(str
, msginfo
->fromname
);
200 while
(*p
&& !isspace
(*p
)) p
++;
206 | SHOW_SENDER_INITIAL
208 #define MAX_SENDER_INITIAL 20
209 if
(msginfo
->fromname
) {
210 gchar tmp
[MAX_SENDER_INITIAL
];
215 p
= msginfo
->fromname
;
218 if
(*p
&& isalnum
(*p
)) {
222 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); */
264 if
(msginfo
->folder
) {
268 if
((fp
= procmime_get_first_text_content
(msginfo
))
270 g_warning
(_
("Can't get text part\n"));
272 while
(fgets
(buf
, sizeof
(buf
), fp
) != NULL
) {
280 | SHOW_QUOTED_MESSAGE
282 if
(msginfo
->folder
) {
286 if
((fp
= procmime_get_first_text_content
(msginfo
))
288 g_warning
(_
("Can't get text part\n"));
290 while
(fgets
(buf
, sizeof
(buf
), fp
) != NULL
) {
300 | SHOW_MESSAGE_NO_SIGNATURE
302 if
(msginfo
->folder
) {
306 if
((fp
= procmime_get_first_text_content
(msginfo
))
308 g_warning
(_
("Can't get text part\n"));
310 while
(fgets
(buf
, sizeof
(buf
), fp
) != NULL
) {
312 if
(strncmp
(buf
, "-- ", 3) == 0)
320 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
322 if
(msginfo
->folder
) {
326 if
((fp
= procmime_get_first_text_content
(msginfo
))
328 g_warning
(_
("Can't get text part\n"));
330 while
(fgets
(buf
, sizeof
(buf
), fp
) != NULL
) {
332 if
(strncmp
(buf
, "-- ", 3) == 0)
370 add_visibility
(msginfo
->date
!= NULL
);
372 OPARENT quote_fmt CPARENT
378 add_visibility
(msginfo
->from
!= NULL
);
380 OPARENT quote_fmt CPARENT
386 add_visibility
(msginfo
->fromname
!= NULL
);
388 OPARENT quote_fmt CPARENT
394 add_visibility
(msginfo
->subject
!= NULL
);
396 OPARENT quote_fmt CPARENT
402 add_visibility
(msginfo
->to
!= NULL
);
404 OPARENT quote_fmt CPARENT
410 add_visibility
(msginfo
->newsgroups
!= NULL
);
412 OPARENT quote_fmt CPARENT
418 add_visibility
(msginfo
->msgid
!= NULL
);
420 OPARENT quote_fmt CPARENT
426 add_visibility
(msginfo
->cc
!= NULL
);
428 OPARENT quote_fmt CPARENT
434 /* add_visibility(msginfo->references != NULL); */
436 OPARENT quote_fmt CPARENT