1#!/usr/local/src/bin/calc/calc -q -f 2/* 3 * plus - add two or more arguments together 4 * 5 * Copyright (C) 1999-2007,2014,2019,2021 Landon Curt Noll 6 * 7 * Calc is open software; you can redistribute it and/or modify it under 8 * the terms of the version 2.1 of the GNU Lesser General Public License 9 * as published by the Free Software Foundation. 10 * 11 * Calc is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 14 * Public License for more details. 15 * 16 * A copy of version 2.1 of the GNU Lesser General Public License is 17 * distributed with calc under the filename COPYING-LGPL. You should have 18 * received a copy with calc; if not, write to Free Software Foundation, Inc. 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Under source code control: 1999/11/29 10:22:37 22 * File existed as early as: 1999 23 * 24 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/ 25 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ 26 * 27 * usage: 28 * plus val ... 29 */ 30 31 32/* 33 * parse args 34 */ 35argc = argv(); 36stderr = files(2); 37program = argv(0); 38if (argc < 2) { 39 /* we include the name of this script in the error message */ 40 fprintf(stderr, "usage: %s value ...\n", program); 41 abort "not enough args"; 42} 43 44/* 45 * print the sum of the args 46 * 47 * Since args are strings, we must eval them before using them numerically. 48 */ 49sum = 0; 50for (i=1; i < argc; ++i) { 51 sum += eval(argv(i)); 52} 53print sum; 54