Thu Jan 7 21:21:35 2021 UTC ()
bc(1): Use more .Ql, misc related fixes.


(uwe)
diff -r1.6 -r1.7 src/external/bsd/bc/dist/bc.1

cvs diff -r1.6 -r1.7 src/external/bsd/bc/dist/bc.1 (expand / switch to unified diff)

--- src/external/bsd/bc/dist/bc.1 2021/01/07 20:37:33 1.6
+++ src/external/bsd/bc/dist/bc.1 2021/01/07 21:21:35 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: bc.1,v 1.6 2021/01/07 20:37:33 uwe Exp $ 1.\" $NetBSD: bc.1,v 1.7 2021/01/07 21:21:35 uwe Exp $
2.\" 2.\"
3.\" bc.1 - the bc manual 3.\" bc.1 - the bc manual
4.\" 4.\"
5.\" Copyright (C) 1991-1994, 1997, 2000, 2003, 2012-2017 Free Software Foundation, Inc. 5.\" Copyright (C) 1991-1994, 1997, 2000, 2003, 2012-2017 Free Software Foundation, Inc.
6.\" Copyright (C) 2004, 2017 Philip A. Nelson 6.\" Copyright (C) 2004, 2017 Philip A. Nelson
7.\" Copyright (C) 2017 Thomas Klausner 7.\" Copyright (C) 2017 Thomas Klausner
8.\" All rights reserved. 8.\" All rights reserved.
9.\" 9.\"
10.\" Redistribution and use in source and binary forms, with or without 10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions 11.\" modification, are permitted provided that the following conditions
12.\" are met: 12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright 13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer. 14.\" notice, this list of conditions and the following disclaimer.
@@ -118,27 +118,28 @@ has a length of 7 and a scale of 3. @@ -118,27 +118,28 @@ has a length of 7 and a scale of 3.
118.El 118.El
119.Ss VARIABLES 119.Ss VARIABLES
120Numbers are stored in two types of variables, simple variables and 120Numbers are stored in two types of variables, simple variables and
121arrays. 121arrays.
122Both simple variables and array variables are named. 122Both simple variables and array variables are named.
123Names begin with a letter followed by any number of letters, digits and 123Names begin with a letter followed by any number of letters, digits and
124underscores. 124underscores.
125All letters must be lower case. 125All letters must be lower case.
126(Full alpha-numeric names are an extension. 126(Full alpha-numeric names are an extension.
127In POSIX 127In POSIX
128.Nm 128.Nm
129all names are a single lower case letter.) 129all names are a single lower case letter.)
130The type of variable is clear by the context 130The type of variable is clear by the context
131because all array variable names will be followed by brackets ([]). 131because all array variable names will be followed by brackets
 132.Pq Ql [] .
