NAME fprintf - formatted print to a file SYNOPSIS fprintf(fd, fmt, x_1, x_2, ...) TYPES fd file fmt string x_1, x_2, ... any return null DESCRIPTION This prints to the file fd exactly what would be printed to the standard output by printf(fmt, x_1, x_2, ...). EXAMPLE ; fprintf(files(1), "h=%d, i=%d\n", 2, 3); h=2, i=3 ; c = config("epsilon", 1e-6); c = config("display", 6); ; c = config("tilde", 1); c = config("outround", 0); ; c = config("fullzero", 0); ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; a = sqrt(3); ; fprintf(files(2), fmt,a,a,a,a,a,a); 1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. ; file = fopen("/tmp/foo", "w"); ; mat A[4] = {sqrt(2), 3/7, "undefined", null()}; ; fprintf(file, "%f%r",A,A); ; fclose(file); ; !cat /tmp/foo mat [4] (4 elements, 4 nonzero): [0] = 1.4142135623730950488 [1] = ~.42857142857142857142 [2] = "undefined" [3] = NULL mat [4] (4 elements, 4 nonzero): [0] = 1767766952966368811/1250000000000000000 [1] = 3/7 [2] = "undefined" [3] = NULL LIMITS The number of arguments of fprintf() is not to exceed 1024. LINK LIBRARY none SEE ALSO printf, strprintf, print ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fprintf,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fprintf,v $ ## ## Under source code control: 1996/03/12 22:50:41 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME freeredc - free the memory used to store redc data SYNOPSIS freeredc() TYPES return null value DESCRIPTION This function frees the memory used for any redc data currently stored by calls to rcin, rcout, etc. EXAMPLE ; a = rcin(10,27) ; b = rcin(10,15) ; show redc 0 1 27 1 2 15 ; freeredc() ; show redc LIMITS none LINK LIBRARY none SEE ALSO free, freeglobals, freestatics ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: freeredc,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeredc,v $ ## ## Under source code control: 1997/09/06 20:03:35 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME fgetstr - read the next null-terminated string from a file SYNOPSIS fgetstr(fs) TYPES fs file stream open for reading return string, null or error value DESCRIPTION If the stream is at end of file, the null value is returned. If the stream cannot be read, an error value is returned. Otherwise the function returns the string of characters from the current file position to the first null character ('\0') (the file position for further reading then being immediately after the '\0'), or if no null character is encountered, the string of characters to the end of file (the string as usual being terminated by '\0'). If the stream being read is from stdin (i.e. files(0)), the characters entered are not displayed and reading ends when a '\0' is entered (on many terminals this is by ctrl-@). EXAMPLE ; f = fopen("/tmp/junk", "w") ; fputstr(f, " Alpha Beta ", "", "Gamma\n\tDelta") ; freopen(f, "r") ; fgetstr(f) " Alpha Beta " ; fgetstr(f) "" ; fgetstr(f) "Gamma Delta" ; fgetstr(f) LIMITS none LINK LIBRARY none SEE ALSO fputstr, fgetword, fgets, fputs, fopen, files, fprintf ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fgetstr,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fgetstr,v $ ## ## Under source code control: 1996/04/30 03:05:17 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME isreal - whether a value is a real value SYNOPSIS isreal(x) TYPES x any, &any return int DESCRIPTION Determine if x is a real value. This function will return 1 if x is a real value, 0 otherwise. EXAMPLE ; print isreal(2.0), isreal(1), isreal("0") 1 1 0 ; print isreal(2i), isreal(1e20), isreal(1/3) 0 1 1 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isreal,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isreal,v $ ## ## Under source code control: 1994/10/21 02:21:30 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME gd - gudermannian function SYNOPSIS gd(z [,eps]) TYPES z number (real or complex) eps nonzero real, defaults to epsilon() return number or "Log of zero or infinity" error value DESCRIPTION Calculate the gudermannian of z to a nultiple of eps with errors in real and imaginary parts less in absolute value than .75 * eps, or return an error value if z is close to one of the branch points at odd multiples of (pi/2) * i. gd(z) is usually defined initially for real z by one of the formulae gd(z) = 2 * atan(exp(z)) - pi/2 = 2 * atan(tanh(z/2)) = atan(sinh(z)), or as the integral from 0 to z of (1/cosh(t))dt. For complex z, the principal branch, approximated by gd(z, eps), has the cut: re(z) = 0, abs(im(z)) >= pi/2; on the cut calc takes gd(z) to be the limit as z is approached from the right or left according as im(z) > or < 0. If z = x + y*i and abs(y) < pi/2, gd(z) is given by gd(z) = atan(sinh(x)/cos(y)) + i * atanh(sin(y)/cosh(x)). EXAMPLE ; print gd(1, 1e-5), gd(1, 1e-10), gd(1, 1e-15) .86577 .8657694832 .865769483239659 ; print gd(2+1i, 1e-5), gd(2+1i, 1e-10) 1.42291+.22751i 1.4229114625+.2275106584i LIMITS none LINK LIBRARY COMPLEX *c_gd(COMPLEX *x, NUMBER *eps) SEE ALSO agd, exp, ln, sin, sinh, etc. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: gd,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/gd,v $ ## ## Under source code control: 1997/09/06 20:03:35 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME select - form a list by selecting element-values from a given list SYNOPSIS select(x, y) TYPES x list y string return list DESCRIPTION If y is to be the name of a user-defined function, select(x, y) returns a list whose members are the values z of elements of x for which the function at z tests as nonzero. The list x is not changed. The order of the returned list is the same as in x. EXAMPLE ; define f(x) = x > 5 ; A = list(2,4,6,8,2,7) ; print select(A, "f") list (3 elements, 3 nonzero): [[0]] = 6 [[1]] = 8 [[2]] = 7 LIMITS none LINK LIBRARY none SEE ALSO append, delete, insert, islist, pop, push, remove, rsearch, search, size ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: select,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/select,v $ ## ## Under source code control: 1995/07/10 02:09:31 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Expression sequences This is a sequence of statements, of which expression statements are the commonest case. Statements are separated with semicolons, and the newline character generally ends the sequence. If any statement is an expression by itself, or is associated with an 'if' statement which is true, then two special things can happen. If the sequence is executed at the top level of the calculator, then the value of '.' is set to the value of the last expression. Also, if an expression is a non-assignment, then the value of the expression is automatically printed if its value is not NULL. Some operations such as pre-increment and plus-equals are also treated as assignments. Examples of this are the following: expression sets '.' to prints ---------- ----------- ------ 3+4 7 7 2*4; 8+1; fact(3) 6 8, 9, and 6 x=3^2 9 - if (3 < 2) 5; else 6 6 6 x++ old x - print fact(4) - 24 null() null() - Variables can be defined at the beginning of an expression sequence. This is most useful for local variables, as in the following example, which sums the square roots of the first few numbers: local s, i; s = 0; for (i = 0; i < 10; i++) s += sqrt(i); s If a return statement is executed in an expression sequence, then the result of the expression sequence is the returned value. In this case, '.' is set to the value, but nothing is printed. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: expression,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/expression,v $ ## ## Under source code control: 1991/07/21 04:37:18 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Calc Todo Items: The following items should be addressed sometime in the short to medium term future, if not before the next release. Code contributions are welcome. Send patches to: calc-contrib at asthe dot com Calc bug reports, however, should send to: calc-bugs at asthe dot com [[ NOTE: Replace 'at' with @, 'dot' is with . and remove the spaces ]] [[ NOTE: The EMail address uses 'asthe' and the web site URL uses 'isthe' ]] See the BUGS file or try the calc command: help bugs See also the 'wishlist' help files for the calc enhancement wish list. =-= Very High priority items: * Improve the way that calc parses statements such as if, for, while and do so that when a C programmer does. This works as expected: if (expr) { ... } However this WILL NOT WORK AS EXPECTED: if (expr) { ... } because calc will parse the if being terminated by an empty statement followed by a if (expr) ; { ... } See also "help statement", "help unexpected", "help todo", and "help bugs". * Consider using GNU autoconf / configure to build calc. * It is overkill to have nearly everything wind up in libcalc. Form a libcalcmath and a libcalclang so that an application that just wants to link with the calc math libs can use them without dragging in all of the other calc language, I/O, and builtin functions. * Fix any 'Known bugs' as noted in the BUGS file or as displayed by 'calc help bugs'. =-= High priority items: * Verify, complete or fix the 'SEE ALSO' help file sections. * Verify, complete or fix the 'LINK LIBRARY' help file sections. * Verify, complete or fix the 'LIMITS' help file sections. * Verify, complete or fix the 'SYNOPSIS' and 'TYPES' help file sections. * Perform a code coverage analysis of the 'make check' action and improve the coverage (within reason) of the regress.cal suite. * Address, if possible and reasonable, any Calc Mis-features as noted in the BUGS file or as displayed by 'calc help bugs'. * Internationalize calc by converting calc error messages and text strings (e.g., calc startup banner, show output, etc.) into calls to the GNU gettext internationalization facility. If somebody translated these strings into another language, setting $LANG would allow calc to produce error messages and text strings in that language. =-= Medium priority items: * Complete the use of CONST where appropriate: CONST is beginning to be used with read-only tables and some function arguments. This allows certain compilers to better optimize the code as well as alerts one to when some value is being changed inappropriately. Use of CONST as in: int foo(CONST int curds, char *CONST whey) while legal C is not as useful because the caller is protected by the fact that args are passed by value. However, the in the following: int bar(CONST char *fizbin, CONST HALF *data) is useful because it calls the compiler that the string pointed at by 'fizbin' and the HALF array pointer at by 'data' should be treated as read-only. One should make available a the fundamental math operations on ZVALUE, NUMBER and perhaps COMPLEX (without all of the other stuff) in a separate library. * Clean the source code and document it better. * Add a builtin function to access the 64 bit FNV hash which is currently being used internally in seed.c. ## Copyright (C) 1999-2007 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.2 $ ## @(#) $Id: todo,v 30.2 2007/09/08 02:52:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/todo,v $ ## ## Under source code control: 1999/10/20 07:42:55 ## File existed as early as: 1999 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME swap - swap values of two variables SYNOPSIS swap(x,y) TYPES x, y lvalues, any type return null value DESCRIPTION swap(x,y) assigns the value of x to a temporary location, temp say, assigns the value of x to y, and then assigns the value at temp to y. swap(x,y) should not be used if the current value of one of the variables is a component of the value of the other; for example, after: A = list(1,2,3); swap(A, A[[1]]); A will have the value 2, but a three-member list remains in memory with no method within calc of recalling the list or freeing the memory used. EXAMPLE ; x = 3/4; y = "abc"; print x, y, swap(x,y), x, y .75 abc abc .75 ; A = list(1,2,3); mat B[3] = {4,5,6}; swap(A[[1]], B[1]); print A[[1]], B[1] 5 2 LIMITS none LINK LIBRARY none SEE ALSO assign ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: swap,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/swap,v $ ## ## Under source code control: 1995/12/18 12:34:58 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME pix - number of primes not exceeding specified number SYNOPSIS pix(n [,err]) TYPES n real err integer return nonnegative integer, or err DESCRIPTION If n is fractional or n >= 2^32, pix(n) causes an error, pix(n, err) returns the value of err. If n is an integer < 2^32, pix(n) returns the number of primes (2, 3, 5, ...) less or equal to n. EXAMPLE ; for (i = 0; i <= 20; i++) print pix(i),:; 0 0 1 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7 8 8 ; print pix(100), pix(1000), pix(1e4), pix(1e5), pix(1e6) 25 168 1229 9592 78498 ; print pix(2^32 - 1, -1), pix(2^32, -1) 203280221 -1 LIMITS none LINK LIBRARY long zpix(ZVALUE z) FULL pix(FULL x) SEE ALSO factor, isprime, lfactor, nextcand, nextprime, prevcand, prevprime, pfact, ptest ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: pix,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/pix,v $ ## ## Under source code control: 1995/12/18 12:34:58 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME protect - read or adjust protect status for a variable or named block SYNOPSIS protect(var [, N [, depth]) protect(nblk [, N [, depth]]) TYPES var lvalue nblk named block N integer, abs(N) < 65536 depth nonnegative integer return null value DESCRIPTION The protection status of the association of an lvalue A with its value is represented by a nonnegative integer less than 2^16. The current value sts of this status is returned by protect(A). Each nonzero bit of the low eight bits of sts corresponds to a builtin kind of protection as follows: bit value protection 1 no assign to A 2 no change of A by assignment 4 no change of type value of A 8 no error value for A 16 no copy to A 32 no relocation for A or its elements 64 no assign from A 128 no copy from A For example, A having protection status 65 = 1 + 64 prevents execution of assignments of the forms A = expression and V = A where V is an lvalue. Attempting either of these assignments will return an error value and leave the value of A or V unchanged. Initally, when created, any lvalue A has zero status corresponding to "no protection". This may be restored at any time by protect(A, 0). If N is positive and A does not already have the protection corresponding to a nonzero bit of N, protect(A, N) adds that protection to the status of A. For example, if protect(A) is 65, protect(A, 17) will add the no-copy-to protection so that the new protection status of A will be 81 = 1 + 16 + 64. Similarly, if N is negative and A has the protection corresponding to a nonzero bit of abs(N), protect(A,N) will remove that kind of protection. For example if protect(A) = 65, then protect(A, -17) will remove the no-assign-to protection and the new value of protect(A) will be 64. Note that protect(A, -65535) has the same effect as protect(A, 0). For the purposes of this function, the depth of a global or local variable is zero; if A has depth d and the value of A is a list, matrix, object or association, its elements have depth d + 1. For example, after: ; obj point {x,y} ; X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} } X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1], X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x and X[2][1].y have depth 3. For any lvalue A, protect(A, N, depth) applies protect(A, N) to A and to all elements, elements of elements, etc., up tothe stated depth. In the above example, protect(X, 20, 2) gives no-type-change and no-copy-to protection to 8 of the listed lvalues, but not to the components of the objects X[2][0] and X[2][1]; With any d >= 3, protect(X, 20, d) would give that protection the 12 listed lvalues. If B is a variable with positive status and assignment of B to A is permitted, execution of the assignment A = B adds to the protections of A all protections of B that A does not already have. Except when the value returned is the result of the evqluation of an lvalue with positive status, calc's builtin operators and functions return values with zero protection status. For example, whatever the protection statuses of X and Y, X + sqrt(Y) will have zero status, but t ? X : Y may have nonzero status. The list, matrix, object or association returned by the use of list, mat, obj or assoc will have zero status, but any element specified by an lvalue will receive its status; e.g. after L = list(X, X^2) , protect(L[0]) equals protect(X) and both protect(L) and protect(L[1]) are zero. Users may define functions that return values with positive status, e.g. ; define noassigntovalue(x) {protect(x,1); return x}; ; S = noassigntovalue(42); will result in S having the value 42 and no-assign-to protection. By using a backquote with a variable as argument, an even simpler function: ; define noassignto(x) = protect(x, 1); gives no-assign-to protection to the variable; i.e. noassignto(`A) achieves the same as protect(A,1). In the brief descriptions above of builtin kinds of protectiopn, "assign" refers to use of '=' as in A = expr to assign the value of expr to A, and in A = {..., expr, ...} to assign the value of expr to some component of A, and to the assignments implicit in quomod(x, y, A, B), and pre or post ++ or --. Swapping of lvalues is prevented if either value has no-assign-to or no-assign-from protection. (Swapping of octets is prevented if at least one of them is in a string or block with no-copy-to or no-copy-from protection.) "Copying" refers to initialization using {...} and to the operations copy and blkcpy as applied to strings, blocks, lists and matrices. Although A = {..., expr, ...) assigns the value of expr to an elment of A, it is also regarded as copying to A. Thus, initialization of A may be prevented either by giving no-copy-to protection to A or no-assignment=to protection to the elements of A. Assignments to and from characters or octets in strings or blocks are also regarded as copying to or from the string or block. For example, after A = "abc", protect(A,16) would prevent the assignment A[0] = 'x'. (Note that in this example, A[0] is not an lvalue in the sense normally understood - the only values it can have are nonnegative integers less than 256. The only kinds of protection relevant to an octet are the no-copy-to, no-copy-from and no-change protections of the string or block in which the octet resides.) The no-relocate protection applies to lists and blocks. For lists, it refers to the operations push, pop, append, remove, insert and delete. For example, if A = list(2,3,5,7), protect(A, 32) will prevent any change in the content or size of the list. No-relocation protection of a block prevents reallocation of the memory used by a block and the freeing of a named block, For example, if a block B has maxsize 256, then after: ; protect(B, 32); copy(A, B) will fail if the copying would cause size(B) to equal or exceed 256; if B is a named block, blkfree(B) will not be permitted. The elements of the list returned by list(...) will initially have zero protection status except when an argument is an lvalue with positive status, in which case the corresponding element will receive that status. E.g., L = list(A,B) will result in L[0] having status protect(A) and L[1] having status protect(B). L itself will have the status L had before the assignment. There is a similar copying of protection status when "= { ... }" initialization is used for matrices, lists or objects. For example, except when A or B has no-assign-from protection, M = mat [2] = {A,B} or mat M[2] = {A,B} will result in M[0] and M[1] having statuses protect(A) and protect(B) respectively. (If A or B has no-assign-from protection, mat[2] = {A,B} returns an error value.) Although M = mat[2] = {...} and mat M[2] = {...} do the same thing, these are different from (M = mat[2]) = {...} and (mat M[3]) = {...}. In the former pair of statements, the result of mat[2] = {...} is being assigned to M. In the latter statments, a matrix with zero elements is being assigned to M and then that matrix is being "reinitialized". Both will fail if M has no-asssign-to protection, but only the latter would be prevented by M having no-copy-to protection. When the functions which mave move elements like of sort, reverse, swap, insert, pop, remove, push and append. are evaluated, the protection statuses move with the values, e.g. if among the values and elements involved, there is just one with value 42, then the lvalue to which the value 42 is moved will get the status the lvalue with value 42 had before the evaluation of the function. This is relevant to evaluation of expressions like A = sort(A), append(A, pop(A)), insert(A,2,B,C). Note that when pop(A) is first evaluated it is located on the stack calc uses for calculating expressions rather than being the value of an lvalue. With an explicit assignment like X = pop(A) or the implied assignment in append(A, pop(A)), it becomes the value of an lvalue. Users may use higher bits values for other kinds of protection or simply to store information about an lvalue and its current value. For example 1024 might be used to indicate that the lvalue is always to have positive value. Then code for evaluating a function might include lines like ; if (protect(A) & 1024 && B <= 0) { ;; return newerror("Prohibited assignment"); ;; } ; A = B; When an operation forbidden by a particular bit in the protection status of A is attempted, an error value is created but unless this causes errcount to exceed errmax, the only immediate evidence for the error might be the incrementing of errcount. Sometimes the failure causes the return of the error value; e.g. swap(A,B) if not permitted returns an appropriate error value rather than the null value. If the value of A is a number and A has no-type-change protection, A = "abc" returns an error value. The error-number of the most recent error value is returned by errno(), a string describing it by strerror(). A named block may be referred to by using the blocks() or blk() functions, or by assigning it to a variable A and then using either A or *A. In the latter cases, protect(A, sts) sets the status for the variable A; protect(*A, sts) assigns the status for the named block. For example, protect(*A,16) will prevent any copying to the named block; protect(A,16) will prevent any copying to the named block only when it is referred to by A. EXAMPLE ; A = 27 ; protect(A,1) ; A = 45 ; A 27 ; strerror() "No-assign-to destination for assign" ; protect(A,64) ; protect(A) 65 ; X = A ; X 0 ; strerror() "No-assign-from source for assign" ; protect(A,-1) ; protect(A) 64 ; protect(A,4) ; protect(A) 68 ; A = "abc" ; A 27 ; strerror() "No-type-change destination for assign" ; B = 45 ; swap(A,B) Error 10372 ; strerror() "No-assign-to-or-from argument for swap" ; protect(A,-64) ; protect(A) 4 ; swap(A,B) ; A 45 ; B 27 ; A = mat[4] = {1,2,3,4} ; B = list(5,6,7,8) ; protect(A,16) ; copy(B,A) Error 10226 ; strerror() "No-copy-to destination variable" ; A = list(1,2,3) ; protect(A,32) ; append(A,4) Error 10402 ; strerror() "No-relocate for list append" ; A = blk(0,5) ; copy("abc", A) ; copy("de",A) Error 10229 ; strerror() "No-relocate destination variable" ; A = blk("alpha") = {1,2,3,4,5} ; protect(A,0) ; protect(*A, 16) ; copy("abc", A) Error 10228 ; strerror() "No-copy-to destination named block" LIMITS none LINK LIBRARY none SEE ALSO assign, copy, blk, error, errno, strerror ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: protect,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/chÉalc/help/RCS/protect,v $ ## ## Under source code control: 1997/07/10 22:38:44 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME calclevel - current calculation level SYNOPSIS calclevel() TYPES return nonnegative integer DESCRIPTION This function returns the calculation level at which it is called. When a command is being read from a terminal or from a file, calc is at calculation level zero. The level is increased by 1 each time calculation starts of a user-defined function or of eval(S) for some expression S which evaluates to a string. It decreases to zero if an error occurs or a quit or abort statement is executed. Otherwise, it decreases by 1 when the calculation is completed. Except when an error occurs or abort is executed, the input level is not affected by changes in the calculation level. Zero calculation level is also called top calculation level; greater values of calclevel() indicate calculation is occurring at greater depths. EXAMPLE n/a LIMITS none LINK LIBRARY none SEE ALSO eval, read, quit, abort, inputlevel ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: calclevel,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calclevel,v $ ## ## Under source code control: 1999/10/31 06:01:21 ## File existed as early as: 1999 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME isfile - whether a value is a file SYNOPSIS isfile(x) TYPES x any return int DESCRIPTION Determine if x is a file. This function will return 1 if x is a file, 0 otherwise. EXAMPLE ; a = files(0) ; print isfile(a), isfile(files(1)), isfile(1) 1 1 0 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isfile,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isfile,v $ ## ## Under source code control: 1994/10/21 02:21:27 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME fib - Fibonacci number SYNOPSIS fib(n) TYPES n integer return integer DESCRIPTION For any integer n, fib(n) returns the Fibonacci number with index n. This may be defined by fib(0) = 0, fib(1) = 1 and for any n (positive or negative) fib(n) = fib(n-1) + fib(n-2). EXAMPLE ; print fib(-2), fib(-1), fib(0), fib(1), fib(2), fib(3), fib(4), fib(5) -1 1 0 1 1 2 3 5 -8 LIMITS none LINK LIBRARY NUMBER *qfib(NUMBER *n) SEE ALSO fact ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fib,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fib,v $ ## ## Under source code control: 1995/10/25 04:03:45 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME char - character corresponding to a value SYNOPSIS char(j) TYPES j integer, 0 <= j < 256 return string DESCRIPTION For j > 0, returns a string of length 1 with a character that has the same value as j. For j = 0, returns the null string "". EXAMPLE ; print char(0102), char(0x6f), char(119), char(0145), char(0x6e) B o w e n LIMITS none LINK LIBRARY none SEE ALSO ord ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: char,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/char,v $ ## ## Under source code control: 1994/09/30 01:45:45 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME calc_tty - restore normal input conditions for interactive use SYNOPSIS calc_tty() TYPES return none if appears to be successful, error-value otherwise DESCRIPTION This may enable a return to normal operation if abnormal activity results from a change of one or more terminal characteristics, as may occur when activity is resumed by an fg command after a ctrl-Z interrupt, or by any of the three commands: ; !stty echo ; !stty -cbreak ; !stty echo -cbreak EXAMPLE ; calc_tty(); LIBRARY none SEE ALSO none ## Copyright (C) 2000-2006 Ernest Bowen ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: calc_tty,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $ ## ## Under source code control: 2000/12/14 01:33:00 ## File existed as early as: 2000 ## ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME reverse - reverse a copy of a list or matrix SYNOPSIS reverse(x) TYPES x list or matrix return same type as x DESCRIPTION For a list or matrix x, reverse(x) returns a list or matrix in which the order of the elements has been reversed. The original list or matrix x is unchanged. In the case of matrix x, the returned value is a matrix with the same dimension and index limits, but the reversing is performed as if the matrix were a linear array. EXAMPLE ; A = list(1, 7, 2, 4, 2) ; print reverse(A) list (5 elements, 5 nonzero): [[0]] = 2 [[1]] = 4 [[2]] = 2 [[3]] = 7 [[4]] = 1 ; mat B[2,3] = {1,2,3,4,5,6} ; print reverse(B) mat [2,3] (6 elements, 6 nonzero): [0,0] = 6 [0,1] = 5 [0,2] = 4 [1,0] = 3 [1,1] = 2 [1,2] = 1 LIMITS none LINK LIBRARY none SEE ALSO join, sort ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: reverse,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/reverse,v $ ## ## Under source code control: 1995/07/09 19:41:26 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME isatty - returns 1 if fd assocatied with a tty SYNOPSIS isatty(fd) TYPES fd any return int DESCRIPTION This function returns 1 if fd is associated with a tty, 0 otherwise. EXAMPLE ; print isatty(files(0)), isatty(files(1)), isatty(files(2)) 1 1 1 ; fd = fopen("/dev/null", "r") ; isatty(fd) 0 LIMITS none LINK LIBRARY none SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt, isassoc, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr, istype ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: isatty,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/isatty,v $ ## ## Under source code control: 1995/07/09 03:49:34 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME null - null value SYNOPSIS null([v_1, v_2,...]) TYPES v_1, v_2,... any return null DESCRIPTION After evaluating in order any arguments it may have, null(...) returns the null value. This is a particular value, different from all other types; it is the only value v for which isnull(v) returns TRUE. The null value tests as FALSE in conditions, and normally delivers no output in print statements, except that when a list or matrix is printed, null elements are printed as "NULL". A few builtin functions may return the null value, e.g. printf(...) returns the null value; if L = list(), then both pop(L) and remove(L) return the null value; when successful, file-handling functions like fclose(fs), fflush(fs), fputs(fs, ...) return the null value when successful (when they fail they return an error-value). User-defined functions where execution ends without a "return" statement or with "return ;" return the null value. Missing expressions in argument lists are assigned the null value. For example, after define f(a,b,c) = ... calling f(1,2) is as if c == null(). Similarly, f(1,,2) is as if b == null(). (Note that this does not occur in initialization lists; missing expressions there indicate no change.) The null value may be used as an argument in some operations, e.g. if v == null(), then for any x, x + v returns x. When calc is used interactively, a function that returns the null value causes no printed output and does not change the "oldvalue". Thus, null(config("mode", "frac")) may be used to change the output mode without printing the current mode or changing the stored oldvalue. EXAMPLE ; L = list(-1,0,1,2); ; while (!isnull(x = pop(L)) print x,; print -1 0 1 2 ; printf("%d %d %d\n", 2, , 3); 2 3 ; L = list(,1,,2,) ; print L list (5 elements, 5 nonzero): [[0]] = NULL [[1]] = 1 [[2]] = NULL [[3]] = 2 [[4]] = NULL ; a = 27 ; null(pi = pi(1e-1000)) ; . 27 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY none SEE ALSO isnull, test ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: null,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/null,v $ ## ## Under source code control: 1996/03/12 23:10:01 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME strcpy - copy head or all of a string to head or all of a string SYNOPSIS strcpy(s1, s2) TYPES s1 string s2 string return string DESCRIPTION Let n1 = size(s1), n2 = size(n2), and m = min(n1, n2). This function replaces the first m characters of s1 by the first m characters of s2, and if m < n1, replaces the next character of s1 by '\0'. The size of s1 and any later characters of s1 are unchanged. s1, with its new value, is returned. Unlike the C Library function with the same name, this function does not require n1 to be greater than or equal to n2, but if this is so, normal printing of the returned value will give the same result as normal printing of s2. EXAMPLE strcpy("", "xyz") == "" strcpy("a", "xyz") == "x" strcpy("ab", "xyz") == "xy" strcpy("abc", "xyz") == "xyz" strcpy("abcd", "xyz") == "xyz\0" strcpy("abcde", "xyz") == "xyz\0e" strcpy("abcdef", "xyz") == "xyz\0ef" strcpy("abc", "") == "\0bc" LIMITS none LINK LIBRARY STRING* stringcpy(STRING *s1, STRING *s2) SEE ALSO strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos, strprintf, strscan, strscanf, substr ## Copyright (C) 2006 Ernest Bowen ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: strcpy,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strcpy,v $ ## ## Under source code control: 2006/03/03 03:32:44 ## File existed as early as: 2006 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/