]>
diplodocus.org Git - nmh/blob - sbr/fmt_scan.c
3 * fmt_scan.c -- format string interpretation
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
9 * This is the engine that processes the format instructions created by
10 * fmt_compile (found in fmt_compile.c).
14 #include <h/addrsbr.h>
15 #include <h/fmt_scan.h>
17 #include <h/fmt_compile.h>
20 #ifdef HAVE_SYS_TIME_H
21 # include <sys/time.h>
24 #ifdef MULTIBYTE_SUPPORT
29 struct mailname fmt_mnull
= { NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0, 0, 0,
35 static int match (char *, char *);
36 static char *get_x400_friendly (char *, char *, int);
37 static int get_x400_comp (char *, char *, char *, int);
41 * test if string "sub" appears anywhere in
42 * string "str" (case insensitive).
46 match (char *str
, char *sub
)
52 c1
= (isascii((unsigned char) c1
) && isalpha((unsigned char) c1
) &&
53 isupper((unsigned char) c1
)) ? tolower((unsigned char) c1
) : c1
;
54 while ((c2
= *str
++) && c1
!= ((isascii((unsigned char) c2
) &&
55 isalpha((unsigned char) c2
) &&
56 isupper((unsigned char) c2
)) ?
57 tolower((unsigned char) c2
) : c2
))
61 s1
= sub
+ 1; s2
= str
;
62 while ((c1
= *s1
++) && ((isascii((unsigned char) c1
) &&
63 isalpha((unsigned char) c1
) &&
64 isupper((unsigned char) c1
)) ?
66 ((isascii((unsigned char) (c2
=*s2
++)) &&
67 isalpha((unsigned char) c2
) &&
68 isupper((unsigned char) c2
)) ?
69 tolower((unsigned char) c2
) : c2
))
78 * copy a number to the destination subject to a maximum width
81 cpnumber(charstring_t dest
, int num
, unsigned int wid
, char fill
, size_t max
) {
82 if (wid
< (num
>= 0 ? max
: max
-1)) {
83 /* Build up the string representation of num in reverse. */
84 charstring_t rev
= charstring_create (0);
85 int i
= num
>= 0 ? num
: -num
;
88 charstring_push_back (rev
, i
% 10 + '0');
90 } while (--wid
> 0 && i
> 0);
92 /* Overflowed the field (wid). */
93 charstring_push_back (rev
, '?');
94 } else if (num
< 0 && wid
> 0) {
95 /* Shouldn't need the wid > 0 check, that's why the condition
96 at the top checks wid < max-1 when num < 0. */
99 charstring_push_back (rev
, '-');
102 while (wid
-- > 0 && fill
!= 0) {
103 charstring_push_back (rev
, fill
);
105 if (num
< 0 && fill
== '0') {
106 charstring_push_back (rev
, '-');
110 /* Output the string in reverse. */
111 size_t b
= charstring_bytes (rev
);
112 const char *cp
= b
? &charstring_buffer (rev
)[b
] : NULL
;
115 charstring_push_back (dest
, *--cp
);
119 charstring_free (rev
);
124 * copy string from str to dest padding with the fill character to a
125 * size of wid characters. if wid is negative, the string is right
126 * aligned no more than max characters are copied
129 cptrimmed(charstring_t dest
, char *str
, int wid
, char fill
, size_t max
) {
130 int remaining
; /* remaining output width available */
132 size_t end
; /* number of input bytes remaining in str */
133 #ifdef MULTIBYTE_SUPPORT
134 int char_len
; /* bytes in current character */
139 char *sp
; /* current position in source string */
144 if ((remaining
= wid
) < 0) {
145 remaining
= -remaining
;
148 if (remaining
> (int) max
) { remaining
= max
; }
151 #ifdef MULTIBYTE_SUPPORT
152 if (mbtowc(NULL
, NULL
, 0)) {} /* reset shift state */
155 while (*sp
&& remaining
> 0 && end
> 0) {
156 #ifdef MULTIBYTE_SUPPORT
157 char_len
= mbtowc(&wide_char
, sp
, end
);
160 * See the relevant comments in cpstripped() to explain what's
161 * going on here; we want to handle the case where we get
162 * characters that mbtowc() cannot handle
167 char_len
= mbtowc(&wide_char
, altstr
, 1);
174 w
= wcwidth(wide_char
);
176 /* If w > remaining, w must be positive. */
183 if (iswcntrl(wide_char
) || iswspace(wide_char
)) {
188 /* isnctrl(), etc., take an int argument. Cygwin's ctype.h
189 intentionally warns if they are passed a char. */
190 c
= (unsigned char) *sp
;
191 if (iscntrl(c
) || isspace(c
)) {
195 charstring_push_back (dest
, ' ');
204 #ifdef MULTIBYTE_SUPPORT
205 if (w
>= 0 && remaining
>= w
) {
206 charstring_push_back_chars (dest
, altstr
? altstr
: sp
,
213 charstring_push_back (dest
, *sp
++);
221 /* copy string to the right */
222 charstring_t copy
= charstring_copy (dest
);
224 /* add padding at the beginning */
225 charstring_clear (dest
);
226 for (; remaining
> 0; --remaining
) {
227 charstring_push_back (dest
, fill
);
230 charstring_append (dest
, copy
);
232 charstring_free (copy
);
235 /* pad remaining space */
236 while (remaining
-- > 0) {
237 charstring_push_back (dest
, fill
);
243 cpstripped (charstring_t dest
, size_t max
, char *str
)
245 int prevCtrl
= 1; /* This is 1 so we strip out leading spaces */
247 #ifdef MULTIBYTE_SUPPORT
251 #endif /* MULTIBYTE_SUPPORT */
259 #ifdef MULTIBYTE_SUPPORT
260 if (mbtowc(NULL
, NULL
, 0)) {} /* Reset shift state */
261 #endif /* MULTIBYTE_SUPPORT */
264 * Process each character at a time; if we have multibyte support
265 * then deal with that here.
268 while (*str
!= '\0' && len
> 0 && max
> 0) {
269 #ifdef MULTIBYTE_SUPPORT
270 char_len
= mbtowc(&wide_char
, str
, len
);
271 w
= wcwidth(wide_char
);
274 * If mbrtowc() failed, then we have a character that isn't valid
275 * in the current encoding. Replace it with a '?'. We do that by
276 * setting the alstr variable to the value of the replacement string;
277 * altstr is used below when the bytes are copied into the output
283 char_len
= mbtowc(&wide_char
, altstr
, 1);
292 if (iswcntrl(wide_char
) || iswspace(wide_char
)) {
294 #else /* MULTIBYTE_SUPPORT */
295 int c
= (unsigned char) *str
;
297 if (iscntrl(c
) || isspace(c
)) {
299 #endif /* MULTIBYTE_SUPPORT */
301 charstring_push_back (dest
, ' ');
311 #ifdef MULTIBYTE_SUPPORT
312 charstring_push_back_chars (dest
, altstr
? altstr
: str
, char_len
, w
);
316 #else /* MULTIBYE_SUPPORT */
317 charstring_push_back (dest
, *str
++);
319 #endif /* MULTIBYTE_SUPPORT */
323 static char *lmonth
[] = { "January", "February","March", "April",
324 "May", "June", "July", "August",
325 "September","October", "November","December" };
328 get_x400_friendly (char *mbox
, char *buffer
, int buffer_len
)
330 char given
[BUFSIZ
], surname
[BUFSIZ
];
339 if (get_x400_comp (mbox
, "/PN=", buffer
, buffer_len
)) {
340 for (mbox
= buffer
; (mbox
= strchr(mbox
, '.')); )
346 if (!get_x400_comp (mbox
, "/S=", surname
, sizeof(surname
)))
349 if (get_x400_comp (mbox
, "/G=", given
, sizeof(given
)))
350 snprintf (buffer
, buffer_len
, "%s %s", given
, surname
);
352 snprintf (buffer
, buffer_len
, "%s", surname
);
358 get_x400_comp (char *mbox
, char *key
, char *buffer
, int buffer_len
)
363 if ((idx
= stringdex (key
, mbox
)) < 0
364 || !(cp
= strchr(mbox
+= idx
+ strlen (key
), '/')))
367 snprintf (buffer
, buffer_len
, "%*.*s", (int)(cp
- mbox
), (int)(cp
- mbox
), mbox
);
372 fmt_scan (struct format
*format
, charstring_t scanlp
, int width
, int *dat
,
373 struct fmt_callbacks
*callbacks
)
377 char buffer
[BUFSIZ
], buffer2
[BUFSIZ
];
388 * max is the same as width, but unsigned so comparisons
389 * with charstring_chars() won't raise compile warnings.
392 savestr
= str
= NULL
;
395 for (fmt
= format
; fmt
->f_type
!= FT_DONE
; fmt
++)
396 switch (fmt
->f_type
) {
399 fmt
->f_comp
->c_flags
&= ~CF_PARSED
;
404 case FT_LS_DECODECOMP
:
406 * Trim these components of any newlines.
408 * But don't trim the "body" and "text" components.
413 if (! (comp
->c_flags
& CF_TRIMMED
) && comp
->c_text
&&
414 (i
= strlen(comp
->c_text
)) > 0) {
415 if (comp
->c_text
[i
- 1] == '\n' &&
416 strcmp(comp
->c_name
, "body") != 0 &&
417 strcmp(comp
->c_name
, "text") != 0)
418 comp
->c_text
[i
- 1] = '\0';
419 comp
->c_flags
|= CF_TRIMMED
;
426 for ( ; charstring_chars (scanlp
) < max
; ) {
427 switch (fmt
->f_type
) {
430 cpstripped (scanlp
, max
- charstring_chars (scanlp
),
431 fmt
->f_comp
->c_text
);
434 cptrimmed (scanlp
, fmt
->f_comp
->c_text
, fmt
->f_width
,
435 fmt
->f_fill
, max
- charstring_chars (scanlp
));
440 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
441 charstring_push_back (scanlp
, c
);
450 rjust
++; /* XXX should do something with this */
452 while ((c
= *sp
++) && --i
>= 0 && charstring_chars (scanlp
) < max
) {
453 charstring_push_back (scanlp
, c
);
455 while (--i
>= 0 && charstring_chars (scanlp
) < max
) {
456 charstring_push_back (scanlp
, fmt
->f_fill
);
461 cpstripped (scanlp
, max
- charstring_chars (scanlp
), str
);
464 cptrimmed (scanlp
, str
, fmt
->f_width
, fmt
->f_fill
,
465 max
- charstring_chars (scanlp
));
470 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
471 charstring_push_back (scanlp
, c
);
476 if (str
) charstring_push_back_chars (scanlp
, str
, strlen (str
), 0);
479 adios (NULL
, "internal error (FT_STRFW)");
485 for (wid
= num
<= 0 ? 1 : 0; num
; ++wid
, num
/= 10) {}
486 cpnumber (scanlp
, value
, wid
, ' ',
487 max
- charstring_chars (scanlp
));
494 unsigned int whole
, tenths
;
495 unsigned int scale
= 0;
496 unsigned int val
= (unsigned int)value
;
497 char *kibisuff
= NULL
;
499 switch (fmt
->f_type
) {
500 case FT_LS_KILO
: scale
= 1000; kibisuff
= ""; break;
501 case FT_LS_KIBI
: scale
= 1024; kibisuff
= "i"; break;
505 snprintf(buffer
, sizeof(buffer
), "%u", val
);
507 /* To prevent divide by 0, found by clang static
509 if (scale
== 0) { scale
= 1; }
511 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
512 for (unitcp
= "KMGT"; val
> (scale
* scale
); val
/= scale
) {
518 strcpy(buffer
, "huge");
520 /* val is scale times too big. we want tenths */
528 tenths
= val
- (whole
* 10);
531 snprintf(buffer
, sizeof(buffer
), "%u.%u%c%s",
532 whole
, tenths
, *unitcp
, kibisuff
);
534 snprintf(buffer
, sizeof(buffer
), "%u%c%s",
535 whole
, *unitcp
, kibisuff
);
543 cpnumber (scanlp
, value
, fmt
->f_width
, fmt
->f_fill
,
544 max
- charstring_chars (scanlp
));
548 charstring_push_back (scanlp
, fmt
->f_char
);
552 if (callbacks
&& callbacks
->trace_func
)
553 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
554 str
, charstring_buffer (scanlp
));
558 if (!(value
= (str
&& *str
))) {
559 if (callbacks
&& callbacks
->trace_func
)
560 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
561 str
, charstring_buffer (scanlp
));
568 if (!(value
= (str
== NULL
|| *str
== 0))) {
569 if (callbacks
&& callbacks
->trace_func
)
570 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
571 str
, charstring_buffer (scanlp
));
578 if (value
!= fmt
->f_value
) {
579 if (callbacks
&& callbacks
->trace_func
)
580 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
581 str
, charstring_buffer (scanlp
));
588 if (value
== fmt
->f_value
) {
589 if (callbacks
&& callbacks
->trace_func
)
590 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
591 str
, charstring_buffer (scanlp
));
598 if (value
<= fmt
->f_value
) {
599 if (callbacks
&& callbacks
->trace_func
)
600 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
601 str
, charstring_buffer (scanlp
));
608 if (!(value
= (str
&& match (str
, fmt
->f_text
)))) {
609 if (callbacks
&& callbacks
->trace_func
)
610 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
611 str
, charstring_buffer (scanlp
));
619 value
= match (str
, fmt
->f_text
);
625 if (!(value
= (str
&& uprf (str
, fmt
->f_text
)))) {
626 if (callbacks
&& callbacks
->trace_func
)
627 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
628 str
, charstring_buffer (scanlp
));
635 value
= uprf (str
, fmt
->f_text
);
639 value
= (str
!= NULL
&& *str
!= 0);
643 value
= (str
== NULL
|| *str
== 0);
647 value
= (fmt
->f_value
== value
);
651 value
= (fmt
->f_value
!= value
);
655 value
= (fmt
->f_value
> value
);
659 if (callbacks
&& callbacks
->trace_func
)
660 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
661 str
, charstring_buffer (scanlp
));
669 str
= fmt
->f_comp
->c_text
;
675 if (!(str
= getenv (fmt
->f_text
)))
679 if (!(str
= context_find (fmt
->f_text
)))
683 case FT_LS_DECODECOMP
:
684 if (decode_rfc2047(fmt
->f_comp
->c_text
, buffer2
, sizeof(buffer2
)))
687 str
= fmt
->f_comp
->c_text
;
691 if (str
&& decode_rfc2047(str
, buffer2
, sizeof(buffer2
)))
699 strncpy(buffer
, str
, sizeof(buffer
));
700 buffer
[sizeof(buffer
)-1] = '\0';
702 while (isspace((unsigned char) *str
))
705 if ((i
= fmt
->f_width
) < 0) {
710 if (!rjust
&& i
> 0 && (int) strlen(str
) > i
)
713 xp
+= strlen(str
) - 1;
714 while (xp
> str
&& isspace((unsigned char) *xp
))
716 if (rjust
&& i
> 0 && (int) strlen(str
) > i
)
717 str
+= strlen(str
) - i
;
722 value
= (fmt
->f_comp
->c_flags
& CF_TRUE
) != 0;
725 value
= (comp
= fmt
->f_comp
)->c_text
? atoi(comp
->c_text
) : 0;
728 value
= fmt
->f_value
;
731 value
= dat
[fmt
->f_value
];
739 case FT_LV_CHAR_LEFT
:
740 value
= max
- charstring_bytes (scanlp
);
743 value
+= fmt
->f_value
;
746 value
= fmt
->f_value
- value
;
748 case FT_LV_MULTIPLY_L
:
749 value
*= fmt
->f_value
;
753 value
= value
/ fmt
->f_value
;
759 value
= value
% fmt
->f_value
;
768 value
= fmt
->f_comp
->c_tws
->tw_sec
;
771 value
= fmt
->f_comp
->c_tws
->tw_min
;
774 value
= fmt
->f_comp
->c_tws
->tw_hour
;
777 value
= fmt
->f_comp
->c_tws
->tw_mday
;
780 value
= fmt
->f_comp
->c_tws
->tw_mon
+ 1;
783 str
= tw_moty
[fmt
->f_comp
->c_tws
->tw_mon
];
786 str
= lmonth
[fmt
->f_comp
->c_tws
->tw_mon
];
789 str
= dtwszone (fmt
->f_comp
->c_tws
);
792 value
= fmt
->f_comp
->c_tws
->tw_year
;
795 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
797 value
= tws
->tw_wday
;
800 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
802 str
= tw_dotw
[tws
->tw_wday
];
805 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
807 str
= tw_ldotw
[tws
->tw_wday
];
810 value
= fmt
->f_comp
->c_tws
->tw_yday
;
813 value
= fmt
->f_comp
->c_tws
->tw_zone
;
816 if ((value
= fmt
->f_comp
->c_tws
->tw_clock
) == 0)
817 value
= dmktime(fmt
->f_comp
->c_tws
);
820 if ((value
= fmt
->f_comp
->c_tws
->tw_clock
) == 0)
821 value
= dmktime(fmt
->f_comp
->c_tws
);
822 value
= time((time_t *) 0) - value
;
825 if (!(((tws
= fmt
->f_comp
->c_tws
)->tw_flags
) & (TW_SEXP
|TW_SIMP
)))
827 switch (fmt
->f_comp
->c_tws
->tw_flags
& TW_SDAY
) {
837 if ((fmt
->f_comp
->c_tws
->tw_flags
& TW_SZONE
) == TW_SZEXP
)
843 value
= fmt
->f_comp
->c_tws
->tw_flags
& TW_DST
? 1 : 0;
846 str
= dasctime (fmt
->f_comp
->c_tws
, TW_ZONE
);
849 str
= dasctime (fmt
->f_comp
->c_tws
, TW_NULL
);
853 str
= fmt
->f_comp
->c_mn
->m_pers
;
856 str
= fmt
->f_comp
->c_mn
->m_mbox
;
859 str
= fmt
->f_comp
->c_mn
->m_host
;
862 str
= fmt
->f_comp
->c_mn
->m_path
;
865 str
= fmt
->f_comp
->c_mn
->m_gname
;
868 str
= fmt
->f_comp
->c_mn
->m_note
;
871 str
= adrformat( fmt
->f_comp
->c_mn
);
874 value
= fmt
->f_comp
->c_mn
->m_type
;
877 value
= fmt
->f_comp
->c_mn
->m_ingrp
;
880 value
= fmt
->f_comp
->c_mn
->m_nohost
;
884 if ((mn
= fmt
->f_comp
->c_mn
) == &fmt_mnull
) {
885 str
= fmt
->f_comp
->c_text
;
888 if (fmt
->f_type
== FT_LS_ADDR
)
890 if ((str
= mn
->m_pers
) == NULL
) {
891 if ((str
= mn
->m_note
)) {
892 strncpy (buffer
, str
, sizeof(buffer
));
893 buffer
[sizeof(buffer
)-1] = '\0';
897 sp
= str
+ strlen(str
) - 1;
906 } else if (!(str
= get_x400_friendly (mn
->m_mbox
,
907 buffer
, sizeof(buffer
)))) {
909 switch (mn
->m_type
) {
914 snprintf (buffer
, sizeof(buffer
), "%s!%s",
915 mn
->m_host
, mn
->m_mbox
);
920 snprintf (buffer
, sizeof(buffer
), "%s@%s",
921 mn
->m_mbox
, mn
->m_host
);
933 /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
936 strncpy(buffer
, str
, sizeof(buffer
));
937 /* strncpy doesn't NUL-terminate if it fills the buffer */
938 buffer
[sizeof(buffer
)-1] = '\0';
939 unquote_string(buffer
, buffer2
);
946 if ((t
= comp
->c_tws
->tw_clock
) == 0)
947 t
= dmktime(comp
->c_tws
);
948 tws
= dlocaltime(&t
);
954 if ((t
= comp
->c_tws
->tw_clock
) == 0)
955 t
= dmktime(comp
->c_tws
);
962 if (comp
->c_flags
& CF_PARSED
)
964 if ((sp
= comp
->c_text
) && (tws
= dparsetime(sp
))) {
966 comp
->c_flags
&= ~CF_TRUE
;
967 } else if ((comp
->c_flags
& CF_DATEFAB
) == 0) {
968 memset (comp
->c_tws
, 0, sizeof *comp
->c_tws
);
969 comp
->c_flags
= CF_TRUE
;
971 comp
->c_flags
|= CF_PARSED
;
975 /* hook for custom address list formatting (see replsbr.c) */
976 if (callbacks
&& callbacks
->formataddr
)
977 str
= callbacks
->formataddr (savestr
, str
);
979 str
= formataddr (savestr
, str
);
983 /* The same as formataddr, but doesn't do duplicate suppression */
984 if (callbacks
&& callbacks
->concataddr
)
985 str
= callbacks
->concataddr (savestr
, str
);
987 str
= concataddr (savestr
, str
);
991 /* output the str register as an address component,
992 * splitting it into multiple lines if necessary. The
993 * value reg. contains the max line length. The lit.
994 * field may contain a string to prepend to the result
999 int indent
, wid
, len
;
1003 len
= str
? strlen (str
) : 0;
1005 indent
= strlen (sp
);
1008 adios(NULL
, "putaddr -- num register (%d) must be greater "
1009 "than label width (%d)", value
, indent
);
1011 while ((c
= *sp
++) && charstring_chars (scanlp
) < max
) {
1012 charstring_push_back (scanlp
, c
);
1015 /* try to break at a comma; failing that, break at a
1018 lastb
= 0; sp
= lp
+ wid
;
1019 while (sp
> lp
&& (c
= (unsigned char) *--sp
) != ',') {
1020 if (! lastb
&& isspace(c
))
1024 if (! (sp
= lastb
)) {
1026 while (*sp
&& *sp
!= ',' &&
1027 !isspace((unsigned char) *sp
))
1034 while (lp
<= sp
&& charstring_chars (scanlp
) < max
) {
1035 charstring_push_back (scanlp
, *lp
++);
1037 while (isspace((unsigned char) *lp
))
1040 if (charstring_chars (scanlp
) < max
) {
1041 charstring_push_back (scanlp
, '\n');
1044 charstring_chars (scanlp
) < max
&& i
> 0;
1046 charstring_push_back (scanlp
, ' ');
1049 cpstripped (scanlp
, max
- charstring_chars (scanlp
), lp
);
1055 if (comp
->c_flags
& CF_PARSED
)
1057 if (comp
->c_mn
!= &fmt_mnull
)
1058 mnfree (comp
->c_mn
);
1059 if ((sp
= comp
->c_text
) && (sp
= getname(sp
)) &&
1060 (mn
= getm (sp
, NULL
, 0, NULL
, 0))) {
1064 comp
->c_flags
|= CF_PARSED
;
1066 while (getname("")) /* XXX */
1068 comp
->c_mn
= &fmt_mnull
;
1076 * if there's no component, we say true. Otherwise we
1077 * say "true" only if we can parse the address and it
1078 * matches one of our addresses.
1081 if (comp
->c_mn
!= &fmt_mnull
)
1082 mnfree (comp
->c_mn
);
1083 if ((sp
= comp
->c_text
) && (sp
= getname(sp
)) &&
1084 (mn
= getm (sp
, NULL
, 0, NULL
, 0))) {
1087 comp
->c_flags
|= CF_TRUE
;
1088 /* Set str for use with FT_GETMYMBOX. With
1089 FT_GETMYADDR, comp->c_mn will be run through
1090 FT_LS_ADDR, which will strip off any pers
1094 comp
->c_flags
&= ~CF_TRUE
;
1096 while ((sp
= getname(sp
)))
1097 if ((comp
->c_flags
& CF_TRUE
) == 0 &&
1098 (mn
= getm (sp
, NULL
, 0, NULL
, 0)))
1100 comp
->c_flags
|= CF_TRUE
;
1101 /* Set str and comp->c_text for use with
1102 FT_GETMYMBOX. With FT_GETMYADDR,
1103 comp->c_mn will be run through
1104 FT_LS_ADDR, which will strip off any
1106 free (comp
->c_text
);
1107 comp
->c_text
= str
= strdup (mn
->m_text
);
1110 comp
->c_flags
|= CF_PARSED
;
1112 while (getname("")) /* XXX */
1114 if (comp
->c_text
== 0)
1115 comp
->c_flags
|= CF_TRUE
;
1117 comp
->c_flags
&= ~CF_TRUE
;
1119 comp
->c_mn
= &fmt_mnull
;
1121 if ((comp
->c_flags
& CF_TRUE
) == 0 &&
1122 (fmt
->f_type
== FT_GETMYMBOX
|| fmt
->f_type
== FT_GETMYADDR
)) {
1123 /* Fool FT_LS_ADDR into not producing an address. */
1124 comp
->c_mn
= &fmt_mnull
; comp
->c_text
= NULL
;
1130 * Call our tracing callback function, if one was supplied
1133 if (callbacks
&& callbacks
->trace_func
)
1134 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1135 str
, charstring_buffer (scanlp
));
1139 /* Emit any trailing sequences of zero display length. */
1140 while (fmt
->f_type
!= FT_DONE
) {
1141 if (fmt
->f_type
== FT_LS_LIT
) {
1143 if (callbacks
&& callbacks
->trace_func
)
1144 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1145 str
, charstring_buffer (scanlp
));
1146 } else if (fmt
->f_type
== FT_STRLITZ
) {
1147 /* Don't want to emit part of an escape sequence. So if
1148 there isn't enough room in the buffer for the entire
1149 string, skip it completely. Need room for null
1150 terminator, and maybe trailing newline (added below). */
1152 for (sp
= str
; *sp
; ++sp
) {
1153 charstring_push_back (scanlp
, *sp
);
1156 if (callbacks
&& callbacks
->trace_func
)
1157 callbacks
->trace_func(callbacks
->trace_context
, fmt
, value
,
1158 str
, charstring_buffer (scanlp
));
1164 if (charstring_bytes (scanlp
) > 0) {
1166 * Append a newline if the last character wasn't.
1168 #ifdef MULTIBYTE_SUPPORT
1170 * It's a little tricky because the last byte might be part of
1171 * a multibyte character, in which case we assume that wasn't
1174 size_t last_char_len
= charstring_last_char_len (scanlp
);
1175 #else /* ! MULTIBYTE_SUPPORT */
1176 size_t last_char_len
= 1;
1177 #endif /* ! MULTIBYTE_SUPPORT */
1179 if (last_char_len
> 1 ||
1180 charstring_buffer (scanlp
)[charstring_bytes (scanlp
) - 1] != '\n') {
1181 charstring_push_back (scanlp
, '\n');
1185 return ((struct format
*)0);