132.Pp 133.Pp
133There are four special variables, 134There are four special variables,
134.Ic scale , 135.Ic scale ,
135.Ic ibase , 136.Ic ibase ,
136.Ic obase , 137.Ic obase ,
137and 138and
138.Ic last . 139.Ic last .
139.Ic scale 140.Ic scale
140defines how some operations use digits after the decimal point. 141defines how some operations use digits after the decimal point.
141The default value of 142The default value of
142.Ic scale 143.Ic scale
143is 0. 144is 0.
144.Ic ibase 145.Ic ibase
@@ -146,41 +147,41 @@ and @@ -146,41 +147,41 @@ and
146.Ic obase 147.Ic obase
147define the conversion base for input and output numbers. 148define the conversion base for input and output numbers.
148The default for both input and output is base 10. 149The default for both input and output is base 10.
149.Ic last 150.Ic last
150(an extension) is a variable that has the value of the last 151(an extension) is a variable that has the value of the last
151printed number. 152printed number.
152These will be discussed in further detail where appropriate. 153These will be discussed in further detail where appropriate.
153All of these variables may have values assigned to them 154All of these variables may have values assigned to them
154as well as used in expressions. 155as well as used in expressions.
155.Ss COMMENTS 156.Ss COMMENTS
156Comments in 157Comments in
157.Nm 158.Nm
158start with the characters 159start with the characters
159.Dq Ic /* 160.Ql /*
160and end with the characters 161and end with the characters
161.Dq Ic */ . 162.Ql */ .
162Comments may start anywhere and appear as a single space in the input. 163Comments may start anywhere and appear as a single space in the input.
163(This causes comments to delimit other input items. 164(This causes comments to delimit other input items.
164For example, a comment can not be found in the middle of 165For example, a comment can not be found in the middle of
165a variable name.) 166a variable name.)
166Comments include any newlines (end of line) between 167Comments include any newlines (end of line) between
167the start and the end of the comment. 168the start and the end of the comment.
168.Pp 169.Pp
169To support the use of scripts for 170To support the use of scripts for
170.Nm , 171.Nm ,
171a single line comment has been added as an extension. 172a single line comment has been added as an extension.
172A single line comment starts at a 173A single line comment starts at a
173.Dq Ic # 174.Ql #
174character and continues to the next end of the line. 175character and continues to the next end of the line.
175The end of line 176The end of line
176character is not part of the comment and is processed normally. 177character is not part of the comment and is processed normally.
177.Ss EXPRESSIONS 178.Ss EXPRESSIONS
178The numbers are manipulated by expressions and statements. 179The numbers are manipulated by expressions and statements.
179Since the language was designed to be interactive, statements and expressions 180Since the language was designed to be interactive, statements and expressions
180are executed as soon as possible. 181are executed as soon as possible.
181There is no 182There is no
182.Dq main 183.Dq main
183program. 184program.
184Instead, code is executed as it is encountered. 185Instead, code is executed as it is encountered.
185(Functions, discussed in 186(Functions, discussed in
186detail later, are defined when encountered.) 187detail later, are defined when encountered.)
@@ -195,33 +196,35 @@ by the variable @@ -195,33 +196,35 @@ by the variable
195The legal values of 196The legal values of
196.Ic ibase 197.Ic ibase
197are 2 through 36. 198are 2 through 36.
198(Base values greater than 16 are an extension.) 199(Base values greater than 16 are an extension.)
199Assigning a value outside this range to 200Assigning a value outside this range to
200.Ic ibase 201.Ic ibase
201will result in a value of 2 or 36. 202will result in a value of 2 or 36.
202Input numbers may contain the characters 0-9 and A-Z. 203Input numbers may contain the characters 0-9 and A-Z.
203(Note: They must be capitals. 204(Note: They must be capitals.
204Lower case letters are variable names.) 205Lower case letters are variable names.)
205Single digit numbers always 206Single digit numbers always
206have the value of the digit regardless of the value of 207have the value of the digit regardless of the value of
207.Ic ibase . 208.Ic ibase .
208(i.e. A = 10.) 209(i.e.\&
 210.Ql A
 211=\~10.)
