//$Header$ //******************************************************************************** //This source file is the main function of a program to support number theory //web pages. //******************************************************************************** //Copyright (C) 2003 David T. Ashley //******************************************************************************** //This program is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. // //This program or source file 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 General Public License for more details. // //You may have received a copy of the GNU General Public License //along with this program; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //******************************************************************************** //This program is written exclusively to support a PHP script which must calculate and //display a number of number theory results. The necessity of this script //(rather than using BCMATH) comes about because SourceForge does not have //bcmath installed on its PHP system. // //This program is meant to be called by the PHP script using the exec() //call, but could also be run by hand (and in fact this method is used for testing). // //The first parameter after the program name is the suboperation to be performed //(each CGI page probably uses a different suboperation). This program //will return a non-zero exit code only if there is a missing or unrecognized //suboperation. Otherwise, error reporting is controlled by the rules of the //suboperation. // //The currently defined suboperations are: // // a)"help" // Display information about what the program is and how to use // it. // b)"gcd" // Calculate the gcd of two integers using Euclid's classic // algorithm and also display the intermediate results. // c)"gmp_prob_prime" // Use Miller-Rabin to determine to high certainty whther a // number is prime or composite. // d)"pfact_18" // Attempt to factor a number of 18 decimal digits or less into // component primes. // e)"cfbrap" // Finds the best rational approximation to a rational number subject // to constraints on the denominator and numerator using continued // fraction techniques. #include #include #include #include "auxfuncs.h" #include "subfunc_cfbrap.h" #include "subfunc_gcd.h" #include "subfunc_gmp_prob_prime.h" #include "subfunc_pfact_18.h" //Single function prototype needed for a forward reference. static void dump_subfunction_choices(int indent); //Implements the help. int SUBFUNC_HELP_main(int argc, char *argv[]) { int i; char *help[] = { "This program is a compiled 'C'-language program designed to be called from a", "PHP script to assist in calculating number theory and large integer", "arithmetic results. This scheme (of having a separate executable like this", "one) was used with SourceForge web content because SourceForge did not have", "the bcmath library compiled into PHP, and it was determined experimentally", "that writing large integer arithmetic functions in PHP directly resulted in", "unusably slow performance. This program makes use of the GMP library, which", "gives it superior performance.", "", "This program can of course be invoked from a shell or from another scripting", "language besides PHP. It is designed, however, for execution from a", "scripting language, as you might guess from the human-unfriendly output.", "", "Please contact Dave Ashley (dtashley@aol.com) with any questions or", "concerns.", "", "Dave Ashley, Detroit, Michigan, USA, April, 2003.", "", "The available subfunction choices (the first parameter on the command", "line) are:", }; for (i=0; i