1 #!/usr/local/src/cmd/calc/calc -q -s -f
3 * fproduct - write the big Endian product of terms to a file
6 * fproduct filename term [term ...]
8 * filename where to write the product, use - for stdout
9 * term ... terms to multiply
11 * Copyright (C) 2001 Landon Curt Noll
13 * Calc is open software; you can redistribute it and/or modify it under
14 * the terms of the version 2.1 of the GNU Lesser General Public License
15 * as published by the Free Software Foundation.
17 * Calc is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
20 * Public License for more details.
22 * A copy of version 2.1 of the GNU Lesser General Public License is
23 * distributed with calc under the filename COPYING-LGPL. You should have
24 * received a copy with calc; if not, write to Free Software Foundation, Inc.
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 * @(#) $Revision: 30.1 $
28 * @(#) $Id: fproduct.calc,v 30.1 2007/03/16 11:12:11 chongo Exp $
29 * @(#) $Source: /usr/local/src/bin/calc/cscript/RCS/fproduct.calc,v $
31 * Under source code control: 2001/04/07 20:13:11
32 * File existed as early as: 2001
34 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
35 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
43 fprintf(files(2), "usage: %s term [term ...]\n", argv(0));
53 for (i=2; i < argc; ++i) {
54 product *= eval(argv(i));
56 product = abs(product);
60 * open the file for writing, "-" is stdout
62 if (filename == "-") {
65 fd = fopen(filename, "w");
66 if (!isfile(fd)) quit "be2file: cannot open file for writing";
71 * write the octets to the file
73 * The most significant bits of the integer become the first file octets.
76 octlen = int((highbit(product)+8) / 8);
77 for (i=octlen-1; i >= 0; --i) {
78 fputc(fd, char(product >> (i*8)));
86 if (filename != "-") {