209For multi-digit numbers, 212For multi-digit numbers,
210.Nm 213.Nm
211changes all input digits greater or equal to ibase to the value of 214changes all input digits greater or equal to ibase to the value of
212.Ic ibase - 1 . 215.Ic ibase - 1 .
213This makes the number 216This makes the number
214.Dq ZZZ 217.Ql ZZZ
215always be the largest 3 digit number of the input base. 218always be the largest 3 digit number of the input base.
216.Pp 219.Pp
217Full expressions are similar to many other high level languages. 220Full expressions are similar to many other high level languages.
218Since there is only one kind of number, there are no rules for mixing 221Since there is only one kind of number, there are no rules for mixing
219types. 222types.
220Instead, there are rules on the scale of expressions. 223Instead, there are rules on the scale of expressions.
221Every expression has a scale. 224Every expression has a scale.
222This is derived from the scale of original 225This is derived from the scale of original
223numbers, the operation performed and in many cases, the value of the 226numbers, the operation performed and in many cases, the value of the
224variable 227variable
225.Ic scale . 228.Ic scale .
226Legal values of the variable 229Legal values of the variable
227.Ic scale 230.Ic scale
@@ -352,72 +355,88 @@ The boolean @@ -352,72 +355,88 @@ The boolean
352operators are: 355operators are:
353.Bl -tag -width 15n 356.Bl -tag -width 15n
354.It Ic "!expr" 357.It Ic "!expr"
355The result is 1 if expr is 0. 358The result is 1 if expr is 0.
356.It Ic "expr && expr" 359.It Ic "expr && expr"
357The result is 1 if both expressions are non-zero. 360The result is 1 if both expressions are non-zero.
358.It Ic "expr || expr" 361.It Ic "expr || expr"
359The result is 1 if either expression is non-zero. 362The result is 1 if either expression is non-zero.
360.El 363.El
361.Pp 364.Pp
362The expression precedence is as follows: (lowest to highest) 365The expression precedence is as follows: (lowest to highest)
363.Bl -enum -offset indent 366.Bl -enum -offset indent
364.It 367.It
365|| operator, left associative 368.Ql ||
 369operator, left associative
366.It 370.It
367&& operator, left associative 371.Ql &&
 372operator, left associative
368.It 373.It
369! operator, nonassociative 374.Ql \&!
 375operator, nonassociative
370.It 376.It
371Relational operators, left associative 377Relational operators, left associative
372.It 378.It
373Assignment operator, right associative 379Assignment operator, right associative
374.It 380.It
375+ and - operators, left associative 381.Ql +
 382and
 383.Ql -
 384operators, left associative
376.It 385.It
377*, / and % operators, left associative 386.Ql * ,
 387.Ql /
 388and
 389.Ql %
 390operators, left associative
378.It 391.It
379^ operator, right associative 392.Ql ^
 393operator, right associative
380.It 394.It
381unary - operator, nonassociative 395unary
 396.Ql -
 397operator, nonassociative
382.It 398.It
383++ and -- operators, nonassociative 399.Ql ++
 400and
 401.Ql --
 402operators, nonassociative
