1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: editorial.c 768 2007-10-24 00:10:03Z hubert@u.washington.edu $";
5 /* ========================================================================
6 * Copyright 2013-2021 Eduardo Chappa
7 * Copyright 2006-2007 University of Washington
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * ========================================================================
18 /*======================================================================
21 Implements editorial text insertion/formatting
26 #include "../pith/headers.h"
27 #include "../pith/conf.h"
28 #include "../pith/state.h"
29 #include "../pith/margin.h"
30 #include "../pith/filter.h"
31 #include "../pith/handle.h"
32 #include "../pith/mailview.h"
33 #include "../pith/editorial.h"
38 int quote_editorial(long, char *, LT_INS_S
**, void *);
42 * Struct to help with editorial comment insertion
44 #define EDITORIAL_MAX 128
45 typedef struct _editorial_s
{
46 char prefix
[EDITORIAL_MAX
];
48 char postfix
[EDITORIAL_MAX
];
55 format_editorial(char *s
, int width
, int flags
, HANDLE_S
**handlesp
, gf_io_t pc
)
62 /* ASSUMPTION #2,341: All MIME-decoding is done by now */
63 gf_set_readc(&gc
, s
, strlen(s
), CharStar
, 0);
65 margin
= format_view_margin();
66 if(flags
& FM_NOINDENT
)
67 margin
[0] = margin
[1] = 0;
70 if(width
- (margin
[0] + margin
[1]) < 5){
71 margin
[0] = margin
[1] = 0;
76 width
-= (margin
[0] + margin
[1]);
81 es
.prelen
= MAX(2, MIN(margin
[0] + 6, sizeof(es
.prefix
) - 3));
82 snprintf(es
.prefix
, sizeof(es
.prefix
), "%s[ ", repeat_char(es
.prelen
- 2, ' '));
84 strncpy(es
.postfix
, " ]", sizeof(es
.postfix
));
85 es
.postfix
[sizeof(es
.postfix
)-1] = '\0';
90 es
.prelen
= MAX(2, MIN(margin
[0] + 3, sizeof(es
.prefix
) - 3));
91 snprintf(es
.prefix
, sizeof(es
.prefix
), "%s[ ", repeat_char(es
.prelen
- 2, ' '));
93 strncpy(es
.postfix
, " ]", sizeof(es
.postfix
));
94 es
.postfix
[sizeof(es
.postfix
)-1] = '\0';
98 strncpy(es
.prefix
, "[", sizeof(es
.prefix
));
99 es
.prefix
[sizeof(es
.prefix
)-1] = '\0';
100 strncpy(es
.postfix
, "]", sizeof(es
.postfix
));
101 es
.postfix
[sizeof(es
.postfix
)-1] = '\0';
106 es
.do_color
= (!(flags
& FM_NOCOLOR
) && (flags
& FM_DISPLAY
) && pico_usingcolor());
111 if((F_ON(F_VIEW_SEL_URL
, ps_global
)
112 || F_ON(F_VIEW_SEL_URL_HOST
, ps_global
)
113 || F_ON(F_SCAN_ADDR
, ps_global
))
115 gf_link_filter(gf_line_test
,
116 gf_line_test_opt(url_hilite
,
117 gf_url_hilite_opt(&uh
,handlesp
,0)));
120 gf_link_filter(gf_wrap
, gf_wrap_filter_opt(width
, width
, NULL
, 0,
121 (handlesp
? GFW_HANDLES
: GFW_NONE
)));
122 gf_link_filter(gf_line_test
, gf_line_test_opt(quote_editorial
, &es
));
124 /* If not for display, change to local end of line */
125 if(!(flags
& FM_DISPLAY
))
126 gf_link_filter(gf_nvtnl_local
, NULL
);
128 return(gf_pipe(gc
, pc
));
133 quote_editorial(long int linenum
, char *line
, LT_INS_S
**ins
, void *local
)
135 COLOR_PAIR
*col
= NULL
;
137 ins
= gf_line_test_new_ins(ins
, line
,
138 ((EDITORIAL_S
*)local
)->prefix
,
139 ((EDITORIAL_S
*)local
)->prelen
);
140 if(((EDITORIAL_S
*)local
)->do_color
141 && ps_global
->VAR_METAMSG_FORE_COLOR
142 && ps_global
->VAR_METAMSG_BACK_COLOR
143 && (col
= new_color_pair(ps_global
->VAR_METAMSG_FORE_COLOR
,
144 ps_global
->VAR_METAMSG_BACK_COLOR
))){
145 if(!pico_is_good_colorpair(col
))
146 free_color_pair(&col
);
150 char normal_embed
[(2 * RGBLEN
) + 5];
151 char quote_color_embed
[(2 * RGBLEN
) + 5];
153 strncpy(quote_color_embed
,
154 color_embed(col
->fg
, col
->bg
),
155 sizeof(quote_color_embed
));
156 quote_color_embed
[sizeof(quote_color_embed
)-1] = '\0';
158 ins
= gf_line_test_new_ins(ins
, line
,
159 quote_color_embed
, (2 * RGBLEN
) + 4);
162 * If there was already a color change back to normal color
163 * in the line that was passed in, then instead of allowing
164 * that color change back to normal we want to change that
165 * to a color change back to our METAMSG color instead.
166 * Search line for that and modify it.
169 strncpy(normal_embed
,
170 color_embed(ps_global
->VAR_NORM_FORE_COLOR
,
171 ps_global
->VAR_NORM_BACK_COLOR
),
172 sizeof(normal_embed
));
173 normal_embed
[sizeof(normal_embed
)-1] = '\0';
175 for(p
= line
; (p
= strstr(p
, normal_embed
)); p
++){
178 * Replace the normal color with our special quoting
179 * color. No need to change it if there are no
180 * characters after the color change because we're
181 * going to change the color to normal right below
184 if(strlen(p
) > strlen(quote_color_embed
))
185 rplstr(p
, strlen(p
)+1, strlen(quote_color_embed
), quote_color_embed
);
188 ins
= gf_line_test_new_ins(ins
, line
+strlen(line
),
189 normal_embed
, (2 * RGBLEN
) + 4);
190 free_color_pair(&col
);
194 ins
= gf_line_test_new_ins(ins
, line
+ strlen(line
),
195 ((EDITORIAL_S
*)local
)->postfix
,
196 ((EDITORIAL_S
*)local
)->postlen
);