X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/42340d0aa25e0d0ec9c53bc81a7c5bf14283fbd7..2db8ea3cc5e4fb968f1872591cf1ff56fc408ff8:/man/mh-format.man diff --git a/man/mh-format.man b/man/mh-format.man index aa1c630a..28ebdadd 100644 --- a/man/mh-format.man +++ b/man/mh-format.man @@ -1,7 +1,7 @@ +.TH MH-FORMAT %manext5% "January 10, 2015" "%nmhversion%" .\" .\" %nmhwarning% .\" -.TH MH-FORMAT %manext5% "%nmhdate%" MH.6.8 [%nmhversion%] .SH NAME mh-format \- format file for nmh message system .SH DESCRIPTION @@ -45,8 +45,8 @@ A format string consists of ordinary text, and special multi-character escape sequences which begin with `%'. When specifying a format string, the usual C backslash characters are honored: `\\b', `\\f', `\\n', `\\r', and `\\t'. Continuation lines in format files end with -`\\' followed by the newline character. - +`\\' followed by the newline character. A literal `%' can be inserted into +a format file by using the sequence `%%'. .\" TALK ABOUT SYNTAX FIRST, THEN SEMANTICS .SS SYNTAX Format strings are built around @@ -73,7 +73,15 @@ All component escapes have a string value. Normally, component values are compressed by converting any control characters (tab and newline included) to spaces, then eliding any leading or multiple spaces. However, commands may give different interpretations to some component escapes; be sure -to refer to each command's manual entry for complete details. +to refer to each command's manual entry for complete details. Some commands +(such as +.B ap +and +.BR mhl ) +use a special component +.RI `%{ text }' +to refer to the text being processed; see their respective man pages for +details and examples. .PP A .I function @@ -92,7 +100,6 @@ or a control escape. When the argument is a function or a component, they are listed without a leading `%'. When control escapes are used as function arguments, they written as normally, with a leading `%'; - .SS "Control escapes" .PP A @@ -129,13 +136,11 @@ if the function return or component value is non-zero, and false if zero. For string valued functions or components, the condition is true if the function return or component value is a non-empty string, and false for an empty string. - .PP -The `%?' control escape is optional, and may there may be more +The `%?' control escape is optional, and there may be more than one `%?' control escape in a conditional block. The `%|' control escape is also optional, but may be included at most once. - .SS "Function escapes" Functions expecting an argument generally require an argument of a particular type. @@ -145,7 +150,7 @@ these include: .RS 5 .nf .ta +\w'Argument 'u +\w'An optional component, 'u -.I Argument Description Example Syntax +.I "Argument Description Example Syntax" literal A literal number %(\fIfunc\fR 1234) or string %(\fIfunc\fR text string) comp Any component %(\fIfunc\fR\^{\fIin-reply-to\fR\^}) @@ -243,18 +248,19 @@ The function escapes may be roughly grouped into a few categories. .RS 5 .nf .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u -.I Function Argument Result Description +.I "Function Argument Result Description" msg integer message number cur integer message is current (0 or 1) unseen integer message is unseen (0 or 1) size integer size of message strlen integer length of \fIstr\fR -width integer output buffer size in bytes +width integer column width of terminal charleft integer bytes left in output buffer timenow integer seconds since the UNIX epoch me string the user's mailbox (username) -myhost string the user's local hostname -myname string the user's name +myhost string the user's local hostname +myname string the user's name +localmbox string the complete local mailbox eq literal boolean \fInum\fR == \fIarg\fR ne literal boolean \fInum\fR != \fIarg\fR gt literal boolean \fInum\fR > \fIarg\fR @@ -262,6 +268,7 @@ match literal boolean \fIstr\fR contains \fIarg\fR amatch literal boolean \fIstr\fR starts with \fIarg\fR plus literal integer \fIarg\fR plus \fInum\fR minus literal integer \fIarg\fR minus \fInum\fR +multiply literal integer \fInum\fR multiplied by \fIarg\fR divide literal integer \fInum\fR divided by \fIarg\fR modulo literal integer \fInum\fR modulo \fIarg\fR num literal integer Set \fInum\fR to \fIarg\fR. @@ -280,18 +287,30 @@ void expr Set \fIstr\fR or \fInum\fR comp comp string Set \fIstr\fR to component text compval comp integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq .\" compflag comp integer Set \fInum\fR to component flags bits (internal) -.\" decodecomp comp string Set \fIstr\fR to RFC-2047 decoded component text -decode expr string decode \fIstr\fR as RFC-2047 (MIME-encoded) +.\" decodecomp comp string Set \fIstr\fR to RFC 2047 decoded component text +decode expr string decode \fIstr\fR as RFC 2047 (MIME-encoded) component -unquote expr string remove RFC-2822 quotes from \fIstr\fR -trim expr trim trailing white-space from \fIstr\fR +unquote expr string remove RFC 2822 quotes from \fIstr\fR +trim expr trim trailing whitespace from \fIstr\fR +kilo expr string express in SI units: 15.9K, 2.3M, etc. + %(kilo) scales by factors of 1000, +kibi expr string express in IEC units: 15.5Ki, 2.2Mi. + %(kibi) scales by factors of 1024. putstr expr print \fIstr\fR putstrf expr print \fIstr\fR in a fixed width putnum expr print \fInum\fR putnumf expr print \fInum\fR in a fixed width .\" addtoseq literal add msg to sequence (LBL option) putlit expr print \fIstr\fR without space compression -nodate string integer Argument not a date string (0 or 1) +zputlit expr print \fIstr\fR without space compression; + \fIstr\fR must occupy no width on display +bold string set terminal bold mode +underline string set terminal underlined mode +standout string set terminal standout mode +resetterm string reset all terminal attributes +hascolor boolean terminal supports color +fgcolor literal string set terminal foreground color +bgcolor literal string set terminal background color formataddr expr append \fIarg\fR to \fIstr\fR as a (comma separated) address list concataddr expr append \fIarg\fR to \fIstr\fR as a @@ -314,15 +333,26 @@ or the local hostname if is not configured. The (\fImyname\fR\^) function will return the value of the .B SIGNATURE -environment variable if set, otherwise will return the passwd GECOS field for -the current user. +environment variable if set, otherwise will return the passwd GECOS field +(truncated at the first comma if it contains one) for +the current user. The (\fIlocalmbox\fR\^) function will return the complete +form of the local mailbox, suitable for use in a \*(lqFrom\*(rq header. +It will return the +.RI \*(lq Local-Mailbox \*(rq +profile entry if it is set; if it is not, it will be equivalent to: +.PP +.RS 5 +.nf +%(myname) <%(me)@%(myhost)> +.fi +.RE .PP The following functions require a date component as an argument: .PP .RS 5 .nf .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u -.I Function Argument Return Description +.I "Function Argument Return Description" sec date integer seconds of the minute min date integer minutes of the hour hour date integer hours of the day (0-23) @@ -337,7 +367,7 @@ mon date integer month of the year month date string month of the year (abbrev.) lmonth date string month of the year year date integer year (may be > 100) -zone date integer timezone in hours +zone date integer timezone in minutes tzone date string timezone string szone date integer timezone explicit? (1=explicit,0=implicit,\-1=unknown) @@ -346,8 +376,9 @@ date2gmt date coerce date to GMT dst date integer daylight savings in effect? (0 or 1) clock date integer seconds since the UNIX epoch rclock date integer seconds prior to current time -tws date string official 822 rendering +tws date string official RFC 822 rendering pretty date string user-friendly rendering +nodate date integer returns 1 if date is invalid .fi .RE .PP @@ -358,14 +389,18 @@ the first address present in the header component. .RS 5 .nf .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u -.I Function Argument Return Description -proper addr string official 822 rendering +.I "Function Argument Return Description" +proper addr string official RFC 822 rendering friendly addr string user-friendly rendering addr addr string mbox@host or host!mbox rendering* pers addr string the personal name* note addr string commentary text* mbox addr string the local mailbox* -mymbox addr integer List has the user's address? (0 or 1) +mymbox addr integer list has the user's address? (0 or 1) +getmymbox addr string the user's (first) address, + with personal name +getmyaddr addr string the user's (first) address, + without personal name host addr string the host domain* nohost addr integer no host was present (0 or 1)* type addr integer host type* (0=local,1=network, @@ -408,11 +443,36 @@ the left up to the field width. The functions (\fIputnum\fR\^) and (\fIputstr\fR\^) are somewhat special: they print their result in the minimum number of characters required, and ignore any leading field width argument. The (\fIputlit\fR\^) -function outputs the exact contents of str register without any changes +function outputs the exact contents of the str register without any changes such as duplicate space removal or control character conversion. +The (\fIzputlit\fR\^) function similarly outputs the exact contents of +the str register, but requires that those contents not occupy any +output width. It can therefore be used for outputting terminal escape +sequences. +.PP +There are a limited number of function escapes to output terminal escape +sequences. These sequences are retrieved from the +.IR terminfo (5) +database according to the current terminal setting. The (\fIbold\fR\^), +(\fIunderline\fR\^), and (\fIstandout\fR\^) escapes set bold mode, +underline mode, and standout mode respectively. +.PP +(\fIhascolor\fR\^) +can be used to determine if the current terminal supports color. +(\fIfgcolor\fR\^) and (\fIbgcolor\fR\^) set the foreground and +background colors respectively. Both of these escapes take one literal +argument, the color name, which can be one of: black, red, green, yellow, +blue, magenta, cyan, white. (\fIresetterm\fR\^) resets all terminal +attributes back to their default setting. +.PP +All of these terminal escape should be used in conjunction with +(\fIzputlit\fR\^) (preferred) or (\fIputlit\fR\^), as the normal +(\fIputstr\fR\^) function will strip out control characters. .PP The available output width is kept in an internal register; any output -past this width will be truncated. +past this width will be truncated. The one exception to this is +(\fIzputlit\fR\^) functions will still be executed in case a terminal reset +code is being placed at the end of the line. .SS Special Handling A few functions have different behavior depending on what command they are being invoked from. @@ -425,6 +485,78 @@ If you need to create an address list that includes previously-seen addresses you may use the (\fIconcataddr\fR\^) function, which is identical to (\fIformataddr\fR\^) in all other respects. Note that (\fIconcataddr\fR\^) will NOT add addresses to the duplicate-suppression cache. +.SS Other Hints and Tips +Sometimes to format function writers it is confusing as to why output is +duplicated. The general rule to remember is simple: If a function or +component escape is used where it starts with a %, then it will generate +text in the output file. Otherwise, it will not. +.PP +A good example is a simple attempt to generate a To: header based on +the From: and Reply-To: headers: +.PP +.RS 5 +.nf +%(formataddr %<{reply-to}%|%{from})%(putaddr To: ) +.fi +.RE +.PP +Unfortuantely if the Reply-to: header is NOT present, the output line that is +generated will be something like: +.PP +.RS 5 +.nf +My From User To: My From User +.fi +.RE +.PP +What went wrong? When performing the test for the +.B if +clause (%<), the component is not output because it is considered an +argument to the +.B if +statement (hence the rule about the lack of % applies). But the component +escape in our +.B else +statement (everything after the `%|') is NOT an argument to anything; the +syntax is that it is written with a %, and thus the value of that component +is output. This also has the side effect of setting the +.I str +register, which is later picked up by the (\fIformataddr\fR\^) function +and then output by (\fIputaddr\fR\^). This format string has another bug +as well; there should always be a valid width value in the +.I num +register when (\fIputaddr\fR\^) is called, otherwise bad formatting can take +place. +.PP +The solution is to use the (\fIvoid\fR\^) function; this will prevent the +function or component from outputting any text. With this in place (and +using (\fIwidth\fR\^) to set the +.I num +register for the width, a better implementation would look like: +.PP +.RS 3 +.nf +%(formataddr %<{reply-to}%|%(void{from})%(void(width))%(putaddr To: ) +.fi +.RE +.PP +It should be noted here that the side-effects of functions and component +escapes still are in force: as a result each component +test in the +.B if\-elseif\-else\-endif +clause sets the +.I str +register. +.PP +As an additional note, the (\fIformataddr\fR\^) and (\fIconcataddr\fR\^) +functions have special behavior when it comes to the +.I str +register. The starting point of the register is saved and is used to +build up entries in the address list. +.PP +You will find the +.B fmttest +utility invaluable when debugging problems with format strings. .SS Examples With all this in mind, here's the default format string for @@ -451,7 +583,7 @@ a space should be printed. Next: .RE .PP the month and date are printed in two digits (zero filled) separated by -a slash. Next, +a slash. Next, .PP .RS 5 .nf @@ -562,7 +694,7 @@ If a switch was given to .B repl (see -.BR repl (1) +.IR repl (1) for more details about %{\fIfcc\fR\^}), an \*(lqFcc:\*(rq header is output. .PP @@ -625,7 +757,7 @@ to have far more than 10000 messages. .\" process 200 messages a day and still get some real work .\" done." The authors apparently only planned to get .\" real work done for about 50 days per folder.) -Nontheless (as noted above) +Nonetheless (as noted above) the various scan format strings are inherited from older MH versions, and are generally hard-coded to 4 digits of message number before formatting problems @@ -649,10 +781,11 @@ conditional is used to test whether the message number has 5 or more digits. -If so, it is printed at full width: otherwise +If so, it is printed at full width, otherwise at 4 digits. .SH "SEE ALSO" -scan(1), repl(1), ap(8), dp(8) - +.IR scan (1), +.IR repl (1), +.IR fmttest (1), .SH CONTEXT None