aboutsummaryrefslogtreecommitdiff
path: root/pkg/language/doc/fprint.hlp
blob: 37a83ef85fcd76af2c05697762af5c744505ec17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.help "fprint,print,printf" Jul95 language
.ih
NAME
.nf
print  -- print to the standard output
fprint -- print to a parameter
printf -- formatted print to the standard output
.fi
.ih
USAGE
.nf
print  expr [expr ...]
fprint param expr [expr ...]
printf format [arg ...]
.fi
.ih
PARAMETERS
.ls expr
Any expression, the string value of which is to be printed.
.le
.ls param
The \fIfprint\fR call will deposit the output string in the value field of 
this parameter.
.le
.ls format
A C-like format specification string containing plain characters, which 
are simply copied into the output string, and conversion specifications,
each of which causes conversion and printing of zero or more \fIargs\fR.
.le
.ls arg    
Any expression, variable, parameter value or constant to be used in the
\fIformat\fR string's conversion specifications.  One arg is required for
each conversion specification.
.le
.ih
DESCRIPTION
The \fIprint\fR and \fIfprint\fR commands format a line of text and write
it to either the standard output or in the case of \fIfprint\fR,
the p_value field of the named parameter.  The output is free format although
spaces may be specifically inserted (as quoted string constants) to make the
output easier to read.  One space is automatically inserted after each
numeric argument; this can be defeated by coercing the argument to a string
with the \fIstr\fR intrinsic function.  A newline is automatically output
at the end of the output line.  I/O redirection may be used with \fIprint\fR
or \fIprintf\fR to write to a file or through a pipe to another task.

The \fIprintf\fR command allows more control over the output format and can
convert arguments for printing as another type.  The \fIformat\fR string
contains plain text characters and format specifications as well as
escape sequences for printing tabs, newlines, etc. Unlike the other
two commands, spaces and newlines must be explicitly given in the format
string.  

A format specification has the form "%[W][.D]Cn", where W is  the  field
width,  D is the number of decimal places or the number of digits of
precision, C is the format  code,  and  N  is  radix  character  for
format  code "r" only.  The W and D fields are optional.  The format
codes C are as follows:

.nf
       b    boolean (YES or NO)
       c    single character (c or '\c' or '\0nnn')
       d    decimal integer
       e    exponential format (D specifies the precision)
       f    fixed format (D specifies the number of decimal places)
       g    general format (D specifies the precision)
       h    hms format (hh:mm:ss.ss, D = no. decimal places)
       m    minutes, seconds (or hours, minutes) (mm:ss.ss)
       o    octal integer
       rN   convert integer in any radix N
       s    string (D field specifies max chars to print)
       t    advance To column given as field W
       u    unsigned decimal integer 
       w    output the number of spaces given by field W
       x    hexadecimal integer
       z    complex format (r,r) (D = precision)
.fi

Conventions for W (field width) specification:

.nf
    W =  n      right justify in field of N characters, blank fill
        -n      left justify in field of N characters, blank fill
        0n      zero fill at left (only if right justified)
    absent, 0   use as much space as needed (D field sets precision)
.fi

Escape sequences (e.g. "\n" for newline):
.nf
        \f      formfeed
        \n      newline (crlf)
        \r      carriage return
        \t      tab
        \"      string delimiter character
        \'      character constant delimiter character
        \\      backslash character
        \nnn    octal value of character
.fi

Compute mode (a parenthesized argument list) is recommended for this task
to avoid surprises.
.ih
EXAMPLES
1. Print the name of the current terminal.

	cl> print ("terminal = ", envget ("terminal"))

2. Output a blank line on the standard output, e.g., in a script.

	print ("")

3. Format a command and send it to the host system.  In this example,
"fname" is a string valued parameter.

	cl> print ("!ls -l ", fname) | cl

4. Write to a file.

.nf
	for (x=1.;  x < 1E5;  x *= 10) 
	    print ("the sqrt of ", x, "is ", sqrt(x), >> "output")
.fi

5. Print a formatted string.

.nf
	cl> printf ("pi = %.6f\n", 2*atan2(1.0,0.0))
	pi = 3.141593
	cl> printf ("RA = %h  DEC = %m\nExptime = %8.2f\n",ra,dec,etime)
	RA = 18:32:33.5 DEC = 23:45.2	Exptime =     1.57
.fi

6. Print to a parameter.  Note that \fIfprint\fR allows you to create a 
formatted string, whereas the scan() example requires a struct parameter.

.nf
	cl> x = 3.14159
	cl> fprint (s1, "pi = ", x)
	cl> = s1
	pi = 3.14159

	     or 

	cl> printf ("pi = %g\n", x) | scan (line)
.fi

.ih
BUGS
The \fIfprint\fR task is not very useful since the same thing can be
accomplished by string concatenation and assignment.
.ih
SEE ALSO
scan, scanf, fscan, fscanf, strings
.endhelp