]>
diplodocus.org Git - nmh/blob - sbr/fmt_scan.c
1 /* fmt_scan.c -- format string interpretation
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
7 * This is the engine that processes the format instructions created by
8 * fmt_compile (found in fmt_compile.c).
15 #include "fmt_rfc2047.h"
17 #include "context_find.h"
19 #include "h/addrsbr.h"
20 #include "h/fmt_scan.h"
22 #include "h/fmt_compile.h"
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
30 #ifdef MULTIBYTE_SUPPORT
35 struct mailname fmt_mnull
= { NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0, 0, 0,
41 static int match (char *, char *) PURE
;
45 * test if string "sub" appears anywhere in
46 * string "str" (case insensitive).
50 match (char *str
, char *sub
)
56 c1
= tolower((unsigned char)c1
);
57 while ((c2
= *str
++) && c1
!= tolower((unsigned char)c2
))
61 s1
= sub
+ 1; s2
= str
;
62 while ((c1
= *s1
++) &&
63 tolower((unsigned char)c1
) == tolower((unsigned char)(c2
= *s2
++)))
71 /* cpnumber formats num as a signed decimal,
72 * appending it to dest if the result doesn't exceed max.
73 * The absolute value of width is the minimum width to produce.
74 * A smaller string is padded;
75 * on the left if width is positive, else the right.
76 * Left-padding uses fill. It is either ' ' or '0'.
77 * Right-padding is always with space. */
79 cpnumber(charstring_t dest
, int num
, int width
, char fill
, size_t max
)
81 if (width
== 0 || width
== INT_MIN
) {
85 bool padright
= width
< 0;
87 width
= -width
; /* Can't overflow after above check. */
91 return; /* The padded result can't fit. */
93 if (num
< 0 && w
== 1) {
94 return; /* No room for `-' and a digit or `?'. */
98 size_t len
= strlen(s
);
100 charstring_append_cstring(dest
, s
);
104 bool neg
= *s
== '-';
107 charstring_append_cstring(dest
, s
);
109 charstring_push_back(dest
, ' ');
114 if (neg
&& fill
== '0') {
115 charstring_push_back(dest
, *s
++);
118 charstring_push_back(dest
, fill
);
120 charstring_append_cstring(dest
, s
);
124 /* Transform 1234567 -> 1234?67 and -1234567 -> 1234-?7. */
125 char *news
= s
+ len
- w
;
130 charstring_append_cstring(dest
, news
);
134 * copy string from str to dest padding with the fill character to a
135 * size of wid characters. if wid is negative, the string is right
136 * aligned no more than max characters are copied
139 cptrimmed(charstring_t dest
, char *str
, int wid
, char fill
, size_t max
)
141 int remaining
; /* remaining output width available */
143 struct charstring
*trimmed
;
144 size_t end
; /* number of input bytes remaining in str */
145 #ifdef MULTIBYTE_SUPPORT
146 int char_len
; /* bytes in current character */
151 char *sp
; /* current position in source string */
155 if ((remaining
= wid
) < 0) {
156 remaining
= -remaining
;
159 if (remaining
> (int) max
) { remaining
= max
; }
161 trimmed
= rjust
? charstring_create(remaining
) : dest
;
163 bool prevCtrl
= true;
165 #ifdef MULTIBYTE_SUPPORT
166 if (mbtowc(NULL
, NULL
, 0)) {} /* reset shift state */
169 while (*sp
&& remaining
> 0 && end
> 0) {
170 #ifdef MULTIBYTE_SUPPORT
171 char_len
= mbtowc(&wide_char
, sp
, end
);
174 * See the relevant comments in cpstripped() to explain what's
175 * going on here; we want to handle the case where we get
176 * characters that mbtowc() cannot handle
181 char_len
= mbtowc(&wide_char
, altstr
, 1);
188 w
= wcwidth(wide_char
);
190 /* If w > remaining, w must be positive. */
197 if (iswcntrl(wide_char
) || iswspace(wide_char
)) {
202 /* isnctrl(), etc., take an int argument. Cygwin's ctype.h
203 intentionally warns if they are passed a char. */
204 c
= (unsigned char) *sp
;
205 if (iscntrl(c
) || isspace(c
)) {
209 charstring_push_back (trimmed
, ' ');
218 #ifdef MULTIBYTE_SUPPORT
219 if (w
>= 0 && remaining
>= w
) {
220 charstring_push_back_chars (trimmed
, altstr
? altstr
: sp
,
227 charstring_push_back (trimmed
, *sp
++);
233 while (remaining
-- > 0) {
234 charstring_push_back(dest
, fill
);
238 charstring_append(dest
, trimmed
);
239 charstring_free(trimmed
);
243 #ifdef MULTIBYTE_SUPPORT
245 cpstripped (charstring_t dest
, size_t max
, char *str
)
248 static char oddchar
[MB_LEN_MAX
* 2];
249 static size_t oddlen
;
250 static char spacechar
[MB_LEN_MAX
* 2];
251 static size_t spacelen
;
262 oddlen
= wcstombs(oddchar
, L
"?", sizeof oddchar
);
264 assert(wcwidth(L
' ') == 1); /* Need to pad in ones. */
265 spacelen
= wcstombs(spacechar
, L
" ", sizeof spacechar
);
266 assert(spacelen
> 0);
270 return; /* It's unclear why no padding in this case. */
271 end
= str
+ strlen(str
);
273 if (mbtowc(NULL
, NULL
, 0))
274 {} /* Reset shift state. */
276 squash
= true; /* Trim `space' or `cntrl' from the start. */
279 return; /* It's unclear why no padding in this case. */
281 srclen
= mbtowc(&rune
, str
, end
- str
);
283 /* Invalid rune, or not enough bytes to finish it. */
287 str
++; /* Skip one byte. */
293 if (iswspace(rune
) || iswcntrl(rune
)) {
295 continue; /* Amidst a run of these. */
312 if ((size_t)w
> max
) {
313 /* No room for rune; pad. */
315 charstring_push_back_chars(dest
, spacechar
, spacelen
, 1);
319 charstring_push_back_chars(dest
, src
, srclen
, w
);
325 #ifndef MULTIBYTE_SUPPORT
327 cpstripped (charstring_t dest
, size_t max
, char *str
)
335 squash
= true; /* Strip leading cases. */
337 c
= (unsigned char)*str
++;
341 if (isspace(c
) || iscntrl(c
)) {
349 charstring_push_back(dest
, (char)c
);
354 static char *lmonth
[] = { "January", "February","March", "April",
355 "May", "June", "July", "August",
356 "September","October", "November","December" };
359 fmt_scan (struct format
*format
, charstring_t scanlp
, int width
, int *dat
,
360 struct fmt_callbacks
*callbacks
)
363 /* If str points to part of buffer[] or buffer2[] then it must only
364 * ever point at their first element as otherwise undefined
365 * behaviour from overlapping strncpy(3)s can result. */
367 char buffer
[NMH_BUFSIZ
], buffer2
[NMH_BUFSIZ
];
379 * max is the same as width, but unsigned so comparisons
380 * with charstring_chars() won't raise compile warnings.
383 savestr
= str
= NULL
;
386 for (fmt
= format
; fmt
->f_type
!= FT_DONE
; fmt
++)
387 switch (fmt
->f_type
) {
390 fmt
->f_comp
->c_flags
&= ~CF_PARSED
;
395 case FT_LS_DECODECOMP
:
397 * Trim these components of any newlines.
399 * But don't trim the "body" and "text" components.
404 if (! (comp
->c_flags
& CF_TRIMMED
) && comp
->c_text
&&
405 (i
= strlen(comp
->c_text
)) > 0) {
406 if (comp
->c_text
[i
- 1] == '\n' &&
407 strcmp(comp
->c_name
, "body") != 0 &&
408 strcmp(comp
->c_name
, "text") != 0)
409 comp
->c_text
[i
- 1] = '\0';
410 comp
->c_flags
|= CF_TRIMMED
;
417 for ( ; charstring_chars (scanlp
) < max
; ) {
418 switch (fmt
->f_type
) {
421 cpstripped (scanlp
, max
- charstring_chars (scanlp
),
422 fmt
->f_comp
->c_text
);
425 cptrimmed (scanlp
, fmt
->f_comp
->c_text
, fmt
->f_width
,
426 fmt
->f_fill
, max
- charstring_chars (scanlp
));
431 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
432 charstring_push_back (scanlp
, c
);
441 rjust
= true; /* XXX should do something with this */
443 while ((c
= *sp
++) && --i
>= 0 && charstring_chars (scanlp
) < max
) {
444 charstring_push_back (scanlp
, c
);
446 while (--i
>= 0 && charstring_chars (scanlp
) < max
) {
447 charstring_push_back (scanlp
, fmt
->f_fill
);
452 cpstripped (scanlp
, max
- charstring_chars (scanlp
), str
);
455 cptrimmed (scanlp
, str
, fmt
->f_width
, fmt
->f_fill
,
456 max
- charstring_chars (scanlp
));
461 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
462 charstring_push_back (scanlp
, c
);
467 if (str
) charstring_push_back_chars (scanlp
, str
, strlen (str
), 0);
470 die("internal error (FT_STRFW)");
476 for (wid
= num
<= 0; num
; ++wid
, num
/= 10) {}
477 cpnumber (scanlp
, value
, wid
, ' ',
478 max
- charstring_chars (scanlp
));
485 unsigned int whole
, tenths
;
486 unsigned int scale
= 0;
487 unsigned int val
= (unsigned int)value
;
488 char *kibisuff
= NULL
;
490 switch (fmt
->f_type
) {
491 case FT_LS_KILO
: scale
= 1000; kibisuff
= ""; break;
492 case FT_LS_KIBI
: scale
= 1024; kibisuff
= "i"; break;
496 snprintf(buffer
, sizeof(buffer
), "%u", val
);
498 /* To prevent divide by 0, found by clang static
500 if (scale
== 0) { scale
= 1; }
502 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
503 for (unitcp
= "KMGT"; val
> (scale
* scale
); val
/= scale
) {
509 strcpy(buffer
, "huge");
511 /* val is scale times too big. we want tenths */
519 tenths
= val
- (whole
* 10);
522 snprintf(buffer
, sizeof(buffer
), "%u.%u%c%s",
523 whole
, tenths
, *unitcp
, kibisuff
);
525 snprintf(buffer
, sizeof(buffer
), "%u%c%s",
526 whole
, *unitcp
, kibisuff
);
535 int digit
= value
% 10;
536 int seconddigit
= (value
/ 10) % 10;
539 if (seconddigit
== 1) {
557 strncpy(buffer
, suffix
, sizeof(buffer
));
562 cpnumber (scanlp
, value
, fmt
->f_width
, fmt
->f_fill
,
563 max
- charstring_chars (scanlp
));
567 charstring_push_back (scanlp
, fmt
->f_char
);
571 if (callbacks
&& callbacks
->trace_func
)
572 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
573 str
, charstring_buffer (scanlp
));
577 if (!(value
= (str
&& *str
))) {
578 if (callbacks
&& callbacks
->trace_func
)
579 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
580 str
, charstring_buffer (scanlp
));
587 if (!(value
= (str
== NULL
|| *str
== 0))) {
588 if (callbacks
&& callbacks
->trace_func
)
589 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
590 str
, charstring_buffer (scanlp
));
597 if (value
!= fmt
->f_value
) {
598 if (callbacks
&& callbacks
->trace_func
)
599 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
600 str
, charstring_buffer (scanlp
));
607 if (value
== fmt
->f_value
) {
608 if (callbacks
&& callbacks
->trace_func
)
609 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
610 str
, charstring_buffer (scanlp
));
617 if (value
<= fmt
->f_value
) {
618 if (callbacks
&& callbacks
->trace_func
)
619 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
620 str
, charstring_buffer (scanlp
));
627 if (!(value
= (str
&& match (str
, fmt
->f_text
)))) {
628 if (callbacks
&& callbacks
->trace_func
)
629 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
630 str
, charstring_buffer (scanlp
));
638 value
= match (str
, fmt
->f_text
);
644 if (!(value
= (str
&& uprf (str
, fmt
->f_text
)))) {
645 if (callbacks
&& callbacks
->trace_func
)
646 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
647 str
, charstring_buffer (scanlp
));
654 value
= uprf (str
, fmt
->f_text
);
658 value
= (str
!= NULL
&& *str
!= 0);
662 value
= (str
== NULL
|| *str
== 0);
666 value
= (fmt
->f_value
== value
);
670 value
= (fmt
->f_value
!= value
);
674 value
= (fmt
->f_value
> value
);
678 if (callbacks
&& callbacks
->trace_func
)
679 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
680 str
, charstring_buffer (scanlp
));
688 str
= fmt
->f_comp
->c_text
;
694 if (!(str
= getenv (fmt
->f_text
)))
698 if (!(str
= context_find (fmt
->f_text
)))
702 case FT_LS_DECODECOMP
:
703 if (decode_rfc2047(fmt
->f_comp
->c_text
, buffer2
, sizeof(buffer2
)))
706 str
= fmt
->f_comp
->c_text
;
710 if (str
&& decode_rfc2047(str
, buffer2
, sizeof(buffer2
)))
719 strncpy(buffer
, str
, sizeof(buffer
));
720 buffer
[sizeof(buffer
)-1] = '\0';
722 while (isspace((unsigned char) *str
))
725 if ((i
= fmt
->f_width
) < 0) {
730 if (!rjust
&& i
> 0 && (int) strlen(str
) > i
)
733 xp
+= strlen(str
) - 1;
734 while (xp
> str
&& isspace((unsigned char) *xp
))
736 if (rjust
&& i
> 0 && (int) strlen(str
) > i
)
737 str
+= strlen(str
) - i
;
738 str
= memmove(buffer
, str
, strlen(str
) + 1);
743 value
= (fmt
->f_comp
->c_flags
& CF_TRUE
) != 0;
746 value
= (comp
= fmt
->f_comp
)->c_text
? atoi(comp
->c_text
) : 0;
749 value
= fmt
->f_value
;
752 value
= dat
[fmt
->f_value
];
760 case FT_LV_CHAR_LEFT
:
761 value
= max
- charstring_bytes (scanlp
);
764 value
+= fmt
->f_value
;
767 value
= fmt
->f_value
- value
;
769 case FT_LV_MULTIPLY_L
:
770 value
*= fmt
->f_value
;
773 if (fmt
->f_value
== 0 || (fmt
->f_value
== -1 && value
== INT_MIN
)) {
774 // FIXME: Tell the user, and probably stop.
777 value
/= fmt
->f_value
;
782 value
%= fmt
->f_value
;
784 // FIXME: Tell the user, and probably stop.
792 value
= fmt
->f_comp
->c_tws
->tw_sec
;
795 value
= fmt
->f_comp
->c_tws
->tw_min
;
798 value
= fmt
->f_comp
->c_tws
->tw_hour
;
801 value
= fmt
->f_comp
->c_tws
->tw_mday
;
804 value
= fmt
->f_comp
->c_tws
->tw_mon
+ 1;
807 str
= tw_moty
[fmt
->f_comp
->c_tws
->tw_mon
];
810 str
= lmonth
[fmt
->f_comp
->c_tws
->tw_mon
];
813 str
= dtwszone (fmt
->f_comp
->c_tws
);
816 value
= fmt
->f_comp
->c_tws
->tw_year
;
819 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
821 value
= tws
->tw_wday
;
824 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
826 str
= tw_dotw
[tws
->tw_wday
];
829 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
831 str
= tw_ldotw
[tws
->tw_wday
];
834 value
= fmt
->f_comp
->c_tws
->tw_yday
;
837 value
= fmt
->f_comp
->c_tws
->tw_zone
;
840 if ((value
= fmt
->f_comp
->c_tws
->tw_clock
) == 0)
841 value
= dmktime(fmt
->f_comp
->c_tws
);
844 if ((value
= fmt
->f_comp
->c_tws
->tw_clock
) == 0)
845 value
= dmktime(fmt
->f_comp
->c_tws
);
846 value
= time(NULL
) - value
;
849 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
851 switch (fmt
->f_comp
->c_tws
->tw_flags
& TW_SDAY
) {
861 if (fmt
->f_comp
->c_tws
->tw_flags
& TW_SZEXP
)
867 value
= fmt
->f_comp
->c_tws
->tw_flags
& TW_DST
? 1 : 0;
870 str
= dasctime (fmt
->f_comp
->c_tws
, TW_ZONE
);
873 str
= dasctime (fmt
->f_comp
->c_tws
, TW_NULL
);
877 str
= fmt
->f_comp
->c_mn
->m_pers
;
880 str
= fmt
->f_comp
->c_mn
->m_mbox
;
883 str
= fmt
->f_comp
->c_mn
->m_host
;
886 str
= fmt
->f_comp
->c_mn
->m_path
;
889 str
= fmt
->f_comp
->c_mn
->m_gname
;
892 str
= fmt
->f_comp
->c_mn
->m_note
;
895 str
= adrformat( fmt
->f_comp
->c_mn
);
898 value
= fmt
->f_comp
->c_mn
->m_type
;
901 value
= fmt
->f_comp
->c_mn
->m_ingrp
;
904 value
= fmt
->f_comp
->c_mn
->m_nohost
;
908 if ((mn
= fmt
->f_comp
->c_mn
) == &fmt_mnull
) {
909 str
= fmt
->f_comp
->c_text
;
912 if (fmt
->f_type
== FT_LS_ADDR
)
914 if ((str
= mn
->m_pers
) == NULL
) {
915 if ((str
= mn
->m_note
)) {
917 strncpy (buffer
, str
, sizeof(buffer
));
918 buffer
[sizeof(buffer
)-1] = '\0';
922 sp
= str
+ strlen(str
) - 1;
931 str
= memmove(buffer
, str
, strlen(str
) + 1);
934 switch (mn
->m_type
) {
939 snprintf (buffer
, sizeof(buffer
), "%s!%s",
940 mn
->m_host
, mn
->m_mbox
);
945 snprintf (buffer
, sizeof(buffer
), "%s@%s",
946 mn
->m_mbox
, mn
->m_host
);
958 /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
962 strncpy(buffer
, str
, sizeof(buffer
));
963 /* strncpy doesn't NUL-terminate if it fills the buffer */
964 buffer
[sizeof(buffer
)-1] = '\0';
965 unquote_string(buffer
, buffer2
);
972 if ((t
= comp
->c_tws
->tw_clock
) == 0)
973 t
= dmktime(comp
->c_tws
);
974 tws
= dlocaltime(&t
);
980 if ((t
= comp
->c_tws
->tw_clock
) == 0)
981 t
= dmktime(comp
->c_tws
);
988 if (comp
->c_flags
& CF_PARSED
)
990 if ((sp
= comp
->c_text
) && (tws
= dparsetime(sp
))) {
992 comp
->c_flags
&= ~CF_TRUE
;
993 } else if ((comp
->c_flags
& CF_DATEFAB
) == 0) {
995 comp
->c_flags
= CF_TRUE
;
997 comp
->c_flags
|= CF_PARSED
;
1001 /* hook for custom address list formatting (see replsbr.c) */
1002 if (callbacks
&& callbacks
->formataddr
)
1003 str
= callbacks
->formataddr (savestr
, str
);
1005 str
= formataddr (savestr
, str
);
1009 /* The same as formataddr, but doesn't do duplicate suppression */
1010 if (callbacks
&& callbacks
->concataddr
)
1011 str
= callbacks
->concataddr (savestr
, str
);
1013 str
= concataddr (savestr
, str
);
1017 /* output the str register as an address component,
1018 * splitting it into multiple lines if necessary. The
1019 * value reg. contains the max line length. The lit.
1020 * field may contain a string to prepend to the result
1025 int indent
, wid
, len
;
1029 len
= str
? strlen (str
) : 0;
1031 indent
= strlen (sp
);
1034 die("putaddr -- num register (%d) must be greater "
1035 "than label width (%d)", value
, indent
);
1037 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
1038 charstring_push_back (scanlp
, c
);
1041 /* try to break at a comma; failing that, break at a
1044 lastb
= 0; sp
= lp
+ wid
;
1045 while (sp
> lp
&& (c
= (unsigned char) *--sp
) != ',') {
1046 if (! lastb
&& isspace(c
))
1050 if (! (sp
= lastb
)) {
1052 while (*sp
&& *sp
!= ',' &&
1053 !isspace((unsigned char) *sp
))
1060 while (lp
<= sp
&& charstring_chars (scanlp
) < max
) {
1061 charstring_push_back (scanlp
, *lp
++);
1063 while (isspace((unsigned char) *lp
))
1066 if (charstring_chars (scanlp
) < max
) {
1067 charstring_push_back (scanlp
, '\n');
1070 charstring_chars (scanlp
) < max
&& i
> 0;
1072 charstring_push_back (scanlp
, ' ');
1075 cpstripped (scanlp
, max
- charstring_chars (scanlp
), lp
);
1081 if (comp
->c_flags
& CF_PARSED
)
1083 if (comp
->c_mn
!= &fmt_mnull
)
1084 mnfree (comp
->c_mn
);
1085 if ((sp
= comp
->c_text
) && (sp
= getname(sp
)) &&
1086 (mn
= getm (sp
, NULL
, 0, NULL
, 0))) {
1090 comp
->c_flags
|= CF_PARSED
;
1092 while (getname("")) /* XXX */
1094 comp
->c_mn
= &fmt_mnull
;
1102 * if there's no component, we say true. Otherwise we
1103 * say "true" only if we can parse the address and it
1104 * matches one of our addresses.
1107 if (comp
->c_mn
!= &fmt_mnull
)
1108 mnfree (comp
->c_mn
);
1109 if ((sp
= comp
->c_text
) && (sp
= getname(sp
)) &&
1110 (mn
= getm (sp
, NULL
, 0, NULL
, 0))) {
1113 comp
->c_flags
|= CF_TRUE
;
1114 /* Set str for use with FT_GETMYMBOX. With
1115 FT_GETMYADDR, comp->c_mn will be run through
1116 FT_LS_ADDR, which will strip off any pers
1120 comp
->c_flags
&= ~CF_TRUE
;
1122 while ((sp
= getname(sp
)))
1123 if ((comp
->c_flags
& CF_TRUE
) == 0 &&
1124 (mn
= getm (sp
, NULL
, 0, NULL
, 0)))
1126 comp
->c_flags
|= CF_TRUE
;
1127 /* Set str and comp->c_text for use with
1128 FT_GETMYMBOX. With FT_GETMYADDR,
1129 comp->c_mn will be run through
1130 FT_LS_ADDR, which will strip off any
1132 /* NB: We remove the call to free() here
1133 because it interferes with the buffer
1134 management in scansbr.c. Revisit this
1135 when we clean up memory handling */
1136 /* free (comp->c_text); */
1137 comp
->c_text
= str
= strdup (mn
->m_text
);
1140 comp
->c_flags
|= CF_PARSED
;
1142 while (getname("")) /* XXX */
1144 if (comp
->c_text
== 0)
1145 comp
->c_flags
|= CF_TRUE
;
1147 comp
->c_flags
&= ~CF_TRUE
;
1149 comp
->c_mn
= &fmt_mnull
;
1151 if ((comp
->c_flags
& CF_TRUE
) == 0 &&
1152 (fmt
->f_type
== FT_GETMYMBOX
|| fmt
->f_type
== FT_GETMYADDR
)) {
1153 /* Fool FT_LS_ADDR into not producing an address. */
1154 comp
->c_mn
= &fmt_mnull
; comp
->c_text
= NULL
;
1160 * Call our tracing callback function, if one was supplied
1163 if (callbacks
&& callbacks
->trace_func
)
1164 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1165 str
, charstring_buffer (scanlp
));
1169 /* Emit any trailing sequences of zero display length. */
1170 while (fmt
->f_type
!= FT_DONE
) {
1171 if (fmt
->f_type
== FT_LS_LIT
) {
1173 if (callbacks
&& callbacks
->trace_func
)
1174 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1175 str
, charstring_buffer (scanlp
));
1176 } else if (fmt
->f_type
== FT_STRLITZ
) {
1177 /* Don't want to emit part of an escape sequence. So if
1178 there isn't enough room in the buffer for the entire
1179 string, skip it completely. Need room for null
1180 terminator, and maybe trailing newline (added below). */
1182 for (sp
= str
; *sp
; ++sp
) {
1183 charstring_push_back (scanlp
, *sp
);
1186 if (callbacks
&& callbacks
->trace_func
)
1187 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1188 str
, charstring_buffer (scanlp
));
1194 if (charstring_bytes (scanlp
) > 0) {
1196 * Append a newline if the last character wasn't.
1198 #ifdef MULTIBYTE_SUPPORT
1200 * It's a little tricky because the last byte might be part of
1201 * a multibyte character, in which case we assume that wasn't
1204 size_t last_char_len
= charstring_last_char_len (scanlp
);
1205 #else /* ! MULTIBYTE_SUPPORT */
1206 size_t last_char_len
= 1;
1207 #endif /* ! MULTIBYTE_SUPPORT */
1209 if (last_char_len
> 1 ||
1210 charstring_buffer (scanlp
)[charstring_bytes (scanlp
) - 1] != '\n') {
1211 charstring_push_back (scanlp
, '\n');