384.El 403.El
385.Pp 404.Pp
386This precedence was chosen so that POSIX compliant 405This precedence was chosen so that POSIX compliant
387.Nm 406.Nm
388programs will run correctly. 407programs will run correctly.
389This will cause the use of the relational and logical operators to 408This will cause the use of the relational and logical operators to
390have some unusual behavior when used with assignment expressions. 409have some unusual behavior when used with assignment expressions.
391Consider the expression: 410Consider the expression:
392.Dl Ic a = 3 < 5 411.Dl a = 3 < 5
393.Pp 412.Pp
394Most C programmers would assume this would assign the result of 413Most C programmers would assume this would assign the result of
395.Dq Ic 3 < 5 414.Dq Li 3 < 5
396(the value 1) to the variable 415(the value 1) to the variable
397.Dq Ic a . 416.Va a .
398What this does in 417What this does in
399.Nm 418.Nm
400is assign the value 3 to the variable 419is assign the value 3 to the variable
401.Dq Ic a 420.Va a
402and then compare 3 to 5. 421and then compare 3 to 5.
403It is best to use parenthesis when using relational and logical operators 422It is best to use parenthesis when using relational and logical operators
404with the assignment operators. 423with the assignment operators.
405.Pp 424.Pp
406There are a few more special expressions that are provided in 425There are a few more special expressions that are provided in
407.Nm . 426.Nm .
408These have to do with user defined functions and standard functions. 427These have to do with user defined functions and standard functions.
409They all appear as 428They all appear as
410.Do Ar name ( Ar parameters ) Dc . 429.Do Ar name Ns Li \&( Ns Ar parameters Ns Li \&) Dc .
411See the section on functions for user defined functions. 430See the section on functions for user defined functions.
412The standard functions are: 431The standard functions are:
413.Bl -tag -width 20n 432.Bl -tag -width 20n
414.It Fn length expression 433.It Fn length expression
415The value of the length function is the number of significant digits in the 434The value of the length function is the number of significant digits in the
416expression. 435expression.
417.It Fn read 436.It Fn read
418The read function (an extension) will read a number from the standard 437The read function (an extension) will read a number from the standard
419input, regardless of where the function occurs. 438input, regardless of where the function occurs.
420Beware, this can cause problems with the mixing of data and program in 439Beware, this can cause problems with the mixing of data and program in
421the standard input. 440the standard input.
422The best use for this function is in a previously written program that 441The best use for this function is in a previously written program that
423needs input from the user, but never allows program code to be input 442needs input from the user, but never allows program code to be input
@@ -452,27 +471,29 @@ An improperly placed newline will cause  @@ -452,27 +471,29 @@ An improperly placed newline will cause
452Because newlines 471Because newlines
453are statement separators, it is possible to hide a newline by using 472are statement separators, it is possible to hide a newline by using
454the backslash character. 473the backslash character.
455The sequence 474The sequence
456.Dq Ic \e<nl> , 475.Dq Ic \e<nl> ,
457where <nl> is the newline appears to 476where <nl> is the newline appears to
458.Nm 477.Nm
459as whitespace instead of a newline. 478as whitespace instead of a newline.
460A statement list is a series of statements separated by semicolons and 479A statement list is a series of statements separated by semicolons and
461newlines. 480newlines.
462The following is a list of 481The following is a list of
463.Nm 482.Nm
464statements and what they do: 483statements and what they do:
465(Things enclosed in brackets ([]) are optional parts of the 484(Things enclosed in brackets
 485.Pq Oo Oc
 486are optional parts of the
466statement.) 487statement.)
467.Bl -tag -width 15n 488.Bl -tag -width 15n
468.It Ar expression 489.It Ar expression
469This statement does one of two things. 490This statement does one of two things.
470If the expression starts with 491If the expression starts with
471.Ao Ar variable Ac Ao Ar assignment Ac ... , 492.Ao Ar variable Ac Ao Ar assignment Ac ... ,
472it is considered to be an assignment statement. 493it is considered to be an assignment statement.
473If the expression is not an assignment statement, the 494If the expression is not an assignment statement, the
474expression is evaluated and printed to the output. 495expression is evaluated and printed to the output.
475After the number is printed, a newline is printed. 496After the number is printed, a newline is printed.
476For example, 497For example,
477.Dq Ic a=1 498.Dq Ic a=1
478is an assignment statement and 499is an assignment statement and
@@ -508,71 +529,73 @@ Due to the interactive nature of @@ -508,71 +529,73 @@ Due to the interactive nature of
508printing a number causes the side effect of assigning the printed value to the 529printing a number causes the side effect of assigning the printed value to the
509special variable 530special variable
510.Ic last . 531.Ic last .
511This allows the user to recover the last value printed without having 532This allows the user to recover the last value printed without having
512to retype the expression that printed the number. 533to retype the expression that printed the number.
513Assigning to 534Assigning to
514.Ic last 535.Ic last
515is legal and will 536is legal and will
516overwrite the last printed value with the assigned value. 537overwrite the last printed value with the assigned value.
517The newly assigned value will remain until the next number is printed 538The newly assigned value will remain until the next number is printed
518or another value is assigned to 539or another value is assigned to
519.Ic last . 540.Ic last .
520(Some installations may allow the 541(Some installations may allow the
521use of a single period (.) which is not part of a number as a short 542use of a single period
522hand notation for 543.Pq Ql \&.
 544which is not part of a number as a short hand notation for
523.Ic last . ) 545.Ic last . )
524.It Ar "string" 546.It Ar "string"
525The 547The
526.Ar string 548.Ar string
527is printed to the output. 549is printed to the output.
528Strings start with a double quote 550Strings start with a double quote
529character and contain all characters until the next double quote character. 551character and contain all characters until the next double quote character.
530All characters are take literally, including any newline. 552All characters are take literally, including any newline.
531No newline character is printed after the string. 553No newline character is printed after the string.
532.It Ic print Ar list 554.It Ic print Ar list
533The 555The
534.Ic print 556.Ic print
535statement (an extension) provides another method of output. 557statement (an extension) provides another method of output.
536The 558The
537.Ar list 559.Ar list
538is a list of strings and expressions separated by commas. 560is a list of strings and expressions separated by commas.
539Each string or expression is printed in the order of the list. 561Each string or expression is printed in the order of the list.
540No terminating newline is printed. 562No terminating newline is printed.
541Expressions are evaluated and their 563Expressions are evaluated and their
542value is printed and assigned to the variable 564value is printed and assigned to the variable
543.Ic last . 565.Ic last .
544Strings in the 566Strings in the
545.Ic print 567.Ic print
546statement are printed to the output and may contain special characters. 568statement are printed to the output and may contain special characters.
547Special characters start with the backslash character (\e). 569Special characters start with the backslash character
 570.Pq Ql \e .
