mh-format.5mh
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 5MH 代码 · 共 497 行
5MH
497 行
.ds MA MH.TH mh-format 5mh.SH Namemh-format \- format file for \*(MA message system.SH Description.NXR "mh-format formatter".NXR "MH system" "file formatter"Several \*(MA commands utilize either a .PN formatstring or a.PN formatfile during their execution.For example,.MS scan 1mhuses a format string which specifies how .PN scan should generate the.PN scan listing for each message;.MS repl 1mhuses a format file which directs it how to generate thereply to a message, and so on..PPThis reference page describes how to write new format commands or modifyexisting ones. You should not attempt this unless you are an experienced \*(MA user..PPA format string is similar to a .PN printfstring, but uses multi-letter escapes.The rest of this reference page assumes a knowledge of the .PN printfroutine.When specifying a string,the usual C backslash characters are honored:.PN \eb ,.PN \ef , .PN \en , .PN \erand .PN \et .Continuation lines in format files end with .PN \efollowed by the newlinecharacter..PPWhen an escape is interpreted and the result is immediately printed,you can specify an optional field width to print the field in exactly a given number of characters.A numeric escape, such as.PN "%4(size)" ,will print at most 4 digits of the value. Any overflow is marked by a .PN ?in the first position, for example .PN ?123 .A string escape, such as.PN "%4(me)" ,will print the first four characters of the string.In both cases, short fields are padded at the right, usually with a blank.If the field width argument begins with a zero, for example.PN "%04(size)" ,the fill character is a zero..PPThe interpretation model is based on a simple machine with two registers,.PN numand .PN str .The former contains an integer value, the latter a string value.When an escape is processed,if it requires an argument,it reads the current value of either .PN numor .PN str ;and,if it returns a value, it writes either .PN numor .PN str ..PPEscapes are of three types:.PN components ,.PN functions ,and .PN control ..\".\".SS Component EscapesA component escape represents a header field in the message being processed.It is written .PN {name} ,where the name is the name of the header field.For example, .PN {date}refers to the .PN Date:field of the message..PPThe value of a component escape is the content of the named field.This is always a string.For example, the header of an unsent message might look as follows:.EXTo: smith@localcc: davisSubject: tomorrow's meeting.EEIn this example, the value of the component escape.PN {subject}is the string .PN "tomorrow's meeting" ..\".\".SS Control EscapesA control escape is one of: .PN %< , .PN %|and .PN %> .Thesecorrespond to if-then-else constructs..PPThere are two syntaxes allowed by these control escapes.The first is:.EX%<(function)Command-string%>%<{component}Command-String%>.EEIf the function or component is non-zero (for integer-valued escapes)or non-empty (for string-valued escapes),everything up to the corresponding .PN %>is interpreted.Otherwise, skip to the next .PN %> and begin interpreting again..PPThe second form of syntax is as follows:.EX%<(function)Then-Command-String%|Else-Command-String%>%<{component}Then-Command-String%|Else-Command-String%>.EEIf the function or component is non-zero or non-null, the.PN Then-Command-String is interpreted.Otherwise, skip to .PN %|and interpret the .PN Else-Command-String .Only one string is ever interpreted; if the first string is interpreted,the system skips from the .PN %|control escape to the.PN %>character..\".\" if .\" .PN escape.\" is non-zero (for integer-valued escapes),.\" or non-empty (for string-valued escapes),.\" then everything up to .\" .PN %|.\" or .\" .PN %>.\" (whichever comes first) is interpreted;.\" else, then skip to .\" .PN %|.\" or .\" .PN %>.\" (whichever comes first).\" and start interpreting again..\".\".SS Function EscapesA function escape is specified as .PN %(name) ,and is statically defined. .PPMost functions expect an argument of a particular type.In the tables of functions that follow, these types are referred to:.TP 10.PN literalA literal number or string; for example,.PN %(func 1234)takes the number 1234 as its argument..TP.PN compAny header component; for example, .PN %(func{from})takes the contents of the \f(CWFrom:\fRheader field as an argument..TP .PN exprAn optional component, function or string, perhaps nested.For example, .PN %(func (func2{comp}))takes the return value of the function .PN (func2{comp})as its argument.If no argument is provided, the function will read either the.PN numor the .PN strregister, as appropriate..PPFunctions return three types of values:.PN string ,.PN integer ,and, for those functions which return a true or false status,.PN boolean .In the tables that follow, .PN strand.PN numrepresent the values stored in these registers..PN argrepresents the value of the argument supplied to the function..PPThe following table lists the function escapes:.PP.TStab(+);l l l ll l l l._.sp 6pEscape+Argument+Returns+Interpretation.sp 6p_.sp 6pmsg+ +integer+message numbercur+ +integer+message is currentsize+ +integer+size of messagestrlen+ +integer+length of \f(CWstr\fRwidth+ +integer+output buffer size in bytescharleft+integer+integer+space left in output buffertimenow+ +integer+seconds since the epochme+ +string+the user's mailboxeq+literal+integer+\f(CWnum\fR =\|= \f(CWarg\fRne+literal+integer+\f(CWnum\fR != \f(CWarg\fRgt+literal+integer+\f(CWnum\fR > \f(CWarg\fRmatch+literal+boolean+\f(CWstr\fR contains \f(CWarg\fRamatch+literal+boolean+\f(CWstr\fR starts with \f(CWarg\fRplus+ +integer+\f(CWarg\fR plus \f(CWnum\fRminus+ +integer+\f(CWarg\fR minus \f(CWnum\fRdivide+literal+integer+\f(CWnum\fR divided by \f(CWarg\fRnum+literal+integer+Set \f(CWnum\fR to \f(CWarg\fRlit+literal+integer+Set \f(CWstr\fR to \f(CWarg\fRnonzero+expr+integer+\f(CWnum\fR is non-zerozero+expr+integer+\f(CWnum\fR is zeronull+expr+integer+\f(CWstr\fR is emptynonnull+expr+integer+\f(CWstr\fR is non-emptyvoid+expr+ +Set \f(CWstr\fR or \f(CWnum\fRcomp+comp+string+Set \f(CWstr\fR to component textcompval+comp+integer+\f(CWnum\fR set to \f(CWatoi(str)\fRtrim+expr+ +trim trailing white space from \f(CWstr\fRputstr+expr+ +print \f(CWstr\fRputstrf+expr+ +print \f(CWstr\fR in a fixed widthputnum+expr+ +print \f(CWnum\fRputnum+expr+ +print \f(CWnum\fR in a fixed width.sp 6p_.TE.PPThe following functions require a date component as an argument:.PP.TSl l l l l l l l. _.sp 6pEscape Argument Returns Interpretation.sp 6p_.sp 6psec date integer seconds of the minutemin date integer minutes of the dayhour date integer hours of the day (24 hour clock)wday date integer day of the week (Sunday=0)day date string day of the weekweekday date string day of the week (long)sday date integer day of the week known 1 for explicit in date 0 for implicit \-1 for unknownmday date integer day of the monthyday date integer day of the yearmon date integer month of the yearmonth date string month of the year (abbreviated)lmonth date string month of the year (long form)year date integer year of the centuryzone date integer timezone in hourstzone date string timezone as a stringszone date integer timezone explicit? 1 for explicit 0 for implicit \-1 for unknowndate2local date coerce date to local timezonedate2gmt date coerce date to GMTdst date integer daylight savings in effect?clock date integer seconds since the epochrclock date integer seconds prior to current timetws date string official RFC 822 rendering of the datepretty date string a more user-friendly renderingnodate date \f(CWstr\fR could not be parsed as a date.sp 6p_.TE.PPThe following functions require an address component as an argument.Some functions return a value based on the first address in the field only.These are indicated by the note \f(CW(first only)\fR..PP.TSl l l ll l l l._.sp 6pEscape Argument Returns Interpretation.sp 6p_.sp 6pproper addr string official RFC 822 rendering of the addressfriendly string string a more user-friendly renderingpers addr string the personal name (first only)note addr string commentary text (first only)mbox addr string the local part of the address (first only)mymbox addr does the address refer to the user's mailbox? (0=no, 1=yes)host addr string the domain part of the address (first only)nohost addr integer no host was present in the address (first only)type addr integer the type of host \-1 for uucp 0 for local 1 for network 2 for unknownpath addr string the route part of the address (first only)ingrp addr integer the address appeared inside a group (first only)gname addr string name of the group (first only)formataddr expr append \f(CWarg\fR to \f(CWstr\fR as an address listputaddr literal print \f(CWstr\fR address list with \f(CWarg\fR as an optional label; get line width from \f(CWnum\fR.sp 6p_.TE.PPSome functions that print their arguments can be controlledby giving field width arguments.The functions.PN (putnumf)and.PN (putstrf)print their arguments as specified by the field width arguments.So .PN %06(putnumf(size))will print the message size in six digits, filled with leading zeros;.PN %14(putsrtf{from})will print the \f(CWFrom:\fRheader field in 14 characters, with trailing spaces as required.With .PN (putstrf) ,supplying a negative field width will cause the string to beright-justified within the field.The functions .PN (putnum)and.PN (putstr)ignore any field width arguments,and print their arguments in the minimum number of characters required..\".\".\".\".SH RestrictionsWhen the \f(CWfriendly\fR format for addresses is used,addresses longer than about 180 characters are truncated to an emptystring.This means that such addresses will not appear in the .PN scandisplay..PPThe function.PN (mymbox{comp})checks each of the addresses in the named header component .PN {comp}against the user's mailbox name, and against any other mailboxeslisted in the \f(CWAlternate-Mailboxes\fRentry in the user's .PN \&.mh_profile .It returns true if any of the address matches.However, it also returns true if the named.PN {comp}header field is not present.If necessary, you can use the .PN (null)or.PN (nonnull)functions to test explicitly for the presence of the field..\".\".\".\".SH ExamplesThe default format string for .PN scanfollows.This has been divided into several pieces for readability.The first part is:.EX%4(msg)%<(cur)+%| %>%<{replied}-%| %>.EEThis means that the message number should be printed in four digits;if the message is the current message then a .PN +is printed. If the message is not the current message, then a space is printed. If a \f(CWReplied:\fRfield is present, a .PN \-is printed. If no \f(CWReplied:\fRfield is present, then a space is printed.Next:.EX%02(mon{date})/%02(mday{date}).EEThe month and date are printed in two digits (zero filled).Next:.EX%<{date} %|*>.EEIf no \f(CWDate:\fRfield is present, then a .PN *is printed, otherwise a space.Next:.EX%<(mymbox{from})To:%14(friendly{to}).EEIf the message is from me,print \f(CWTo:\fRfollowed by a user-friendly rendering of the first address in the \f(CWTo:\fR field..EX%|%17(friendly{from})%>.EEIf the message is not from me, then the \f(CWFrom:\fRaddress is printed.And finally:.EX%{subject}%<{body}<<%{body}%>.EEThe subject and initial body are printed preceded by the string \f(CW<<\fR..PPAlthough this seems complicated,this method is flexible enough to extract individual fields and print them in any format the user desires..PPIf the .B \-form .I formatfileswitch is given with the.PN scancommand, it will treat each line in the named file as a format string, and act accordingly.This lets the user develop template .PN scan listing formats.Some examples can be found in .PN /usr/lib/mh/scan.time ,.PN /usr/lib/mh/scan.size , and .PN /usr/lib/mh/scan.timely ..\".\".\".\".SH See Alsoscan(1mh),ap(8mh), dp(8mh)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?