Charles.Forsyth20061220965a0ca19 years agoHistory
276 lines · 5.2 KB · Text
RawDownload
.TH SYS-PRINT 2.SH NAMEprint, aprint, fprint, sprint \- print formatted output.SH SYNOPSIS.EXinclude "sys.m";sys := load Sys Sys->PATH; aprint: fn(format: string, *): array of byte;fprint: fn(fd: ref FD, format: string, *): int;print:  fn(format: string, *): int;sprint: fn(format: string, *): string;.EE.SH DESCRIPTIONThese functions format and print their arguments as.SM UTFtext..B Printwrites text to the standard output..B Fprintwrites to the named outputfile descriptor..B Sprintplaces textin a string, which it returns..B Aprintis similar but returns the text in.IR utf (6)representation as an array of bytes..B Printand.B fprintreturn the number of bytes transmittedora negative value if an  error was encountered when writing the output..PPEach of these functionsconverts, formats, and prints itstrailing argumentsunder control of a.IR format string.Theformatcontains two types of objects:plain characters, which are simply copied to theoutput stream,and conversion specifications,each of which results in fetching ofzero or morearguments.The Limbo compiler recognizes calls to these functionsand checks that the arguments match the format specifications in number and type..PPEach conversion specification has the following format:.IP.BI "%" " \fR[\fPflags\fR]\fP verb".PPThe verb is a single character and each flag is a single character or a(decimal) numeric string.Up to two numeric strings may be used;the first is called.IR f1 ,the second.IR f2 .They can be separated by.RB ` . ',and if one is present, then.I f1and.I f2are taken to be zero if missing, otherwise they are considered `omitted'.Either or both of the numbers may be replaced with the character.BR * ,meaning that the actual number will be obtained from the argument listas an integer.The flags and numbers are arguments tothe.I verbdescribed below..PP.TP.BR d ", " o ", " x ", " XThe numeric verbs.BR d ,.BR o ,and.B xformat their.B intarguments in decimal, octal, and hexadecimal (with hex digits in lower-case).The flag.B bis required when the corresponding value is a Limbo.BR  big ,not an.BR int .Arguments are taken to be signed, unless the.B uflag is given, to force them to be treated as unsigned.Each interprets the flags.B \- ,.B , ,and.B #to mean left justified, commas every three digits, and alternative format.If.I f2is not omitted, the number is padded on the left with zerosuntil at least.I f2digits appear.Then, if alternative format is specifiedfor.B xconversion, the number is preceded by.BR 0x .Finally, if.I f1is not omitted, the number is padded on the left (or right, ifleft justification is specified) with enough blanks tomake the field at least.I f1characters long.The verb.B Xis similar to.BR x ,except that the hexadecimal digits are displayed in upper-case,and in alternative format, the number is preceded by.BR 0X ..PP.TP.BR e ", " f ", " gThe floating point verbs.BR e ,.BR f ,and.BR gtake a.B realargument.Each interprets the flags.BR + ,.BR \- ,and.B #to meanalways print a sign,left justified,andalternative format..I F1is the minimum field width and,if the converted value takes up less than.I f1characters, it is padded on the left (or right, if `left justified')with spaces..I F2is the number of digits that are converted after the decimal place for.BR eand.B fconversions,and.I f2is the maximum number of significant digits for.B gconversions.The .B fverb produces output of the form.RB [ \- ]\c.IR digits [\c.BI \&. digits\fR].The.B econversion appends an exponent.BR e [ \- ]\c.IR digits .The.B gverb will output the argument in either.B eor.B fwith the goal of producing the smallest output.Also, trailing zeros are omitted from the fraction part ofthe output, and a trailing decimal point appears only if it is followedby a digit.When alternative format is specified, the result will always contain a decimal point,and for.B gconversions, trailing zeros are not removed..TP.BR E ", " GThese are the same as.B eand.B grespectively, but use.B Enot.B eto specify an exponent when one appears..TP.B cThe.B cverb converts a single Unicode characterfrom an.B intargument to a UTF encoding,justified within a field of.I f1characters as described above..TP.B rThe.B rverb takes no arguments; it prints the error stringassociated with the most recent system error..TP.B sThe.B sverb copies a.B stringto the output.The number of characters copied.RI ( n )is the minimumof the size of the string and.IR f2 .These.I ncharacters are justified within a field of.I f1characters as described above..TP.B qThe.B qverb copies a.B stringto the output as for.BR s ,but quotes the string in the style of.IR sh (1)only if necessary to avoid ambiguity (for instanceif the string contains quotes or spaces).If the format string, however, includes the specifier.B #(for example.BR %#q ),the printed string will always be quoted..SH SOURCE.B /libinterp/runt.c:/^xprint.br.B /os/port/print.c.br.B /lib9/print.c.SH SEE ALSO.IR sys-intro (2),.IR sys-open (2).SH BUGSThe.B xverb does not apply the.B 0xprefix when.I f2is present.The prefix should probably be.B 16ranyway.