548The special characters recognized by 571The special characters recognized by
549.Nm 572.Nm
550are 573are
551.Sq a 574.Ql a
552(alert or bell), 575(alert or bell),
553.Sq b 576.Ql b
554(backspace), 577(backspace),
555.Sq f 578.Ql f
556(form feed), 579(form feed),
557.Sq n 580.Ql n
558(newline), 581(newline),
559.Sq r 582.Ql r
560(carriage return), 583(carriage return),
561.Sq q 584.Ql q
562(double quote), 585(double quote),
563.Sq t 586.Ql t
564(tab), and 587(tab), and
565.Sq \e 588.Ql \e
566(backslash). 589(backslash).
567Any other character following the backslash will be ignored. 590Any other character following the backslash will be ignored.
568.It { Ar statement_list } 591.It { Ar statement_list }
569This is the compound statement. 592This is the compound statement.
570It allows multiple statements to be grouped together for execution. 593It allows multiple statements to be grouped together for execution.
571.It Ic if ( Ar expression ) Ar statement1 [ Ic else Ar statement2 ] 594.It Ic if ( Ar expression ) Ar statement1 [ Ic else Ar statement2 ]
572The 595The
573.Ic if 596.Ic if
574statement evaluates the 597statement evaluates the
575.Ar expression 598.Ar expression
576and executes 599and executes
577.Ar statement1 600.Ar statement1
578or 601or
@@ -637,27 +660,27 @@ or @@ -637,27 +660,27 @@ or
637are missing, nothing is evaluated at the point they would be evaluated. 660are missing, nothing is evaluated at the point they would be evaluated.
638If 661If
639.Ar expression2 662.Ar expression2
640is missing, it is the same as substituting the value 1 for 663is missing, it is the same as substituting the value 1 for
641.Ar expression2 . 664.Ar expression2 .
642(The optional expressions are an 665(The optional expressions are an
643extension. 666extension.
644POSIX 667POSIX
645.Nm 668.Nm
646requires all three expressions.) 669requires all three expressions.)
647The following is equivalent code for the 670The following is equivalent code for the
648.Ic for 671.Ic for
649statement: 672statement:
650.Bd -literal 673.Bd -literal -offset indent
651expression1; 674expression1;
652while (expression2) { 675while (expression2) {
653 statement; 676 statement;
654 expression3; 677 expression3;
655} 678}
656.Ed 679.Ed
657.It Ic break 680.It Ic break
658This statement causes a forced exit of the most recent enclosing 681This statement causes a forced exit of the most recent enclosing
659.Ic while 682.Ic while
660statement or 683statement or
661.Ic for 684.Ic for
662statement. 685statement.
663.It Ic continue 686.It Ic continue